tests/emdL1tests.R

stopifnot(require(earthmovdist))

## these input values come from the upstream file emdl1_test.cpp include the archive EmdL1_v3.zip
H1 <- c(0.13427605409811,   0.12596191914837,   0.11608453139343,
        0.03266541515774,   0.10770255919829,   0.06284725030894,
        0.08576141042119,   0.06450982814690,   0.08697535015397,
        0.06868097771456,   0.00261500854742,   0.11191969571108)
H2 <- c(0.13899317383795,   0.14105236814269,   0.00872898998490,
        0.11130866162850,   0.13825305376936,   0.05320630453212,
        0.02657783264179,   0.06186152724099,   0.12261119761378,
        0.06117335727411,   0.13474662273423,   0.00148691059958)
H3 <- c(0.00221808613936,   0.00175908403096,   0.00046628327788,   0.00523651323436,   0.00507985277987,   0.00402042930375,   0.00578093227631,   0.00289743768321,   0.00679510578451,  0.00674997506366,
        0.00519274211643,   0.00662962368353,   0.00540351838006,   0.00276283999438,   0.00056304529053,   0.00355381970650,   0.00067341750559,   0.00106132689745,   0.00538584303094,  0.00215777293085,
        0.00881492287155,   0.00929868730481,   0.00663172268788,   0.00811830972881,   0.00084178302040,   0.00157220006628,   0.00297381495833,   0.00419454340379,   0.00436028710191,  0.00425464931451,
        0.00317173926072,   0.00763264985959,   0.00910546196141,   0.00317701646670,   0.00256719983775,   0.00788353058807,   0.00575670978022,   0.00441664815641,   0.00421362975097,  0.00162940549548,
        0.00620283270825,   0.00665736951675,   0.00710163004734,   0.00643629414517,   0.00387076572636,   0.00793546202078,   0.00165609378977,   0.00013880132555,   0.00083026594801,  0.00916726862431,
        0.00370831589809,   0.00458887309387,   0.00700203755513,   0.00050570724620,   0.00448552328828,   0.00427330826006,   0.00587634902738,   0.00628345919397,   0.00419637204367,  0.00336589314985,
        0.00593584187377,   0.00108450110869,   0.00408651633143,   0.00337478234675,   0.00860113159024,   0.00905165101492,   0.00232734713393,   0.00685129043885,   0.00346603970688,  0.00046409589207,
        0.00661490727394,   0.00629106405652,   0.00600161592572,   0.00471510849612,   0.00564187039220,   0.00139240834013,   0.00555776072021,   0.00266490216009,   0.00286266630779,  0.00714724155795,
        0.00375827445693,   0.00345727804775,   0.00759847761703,   0.00411080750432,   0.00311267436106,   0.00823156796327,   0.00478843052745,   0.00247740735968,   0.00806041164726,  0.00846698845861,
        0.00391388145758,   0.00132514291880,   0.00079370740692,   0.00532215131532,   0.00452481999459,   0.00728063946522,   0.00439787846620,   0.00670377027809,   0.00718642320964,  0.00270763436411,
        0.00619982266812,   0.00536297531137,   0.00894625427803,   0.00583465525476,   0.00565061016360,   0.00420279127369,   0.00512306934048,   0.00741711067406,   0.00898690902684,  0.00237693539139,
        0.00792548302213,   0.00778755308694,   0.00866692402391,   0.00107245710984,   0.00152767685061,   0.00587249491303,   0.00891657843275,   0.00933132282791,   0.00527938258095,  0.00882583138004,
        0.00351626736738,   0.00637710538178,   0.00569618670656,   0.00849952909830,   0.00784873573057,   0.00900517123313,   0.00323382766693,   0.00447891155243,   0.00013467709276,  0.00123939565864,
        0.00402387374412,   0.00945707207296,   0.00239926673078,   0.00713979286656,   0.00904711880525,   0.00605596454152,   0.00380199397019,   0.00854274431701,   0.00564120752376,  0.00890231848648,
        0.00562688431408,   0.00909929394511,   0.00826485516472,   0.00748584647072,   0.00563525489102,   0.00234028867971,   0.00291143611794,   0.00426805414626,   0.00772318478391,  0.00664114657593,
        0.00535318913180,   0.00055697157652,   0.00485795248303,   0.00771132245220,   0.00027202427078,   0.00333737273405,   0.00389438025902,   0.00761258087898,   0.00924554278741,  0.00802097060488,
        0.00678014044419,   0.00340937305569,   0.00693256158559,   0.00633977880382,   0.00768450393198,   0.00177759257034,   0.00270564332494,   0.00784296585912,   0.00209976122942,  0.00198019143057,
        0.00483818325700,   0.00519019380686,   0.00399523540288,   0.00190075324574,   0.00577307881451,   0.00464262501275,   0.00372935442066,   0.00157329803122,   0.00665846726112,  0.00430621494313,
        0.00734654261653,   0.00247694268275,   0.00909677310944,   0.00258404261358,   0.00663773472813,   0.00387267723797,   0.00475967489198,   0.00372725751906,   0.00493989795964,  0.00076714405957,
        0.00463033459716,   0.00565225725393,   0.00068184626556,   0.00592562117379,   0.00087238829867,   0.00438601898442,   0.00683159122873,   0.00492756450277,   0.00882735353601,  0.00805357706062)
H4 <- c(0.00582847661582,   0.00105344716288,   0.00018005211040,   0.00909277702364,   0.00799408831249,   0.00434954102140,   0.00698581988827,   0.00488591346963,   0.00071883405391,  0.00821133857378,
        0.00331112068187,   0.00067731513447,   0.00849715112731,   0.00013367521758,   0.00325547178058,   0.00220875630889,   0.00992756822982,   0.00154835663775,   0.00884493757926,  0.00158240450506,
        0.00388772657940,   0.00242970150756,   0.00644124356677,   0.00321888866872,   0.00661809983604,   0.00036917367508,   0.00198965865223,   0.00140892146444,   0.00187003929036,  0.00863853959680,
        0.00899909054830,   0.00967628345969,   0.00580953430158,   0.00807909593157,   0.01023075427011,   0.00084167220938,   0.00115332076487,   0.00552203681281,   0.00033618234949,  0.00198963292151,
        0.00385948869396,   0.00065463985724,   0.00253062083208,   0.00318667780908,   0.00521485057127,   0.00882042572718,   0.00585964065128,   0.00752647625503,   0.00761085686179,  0.00662632690772,
        0.00076417005192,   0.00273995214088,   0.00852426525965,   0.00960970657799,   0.00982773770519,   0.00352792902108,   0.01005030914886,   0.00413457322881,   0.00556370984568,  0.00693756872155,
        0.00207233133639,   0.01036520008599,   0.00272952260397,   0.00703836356235,   0.00858667488750,   0.00483405353200,   0.00024622528612,   0.00371682031564,   0.00286244324685,  0.00800659422447,
        0.00051324811393,   0.00219832718048,   0.00781523281526,   0.00077071809155,   0.00951512017734,   0.00947577656110,   0.00902418737265,   0.00295836366538,   0.00382093192200,  0.00393873158050,
        0.00587681251384,   0.00516853784621,   0.00684055393275,   0.00073284351774,   0.00117264423405,   0.00237035338864,   0.00027871178966,   0.00900779668916,   0.00013363171888,  0.00457926649905,
        0.00126436656298,   0.00301238007779,   0.00221984394192,   0.00012371961539,   0.00842179165307,   0.00893945444972,   0.00538754192994,   0.00649593492251,   0.00922111746968,  0.00500935949909,
        0.00541432856597,   0.00697650135308,   0.00624398644913,   0.00235559689343,   0.00941873423283,   0.00680917141265,   0.00199407292581,   0.00250097050183,   0.00898068270285,  0.00630609010677,
        0.00121392041119,   0.00993442218397,   0.00627323210116,   0.00535356245393,   0.00162162921687,   0.00924161614721,   0.00742173595893,   0.01014276215011,   0.00263655511523,  0.00182508477088,
        0.00798409822871,   0.00794918283753,   0.00683906841548,   0.00475160367041,   0.00126637852848,   0.00506207593766,   0.00259949094267,   0.00664202937367,   0.00590554604907,  0.00002100518216,
        0.00388934985841,   0.00690774089651,   0.00190149125669,   0.00729225845443,   0.00790889449678,   0.01029379158983,   0.00968423104364,   0.00238354349479,   0.00165158518576,  0.00819466766907,
        0.00853857194705,   0.00135790522324,   0.00660102746888,   0.00604039078185,   0.00748510984070,   0.00387141115250,   0.00142266094283,   0.00706548415486,   0.00616359266703,  0.00532614925834,
        0.00048361947103,   0.00098943838604,   0.00176611512013,   0.00528049508553,   0.00675754181367,   0.00551042325879,   0.00540925320757,   0.00690462646530,   0.00343352659836,  0.00221120071391,
        0.00620039439486,   0.00015414402157,   0.00559569403651,   0.00077038745484,   0.00781925776057,   0.00188026060203,   0.00928329224332,   0.00139703302031,   0.00682985053251,  0.00107278024462,
        0.00984274336059,   0.00298858132002,   0.00646463298850,   0.00200387151919,   0.00687702758975,   0.00520519119121,   0.00977260921452,   0.00023325672696,   0.00895593576715,  0.00163159013854,
        0.00299484801971,   0.00846954895147,   0.00711271787843,   0.00393651636740,   0.00916187766487,   0.00437818427763,   0.00347483361987,   0.00271902314358,   0.00588628592087,  0.00422595342940,
        0.00921724452151,   0.01021951982517,   0.00702411590145,   0.00286664371174,   0.00282228803312,   0.00684866954652,   0.00453548762840,   0.00120826880583,   0.01016764636167,  0.00422846341728)

## these results were obtained by running emdL1_test.cpp and emdL1.cpp on Linux using g++ 4.3
res1 <- 0.3979566124
res2 <- 0.4315793480
res3 <- 0.5589762218

epsilon <- 1.0e-9

stopifnot( abs(emdL1(H1, H2, c(12))     - res1) < epsilon )
stopifnot( abs(emdL1(H1, H2, c(3, 4))   - res2) < epsilon )
stopifnot( abs(emdL1(H3, H4, c(10, 20)) - res3) < epsilon )

cat("Tests done.\n")

Try the earthmovdist package in your browser

Any scripts or data that you put into this service are public.

earthmovdist documentation built on May 2, 2019, 4:24 p.m.