Simulating a discrete system model

Hi,

I found the following code to simulate a system in the template class
systemmodel.cpp:

// Simulate from the system model
template T
SystemModel::Simulate (const T& x, const T& u, int sampling_method,
void * sampling_args)
{
assert(_systemWithoutInputs == false);
_SystemPdf->ConditionalArgumentSet(0,x);
_SystemPdf->ConditionalArgumentSet(1,u);
Sample Simulated(StateSizeGet());
_SystemPdf->SampleFrom(Simulated, sampling_method,sampling_args);
T result = Simulated.ValueGet();
return result;
}

and
// Get State Size
template int
SystemModel::StateSizeGet() const
{
return _SystemPdf->DimensionGet();
}

I wonder if this code is correct for a discrete pdf. Since the dimension of a
discretepdf was defined as the number of states, a sample with size equal to
the number of states will be created, while IMHO we need just a sample with
dimension 1.

Tinne
_______________________________________________
I hereby promise not to top-post on the
BFL mailing list
BFL [..] ...
http://lists.mech.kuleuven.be/mailman/listinfo/bfl

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

Simulating a discrete system model

> I found the following code to simulate a system in the template class
> systemmodel.cpp:
>
> // Simulate from the system model
> template T
> SystemModel::Simulate (const T& x, const T& u, int sampling_method,
> void * sampling_args)
> {
> assert(_systemWithoutInputs == false);
> _SystemPdf->ConditionalArgumentSet(0,x);
> _SystemPdf->ConditionalArgumentSet(1,u);
> Sample Simulated(StateSizeGet());
> _SystemPdf->SampleFrom(Simulated, sampling_method,sampling_args);
> T result = Simulated.ValueGet();
> return result;
> }
>
> and
> // Get State Size
> template int
> SystemModel::StateSizeGet() const
> {
> return _SystemPdf->DimensionGet();
> }
>
> I wonder if this code is correct for a discrete pdf. Since the dimension of a
> discretepdf was defined as the number of states, a sample with size equal to
> the number of states will be created, while IMHO we need just a sample with
> dimension 1.

AFAIS this will work due to the template specialisation mechanism used
in sample.h and sample.cpp, e.g.

// constructor
template Sample::Sample (unsigned int dimension)
{};

template <> inline
Sample::Sample (unsigned int dimension)
: Value(dimension)
{};

// Template Specialisation for T = int
template <> inline unsigned int
Sample::DimensionGet() const
{
return 1;
};

However, a quick svn praise on that file points out it has been edited
by several people, and its code seems to have arrived in a very
inconsistent state to me (see e.g. the doxygen comments for the
constructor that are not correct anymore :-(
Seems like this is worth another bugzilla report...

Klaas
_______________________________________________
I hereby promise not to top-post on the
BFL mailing list
BFL [..] ...
http://lists.mech.kuleuven.be/mailman/listinfo/bfl

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm