Using different seeds for the component distributions to avoid getting
the same sequence of random numbers for all of them. Update to the
"testSampling" unit test contributed by Jared Becksfort.


git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1401894 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gilles Sadowski 2012-10-24 21:27:44 +00:00
parent f5765cf99d
commit e0426dfbfb
2 changed files with 116 additions and 118 deletions

View File

@ -140,9 +140,8 @@ public class MixtureMultivariateRealDistribution<T extends MultivariateRealDistr
for (int i = 0; i < distribution.size(); i++) { for (int i = 0; i < distribution.size(); i++) {
// Make each component's seed different in order to avoid // Make each component's seed different in order to avoid
// using the same sequence of random numbers. XXX // using the same sequence of random numbers.
// components.get(i).reseedRandomGenerator(i + 1 + seed); distribution.get(i).reseedRandomGenerator(i + 1 + seed);
distribution.get(i).reseedRandomGenerator(seed); // XXX original code.
} }
} }

View File

@ -165,125 +165,124 @@ public class MultivariateNormalMixtureModelDistributionTest {
* Values used in {@link #testSampling()}. * Values used in {@link #testSampling()}.
*/ */
private double[][] getCorrectSamples() { private double[][] getCorrectSamples() {
// These were sampled from the MultivariateNormalMixtureModel class // These were sampled from the MultivariateNormalMixtureModelDistribution class
// with seed 50. They were then fit to a MVN mixture model in R // with seed 50.
// using mixtools. The fitted parameters were:
// //
// - component weights: {0.3730363, 0.6269637} // They were then fit to a MVN mixture model in R using mixtools.
// - mean vectors: {-1.760221, 2.080246}, {4.042673 8.239901} //
// The optimal parameters were:
// - component weights: {0.3595186, 0.6404814}
// - mean vectors: {-1.645879, 1.989797}, {3.474328, 7.782232}
// - covariance matrices: // - covariance matrices:
// {2.343314 -1.161423 // { 1.397738 -1.167732
// -1.161423 2.168186}, // -1.167732 1.801782 }
// {4.538306 1.999180 // and
// 1.999180 3.707478} // { 3.934593 2.354787
// 2.354787 4.428024 }
// //
// These parameters are quite close to the given test parameters, // It is considered fairly close to the actual test parameters,
// considering that the sample size is only 100. This indicates that // considering that the sample size is only 100.
// we are sampling from the given distributions correctly.
//
// MVN mixture model fitting is tested more directly in
// MultivariateNormalMixtureModelEMTest.java.
return new double[][] { return new double[][] {
{ 0.2583074099703975, 8.664499710373795 }, { 6.259990922080121, 11.972954175355897 },
{ -4.813531184031044, 3.9231359989545105 }, { -2.5296544304801847, 1.0031292519854365 },
{ -0.7419261132564453, 2.4007823469659315 }, { 0.49037886081440396, 0.9758251727325711 },
{ 5.509216904195162, 9.422233433392439 }, { 5.022970993312015, 9.289348879616787 },
{ -2.381049190850173, 4.943660886154495 }, { -1.686183146603914, 2.007244382745706 },
{ -0.8993376528270461, 0.8938743025320182 }, { -1.4729253946002685, 2.762166644212484 },
{ 4.894770663858121, 12.166851725156436 }, { 4.329788143963888, 11.514016497132253 },
{ 4.0897683028395075, 6.918843155044206 }, { 3.008674596114442, 4.960246550446107 },
{ 4.719618558675267, 8.341707066796028 }, { 3.342379304090846, 5.937630105198625 },
{ 5.0119792918378385, 8.718202270235704 }, { 2.6993068328674754, 7.42190871572571 },
{ -0.9575382403048307, 1.8229677546531289 }, { -2.446569340219571, 1.9687117791378763 },
{ 6.096419130934251, 10.015298483992137 }, { 1.922417883170056, 4.917616702617099 },
{ -0.8680257551663279, 2.017226810559624 }, { -1.1969741543898518, 2.4576126277884387 },
{ 1.5561509591914775, 6.428382522063888 }, { 2.4216948702967196, 8.227710158117134 },
{ 2.9573609580937585, 4.984112447026558 }, { 6.701424725804463, 9.098666475042428 },
{ 2.9607883517629716, 5.040859511876173 }, { 2.9890253545698964, 9.643807939324331 },
{ 6.693223483958679, 8.293058555022974 }, { 0.7162632354907799, 8.978811120287553 },
{ -0.49520319305205684, 2.654804424012847 }, { -2.7548699149775877, 4.1354812280794215 },
{ 2.5982446884625903, 4.403704372523807 }, { 8.304528180745018, 11.602319388898287 },
{ -2.8126962615987825, 1.524225284837275 }, { -2.7633253389165926, 2.786173883989795 },
{ 4.617557399108285, 10.112045833514983 }, { 1.3322228389460813, 5.447481218602913 },
{ -1.0505336217175474, -0.25620619814406176 }, { -1.8120096092851508, 1.605624499560037 },
{ 6.468546093824413, 8.492764345471349 }, { 3.6546253437206504, 8.195304526564376 },
{ -1.070959919055369, -0.21025004020250515 }, { -2.312349539658588, 1.868941220444169 },
{ 0.7096492923917137, 0.972470062045611 }, { -1.882322136356522, 2.033795570464242 },
{ 5.398941052924385, 9.02323432480054 }, { 4.562770714939441, 7.414967958885031 },
{ 4.0619884910872885, 3.9387544688324274 }, { 4.731882017875329, 8.890676665580747 },
{ 3.060654105075946, 8.375879742835302 }, { 3.492186010427425, 8.9005225241848 },
{ -1.1120837945401831, -0.5932624462175884 }, { -1.619700190174894, 3.314060142479045 },
{ 1.7076086958821626, 10.076176310641726 }, { 3.5466090064003315, 7.75182101001913 },
{ 0.8025522475696087, 7.376934311816509 }, { 5.455682472787392, 8.143119287755635 },
{ -1.7692026721062535, 3.342422431805849 }, { -2.3859602945473197, 1.8826732217294837 },
{ 6.347756985325947, 9.473453725270733 }, { 3.9095306088680015, 9.258129209626317 },
{ 5.881105197046502, 7.489181251843213 }, { 7.443020189508173, 7.837840713329312 },
{ 1.2360421752575719, 6.795186398153966 }, { 2.136004873917428, 6.917636475958297 },
{ 0.4401756166827726, 1.2313491852695706 }, { -1.7203379410395119, 2.3212878757611524 },
{ 2.3000936045037568, 8.287718300406317 }, { 4.618991257611526, 12.095065976419436 },
{ -0.670230868276056, 2.1130200354211004 }, { -0.4837044029854387, 0.8255970441255125 },
{ 0.3003945370882637, -1.5819884144799348 }, { -4.438938966557163, 4.948666297280241 },
{ 7.277242408774614, 10.927490482503183 }, { -0.4539625134045906, 4.700922454655341 },
{ 7.923140481277026, 12.004508589648411 }, { 2.1285488271265356, 8.457941480487563 },
{ 5.522112916642092, 9.78447909183086 }, { 3.4873561871454393, 11.99809827845933 },
{ 1.7119808481577339, 6.085145192818114 }, { 4.723049431412658, 7.813095742563365 },
{ 2.105629604263621, 10.1449475519281 }, { 1.1245583037967455, 5.20587873556688 },
{ 4.972245882289706, 9.190876138075419 }, { 1.3411933634409197, 6.069796875785409 },
{ 3.55810426807224, 7.654818193514658 }, { 4.585119332463686, 7.967669543767418 },
{ -2.356177988964854, 2.532266732955841 }, { 1.3076522817963823, -0.647431033653445 },
{ -4.1832049468547385, 4.506619880263655 }, { -1.4449446442803178, 1.9400424267464862 },
{ -3.830920610669877, 2.6251612200440366 }, { -2.069794456383682, 3.5824162107496544 },
{ -0.06307681885555017, 2.099426408596512 }, { -0.15959481421417276, 1.5466782303315405 },
{ 0.36171488935238116, 0.6347956010120039 }, { -2.0823081278810136, 3.0914366458581437 },
{ 4.151714086462804, 8.647657431234045 }, { 3.521944615248141, 10.276112932926408 },
{ 0.7057392641959304, 6.692562958393579 }, { 1.0164326704884257, 4.342329556442856 },
{ -0.6550353398872, 7.692019868324891 }, { 5.3718868590295275, 8.374761158360922 },
{ 4.320276127581665, 7.202292152597195 }, { 0.3673656866959396, 8.75168581694866 },
{ -3.2303904191995527, 1.961730492225101 }, { -2.250268955954753, 1.4610850300996527 },
{ -2.954784139519494, 2.7707906587677087 }, { -2.312739727403522, 1.5921126297576362 },
{ 4.467020781304962, 11.98783401317258 }, { 3.138993360831055, 6.7338392374947365 },
{ 2.516614661485048, 5.7484664274488395 }, { 2.6978650950790115, 7.941857288979095 },
{ 0.5769047448998346, 5.631710672821962 }, { 4.387985088655384, 8.253499976968 },
{ 0.1160140182849414, 2.9315783896969196 }, { -1.8928961721456705, 0.23631082388724223 },
{ 2.5049583778078652, 8.761243869910377 }, { 4.43509029544109, 8.565290285488782 },
{ 5.709406025351957, 8.257826327804949 }, { 4.904728034106502, 5.79936660133754 },
{ 0.21312967519917736, 3.5654341612096037 }, { -1.7640371853739507, 2.7343727594167433 },
{ 3.6569574551599913, 5.771827106887553 }, { 2.4553674733053463, 7.875871017408807 },
{ -0.8798149482991884, 2.6978303136418855 }, { -2.6478965122565006, 4.465127753193949 },
{ 2.414118561546714, 4.53422981267982 }, { 3.493873671142299, 10.443093773532448 },
{ 1.4898922645162216, 7.761630474438329 }, { 1.1321916197409103, 7.127108479263268 },
{ -2.541784545189355, 1.1738033253079712 }, { -1.7335075535240392, 2.550629648463023 },
{ -3.879227113624057, 4.4006851836938345 }, { -0.9772679734368084, 4.377196298969238 },
{ 6.661993934276366, 7.141516646050444 }, { 3.6388366973980357, 6.947299283206256 },
{ 3.181178356801352, 8.231063903955624 }, { 0.27043799318823325, 6.587978599614367 },
{ 1.8841679086668033, 7.8838333882950895 }, { 5.356782352010253, 7.388957912116327 },
{ -1.0951561728318044, 2.4280383085698944 }, { -0.09187745751354681, 0.23612399246659743 },
{ 5.35219559310147, 10.747404919992816 }, { 2.903203580353435, 3.8076727621794415 },
{ 6.960010647189781, 6.95945895094293 }, { 5.297014824937293, 8.650985262326508 },
{ 8.66048279380016, 10.240215090544776 }, { 4.934508602170976, 9.164571423190052 },
{ 5.322414316267673, 11.183073632332036 }, { -1.0004911869654256, 4.797064194444461 },
{ 4.286246289231014, 9.881220496364916 }, { 6.782491700298046, 11.852373338280497 },
{ 3.1594608386471306, 7.472785192202438 }, { 2.8983678524536014, 8.303837362117521 },
{ 7.490325449520623, 9.327482647357861 }, { 4.805003269830865, 6.790462904325329 },
{ -1.6450957033850353, 1.7263141708037384 }, { -0.8815799740744226, 1.3015810062131394 },
{ 7.640267915158525, 9.040106401524124 }, { 5.115138859802104, 6.376895810201089 },
{ 3.225359471647853, 7.698098961183428 }, { 4.301239328205988, 8.60546337560793 },
{ 5.511639004578083, 9.186863380867411 }, { 3.276423626317666, 9.889429652591947 },
{ -1.5570773470706916, 2.3113691458388006 }, { -4.001924973153122, 4.3353864592328515 },
{ 3.6254977322201625, 8.605119642693507 }, { 3.9571892554119517, 4.500569057308562 },
{ 6.825831664908241, 8.090893354857114 }, { 4.783067027436208, 7.451125480601317 },
{ 4.614281342893763, 9.430714925646987 }, { 4.79065438272821, 9.614122776979698 },
{ 3.244449074987682, 7.4974070774986705 }, { 2.677655270279617, 6.8875223698210135 },
{ -3.630882697488002, 2.0936948617188036 }, { -1.3714746289327362, 2.3992153193382437 },
{ 4.668632614740622, 9.56561505235852 }, { 3.240136859745249, 7.748339397522042 },
{ 3.291602850422323, 7.676202933382092 }, { 5.107885374416291, 8.508324480583724 },
{ -5.17676202387167, 3.486280073084009 }, { -1.5830830226666048, 0.9139127045208315 },
{ -0.8232665608471817, 1.035856623121346 }, { -1.1596156791652918, -0.04502759384531929 },
{ -2.664598562579467, 4.969780569462966 }, { -0.4670021307952068, 3.6193633227841624 },
{ -1.7320549381441652, 0.5626102308837451 }, { -0.7026065228267798, 0.4811423031997131 },
{ -3.3030769989674384, 1.2611477988721695 }, { -2.719979836732917, 2.5165041618080104 },
{ -2.978115812942412, 3.0819389792053005 }, { 1.0336754331123372, -0.34966029029320644 },
{ 4.061270197659891, 10.977521917377931 } { 4.743217291882213, 5.750060115251131 }
}; };
} }
} }