26 #define DIMENSION_INPUT 2 42 #define NUM_COND_ARGS_DIS 1 53 for (
unsigned int rows=1; rows <
DIMENSION + 1; rows++){ _sigma(rows,rows)=
SIGMA; }
54 _width.resize(DIMENSION);
78 CPPUNIT_ASSERT_EQUAL(
true, a_gaussian.SampleFrom(a_sample,
DEFAULT,NULL));
83 CPPUNIT_ASSERT( (a_sample.
ValueGet())(j) > _mu(j) - 4.0 * sqrt(_sigma(j,j) ) );
84 CPPUNIT_ASSERT( (a_sample.
ValueGet())(j) < _mu(j) + 4.0 * sqrt(_sigma(j,j) ) );
87 CPPUNIT_ASSERT_EQUAL(
false, a_gaussian.SampleFrom(a_sample,
BOXMULLER,NULL));
88 CPPUNIT_ASSERT_EQUAL(
true, a_gaussian.SampleFrom(a_sample,
CHOLESKY,NULL));
93 CPPUNIT_ASSERT( (a_sample.
ValueGet())(j) > _mu(j) - 4.0 * sqrt(_sigma(j,j) ) );
94 CPPUNIT_ASSERT( (a_sample.
ValueGet())(j) < _mu(j) + 4.0 * sqrt(_sigma(j,j) ) );
110 CPPUNIT_ASSERT( (a_sample.
ValueGet())(j) > _mu(j) - 4.0 * sqrt(_sigma(j,j) ) );
111 CPPUNIT_ASSERT( (a_sample.
ValueGet())(j) < _mu(j) + 4.0 * sqrt(_sigma(j,j) ) );
117 sample_mean = sample_mean / (double)NUM_SAMPLES;
120 CPPUNIT_ASSERT( sample_mean(j) <= _mu(j) + 3.0 * 1/sqrt(NUM_SAMPLES) * sqrt(_sigma(j,j)) );
121 CPPUNIT_ASSERT( sample_mean(j) >= _mu(j) - 3.0 * 1/sqrt(NUM_SAMPLES) * sqrt(_sigma(j,j)) );
124 CPPUNIT_ASSERT_EQUAL(
false, a_gaussian.SampleFrom(los,NUM_SAMPLES,
BOXMULLER,NULL));
125 CPPUNIT_ASSERT_EQUAL(
true, a_gaussian.SampleFrom(los,NUM_SAMPLES,
CHOLESKY,NULL));
135 CPPUNIT_ASSERT( (a_sample.
ValueGet())(j) > _mu(j) - 4.0 * sqrt(_sigma(j,j) ) );
136 CPPUNIT_ASSERT( (a_sample.
ValueGet())(j) < _mu(j) + 4.0 * sqrt(_sigma(j,j) ) );
142 sample_mean = sample_mean / (double)NUM_SAMPLES;
145 CPPUNIT_ASSERT( sample_mean(j) <= _mu(j) + 3.0 * 1/sqrt(NUM_SAMPLES) * sqrt(_sigma(j,j)) );
146 CPPUNIT_ASSERT( sample_mean(j) >= _mu(j) - 3.0 * 1/sqrt(NUM_SAMPLES) * sqrt(_sigma(j,j)) );
150 CPPUNIT_ASSERT_EQUAL( _mu, a_gaussian.ExpectedValueGet());
151 CPPUNIT_ASSERT_EQUAL( _sigma, a_gaussian.CovarianceGet());
155 CPPUNIT_ASSERT_EQUAL( _mu, b_gaussian.ExpectedValueGet());
156 CPPUNIT_ASSERT_EQUAL( _sigma, b_gaussian.CovarianceGet());
161 CPPUNIT_ASSERT_EQUAL( _mu, c_gaussian.ExpectedValueGet());
162 c_gaussian.CovarianceSet(_sigma);
163 CPPUNIT_ASSERT_EQUAL( _sigma, c_gaussian.CovarianceGet());
167 clone = c_gaussian.
Clone();
168 CPPUNIT_ASSERT_EQUAL( c_gaussian.ExpectedValueGet(), clone->ExpectedValueGet());
169 CPPUNIT_ASSERT_EQUAL( c_gaussian.CovarianceGet(), clone->CovarianceGet());
185 vector<Sample<ColumnVector > >::iterator los_it;
186 for (los_it = los.begin(); los_it!=los.end(); los_it++)
188 ColumnVector current_sample = los_it->ValueGet();
189 for (
int i = 1; i < _mu.rows()+1 ; i++)
191 CPPUNIT_ASSERT(current_sample(i) > (_mu(i)-_width(i)/2) ) ;
192 CPPUNIT_ASSERT(current_sample(i) < (_mu(i)+_width(i)/2) ) ;
204 for (
int i =1 ; i <
DIMENSION + 1 ; i++) area = area * _width(i);
205 CPPUNIT_ASSERT_EQUAL(1/area, (
double)a_uniform.
ProbabilityGet(_mu));
206 CPPUNIT_ASSERT_EQUAL(0.0, (
double)a_uniform.
ProbabilityGet(_mu + _width));
207 CPPUNIT_ASSERT_EQUAL(0.0, (
double)a_uniform.
ProbabilityGet(_mu - _width));
208 ColumnVector test_prob(DIMENSION);
210 test_prob(DIMENSION) = _mu(DIMENSION) + _width(DIMENSION)*2/3;
211 CPPUNIT_ASSERT_EQUAL(0.0, (
double)a_uniform.
ProbabilityGet(test_prob));
225 for (
int i =1 ; i < DIMENSION + 1 ; i++) area = area * _width(i);
226 CPPUNIT_ASSERT_EQUAL(1/area, (
double)c_uniform.
ProbabilityGet(_mu));
227 CPPUNIT_ASSERT_EQUAL(0.0, (
double)c_uniform.
ProbabilityGet(_mu + _width));
228 CPPUNIT_ASSERT_EQUAL(0.0, (
double)c_uniform.
ProbabilityGet(_mu - _width));
230 test_prob(DIMENSION) = _mu(DIMENSION) + _width(DIMENSION)*2/3;
231 CPPUNIT_ASSERT_EQUAL(0.0, (
double)c_uniform.
ProbabilityGet(test_prob));
235 clone = c_uniform.
Clone();
236 CPPUNIT_ASSERT_EQUAL( c_uniform.
CenterGet(), clone->CenterGet());
237 CPPUNIT_ASSERT_EQUAL( c_uniform.
WidthGet(), clone->WidthGet());
244 vector<Probability> uniform_vector(
NUM_DS);
249 for (
int state = 0; state <
NUM_DS ; state++) CPPUNIT_ASSERT_EQUAL( (
double) (uniform_vector[state]),
double(result_proba[state] )) ;
252 CPPUNIT_ASSERT_EQUAL(1,(
int)a_discretepdf.
DimensionGet());
255 CPPUNIT_ASSERT_EQUAL(NUM_DS,(
int)a_discretepdf.
NumStatesGet());
259 vector<Probability> result_probb = b_discretepdf.ProbabilitiesGet();
260 for (
int state = 0; state <
NUM_DS ; state++) CPPUNIT_ASSERT_EQUAL( (
double) (result_proba[state]),
double(result_probb[state] )) ;
261 CPPUNIT_ASSERT_EQUAL(a_discretepdf.
DimensionGet(), b_discretepdf.DimensionGet());
262 CPPUNIT_ASSERT_EQUAL(a_discretepdf.
NumStatesGet(), b_discretepdf.NumStatesGet());
266 double prob_new = 0.57;
267 int new_el = NUM_DS-1;
268 CPPUNIT_ASSERT_EQUAL(
true, a_discretepdf.
ProbabilitySet(new_el,prob_new));
269 CPPUNIT_ASSERT_EQUAL(prob_new, (
double) a_discretepdf.
ProbabilityGet(new_el));
271 double sumProb = 0.0;
272 for (
int state = 0; state <
NUM_DS ; state++)
276 CPPUNIT_ASSERT_EQUAL(1.0, sumProb);
279 for (
int new_el_c = 0; new_el_c <
NUM_DS; new_el_c++)
281 CPPUNIT_ASSERT_EQUAL(
true, a_discretepdf.
ProbabilitySet(new_el_c,prob_new));
282 CPPUNIT_ASSERT_EQUAL(prob_new, (
double) a_discretepdf.
ProbabilityGet(new_el_c));
286 for (
int state = 0; state <
NUM_DS ; state++)
290 CPPUNIT_ASSERT_EQUAL(1.0, sumProb);
293 vector<Probability> prob_vec(NUM_DS);
295 for (
int state = 1; state <
NUM_DS ; state++)
297 prob_vec[state] = (
Probability)( (1-0.9)/(NUM_DS-1) );
301 for (
int state = 0; state <
NUM_DS ; state++) CPPUNIT_ASSERT_EQUAL( (
double) (prob_vec[state]),
double(result_proba[state] )) ;
305 for (
int state = 0; state <
NUM_DS ; state++)
309 CPPUNIT_ASSERT_EQUAL(1.0, sumProb);
314 vector<Probability> prob_vecc(NUM_DS);
316 for (
int state = 1; state <
NUM_DS ; state++)
318 prob_vecc[state] = 0.0;
322 double new_prob_other = (1-new_prob0)/(NUM_DS-1);
324 CPPUNIT_ASSERT_EQUAL((
double)new_prob0, (
double)(c_discretepdf.
ProbabilityGet(0)));
325 for (
int state = 1; state <
NUM_DS ; state++)
327 CPPUNIT_ASSERT_EQUAL( new_prob_other, (
double)(c_discretepdf.
ProbabilityGet(state)));
332 vector<Probability> prob_vecd(NUM_DS);
340 vector<Sample<int> >::iterator it;
348 vector<unsigned int> num_samples(NUM_DS,0);
349 for (it = los.begin(); it!=los.end();it++)
351 num_samples[it->ValueGet()] +=1;
353 for (
int i = 0 ; i<
NUM_DS ; i++)
363 vector<unsigned int> num_samples2(NUM_DS,0);
364 for (it = los.begin(); it!=los.end();it++)
366 num_samples2[it->ValueGet()] +=1;
368 for (
int i = 0 ; i<
NUM_DS ; i++)
387 vector<unsigned int> num_samples3(NUM_DS,0);
388 for (it = los.begin(); it!=los.end();it++)
390 num_samples3[it->ValueGet()] +=1;
392 for (
int i = 0 ; i<
NUM_DS ; i++)
402 vector<unsigned int> num_samples4(NUM_DS,0);
403 for (it = los.begin(); it!=los.end();it++)
405 num_samples4[it->ValueGet()] +=1;
407 for (
int i = 0 ; i<
NUM_DS ; i++)
416 CPPUNIT_ASSERT_EQUAL(
false, d_discretepdf.
SampleFrom(a_sample,
RIPLEY,NULL));
420 clone = d_discretepdf.
Clone();
421 CPPUNIT_ASSERT_EQUAL( d_discretepdf.
NumStatesGet(), clone->NumStatesGet());
423 vector<Probability> result_probClone = clone->ProbabilitiesGet();
426 CPPUNIT_ASSERT_EQUAL( (
double)result_probd[i],(
double)result_probClone[i]);
440 vector<Matrix> v(2); v[0] = a; v[1] = b;
450 CPPUNIT_ASSERT_EQUAL( v[i], a_condgaussian.
MatrixGet(i));
473 std::vector<ColumnVector> cond_args(NUM_COND_ARGS);
475 cond_args[NUM_COND_ARGS-1] = u;
500 CPPUNIT_ASSERT_EQUAL( v[i], a_condgaussian.
dfGet(i));
508 exp = exp + v[i]*cond_args[i];
512 CPPUNIT_ASSERT_EQUAL( _sigma, a_condgaussian.
CovarianceGet());
516 CPPUNIT_ASSERT_EQUAL( _mu, b_condgaussian.AdditiveNoiseMuGet());
517 CPPUNIT_ASSERT_EQUAL( _sigma, b_condgaussian.AdditiveNoiseSigmaGet());
526 CPPUNIT_ASSERT_EQUAL( a2, a_condgaussian.
MatrixGet(0));
527 CPPUNIT_ASSERT_EQUAL( b2, a_condgaussian.
MatrixGet(1));
531 SymmetricMatrix sigma2;
537 for (
unsigned int rows=1; rows <
DIMENSION + 1; rows++){ sigma2(rows,rows)=sig2; }
549 clone = a_condgaussian.
Clone();
550 CPPUNIT_ASSERT_EQUAL( a_condgaussian.
AdditiveNoiseMuGet(), clone->AdditiveNoiseMuGet());
552 CPPUNIT_ASSERT_EQUAL( a_condgaussian.
MatrixGet(0), clone->MatrixGet(0));
553 CPPUNIT_ASSERT_EQUAL( a_condgaussian.
MatrixGet(1), clone->MatrixGet(1));
560 int state_k;
int state_kMinusOne;
565 CPPUNIT_ASSERT_EQUAL( 1, (
int)a_discretecondpdf.
DimensionGet());
575 double prob_diag = 0.9;
576 double prob_nondiag = (1-0.9)/(
NUM_DS-1);
577 for (state_kMinusOne = 0 ; state_kMinusOne <
NUM_DS ; state_kMinusOne++)
579 cond_args[0] = state_kMinusOne;
580 for (state_k = 0 ; state_k <
NUM_DS ; state_k++)
582 if (state_kMinusOne == state_k) a_discretecondpdf.
ProbabilitySet(prob_diag,state_k,cond_args);
583 else a_discretecondpdf.
ProbabilitySet(prob_nondiag,state_k,cond_args);
588 int cond_arg = NUM_DS - 1;
593 for (cond_arg = 0 ; cond_arg <
NUM_DS ; cond_arg++)
596 for (state_k = 0 ; state_k <
NUM_DS ; state_k++)
598 if( state_k == cond_arg) CPPUNIT_ASSERT_EQUAL( prob_diag, (
double)a_discretecondpdf.
ProbabilityGet(state_k));
599 else CPPUNIT_ASSERT_EQUAL( prob_nondiag, (
double)a_discretecondpdf.
ProbabilityGet(state_k));
607 CPPUNIT_ASSERT_EQUAL(
true, a_discretecondpdf.
SampleFrom(a_sample,
DEFAULT,NULL));
611 CPPUNIT_ASSERT_EQUAL( a_discretecondpdf.
DimensionGet(),b_discretecondpdf.DimensionGet() );
613 CPPUNIT_ASSERT_EQUAL( a_discretecondpdf.
NumStatesGet(),b_discretecondpdf.NumStatesGet());
614 for (cond_arg = 0 ; cond_arg <
NUM_DS ; cond_arg++)
617 b_discretecondpdf.ConditionalArgumentSet(0, cond_arg);
618 for (state_k = 0 ; state_k <
NUM_DS ; state_k++)
620 CPPUNIT_ASSERT_EQUAL( (
double)a_discretecondpdf.
ProbabilityGet(state_k) , (double)b_discretecondpdf.ProbabilityGet(state_k));
626 clone = a_discretecondpdf.
Clone();
627 CPPUNIT_ASSERT_EQUAL( a_discretecondpdf.
DimensionGet(), clone->DimensionGet());
629 CPPUNIT_ASSERT_EQUAL( a_discretecondpdf.
NumStatesGet(),clone->NumStatesGet());
630 for (cond_arg = 0 ; cond_arg <
NUM_DS ; cond_arg++)
633 clone->ConditionalArgumentSet(0, cond_arg);
634 for (state_k = 0 ; state_k <
NUM_DS ; state_k++)
635 CPPUNIT_ASSERT_EQUAL( (
double)a_discretecondpdf.
ProbabilityGet(state_k) , (double)clone->ProbabilityGet(state_k));
651 vector<Sample<ColumnVector> > exact_samples(
NUM_SAMPLES);
652 vector<Sample<ColumnVector> >::iterator it;
657 const vector<WeightedSample<ColumnVector> > mcpdf_samples = a_mcpdf.
ListOfSamplesGet();
660 CPPUNIT_ASSERT_EQUAL( exact_samples[i].ValueGet(), mcpdf_samples[i].ValueGet());
661 CPPUNIT_ASSERT_EQUAL( exact_samples[i].ValueGet(), a_mcpdf.
SampleGet(i).
ValueGet());
662 CPPUNIT_ASSERT_EQUAL( 1.0/NUM_SAMPLES, mcpdf_samples[i].WeightGet());
666 vector<WeightedSample<ColumnVector> > samples_weighted = mcpdf_samples;
670 samples_weighted[i].WeightSet(i+1);
672 double tot_weight = (double)(NUM_SAMPLES+1)*((double)NUM_SAMPLES)/2.0;
676 CPPUNIT_ASSERT_EQUAL( samples_weighted[i].ValueGet(), a_mcpdf.
SampleGet(i).
ValueGet());
677 CPPUNIT_ASSERT_EQUAL( (
double)(samples_weighted[i].WeightGet())/tot_weight, a_mcpdf.
SampleGet(i).
WeightGet());
684 CPPUNIT_ASSERT_EQUAL( a_mcpdf.
SampleGet(i).
ValueGet(), b_mcpdf.SampleGet(i).ValueGet());
685 CPPUNIT_ASSERT_EQUAL( a_mcpdf.
SampleGet(i).
WeightGet(), b_mcpdf.SampleGet(i).WeightGet());
689 vector<Sample<ColumnVector> > samples_test(NUM_SAMPLES);
690 CPPUNIT_ASSERT_EQUAL(
true, a_mcpdf.
SampleFrom(samples_test,NUM_SAMPLES,
RIPLEY,NULL));
691 CPPUNIT_ASSERT_EQUAL(
true, a_mcpdf.
SampleFrom(samples_test,NUM_SAMPLES,
DEFAULT,NULL));
695 vector<WeightedSample<ColumnVector> >::iterator it2;
698 double sumWeights = 0.0;
699 for ( it2 = los.begin() ; it2!= los.end() ; it2++ )
701 cumSum += ( it2->ValueGet() * it2->WeightGet() );
702 sumWeights += it2->WeightGet();
712 vector<double>::iterator cumPDFit;
713 cumPDFit = cumPDF.begin(); *cumPDFit = 0.0;
714 double cumSumW = 0.0;
715 for (it2 = los.begin(); it2 != los.end(); it2++)
717 diff = (it2->ValueGet() - mean);
718 diffsum += diff * (diff.transpose() * it2->WeightGet());
720 cumSumW += ( it2->WeightGet() / sumWeights);
734 unsigned int one = 1;
736 CPPUNIT_ASSERT_EQUAL( NUM_SAMPLES , a_mcpdf_uint.
NumSamplesGet());
740 unsigned int num_states = 10;
743 vector<Sample<int> > samples_discrete_int(NUM_SAMPLES);
744 vector<Sample<int> >::iterator it_discrete_int;
745 discrete.
SampleFrom(samples_discrete_int, NUM_SAMPLES);
747 vector<Sample<unsigned int> > samples_discrete(NUM_SAMPLES);
748 vector<Sample<unsigned int> >::iterator it_discrete;
749 it_discrete = samples_discrete.begin();
752 for(it_discrete_int = samples_discrete_int.begin(); it_discrete_int != samples_discrete_int.end(); it_discrete_int++)
754 temp_sample.
ValueSet((*it_discrete_int).ValueGet());
755 (*it_discrete)= temp_sample;
761 const vector<WeightedSample<unsigned int> > mcpdf_samples_uint = a_mcpdf_uint.
ListOfSamplesGet();
764 CPPUNIT_ASSERT_EQUAL( samples_discrete[i].ValueGet(), mcpdf_samples_uint[i].ValueGet());
765 CPPUNIT_ASSERT_EQUAL( samples_discrete[i].ValueGet(), a_mcpdf_uint.
SampleGet(i).ValueGet());
766 CPPUNIT_ASSERT_EQUAL( 1.0/NUM_SAMPLES, mcpdf_samples_uint[i].WeightGet());
770 vector<WeightedSample<unsigned int > > samples_weighted_uint = mcpdf_samples_uint;
774 samples_weighted_uint[i].WeightSet(i+1);
776 double tot_weight_uint = (double)(NUM_SAMPLES+1)*((double)NUM_SAMPLES)/2.0;
780 CPPUNIT_ASSERT_EQUAL( samples_weighted_uint[i].ValueGet(), a_mcpdf_uint.
SampleGet(i).ValueGet());
781 CPPUNIT_ASSERT_EQUAL( (
double)(samples_weighted_uint[i].WeightGet())/tot_weight_uint, a_mcpdf_uint.
SampleGet(i).WeightGet());
788 CPPUNIT_ASSERT_EQUAL( a_mcpdf_uint.
SampleGet(i).ValueGet(), b_mcpdf_uint.SampleGet(i).ValueGet());
789 CPPUNIT_ASSERT_EQUAL( a_mcpdf_uint.
SampleGet(i).WeightGet(), b_mcpdf_uint.SampleGet(i).WeightGet());
793 vector<Sample<unsigned int> > samples_test_uint(NUM_SAMPLES);
794 CPPUNIT_ASSERT_EQUAL(
true, a_mcpdf_uint.
SampleFrom(samples_test_uint,NUM_SAMPLES,
DEFAULT,NULL));
797 vector<WeightedSample<unsigned int> > los_uint = a_mcpdf_uint.
ListOfSamplesGet();
798 vector<WeightedSample<unsigned int> >::iterator it2_uint;
799 double cumSum_double;
802 for ( it2_uint = los_uint.begin() ; it2_uint!= los_uint.end() ; it2_uint++ )
804 cumSum_double += ( (double)it2_uint->ValueGet() * it2_uint->WeightGet() );
805 sumWeights += it2_uint->WeightGet();
811 unsigned int diff_uint;
815 vector<double>::iterator cumPDFit_uint;
816 cumPDFit_uint = cumPDF_uint.begin(); *cumPDFit_uint = 0.0;
817 double cumSumW_uint = 0.0;
818 for (it2_uint = los_uint.begin(); it2_uint != los_uint.end(); it2_uint++)
820 diff_uint = (it2_uint->ValueGet() - mean_uint);
821 diffsum_uint += (double)(diff_uint * diff_uint) * it2_uint->WeightGet();
823 cumSumW_uint += ( it2_uint->WeightGet() / sumWeights);
827 Matrix test_diff(1,1);
828 test_diff(1,1) = diffsum_uint/sumWeights;
888 comp1.ExpectedValueSet(_mu);
889 comp1.CovarianceSet(_sigma);
890 CPPUNIT_ASSERT_EQUAL(
true, mixture.
AddComponent(comp1));
891 CPPUNIT_ASSERT_EQUAL(1.0, (
double)mixture.
WeightGet(0));
896 CPPUNIT_ASSERT_EQUAL((
double)comp1.ProbabilityGet(cv1),(double)mixture.
ProbabilityGet(cv1)) ;
898 ColumnVector expected_comp1 = comp1.ExpectedValueGet() ;
900 CPPUNIT_ASSERT_EQUAL(expected_comp1(j), expected_mix(j) ) ;
901 vector<Probability> vecW(1);
903 vector<Probability> mixWeights = mixture.
WeightsGet() ;
905 CPPUNIT_ASSERT_EQUAL( (
double)vecW[j-1], (double)mixWeights[j-1] );
906 CPPUNIT_ASSERT_EQUAL(1.0,(
double)mixture.
WeightGet(0) ) ;
910 CPPUNIT_ASSERT_EQUAL( (
double)vecW[j-1], (double)mixWeights[j-1] );
912 CPPUNIT_ASSERT_EQUAL(1.0 , (
double)mixture.
WeightGet(0) ) ;
922 CPPUNIT_ASSERT( (sample.
ValueGet())(j) > _mu(j) - 4.0 * sqrt(_sigma(j,j) ) );
923 CPPUNIT_ASSERT( (sample.
ValueGet())(j) < _mu(j) + 4.0 * sqrt(_sigma(j,j) ) );
941 CPPUNIT_ASSERT( (sample.
ValueGet())(j) > _mu(j) - 4.0 * sqrt(_sigma(j,j) ) );
942 CPPUNIT_ASSERT( (sample.
ValueGet())(j) < _mu(j) + 4.0 * sqrt(_sigma(j,j) ) );
948 sample_mean = sample_mean / (double)NUM_SAMPLES;
951 CPPUNIT_ASSERT( sample_mean(j) <= _mu(j) + 3.0 * 1/sqrt(NUM_SAMPLES) * sqrt(_sigma(j,j)) );
952 CPPUNIT_ASSERT( sample_mean(j) >= _mu(j) - 3.0 * 1/sqrt(NUM_SAMPLES) * sqrt(_sigma(j,j)) );
957 CPPUNIT_ASSERT_EQUAL(
true, mixture.
SampleFrom(los,NUM_SAMPLES,
RIPLEY,NULL));
967 CPPUNIT_ASSERT( (sample.
ValueGet())(j) > _mu(j) - 4.0 * sqrt(_sigma(j,j) ) );
968 CPPUNIT_ASSERT( (sample.
ValueGet())(j) < _mu(j) + 4.0 * sqrt(_sigma(j,j) ) );
974 sample_mean = sample_mean / (double)NUM_SAMPLES;
977 CPPUNIT_ASSERT( sample_mean(j) <= _mu(j) + 3.0 * 1/sqrt(NUM_SAMPLES) * sqrt(_sigma(j,j)) );
978 CPPUNIT_ASSERT( sample_mean(j) >= _mu(j) - 3.0 * 1/sqrt(NUM_SAMPLES) * sqrt(_sigma(j,j)) );
988 CPPUNIT_ASSERT_EQUAL(
true, mixture1.
AddComponent(comp2,w1));
989 CPPUNIT_ASSERT_EQUAL(1.0, (
double)mixture1.
WeightGet(0));
992 CPPUNIT_ASSERT_EQUAL((
double)comp2.ProbabilityGet(cv1),(double)mixture1.
ProbabilityGet(cv1)) ;
996 mu3(1) =1.2; mu3(2) = 1.5;
999 for (
unsigned int rows=1; rows <
DIMENSION + 1; rows++){ sigma3(rows,rows)=2.3; }
1001 CPPUNIT_ASSERT_EQUAL(
true, mixture1.
AddComponent(comp3));
1002 CPPUNIT_ASSERT_EQUAL(1.0, (
double)mixture1.
WeightGet(0));
1003 CPPUNIT_ASSERT_EQUAL(0.0, (
double)mixture1.
WeightGet(1));
1004 CPPUNIT_ASSERT_EQUAL( DIMENSION, mixture1.
DimensionGet() );
1006 CPPUNIT_ASSERT_EQUAL((
double)comp2.ProbabilityGet(cv1),(double)mixture1.
ProbabilityGet(cv1)) ;
1012 CPPUNIT_ASSERT_EQUAL( (
double)vecW[j-1], (double)mixWeights[j-1] );
1014 CPPUNIT_ASSERT_EQUAL(
true, mixture1.
WeightSet(1,0.2));
1019 CPPUNIT_ASSERT_EQUAL( (
double)vecW[j-1], (double)mixWeights[j-1] );
1023 CPPUNIT_ASSERT_EQUAL(
true, mixture1.
WeightsSet(vecW));
1025 double sumVecW = 0.0;
1026 for(
int j = 0 ; j < vecW.size(); j++)
1027 sumVecW += (
double)vecW[j];
1028 for(
int j = 0 ; j < vecW.size(); j++)
1029 vecW[j] = (
double)vecW[j]/sumVecW;
1031 CPPUNIT_ASSERT_EQUAL( (
double)vecW[j-1], (double)mixWeights[j-1] );
1034 prob = vecW[0] * comp2.ProbabilityGet(cv1) + vecW[1] * comp3.
ProbabilityGet(cv1);
1035 CPPUNIT_ASSERT_EQUAL((
double)prob,(
double)mixture1.
ProbabilityGet(cv1)) ;
1038 ColumnVector expected_true = comp2.ExpectedValueGet() * (double)vecW[0] + comp3.
ExpectedValueGet() * (double)vecW[1];
1040 CPPUNIT_ASSERT_EQUAL(expected_true(j), expected_mix(j) ) ;
1045 CPPUNIT_ASSERT_EQUAL(
true, mixture1.
WeightsSet(vecW));
1049 CPPUNIT_ASSERT_EQUAL(
true, mixture1.
WeightsSet(vecW));
1055 CPPUNIT_ASSERT_EQUAL(1.0, (
double)mixture1.
WeightGet(0));
1056 CPPUNIT_ASSERT_EQUAL( DIMENSION, mixture1.
DimensionGet() );
1057 CPPUNIT_ASSERT_EQUAL((
double)comp2.ProbabilityGet(cv1),(double)mixture1.
ProbabilityGet(cv1)) ;
1061 ColumnVector muVec1(DIMENSION);
1062 ColumnVector muVec2(DIMENSION);
1063 muVec1(1) =1.2; muVec1(2) = 1.5;
1064 muVec2(1) =0.2; muVec2(2) = -1.1;
1065 SymmetricMatrix sigmaVec1(DIMENSION);
1066 SymmetricMatrix sigmaVec2(DIMENSION);
1069 double sigmaValVec1 = 2.3;
1070 double sigmaValVec2 = 0.3;
1071 for (
unsigned int rows=1; rows < DIMENSION + 1; rows++){
1072 sigmaVec1(rows,rows)=sigmaValVec1;
1073 sigmaVec2(rows,rows)=sigmaValVec2;
1076 Gaussian compVec1(muVec1,sigmaVec1);
1077 Gaussian compVec2(muVec2,sigmaVec2);
1080 vector<Gaussian*> componentVec(2);
1081 componentVec[0] = &compVec1;
1082 componentVec[1] = &compVec2;
1086 CPPUNIT_ASSERT_EQUAL(0.5, (
double)mixtureVec.
WeightGet(0));
1087 CPPUNIT_ASSERT_EQUAL(0.5, (
double)mixtureVec.
WeightGet(1));
1092 CPPUNIT_ASSERT_EQUAL( (
double)vecW[j-1], (double)mixWeights[j-1] );
1093 CPPUNIT_ASSERT_EQUAL( DIMENSION, mixtureVec.
DimensionGet() );
1096 CPPUNIT_ASSERT_EQUAL( (
double)vecW[j-1], (double)mixWeights[j-1] );
1101 ColumnVector expectedComp(DIMENSION);
1102 ColumnVector expectedMix(DIMENSION);
1105 expectedComp = componentVec[j-1]->ExpectedValueGet();
1108 CPPUNIT_ASSERT_EQUAL(expectedComp(i), expectedMix(i) ) ;
1113 CPPUNIT_ASSERT_EQUAL(
true, mixtureVec.
WeightsSet(vecW));
1116 CPPUNIT_ASSERT_EQUAL( (
double)vecW[j-1], (double)mixWeights[j-1] );
1120 CPPUNIT_ASSERT_EQUAL(
true, mixtureVec.
WeightsSet(vecW));
1123 for(
int j = 0 ; j < vecW.size(); j++)
1124 sumVecW += (
double)vecW[j];
1125 for(
int j = 0 ; j < vecW.size(); j++)
1126 vecW[j] = (
double)vecW[j]/sumVecW;
1128 CPPUNIT_ASSERT_EQUAL( (
double)vecW[j-1], (double)mixWeights[j-1] );
1131 for(
int j = 1 ; j <= componentVec.size();j++)
1133 prob = prob + vecW[j-1] * componentVec[j-1]->ProbabilityGet(cv1) ;
1135 CPPUNIT_ASSERT_EQUAL((
double)prob,(
double)mixtureVec.
ProbabilityGet(cv1)) ;
1139 for(
int j = 1 ; j <= componentVec.size();j++)
1140 expectedComp = expectedComp + componentVec[j-1]->ExpectedValueGet() * (double)vecW[j-1] ;
1142 CPPUNIT_ASSERT_EQUAL(expectedComp(j), expectedMix(j) ) ;
1147 CPPUNIT_ASSERT_EQUAL(
true, mixtureVec.
WeightsSet(vecW));
1155 vector<Probability> probs1(
NUM_DS);
1156 disc1.ProbabilitySet(1,0.8);
1158 unsigned int dim_int = 1;
1161 CPPUNIT_ASSERT_EQUAL(
true, mixture_int.
AddComponent(disc1,w1));
1162 CPPUNIT_ASSERT_EQUAL(1.0, (
double)mixture_int.
WeightGet(0));
1164 for(
int state = 0; state<
NUM_DS ; state++)
1165 CPPUNIT_ASSERT_EQUAL((
double)disc1.ProbabilityGet(state),(double)mixture_int.
ProbabilityGet(state)) ;
1169 vector<Probability> probs2(2);
1172 CPPUNIT_ASSERT_EQUAL(
true, mixture_int.
AddComponent(disc2));
1173 CPPUNIT_ASSERT_EQUAL(1.0, (
double)mixture_int.
WeightGet(0));
1174 CPPUNIT_ASSERT_EQUAL(0.0, (
double)mixture_int.
WeightGet(1));
1175 CPPUNIT_ASSERT_EQUAL( 1, (
int)mixture_int.
DimensionGet() );
1177 for(
int state = 0; state<
NUM_DS ; state++)
1178 CPPUNIT_ASSERT_EQUAL((
double)disc1.ProbabilityGet(state),(double)mixture_int.
ProbabilityGet(state)) ;
1184 CPPUNIT_ASSERT_EQUAL( (
double)vecW[j-1], (double)mixWeights[j-1] );
1186 CPPUNIT_ASSERT_EQUAL(
true, mixture_int.
WeightSet(1,0.2));
1191 CPPUNIT_ASSERT_EQUAL( (
double)vecW[j-1], (double)mixWeights[j-1] );
1195 CPPUNIT_ASSERT_EQUAL(
true, mixture_int.
WeightsSet(vecW));
1198 for(
int j = 0 ; j < vecW.size(); j++)
1199 sumVecW += (
double)vecW[j];
1200 for(
int j = 0 ; j < vecW.size(); j++)
1201 vecW[j] = (
double)vecW[j]/sumVecW;
1203 CPPUNIT_ASSERT_EQUAL( (
double)vecW[j-1], (double)mixWeights[j-1] );
1205 for(
int state = 0; state<
NUM_DS ; state++)
1207 prob = vecW[0] * disc1.ProbabilityGet(state) + vecW[1] * disc2.
ProbabilityGet(state);
1208 CPPUNIT_ASSERT_EQUAL((
double)prob,(
double)mixture_int.
ProbabilityGet(state)) ;
1211 probs1 = disc1.ProbabilitiesGet();
1213 vector<Probability> probs(probs1.size());
1215 int mostProbState = -1;
1216 double probMostProbState = -1.0;
1217 double probState = 0.0;
1218 for(
int i = 0 ; i<probs.size() ; i++)
1220 probState = (double)(probs1[i]) * (double)vecW[0] + (
double)probs2[i] * (double) vecW[1];
1221 if(probState > probMostProbState)
1223 probMostProbState = probState;
1232 CPPUNIT_ASSERT_EQUAL(
true, mixture_int.
WeightsSet(vecW));
1236 CPPUNIT_ASSERT_EQUAL(
true, mixture_int.
WeightsSet(vecW));
virtual MatrixWrapper::Matrix dfGet(unsigned int i) const
returns derivative from function to n-th conditional variable
Class representing a PDF on a discrete variable.
virtual MatrixWrapper::ColumnVector ExpectedValueGet() const
Get the expected value E[x] of the pdf.
T ExpectedValueGet() const
Get the expected value E[x] of the pdf.
void ExpectedValueSet(const MatrixWrapper::ColumnVector &mu)
Set the Expected Value.
bool WeightSet(unsigned int componentNumber, Probability w)
Function to change/set the weigth of a single component.
Probability ProbabilityGet(const int &state) const
Implementation of virtual base class method.
virtual Gaussian * Clone() const
Clone function.
bool SampleFrom(vector< Sample< MatrixWrapper::ColumnVector > > &list_samples, const int num_samples, int method=DEFAULT, void *args=NULL) const
void MatrixSet(unsigned int i, const MatrixWrapper::Matrix &m)
Set the i-th Matrix for calculation of .
virtual bool SampleFrom(Sample< int > &one_sample, int method, void *args) const
Draw 1 sample from the Pdf:
#define NUM_COND_ARGS_DIS
bool ProbabilitiesSet(vector< Probability > &values)
Set all probabilities.
const MatrixWrapper::Matrix & MatrixGet(unsigned int i) const
Get the i-th matrix of the system.
bool ProbabilitySet(int state, Probability a)
Function to change/set the probability of a single state.
Class representing Gaussian (or normal density)
const MatrixWrapper::ColumnVector & AdditiveNoiseMuGet() const
Get the mean Value of the Additive Gaussian uncertainty.
unsigned int NumStatesGet() const
Get the number of discrete States.
bool ListOfSamplesUpdate(const vector< WeightedSample< T > > &list_of_samples)
Update the list of samples (overloaded)
void ValueSet(const T &value)
Set the value of the Sample.
vector< Probability > WeightsGet() const
Get all component weights.
virtual bool SampleFrom(Sample< MatrixWrapper::ColumnVector > &sample, int method=DEFAULT, void *args=NULL) const
virtual void ConditionalArgumentsSet(std::vector< CondArg > ConditionalArguments)
Set the whole list of conditional arguments.
const WeightedSample< T > & SampleGet(unsigned int i) const
Get one sample.
virtual void ConditionalArgumentSet(unsigned int n_argument, const CondArg &argument)
Set the n-th argument of the list.
bool WeightsSet(vector< Probability > &weights)
Set all component weights.
unsigned int NumComponentsGet() const
Get the number of components.
virtual MatrixWrapper::SymmetricMatrix CovarianceGet() const
Get the Covariance Matrix E[(x - E[x])^2] of the Analytic pdf.
bool AddComponent(Pdf< T > &pdf)
Add a component pdf: THIS IS A NON-REALTIME OPERATION.
const MatrixWrapper::SymmetricMatrix & AdditiveNoiseSigmaGet() const
Get the covariance matrix of the Additive Gaussian uncertainty.
vector< double > & CumulativePDFGet()
Add a sample to the list.
vector< Probability > ProbabilitiesGet() const
Get all probabilities.
Class representing a mixture of PDFs, the mixture can contain different.
T ExpectedValueGet() const
Get the expected value E[x] of the pdf.
void AdditiveNoiseMuSet(const MatrixWrapper::ColumnVector &mu)
Set the mean Value of the Additive Gaussian uncertainty.
int MostProbableStateGet()
Get the index of the most probable state.
Probability ProbabilityGet(const int &input) const
Get the probability of a certain argument.
const unsigned int NUM_COND_ARGS
const unsigned int DIMENSION
bool SampleFrom(vector< Sample< T > > &list_samples, const unsigned int num_samples, int method=DEFAULT, void *args=NULL) const
Monte Carlo Pdf: Sample based implementation of Pdf.
unsigned int NumConditionalArgumentsGet() const
Get the Number of conditional arguments.
const CondArg & ConditionalArgumentGet(unsigned int n_argument) const
Get the n-th argument of the list.
void testLinearAnalyticConditionalGaussian()
T & ValueGet()
Get the value of the Sample.
Abstract Class representing all FULLY Discrete Conditional PDF's.
int MostProbableComponentGet() const
Get the index of the most probable component, if a few component are.
Linear Conditional Gaussian.
CPPUNIT_TEST_SUITE_REGISTRATION(PdfTest)
virtual DiscretePdf * Clone() const
Clone function.
Probability ProbabilityGet(const T &state) const
Implementation of virtual base class method.
double WeightGet() const
Get the weight.
MatrixWrapper::SymmetricMatrix CovarianceGet() const
Get the Covariance Matrix E[(x - E[x])^2] of the Analytic pdf.
const unsigned int NUM_SAMPLES
void CovarianceSet(const MatrixWrapper::SymmetricMatrix &cov)
Set the Covariance Matrix.
Probability WeightGet(unsigned int componentNumber) const
Get the component weight of component "componentNumber".
Class representing a probability (a double between 0 and 1)
bool SampleFrom(Sample< T > &one_sample, int method=DEFAULT, void *args=NULL) const
virtual Probability ProbabilityGet(const MatrixWrapper::ColumnVector &input) const
Get the probability of a certain argument.
const vector< WeightedSample< T > > & ListOfSamplesGet() const
Get the list of weighted samples.
unsigned int NumSamplesGet() const
Get number of samples.
void testDiscreteConditionalPdf()
unsigned int DimensionGet() const
Get the dimension of the argument.
Pdf< T > * ComponentGet(unsigned int componentNumber) const
Get the pointer to the component pdf of component "componentNumber".
bool DeleteComponent(unsigned int componentNumber)
Delete a component pdf: THIS IS A NON_REALTIME OPERATION.
virtual MatrixWrapper::ColumnVector ExpectedValueGet() const
Get the expected value E[x] of the pdf.
virtual LinearAnalyticConditionalGaussian * Clone() const
Clone function.
bool approxEqual(double a, double b, double epsilon)
bool ListOfSamplesSet(const vector< WeightedSample< T > > &list_of_samples)
Set the list of weighted samples.
void AdditiveNoiseSigmaSet(const MatrixWrapper::SymmetricMatrix &sigma)
Set the covariance of the Additive Gaussian uncertainty.
virtual DiscreteConditionalPdf * Clone() const
Clone function.
virtual T ExpectedValueGet() const
Get the expected value E[x] of the pdf.
T & ValueGet()
Get the value of the Sample.
bool SampleFrom(vector< Sample< int > > &list_samples, const unsigned int num_samples, int method=DEFAULT, void *args=NULL) const
void ProbabilitySet(const double &prob, const int &input, const std::vector< int > &condargs) const
Set the probability (Typical for discrete Pdf's)
const std::vector< CondArg > & ConditionalArgumentsGet() const
Get the whole list of conditional arguments.
unsigned int NumStatesGet() const
Get the number of discrete states.