31 #include <MathAlgo/UnscentedTransform.hh>
32 #include <MathAlgo/MonteCarloTransform.hh>
33 #include <Base/Math/Random.hh>
42 const int dim = src.
Size();
50 const int dim = src.
Size();
52 const double c[] = { 1.0, 2.0, 0.0 };
54 const int num = dim*dim;
55 for (
int i=0; i<num; i++){
63 const double c[] = { 1.57, 3.14, 6.28 };
65 const int dim = src.
Size();
68 for (
int i=0; i<dim; i++){
69 dst[i] = c[0] + c[1] * src[i] + c[2] * src[i] * src[i];
75 MyLinTransform(src, dst);
81 class MyUnscentedTransform
91 virtual ~MyUnscentedTransform() {};
98 MyTransform(src, dst);
103 class MyMonteCarloTransform
113 virtual ~MyMonteCarloTransform() {};
120 MyTransform(src, dst);
130 int main(
int ,
char ** )
140 for (
int r=0; r<dim; r++){
142 for (
int c=r; c<dim; c++){
143 src_cov[r][c] = src_cov[c][r] =
146 src_cov = src_cov * src_cov;
155 cout <<
"src: "<<src<<endl;
156 cout <<
"src_cov: "<<src_cov<<endl;
158 MyTransform(src, gt_dst);
159 gt_dst_cov = T * src_cov * T.
Transpose();
160 cout <<
"T: "<<T<<endl;
161 cout <<
"gt: dst: "<<gt_dst<<endl;
162 cout <<
"gt: dst_cov: "<<gt_dst_cov<<endl;
164 MyUnscentedTransform mut;
168 if (mut.Transform(src, src_cov, dst, dst_cov)!=0){
169 BIASERR(
"error transforming (unscented)");
172 cout <<
"ut: dst: "<<dst<<endl;
173 cout <<
"ut: dst_cov: "<<dst_cov<<endl;
175 cout <<
"diff: "<<(dst - gt_dst)<<endl;
176 cout <<
"diff cov: "<<(dst_cov - gt_dst_cov)<<endl;
178 MyMonteCarloTransform mmct;
182 mmct.SetNumSamplesPerDimension((
int)1e2);
183 mmct.SetUseQuasiRandomNumbers(
true);
184 if (mmct.Transform(src, src_cov, dst, dst_cov)!=0){
185 BIASERR(
"error transforming (monte carlo)");
188 cout <<
"mc: dst: "<<dst<<endl;
189 cout <<
"mc: dst_cov: "<<dst_cov<<endl;
191 cout <<
"diff: "<<(dst - gt_dst)<<endl;
192 cout <<
"diff cov: "<<(dst_cov - gt_dst_cov)<<endl;
Matrix< T > Transpose() const
transpose function, storing data destination matrix
Matrix< T > & newsize(Subscript M, Subscript N)
unsigned int Size() const
length of the vector
double GetUniformDistributed(const double min, const double max)
on succesive calls return uniform distributed random variable between min and max ...
Vector< T > & newsize(Subscript N)
T * GetData()
get the pointer to the data array of the matrix (for faster direct memeory access) ...
void SetIdentity()
Converts matrix to identity matrix.
class for producing random numbers from different distributions