diff --git a/fastlib/u/pram/mog_em/faster/build.py b/fastlib/u/pram/mog_em/faster/build.py deleted file mode 100644 index 6ec98e8330..0000000000 --- a/fastlib/u/pram/mog_em/faster/build.py +++ /dev/null @@ -1,26 +0,0 @@ - -librule( - name = "mog_em", # this line can be safely omitted - sources = ["mog.cc"], # files that must be compiled - headers = ["mog.h","phi.h","math_functions.h"],# include files part of the 'lib' - deplibs = ["fastlib:fastlib"], # depends on fastlib core - #tests = ["mog_em_tests.cc"] # this file contains a main with test functions - ) - -binrule( - name = "mog_em_main", # the executable name - sources = ["mog_em_main.cc"], # compile main.cc - #headers = ["mog_em_main.h"], # no extra headers - deplibs = [":mog_em", "fastlib:fastlib"] # - ) - -# to build: -# 1. make sure have environment variables set up: -# $ source /full/path/to/fastlib/script/fl-env /full/path/to/fastlib -# (you might want to put this in bashrc) -# 2. fl-build main -# - this automatically will assume --mode=check, the default -# - type fl-build --help for help -# 3. ./main -# - to build same target again, type: make -# - to force recompilation, type: make clean diff --git a/fastlib/u/pram/mog_em/faster/data.arff b/fastlib/u/pram/mog_em/faster/data.arff deleted file mode 100644 index d95f367d0f..0000000000 --- a/fastlib/u/pram/mog_em/faster/data.arff +++ /dev/null @@ -1,1000 +0,0 @@ --0.28992,-0.13173,-0.61575 --1.2142,-1.1994,-0.4661 -0.031128,0.084721,-0.057328 --0.86099,-0.79692,-0.35194 --0.45353,-0.11696,-0.15629 -0.82319,0.31796,0.5654 -0.87603,0.62511,0.54203 --1.8458,-1.2202,-1.6845 -1.3571,0.86032,0.95889 --0.88157,-0.092799,-0.21391 --1.7254,-0.80534,-1.2231 --3.7444,-2.7681,-2.8587 --1.9593,-1.9499,-1.6215 -0.036513,-0.65684,-0.16414 --1.0091,-0.9538,-0.82084 --2.6299,-2.4503,-2.0805 -1.4404,0.91235,1.0368 -2.3232,1.7905,1.3835 --0.22953,0.29435,-0.55121 -0.52442,0.53273,0.29293 -1.9345,1.1211,1.5277 --0.71909,-0.91217,-0.13798 --1.0023,-0.31518,-0.83793 -0.88445,0.55393,0.63455 --0.14286,0.75819,0.10212 --0.57519,-0.41389,-0.16138 --0.54536,-0.54785,0.19468 -0.18259,-0.038652,-0.11602 -1.5583,1.5063,1.1687 -0.67228,0.25056,0.28417 -1.8047,1.3339,1.8819 -1.6772,1.8611,1.5816 -0.30442,0.39109,0.31353 --0.66552,-0.38255,-0.36366 --0.99614,-0.31771,0.10233 -0.65813,0.72853,0.66725 -1.3433,0.87076,0.9503 -0.5952,0.54358,0.15799 -0.80337,0.48182,0.92845 --1.0895,-0.77068,-0.43275 --1.2246,-1.0886,-0.81559 --3.2332,-2.2593,-1.8321 -2.36,1.5532,1.98 --1.417,-0.72475,-1.6775 -0.48999,0.27822,0.63959 -1.7494,1.1849,1.2174 -0.098846,0.48884,0.58291 --2.2389,-1.239,-1.5603 --2.5684,-2.0838,-2.044 -1.833,1.9878,1.488 --1.3408,-0.41722,-0.78372 -0.41603,-0.03137,-0.19393 -1.3308,0.97246,0.50187 -1.8763,1.4224,1.5111 -0.47414,0.35165,0.45279 -0.72983,0.62162,0.81429 -0.072535,-0.15613,0.19178 -0.24045,0.31484,0.73666 --0.63399,-0.44661,0.16174 --0.7575,-0.29941,-0.23175 --0.22151,0.13724,-0.053466 --0.61552,-0.30699,-0.18651 -0.13717,0.14514,-0.13645 -0.79648,1.0154,0.66609 -0.02903,0.11115,-0.027887 -1.2644,0.91254,0.91018 --0.36039,-0.27273,-0.093994 -1.8088,1.6939,1.1004 --1.4649,-1.1623,-1.3663 -0.16635,0.21012,-0.5929 --1.9238,-0.92677,-1.2546 --1.1433,-1.2331,-0.83555 --1.3747,-1.2459,-0.9011 -0.66298,0.6126,0.17198 --0.4638,-0.12425,-0.29331 --1.1176,-0.7349,-0.67311 -0.13308,0.25935,0.25244 --0.068732,-0.5169,-0.16423 --0.56212,-0.51442,-0.3723 --1.7361,-1.4933,-1.4681 -0.98691,0.45932,0.37285 -0.21825,-0.36061,-0.26815 -0.90569,0.70056,0.68695 -1.9013,1.2122,1.4488 --1.7678,-1.0156,-1.173 -0.38102,-0.26481,0.1876 --1.7408,-1.4657,-1.3288 --0.40932,-0.036133,0.12221 -0.15014,0.23639,0.54873 --1.9972,-1.75,-1.8577 --1.8673,-1.0512,-1.2368 -0.33336,1.028,0.67552 -0.12516,0.33989,0.54363 -1.2947,1.1484,1.3026 --2.6568,-1.9047,-1.6224 -0.80258,1.1538,0.43664 -0.68373,0.22631,-0.13506 -2.0724,1.9613,1.4781 --0.057605,0.069219,0.048158 -0.25527,0.50668,-0.053834 -0.017855,-0.36902,-0.23829 --1.3289,-0.86749,-1.0304 -0.66139,0.22237,0.9768 --2.1005,-1.4237,-1.72 --1.234,-0.94788,-1.1833 -0.10204,0.51948,0.74726 -0.89834,0.80405,1.2404 -1.012,1.4959,1.1823 -0.30367,0.5883,-0.0046778 -2.7521,1.9868,1.8043 -2.097,1.4677,0.92925 --1.1235,-1.4098,-1.2711 -1.9084,1.657,1.1495 -0.78211,0.49159,0.83696 -2.7431,1.8348,1.6386 -0.87418,0.68548,0.7164 -0.066816,0.048781,0.49303 -0.62474,0.62775,0.61916 -2.9857,1.2037,1.6174 -0.050662,-0.24521,-0.2071 --3.307,-2.388,-2.5187 --2.6089,-1.4105,-1.8392 --1.4298,-0.83004,-0.81826 --1.9463,-0.7075,-1.1085 --1.0799,-1.2061,-1.2246 --0.54161,-0.25041,0.083609 --0.99172,-0.78297,-0.77374 --2.3501,-2.3071,-1.7381 --0.51825,-0.2618,0.25004 -1.205,1.3003,1.2781 --0.47089,-0.52361,0.071943 --1.581,-1.0454,-1.438 -0.19374,0.0014186,-0.52438 --0.41816,-0.055584,-0.097029 -0.2367,0.78135,0.15525 -0.52643,-0.097311,0.22236 --3.2296,-2.0068,-2.1137 -0.92813,0.43725,0.67604 -0.45642,0.71451,0.11568 --0.82585,0.051156,-0.10125 -0.86194,0.50485,0.6331 -0.53631,-0.35131,0.16827 -0.82404,0.35693,0.2579 --1.9772,-0.79196,-0.85444 --0.89974,-0.71668,-0.65297 --0.91065,-0.59001,-0.6308 --1.3831,-1.0118,-0.89703 --0.15873,-0.020554,-0.13402 -0.95565,0.33478,0.57809 -1.6549,1.2895,1.165 -1.2448,1.0888,0.91904 -0.11118,-0.25732,0.31858 --1.6271,-1.1146,-1.0263 --0.29143,-0.27272,-0.71234 -0.56502,0.20699,0.73495 -0.041273,0.73347,0.24046 -0.13242,0.022178,0.46973 --1.2083,-1.0423,-1.0835 --2.4447,-1.4434,-2.3133 --0.27241,-0.41174,-0.14483 -1.0588,0.39549,0.48859 -0.017031,0.30603,-0.10919 -0.72013,0.87843,0.4069 --0.083852,0.054321,-0.3228 -0.85398,0.51678,0.74805 -1.8232,1.168,1.4461 --1.6247,-1.3238,-1.5044 --1.7106,-1.0363,-1.4024 --1.5783,-0.85538,-1.0742 -1.4944,1.4094,0.90905 -1.0882,0.097209,0.051214 --1.0669,-1.3542,-0.72685 -0.51076,0.16209,0.48204 --1.8495,-1.21,-1.2395 --0.22546,-0.4974,-0.017868 -3.0372,1.9304,1.8972 --0.28054,0.059221,-0.054742 -0.93185,0.74408,0.8145 -0.52087,0.16419,0.37096 --0.33261,-0.3717,-0.52816 --1.547,-0.94888,-1.2357 --2.7099,-1.1015,-1.7222 --0.53998,-0.040121,-0.46382 --1.1362,-0.51085,-1.1435 --1.6958,-1.0641,-0.91265 -0.98161,0.38866,0.73232 --1.1036,-1.0885,-1.037 -0.30512,-0.26361,0.48154 -0.59232,0.019852,0.26333 --0.42607,0.0024313,0.17732 -0.54953,0.36402,0.68034 -2.3398,1.6947,1.5355 --2.0822,-1.5711,-1.6259 --0.87478,-0.86737,-0.3825 --0.77088,-0.57907,-0.37721 --2.1322,-1.548,-1.7005 --0.036936,-0.0048763,-0.24452 -1.1224,0.72815,1.0709 -3.1389,2.084,1.9859 -1.9767,1.6508,1.262 -1.6246,1.1363,1.1108 --1.5215,-1.2044,-0.87585 -1.0962,0.40736,0.56413 -1.6983,1.4339,1.5041 --0.23987,0.020822,-0.19235 -1.0057,-0.083055,0.30357 --2.1844,-1.4789,-1.6182 -1.2439,0.73236,0.24275 --2.5633,-1.6744,-1.4432 --2.2554,-1.38,-1.5194 --0.91629,-0.86468,-0.73961 --0.14336,-0.21176,-0.39803 -2.9825,1.4866,1.854 -1.1837,0.86268,0.92964 --0.21804,-0.34317,0.5976 -1.3107,1.2574,1.3898 -0.15858,0.26123,0.30541 --0.88425,-0.96351,-0.81885 --0.54766,-0.75486,-1.1235 --0.23576,0.031025,0.43233 -0.80035,0.01489,0.042148 -0.40758,0.29289,0.42509 -0.72433,0.26164,0.64014 -0.94726,1.3294,0.50632 --3.0347,-2.109,-2.6678 -1.435,1.3302,1.3962 --0.11631,-0.27703,-0.18536 -0.5284,0.16278,0.5905 -1.6569,0.9584,0.83698 -0.73339,0.58781,0.6293 --0.053974,-0.6296,-0.30961 -2.7122,1.4535,1.7442 -1.2501,1.0896,1.159 --0.64861,-0.77736,-0.51812 -0.67061,0.39535,0.036823 --0.22732,-0.23807,-0.36535 -4.0119,2.9058,3.3315 --1.1107,-1.0786,-0.90756 -2.3708,1.8353,1.6397 --0.94586,-0.99019,-0.71511 --0.97851,-1.0936,-0.27488 --0.7327,-0.52786,-1.1667 --1.4273,-1.1405,-1.223 -0.51143,0.040569,-0.26151 --0.61625,-0.34615,-0.38091 -0.45988,0.15269,0.12729 -1.1693,1.1108,1.1646 --2.6679,-1.8987,-1.9899 --2.3344,-1.4175,-1.4573 -1.8448,1.8321,1.3634 --0.76893,-1.1111,-0.90136 --1.3488,-1.2946,-0.92539 --0.56119,0.0089323,0.39697 -0.24172,-0.19342,0.17267 --1.7258,-1.2037,-1.8982 -0.081487,0.12775,-0.31101 -0.62851,0.68749,0.052709 --0.042665,-0.5202,0.28434 --0.075984,-0.13484,-0.029599 --2.0731,-1.6632,-1.2765 --1.0135,-0.60056,-0.93672 --1.64,-1.1715,-1.1609 -0.1515,0.23287,0.018319 --0.47086,-0.088765,-0.57017 --0.68252,-0.4449,-0.9225 --0.88742,-0.84848,-0.84975 --0.43817,0.052193,-0.10879 --1.3142,-1.4088,-0.83819 --0.52877,-0.23247,-0.49379 --2.088,-1.2951,-1.9012 -0.2602,0.29949,0.060943 --1.382,-0.94575,-0.60689 --1.8747,-1.3917,-1.0491 -1.3077,0.88104,0.55847 --1.407,-1.211,-1.0713 -0.63563,0.45859,0.19683 --0.063227,0.21199,0.21755 -3.0411,1.8563,1.9391 --2.8918,-1.6217,-1.8298 -0.78294,0.4287,0.42804 -0.84344,0.046024,0.64389 -1.0506,0.6435,0.5678 -0.061037,0.4905,0.16965 --0.13804,0.58693,-0.16488 -1.6125,1.0261,1.0157 --1.3996,-0.59624,-0.90646 --1.0525,-0.98884,-1.1838 -0.059208,0.058424,0.5449 -0.53041,0.087684,-0.29765 --2.6413,-1.5416,-2.0573 -0.26177,0.33753,0.46196 -0.19761,0.91216,0.11736 --0.087715,0.19543,0.29375 --0.25043,-0.069569,-0.20773 --0.72471,-0.63506,-0.90416 -2.2606,1.4825,1.0713 -2.3652,1.6683,1.9505 --1.2109,-1.1055,-0.74173 -0.54285,0.061023,0.39969 -0.2859,0.063151,0.2034 -1.1835,1.2188,0.55349 --0.13362,0.23424,0.3584 --0.6543,-0.18228,-0.18086 -0.069821,0.062013,-0.27292 --1.9428,-1.0853,-1.4398 --0.30367,0.21577,-0.17411 --2.5954,-1.661,-1.9047 -2.0915,1.5547,0.99733 --0.66147,0.24669,-0.91247 -1.0449,0.93571,0.67609 -2.79,1.6598,1.3183 --1.2251,-0.86033,-0.92547 --0.47749,-0.31028,0.28381 --0.83917,-0.55704,-0.72098 --0.44424,-0.20055,0.036599 -1.3774,0.44726,0.93602 --2.7122,-1.6899,-1.971 -1.5795,1.0201,1.3349 -1.0198,0.64548,0.78483 -0.26586,0.082714,0.14744 -0.89318,0.52973,0.95247 --0.50549,-0.28303,-0.15591 -1.9199,0.92191,2.0471 -0.16854,0.075471,-0.0013041 --0.8304,-0.81052,-0.71957 --0.52592,-0.13178,-0.058918 -2.0492,1.3384,1.0921 -0.096086,0.16658,0.25358 --0.32496,-0.19822,0.047477 -0.69332,0.40949,0.34234 --0.12205,0.11174,0.32665 -0.53087,0.70807,1.0442 --0.21918,-0.55076,-0.66202 -0.73438,0.60177,0.67892 -1.9349,1.0854,1.4055 --0.58814,-0.50452,-0.40968 -0.94596,0.74697,0.40055 --0.59185,0.085186,0.24409 --0.4935,-0.24149,0.022901 --0.087221,-0.66966,-0.010703 --0.38608,0.45916,0.33462 --0.83084,-0.54879,-0.093242 --2.0117,-1.4792,-1.8427 --1.5199,-0.84139,-1.1674 -0.79155,1.0173,0.5015 -2.1129,1.4386,1.2234 --1.7672,-0.78334,-1.3781 --0.69014,-0.36502,-0.53744 -1.1194,0.45094,0.47608 --0.13543,-0.19676,0.25159 -1.7041,1.1424,1.1918 --1.0752,-0.47173,-0.44865 --0.58392,-0.19985,0.27945 --2.5241,-1.8118,-2.0555 --1.4358,-0.95961,-0.83982 -1.6939,1.1447,0.99691 -0.42971,0.30098,0.54495 --0.67714,-0.53533,-0.93412 -0.43609,0.48985,0.51845 --0.89748,-0.25206,-0.7519 -0.76077,0.42051,0.41068 --2.5801,-1.5242,-1.5598 -1.5621,0.59058,1.3707 -0.19413,0.44966,0.18559 -0.83287,0.63661,0.71923 --0.92841,-0.9159,-0.54169 --1.7753,-0.94777,-1.5999 --1.8257,-1.6419,-2.0978 --2.7582,-2.0063,-2.1803 -0.19403,0.29537,0.3785 --2.1425,-1.4675,-1.5275 -1.6869,1.6411,1.7868 --0.82573,-0.77426,-0.8585 -1.7926,1.2485,1.1358 --0.07777,-0.38398,0.2103 --1.4628,-1.5751,-0.94737 -0.15511,0.2456,-0.00015967 -2.2556,1.3402,1.3315 --0.56449,-0.88906,-0.45505 --0.44463,-0.27583,-0.30232 -0.56572,0.67416,0.29062 -0.7031,0.3405,0.10012 --0.61347,0.2538,-0.45746 -0.85989,0.54276,0.17189 --1.0203,-0.451,-0.50111 --0.21224,-0.086635,-0.52003 -1.6299,1.6604,0.9542 -1.3413,0.85207,1.3466 -2.1215,1.5051,2.0916 -0.88292,0.85124,1.3464 -1.1126,1.188,0.71626 --0.94161,-0.84941,-1.1167 -0.59511,0.12208,0.69344 -0.82957,0.75011,0.21263 --0.22286,-0.10623,-0.08017 -2.223,1.0819,1.7043 -1.9981,0.84063,1.3287 --0.51718,-0.41875,-0.75394 --1.6022,-0.73683,-1.0581 --2.2361,-1.473,-1.1966 -0.2003,0.21059,0.25599 --1.2367,-0.6639,-0.74914 --0.93371,-0.45712,-0.68751 -1.7027,1.4047,1.3026 --1.2774,-1.2503,-0.58362 -0.46436,0.094888,0.25718 --0.88083,-0.53589,-0.13703 --1.7564,-1.0257,-0.9537 -1.6325,0.86482,1.1866 -1.2362,0.68078,0.64673 -1.0107,0.46862,0.37726 -0.24317,-0.20648,-0.024893 --0.082012,-0.38708,-0.16586 -0.015307,0.4308,0.42156 -1.1262,0.74924,1.176 --0.0027826,0.095791,-0.051756 --1.0674,-0.63713,-1.117 --1.1382,-1.0559,-1.1707 -2.0877,1.6548,2.0732 -0.16446,-0.085562,-0.15265 --2.3137,-1.3404,-1.9408 --0.72977,-0.31892,-0.49911 --0.49288,-0.26296,-0.29842 -0.75772,0.54729,0.50426 -2.132,2.0393,0.97536 -1.9366,1.5312,1.0894 --0.090977,0.036628,-0.079983 --0.35219,-0.37494,-0.88215 -0.69166,0.61819,0.96796 -0.97703,0.60073,0.24864 -0.5783,-0.29955,-0.014528 -0.089841,-0.12908,-0.20564 --1.0136,-0.64365,-0.39528 --1.1332,-0.7829,-0.61792 --0.082685,-0.36395,-0.18751 --0.97684,-0.69191,-0.81254 --1.5796,-0.8954,-1.0024 -0.27864,0.38203,0.63516 --2.2827,-1.5331,-1.4515 -0.069051,0.2767,-0.032954 -1.3377,0.66931,1.1616 --0.047892,0.25714,-0.061226 --1.0783,-1.0994,-0.9987 --0.84075,-0.24306,-0.46729 --0.052014,-0.016192,0.72783 --0.46478,-0.58935,0.35058 --1.4389,-0.44225,-0.77327 -1.1587,0.8115,1.07 -1.4183,1.272,1.0778 --0.2868,-0.67613,-0.34787 -1.0943,0.54473,0.59771 --0.29326,0.13868,-0.49131 -2.1389,1.6149,1.013 --1.4802,-0.36252,-1.1231 --1.5628,-0.9868,-0.87139 -1.2949,0.59369,1.2511 -1.0876,0.47897,0.82238 -0.11324,0.46251,-0.29949 -1.1912,0.36098,0.58126 -2.4647,1.8699,1.2898 --0.76676,-0.79698,-0.20654 --1.2144,-1.0235,-0.98019 -3.3002,2.1348,1.8857 --0.74422,-0.54289,-0.3079 --3.3523,-2.2829,-2.2629 -0.66829,-0.1914,0.56563 --1.5449,-0.82442,-0.79914 --0.3981,-0.25903,-0.47908 --1.0606,-0.88289,-0.93594 --0.40896,-0.53047,-0.68026 -1.1676,0.74974,1.0582 -0.88298,0.83254,1.0817 --0.80907,-0.8498,-0.9464 --1.7035,-0.75615,-1.0524 -3.0057,1.8151,1.7273 -0.43203,-0.022721,-0.18269 --2.1328,-1.496,-1.6208 -0.82725,0.46021,0.89021 -0.12842,0.20307,0.7547 --0.35628,-1.0951,-0.21788 -0.78708,0.32786,0.35763 --0.84097,-0.71616,-0.78011 --0.26128,-0.28711,-0.20192 --2.3,-1.5424,-1.6931 -0.19481,0.16885,0.48323 --0.21151,-0.42079,-0.48766 --3.7346,-3.0009,-2.5214 --3.6375,-2.126,-2.9477 -1.0444,0.93172,0.6988 --1.0959,-0.71016,-0.27227 --0.23977,-0.11101,-0.28146 --1.6543,-1.2306,-1.2255 --0.17048,0.00054806,-0.19426 --1.4264,-0.57421,-1.2455 -2.1076,1.4061,1.6389 -1.041,1.3285,0.86943 --3.0801,-2.1722,-2.2572 -2.0788,1.7827,2.0537 --0.22575,-0.92116,-0.91268 -0.44154,0.68306,0.71689 -1.4441,1.93,1.7792 -0.58056,0.32374,0.32775 -1.6292,1.4378,0.96915 --1.2164,-0.95555,-0.38366 --1.6149,-1.3085,-1.4474 -0.48657,0.20761,0.36362 -0.071001,-0.27576,-0.33847 --1.356,-1.2666,-0.51153 --0.095902,-0.51068,-0.15741 --2.4017,-1.7503,-1.5108 -0.96453,0.63806,0.56845 -0.36505,0.055197,0.67804 -0.94694,0.19412,0.62757 -1.6745,0.7548,1.0322 --0.94291,-0.63664,-0.60832 --0.64385,-0.18336,-0.50873 --0.13981,-0.85884,-0.26774 -0.97832,0.97541,0.6758 -1.5173,1.2477,1.1503 -0.5587,0.35433,1.3336 --0.078039,0.082989,-0.16007 -1.6394,1.2077,0.93681 --0.57367,-0.79813,-0.26396 -2.036,1.0049,1.1221 --1.6846,-0.83132,-1.1526 --0.33544,0.11605,-0.84109 --0.57212,-0.072023,-0.10241 --3.291,-1.716,-2.4594 --1.0749,-0.7409,-0.61314 --0.19901,-0.48184,-0.077611 --0.65909,-0.50267,-0.25114 -1.0921,0.49644,0.59822 --0.75208,-0.4143,-0.75187 -0.91208,0.80484,0.81955 --0.59465,-0.086926,0.024274 --1.567,-1.2596,-1.4882 -1.5991,1.3991,0.67735 -0.56413,0.47411,0.096418 --1.4452,-0.6456,-1.0912 -0.36851,0.66575,0.85542 --0.049404,-0.12279,-0.8877 --0.56902,0.097645,-0.29639 --0.86831,-0.66553,-0.71082 -0.72599,0.72612,0.40655 -1.4592,0.61515,0.65803 --0.4995,-0.6516,-0.73246 -2.0153,1.3239,1.7313 -0.45817,0.062575,0.35973 -1.4545,1.1961,0.82625 --0.75193,-0.6329,-0.75079 -0.77603,0.18932,0.22198 --2.5723,-1.6475,-1.5168 -3.1285,2.3162,2.1798 --0.29639,-0.32025,-0.17339 -1.0184,0.50337,0.45093 -1.7865,0.95189,0.86104 -1.1024,0.62887,1.0473 --1.5952,-0.74729,-1.0423 --0.38743,-0.4073,-0.017346 --0.41171,-0.47334,-0.21696 -0.54783,0.34265,0.1377 -0.22118,0.62041,0.68178 -0.11464,0.25669,0.18489 -2.7897,1.5837,2.0197 -2.7931,2.2432,1.7687 -3.1972,2.364,2.2072 -1.6225,1.4032,1.3007 --1.2668,-0.79879,-0.79138 --2.493,-1.7277,-1.7401 --1.0841,-0.69391,-0.99664 -1.0084,0.80389,0.96019 --0.092502,-0.026961,-0.24254 --0.11268,-0.11617,-0.27867 --0.2337,-0.39813,-0.34348 -1.8125,1.1174,1.4553 -1.4619,1.0344,1.2254 --0.16767,-0.55547,-0.41427 -0.74407,0.74255,0.63021 -2.2155,1.7229,1.445 --0.31377,-0.54679,-0.63182 --4.0817,-2.4425,-2.7721 -1.52,1.1267,1.3242 --4.3414,-3.1472,-2.9687 -0.2646,-0.38891,0.0041942 --0.11866,0.10528,0.49905 --0.44437,-0.12049,-0.62861 --0.96011,-0.69258,-0.83422 -0.8599,0.86347,0.43738 -1.8198,1.0826,0.79188 -0.79687,0.75117,0.97561 -0.61907,0.5121,0.86484 --0.21279,0.24918,-0.14006 -1.4138,1.5817,0.6476 -0.82272,1.4893,1.2821 --3.0504,-1.9808,-2.2807 -0.50188,0.31133,0.64678 -0.69242,0.18996,0.70653 --0.69502,-0.89104,-0.61337 --0.086855,0.39483,-0.43195 --0.94864,-0.32641,-0.52372 --0.2027,-0.11435,0.019343 --0.21543,-0.70036,0.20125 -0.45425,0.40563,0.2627 --1.5945,-1.2596,-1.1636 -0.68887,0.97224,0.8808 -0.72542,0.54717,0.51627 --1.2184,-1.295,-0.78843 -0.050938,-0.59564,0.26942 --0.50778,-0.33381,-0.32208 -1.2101,0.89738,1.1816 -0.19303,0.55456,0.36781 -1.0831,0.63724,0.6597 --2.1071,-1.0357,-1.1528 --0.6975,1.4989,-2.0576 -1.3339,3.158,0.28043 --0.21156,1.7577,-1.1117 -0.71906,2.757,-0.16608 --2.9855,-0.098775,-3.1358 -1.2023,3.2514,0.23115 --1.4018,0.36674,-2.1768 --1.3135,0.69125,-2.3323 -0.40552,2.1893,-1.0071 -1.7846,3.3717,0.52439 -1.6608,3.4361,0.42267 --0.073565,2.2652,-0.91654 -1.7209,3.5658,0.3006 -3.1882,4.5977,1.2658 --0.98642,1.5746,-1.7768 --0.27873,1.9078,-0.75813 --1.6402,0.6321,-2.0068 --0.70304,1.7379,-1.8066 --1.218,1.3822,-2.2175 --1.4349,0.51271,-1.8798 -2.2768,3.5436,0.57225 -1.5041,3.1356,-0.040765 --1.4241,1.156,-1.7804 --0.11436,1.5936,-1.7267 -2.0326,3.2524,0.28491 -0.47749,2.5039,-0.43539 -1.9338,3.4122,-0.24489 --2.3058,0.33874,-2.5696 -0.56056,2.3458,-0.67084 -0.83114,2.5705,-0.81666 --1.0925,0.69583,-2.2979 -2.2531,3.6528,1.0971 -0.70366,2.8862,-0.69233 --3.1376,-0.77693,-3.1593 --2.0105,0.65166,-2.1592 -1.7621,3.2052,0.65159 -0.045573,2.2617,-1.1421 -1.7276,3.0103,-0.11184 --0.14445,1.8207,-1.6921 -0.63983,2.5637,-0.88859 --1.9887,0.61969,-2.5127 --0.77862,1.8045,-1.3129 --0.47354,2.0831,-1.0346 -1.6157,2.9863,-0.098237 --0.66193,1.694,-1.5622 -0.16656,1.9625,-1.3294 -0.019699,2.3942,-0.63286 --0.92534,0.80855,-1.6135 -1.6386,2.9127,0.12334 -2.0057,4.3021,0.98863 -0.42154,2.4704,-0.60246 -0.82108,2.811,0.2437 -1.0293,2.9829,-0.098867 --1.813,0.67728,-1.8287 -1.783,3.1082,0.53828 --2.8269,0.13975,-2.0776 --1.434,1.1184,-2.6909 --0.83207,1.3951,-1.8767 -0.56244,1.7977,-0.35071 -0.47069,2.6147,-0.092379 --0.8347,1.2527,-1.6997 --1.8894,0.99539,-3.1665 -0.8026,2.5401,-0.56001 --0.91527,1.3677,-1.2284 -0.86685,2.4212,-0.52196 -0.73631,2.0199,-0.17259 -1.7798,3.0943,0.51861 --1.5598,1.2132,-2.2322 --1.103,0.6916,-2.3906 -0.51962,2.6022,-0.29134 --1.5924,0.95891,-1.7576 --0.95417,1.1914,-1.8069 --0.12115,2.0963,-1.5694 --0.41383,1.4943,-1.2149 -1.0867,2.4675,-0.14368 --1.0036,1.2464,-1.7938 -0.72484,2.6398,-0.6255 --0.85135,1.4769,-1.917 --1.3774,1.1765,-1.0353 -2.3671,4.151,1.2582 --0.13561,2.2608,-0.94996 --0.23044,2.4257,-0.97189 --0.88372,2.1966,-1.726 --0.58,1.0952,-1.7096 -1.4994,2.8147,-0.32391 --1.0274,1.2879,-2.0903 --1.2796,1.5774,-1.5094 --0.5797,1.8505,-1.12 --2.2636,0.93248,-2.4786 -0.44527,2.4684,-0.79258 --0.9497,1.1252,-1.845 -3.1904,4.0746,0.9626 -1.1631,2.7269,-0.16504 --1.4672,0.83207,-1.7914 -2.8576,3.866,0.88194 -0.029754,2.0093,-0.92291 --0.91592,1.0553,-1.8036 --1.0762,1.5832,-1.6021 -0.18524,2.2429,-0.86124 --0.10256,1.8428,-0.66094 -1.2697,2.7612,-0.24163 -0.11362,2.0066,-0.96279 -0.19997,2.1961,-0.8314 --1.7592,1.0069,-2.2993 --1.1581,1.1919,-2.1469 --0.63746,1.4558,-2.0375 -2.334,3.4055,0.20539 --2.5274,0.11164,-2.7256 --1.4836,1.1463,-1.8476 --0.58334,1.9402,-1.4465 --0.36482,2.1239,-1.1651 --0.52351,1.4415,-0.65888 --1.949,0.21604,-2.2428 -3.5584,4.8393,1.1236 -1.4703,3.0185,0.49572 --2.8211,0.43784,-2.1897 --0.16361,2.1039,-1.3668 -2.5709,4.0932,0.87071 -0.73265,2.5907,-0.57969 -0.51022,2.1651,-1.2727 -0.76899,1.438,-0.98371 --0.17128,1.686,-1.092 --1.3756,1.0289,-2.1046 -1.0948,2.3309,-0.51105 -3.3282,4.1039,1.2859 --2.0546,0.42604,-2.4117 -0.43204,2.4321,-0.94615 -0.83036,2.5444,-0.22365 -1.4318,3.6561,0.58497 -0.15545,2.3575,-0.61828 -0.98966,2.4873,-0.43824 -3.0079,3.8561,1.0926 -0.20354,2.3151,-1.1964 --1.9902,0.65356,-1.8136 --2.4573,0.54143,-2.7738 --1.1332,1.4395,-1.7194 -0.92719,2.376,-0.82608 -0.92359,2.7603,0.046319 -1.1171,2.9485,-0.0073154 --0.55831,1.2599,-1.718 --2.3207,0.38527,-1.8988 -1.4801,2.986,-0.28044 -0.30903,1.3085,-0.55672 --0.69243,1.3502,-1.4509 -1.3048,3.1819,0.33704 -0.91085,2.0965,-0.30135 --0.80932,1.4345,-1.6792 -0.81549,2.4671,-0.33384 -0.38334,2.0974,-0.69991 --0.01149,1.5004,-1.4347 --3.0522,-0.024838,-3.4975 --1.455,1.1918,-1.8266 --0.85504,1.7392,-1.711 -1.5975,2.9864,0.22816 -0.14029,2.346,-0.95771 -0.29979,2.358,-0.81355 --1.0671,1.1941,-1.6453 --1.8216,1.0167,-1.8793 -0.84552,2.7756,-0.83241 -0.93044,2.5845,-0.55008 --0.9566,0.62371,-1.7985 --1.1376,1.7187,-1.1157 --1.1067,1.5265,-1.3179 --0.36322,1.9674,-1.1235 -1.366,2.7897,-0.055666 -0.332,2.0888,-0.83667 --1.9542,0.9743,-2.0177 -0.096801,2.5064,-0.8073 -1.5374,3.0921,-0.22269 -0.41843,2.5863,-0.77146 -0.80082,3.0112,-0.32801 -1.6812,3.4572,-0.51982 --0.55307,1.8701,-1.69 --0.24206,1.3421,-1.4736 --0.25654,2.2437,-0.99187 -0.014638,1.7969,-1.4376 --0.1745,1.9168,-1.5279 -0.11876,1.9746,-0.49863 -1.6836,3.1278,-0.030485 --1.7754,0.26854,-2.9489 --1.1159,0.95009,-1.4111 --0.8181,1.4136,-1.5501 --0.54368,1.8649,-1.1626 --1.1901,1.5496,-1.6707 --2.0537,0.3338,-2.5033 --0.24753,1.8794,-1.0107 --0.72903,1.8224,-1.6435 -0.038166,1.9963,-0.67844 --0.638,1.774,-1.5228 -0.42271,1.9838,-1.1418 --1.2348,0.98551,-1.8549 --1.7239,1.1747,-2.1135 --0.015513,1.3959,-0.86992 -1.7031,3.0449,-0.25698 --1.3881,1.0682,-2.1338 --1.1969,1.7697,3.9208 --1.2424,1.4604,3.6047 --1.3163,0.93889,2.8365 --2.8288,0.045368,2.2851 --2.7684,0.13886,1.9198 --0.60191,2.4719,3.8042 --0.39537,1.8476,4.2524 -0.44816,2.6351,4.8098 --1.0442,1.5827,3.8989 --3.6402,0.14778,1.9706 --2.45,0.78979,2.5683 --1.7225,0.73554,3.158 --0.69631,2.2939,4.1272 --2.8072,-0.069145,1.7978 --1.6416,1.5689,3.3282 --3.0648,0.17403,2.4512 --2.0258,0.87394,3.389 --2.5863,0.45752,2.9173 --1.5265,1.8141,4.0588 --4.2433,-0.17808,1.6443 --2.9551,0.18985,1.9159 --1.2529,1.4453,3.5425 --1.8285,0.64726,2.5959 --3.1628,0.046687,1.7174 --1.6728,1.4828,3.2985 --1.6953,1.3002,3.2336 --1.6847,0.97183,3.1077 --1.5924,1.4341,3.4936 --0.70679,1.4356,3.8973 --2.3524,0.85287,2.8275 --2.3738,0.65846,2.3619 --3.539,-0.56682,2.2519 --1.0962,1.2734,3.7768 --3.8573,-0.16291,1.432 --3.8752,-0.40234,2.4318 -0.33871,2.711,5.3221 --2.0428,1.2251,3.07 --1.9655,1.2908,2.9416 --3.0731,0.43096,2.0358 --1.9089,1.0828,2.672 --1.3803,1.7463,3.5046 --0.034521,1.9667,4.0039 --1.1235,1.1656,3.2068 --1.8109,1.4349,3.0943 --2.0088,1.0847,2.9151 --0.31351,1.8273,3.5788 --1.295,1.4664,3.2349 --1.2371,1.9161,4.2493 --2.7012,0.30699,2.9857 --3.0858,0.35541,2.2666 --2.5561,0.22266,1.7668 --2.0615,0.95838,2.3282 --6.4281,-2.209,0.059564 --0.61075,1.7083,3.6271 -0.72189,2.6927,4.7195 --2.3989,0.63415,3.1581 --1.0935,1.3178,3.712 --2.2726,0.72421,2.978 --0.70414,1.7072,3.6075 --0.55165,1.7327,4.2121 --1.3224,0.73273,3.2907 --1.4177,1.6338,3.6401 -0.068642,1.954,4.1146 --3.7918,-0.48566,1.8536 --2.5556,0.73785,2.9208 --1.5831,1.1366,3.1914 -0.41068,2.7159,4.8655 --1.428,1.1453,3.0639 --0.46294,1.8412,4.3182 -0.22348,2.0181,4.379 --2.2658,1.0376,2.7409 --3.591,0.30847,1.7559 --2.0455,0.58627,2.9203 -0.93646,3.1056,5.0571 --0.70905,1.8272,3.9991 --1.1255,1.9211,3.5726 -0.37208,3.0153,4.8578 -0.27377,2.3156,4.8376 --0.53999,2.2613,4.4015 --2.1156,0.66801,2.4573 -0.015444,2.664,4.6196 --1.7627,0.95155,3.4429 --2.6128,0.63736,2.3568 --7.4142,-3.0846,-0.83159 --2.9964,-0.16066,2.233 --2.5093,-0.088607,2.1958 --5.7356,-1.9153,0.27291 --1.7637,1.2192,3.3577 --3.0144,0.33408,2.272 --1.1035,2.0463,3.6744 -0.29377,2.7,4.0339 -7.6709,-0.65356,-6.146 --1.2698,0.37012,3.5987 --3.8242,-5.9383,8.3664 -6.4851,1.6129,-9.0761 -3.7499,1.954,7.6171 -0.60828,3.1314,-1.5524 --6.4482,1.6296,-0.8863 -7.9403,5.2769,2.3478 -6.1994,-6.7288,4.8542 --2.2174,6.795,9.9198 --0.42004,9.9264,8.5588 -2.148,3.2027,-9.6178 -3.0381,-7.5349,-2.3754 -5.2505,1.7427,3.1399 --1.0458,-7.0753,-9.4356 -2.8597,8.9945,2.2305 --4.3883,4.8396,0.47878 --1.1343,7.4522,2.4586 --5.0359,-6.7081,-7.2111 --6.9676,-0.5243,-0.97505 --5.8695,-3.0673,-1.8167 -8.2832,-4.0377,8.1787 -1.6522,-9.1964,-1.9773 -3.8661,-2.368,-6.1853 -7.1298,-7.3613,6.3322 --0.27049,-7.1403,-1.549 --3.1454,-2.3609,-2.2842 --1.6271,2.7362,4.3218 --7.6258,5.6069,2.1053 -0.37131,-1.4426,-8.3637 -9.4317,-6.5751,-7.3919 --3.4185,-2.6663,-2.6426 --3.2166,9.5563,1.2013 -6.0375,-0.81393,4.8038 --6.806,7.4827,9.649 --6.8151,-6.9582,-0.28445 --6.7267,-1.1509,-9.9922 -8.287,8.4159,5.6332 -5.5004,9.6078,-3.0566 --1.4023,-0.72913,-4.0823 --4.8169,-3.1102,6.6306 -2.4477,-5.8111,-8.0409 -9.705,-3.6756,-2.5232 -2.7386,7.9568,2.8053 --5.3387,-8.5872,-9.3185 -5.69,-5.0415,-3.6123 --9.9319,-9.6028,9.2331 -5.9482,9.9372,3.3279 --5.8469,-7.9974,-8.2701 --6.0094,8.3772,-4.8887 -9.5516,-7.3199,-7.1452 -2.4614,-5.899,-4.4542 --8.8957,-6.7169,5.5289 --7.154,5.541,4.1596 --1.8432,1.2028,2.0585 -5.563,3.3022,-9.2116 --6.7447,7.4713,6.9136 --9.4759,2.1966,-5.4052 -7.0271,8.7768,-0.098737 --4.9415,-4.2886,-9.3987 --2.0969,5.2979,2.9589 -3.7458,-7.0135,-1.9911 -7.4198,2.3875,5.3503 -3.6197,2.4641,-2.3227 --7.216,6.167,7.8282 -1.5398,-3.6429,-1.8442 -3.6883,-3.0284,-2.4634 --3.6761,-4.9286,-8.231 -0.2367,8.4299,9.6515 --1.078,4.0697,8.4339 -0.40362,4.1245,-0.76191 --2.6794,-6.9877,1.2293 -3.0462,4.0747,-0.13222 -7.4312,-8.5241,9.8795 -7.3594,-8.9495,-9.4865 -0.59609,0.47255,-4.8097 -9.1863,2.9909,-3.4567 -1.8203,-5.3323,-7.5425 --9.5337,-7.1973,4.9186 --6.3554,-5.2483,2.5872 --0.65065,7.4834,-6.0681 -2.2684,7.2147,-0.72463 --7.2069,3.0322,-4.6809 --5.7646,7.4828,-9.9276 -9.8014,9.2737,-7.6849 --3.3992,8.9312,1.1783 --1.4833,7.7265,7.8454 --7.0749,0.75356,8.0241 -0.91467,6.2634,3.9977 --8.1604,-5.15,-5.3245 --1.3009,-2.721,0.59003 --8.3264,3.5507,6.0953 -1.0982,-6.0583,3.9963 --9.6435,-6.1097,-9.9918 -2.8821,1.0076,-4.2984 --2.1547,-9.6324,-6.5842 --3.4672,-6.7797,-5.9353 --4.7036,0.70339,-8.1064 -0.20557,-1.4378,-9.2265 --0.88981,-1.8582,-2.1328 -6.2075,6.6453,-5.3313 diff --git a/fastlib/u/pram/mog_em/faster/math_functions.h b/fastlib/u/pram/mog_em/faster/math_functions.h deleted file mode 100644 index 2349bc9d06..0000000000 --- a/fastlib/u/pram/mog_em/faster/math_functions.h +++ /dev/null @@ -1,138 +0,0 @@ -/** - * @author Parikshit Ram (pram@cc.gatech.edu) - * @file math_functions.h - * - * This file has certain functions that find the - * highest or lowest element in an array or - * in a row of a matrix and returns them - * - */ - -#include "fastlib/fastlib.h" -#include "fastlib/fastlib_int.h" - - -/** - * Finds the index of the minimum element - * in each row of a matrix - * - * Example use: - * @code - * Matrix& mat; - * index_t indices[mat.n_rows()]; - * - * ... - * - * min_element(mat, indices); - * @endcode - */ - -void min_element(Matrix& element, index_t *indices) { - - index_t last = element.n_cols() - 1; - index_t first, lowest; - index_t i; - - for (i = 0; i < element.n_rows(); i++) { - - first = lowest = 0; - if (first == last) { - indices[i] = last; - } - while (++first <= last) { - if (element.get(i, first) < element.get(i, lowest)) { - lowest = first; - } - } - indices[i] = lowest; - } - return; -} - -/** - * Returns the index of the maximum element - * in a float array 'array' of length 'length'. - * - * Example use: - * @code - * index_t length, index; - * float array[length]; - * ... - * index = max_element_index(array, length); - * @endcode - */ -int max_element_index(float *array, int length) { - - int last = length - 1; - int first = 0; - int highest = 0; - - if (first == last) { - return last; - } - while (++first <= last) { - if (array[first] > array[highest]) { - highest = first; - } - } - return highest; -} - -/** - * Finds the index of the maximum element in an arraylist - * of floats - * - * Example use: - * @code - * index_t index; - * ArrayList array; - * ... - * index = max_element_index(array); - * @endcode - */ -int max_element_index(ArrayList& array){ - - int last = array.size() - 1; - int first = 0; - int highest = 0; - - if (first == last) { - return last; - } - while (++first <= last) { - if (array[first] > array[highest]) { - highest = first; - } - } - return highest; -} - -/** - * Returns the index of the maximum element in - * an arraylist of doubles - * - * Example use: - * @code - * index_t index; - * ArrayList array; - * ... - * index = max_element_index(array); - * @endcode - */ -int max_element_index(ArrayList& array) { - - int last = array.size() - 1; - int first = 0; - int highest = 0; - - if (first == last) { - return last; - } - while (++first <= last) { - if(array[first] > array[highest]) { - highest = first; - } - } - return highest; -} - diff --git a/fastlib/u/pram/mog_em/faster/mog.cc b/fastlib/u/pram/mog_em/faster/mog.cc deleted file mode 100644 index 85d377d2ce..0000000000 --- a/fastlib/u/pram/mog_em/faster/mog.cc +++ /dev/null @@ -1,301 +0,0 @@ -/** - * @author Parikshit Ram (pram@cc.gatech.edu) - * @file mog.cc - * - * Implementation for the loglikelihood function, the EM algorithm - * and also computes the K-means for getting an initial point - * - */ - -#include "mog.h" -#include "phi.h" -#include "math_functions.h" - -void MoGEM::ExpectationMaximization(Matrix& data_points) { - - // Declaration of the variables */ - index_t num_points; - index_t dim, num_gauss; - double sum, tmp; - ArrayList mu_temp, mu; - ArrayList sigma_temp, sigma; - Vector omega_temp, omega, x; - Matrix cond_prob; - long double l, l_old, best_l, INFTY = 99999, TINY = 1.0e-10; - - // Initializing values - dim = dimension(); - num_gauss = number_of_gaussians(); - num_points = data_points.n_cols(); - - // Initializing the number of the vectors and matrices - // according to the parameters input - mu_temp.Init(num_gauss); - mu.Init(num_gauss); - sigma_temp.Init(num_gauss); - sigma.Init(num_gauss); - omega_temp.Init(num_gauss); - omega.Init(num_gauss); - - // Allocating size to the vectors and matrices - // according to the dimensionality of the data - for(index_t i = 0; i < num_gauss; i++) { - mu_temp[i].Init(dim); - mu[i].Init(dim); - sigma_temp[i].Init(dim, dim); - sigma[i].Init(dim, dim); - } - x.Init(dim); - cond_prob.Init(num_gauss, num_points); - - best_l = -INFTY; - index_t restarts = 0; - // performing 5 restarts and choosing the best from them - while (restarts < 1) { - - // assign initial values to 'mu', 'sig' and 'omega' using k-means - KMeans(data_points, &mu_temp, &sigma_temp, &omega_temp, num_gauss); - - l_old = -INFTY; - - // calculates the loglikelihood value - l = Loglikelihood(data_points, mu_temp, sigma_temp, omega_temp); - - // added a check here to see if any - // significant change is being made - // at every iteration - while (l - l_old > TINY) { - // calculating the conditional probabilities - // of choosing a particular gaussian given - // the data and the present theta value - /********** - for (index_t j = 0; j < num_points; j++) { - x.CopyValues(data_points.GetColumnPtr(j)); - sum = 0; - for (index_t i = 0; i < num_gauss; i++) { - tmp = phi(x, mu_temp[i], sigma_temp[i]) * omega_temp.get(i); // can be made faster by sending all the data at once instead of looping over - cond_prob.set(i, j, tmp); - sum += tmp; - } - for (index_t i = 0; i < num_gauss; i++) { - tmp = cond_prob.get(i, j); - cond_prob.set(i, j, tmp / sum); - } - } - ******/ - - /*******FIX THIS SOON********/ - Vector phi_val; - phi_val.Init(num_points); - - for(index_t i = 0; i < num_gauss; i++) { - phi_val.CopyValues(phi(data_points, mu_temp[i], sigma_temp[i])); - la::Scale(omega_temp.get(i), &phi_val); - */ - - // calculating the new value of the mu - // using the updated conditional probabilities - for (index_t i = 0; i < num_gauss; i++) { - sum = 0; - mu_temp[i].SetZero(); - for (index_t j = 0; j < num_points; j++) { - x.CopyValues(data_points.GetColumnPtr(j)); - la::AddExpert(cond_prob.get(i, j), x, &mu_temp[i]); - sum += cond_prob.get(i, j); - } - la::Scale((1.0 / sum), &mu_temp[i]); - } - - // calculating the new value of the sig - // using the updated conditional probabilities - // and the updated mu - for (index_t i = 0; i < num_gauss; i++) { - sum = 0; - sigma_temp[i].SetZero(); - for (index_t j = 0; j < num_points; j++) { - Matrix co, ro, c; - c.Init(dim, dim); - x.CopyValues(data_points.GetColumnPtr(j)); - la::SubFrom(mu_temp[i] , &x); - co.AliasColVector(x); - ro.AliasRowVector(x); - la::MulOverwrite(co, ro, &c); - la::AddExpert(cond_prob.get(i, j), c, &sigma_temp[i]); - sum += cond_prob.get(i, j); - } - la::Scale((1.0 / sum), &sigma_temp[i]); - } - - // calculating the new values for omega - // using the updated conditional probabilities - Vector identity_vector; - identity_vector.Init(num_points); - identity_vector.SetAll(1.0 / num_points); - la::MulOverwrite(cond_prob, identity_vector, &omega_temp); - - l_old = l; - l = Loglikelihood(data_points, mu_temp, sigma_temp, omega_temp); - } - - // putting a check to see if the best one is chosen - if(l > best_l){ - best_l = l; - for (index_t i = 0; i < num_gauss; i++) { - mu[i].CopyValues(mu_temp[i]); - sigma[i].CopyValues(sigma_temp[i]); - } - omega.CopyValues(omega_temp); - } - restarts++; - } - - for (index_t i = 0; i < num_gauss; i++) { - set_mu(i, mu[i]); - set_sigma(i, sigma[i]); - } - set_omega(omega); - - NOTIFY("loglikelihood value of the estimated model: %Lf\n", best_l); - return; -} - -long double MoGEM::Loglikelihood(Matrix& data_points, ArrayList& means, - ArrayList& covars, Vector& weights) { - - index_t i, j; - Vector x; - long double likelihood, loglikelihood = 0; - - x.Init(data_points.n_rows()); - - for (j = 0; j < data_points.n_cols(); j++) { - x.CopyValues(data_points.GetColumnPtr(j)); - likelihood = 0; - for(i = 0; i < number_of_gaussians() ; i++){ - likelihood += weights.get(i) * phi(x, means[i], covars[i]); - } - loglikelihood += log(likelihood); - } - return loglikelihood; -} - -void MoGEM::KMeans(Matrix& data, ArrayList *means, - ArrayList *covars, Vector *weights, index_t value_of_k){ - - - ArrayList mu, mu_old; - double* tmpssq; - double* sig; - double* sig_best; - index_t *y; - Vector x, diff; - Matrix ssq; - index_t i, j, k, n, t, dim; - double score, score_old, sum; - - n = data.n_cols(); - dim = data.n_rows(); - mu.Init(value_of_k); - mu_old.Init(value_of_k); - tmpssq = (double*)malloc(value_of_k * sizeof( double )); - sig = (double*)malloc(value_of_k * sizeof( double )); - sig_best = (double*)malloc(value_of_k * sizeof( double )); - ssq.Init(n, value_of_k); - - for( i = 0; i < value_of_k; i++){ - mu[i].Init(dim); - mu_old[i].Init(dim); - } - x.Init(dim); - y = (index_t*)malloc(n * sizeof(index_t)); - diff.Init(dim); - - score_old = 999999; - - // putting 5 random restarts to obtain the k-means - for(i = 0; i < 5; i++){ - t = -1; - for (k = 0; k < value_of_k; k++){ - t = (t + 1 + (rand()%((n - 1 - (value_of_k - k)) - (t + 1)))); - mu[k].CopyValues(data.GetColumnPtr(t)); - for(j = 0; j < n; j++){ - x.CopyValues( data.GetColumnPtr(j)); - la::SubOverwrite(mu[k], x, &diff); - ssq.set( j, k, la::Dot(diff, diff)); - } - } - min_element(ssq, y); - - do{ - for(k = 0; k < value_of_k; k++){ - mu_old[k].CopyValues(mu[k]); - } - - for(k = 0; k < value_of_k; k++){ - index_t p = 0; - mu[k].SetZero(); - for(j = 0; j < n; j++){ - x.CopyValues(data.GetColumnPtr(j)); - if(y[j] == k){ - la::AddTo(x, &mu[k]); - p++; - } - } - - if(p == 0){ - } - else{ - double sc = 1 ; - sc = sc / p; - la::Scale(sc , &mu[k]); - } - for(j = 0; j < n; j++){ - x.CopyValues(data.GetColumnPtr(j)); - la::SubOverwrite(mu[k], x, &diff); - ssq.set(j, k, la::Dot(diff, diff)); - } - } - min_element(ssq, y); - - sum = 0; - for(k = 0; k < value_of_k; k++) { - la::SubOverwrite(mu[k], mu_old[k], &diff); - sum += la::Dot(diff, diff); - } - }while(sum != 0); - - for(k = 0; k < value_of_k; k++){ - index_t p = 0; - tmpssq[k] = 0; - for(j = 0; j < n; j++){ - if(y[j] == k){ - tmpssq[k] += ssq.get(j, k); - p++; - } - } - sig[k] = sqrt(tmpssq[k] / p); - } - - score = 0; - for(k = 0; k < value_of_k; k++){ - score += tmpssq[k]; - } - score = score / n; - - if (score < score_old) { - score_old = score; - for(k = 0; k < value_of_k; k++){ - (*means)[k].CopyValues(mu[k]); - sig_best[k] = sig[k]; - } - } - } - - for(k = 0; k < value_of_k; k++){ - x.SetAll(sig_best[k]); - (*covars)[k].SetDiagonal(x); - } - double tmp = 1; - (*weights).SetAll(tmp / value_of_k); - return; -} diff --git a/fastlib/u/pram/mog_em/faster/mog.h b/fastlib/u/pram/mog_em/faster/mog.h deleted file mode 100644 index 3acefe9bca..0000000000 --- a/fastlib/u/pram/mog_em/faster/mog.h +++ /dev/null @@ -1,244 +0,0 @@ -/** - * @author Parikshit Ram (pram@cc.gatech.edu) - * @file mog.h - * - * Defines a Gaussian Mixture model and - * estimates the parameters of the model - */ - -#ifndef MOGEM_H -#define MOGEM_H - -#include - -/** - * A Gaussian mixture model class. - * - * This class uses maximum likelihood loss functions to - * estimate the parameters of a gaussian mixture - * model on a given data via the EM algorithm. - * - * - * Example use: - * - * @code - * MoGEM mog; - * ArrayList results; - * - * mog.Init(number_of_gaussians, dimension); - * mog.ExpectationMaximization(data, &results, optim_flag); - * @endcode - */ -class MoGEM { - - private: - - // The parameters of the mixture model - ArrayList mu_; - ArrayList sigma_; - Vector omega_; - index_t number_of_gaussians_; - index_t dimension_; - - public: - - MoGEM() { - mu_.Init(0); - sigma_.Init(0); - } - - ~MoGEM() { - } - - void Init(index_t num_gauss, index_t dimension) { - - // Initialize the private variables - number_of_gaussians_ = num_gauss; - dimension_ = dimension; - - // Resize the ArrayList of Vectors and Matrices - mu_.Resize(number_of_gaussians_); - sigma_.Resize(number_of_gaussians_); - } - - void Init(datanode *mog_em_module) { - - index_t num_gauss = fx_param_int_req(mog_em_module, "K"); - index_t dim = fx_param_int_req(mog_em_module, "D"); - Init(num_gauss, dim); - } - // The get functions - - ArrayList& mu() { - return mu_; - } - - ArrayList& sigma() { - return sigma_; - } - - Vector& omega() { - return omega_; - } - - index_t number_of_gaussians() { - return number_of_gaussians_; - } - - index_t dimension() { - return dimension_; - } - - Vector& mu(index_t i) { - return mu_[i] ; - } - - Matrix& sigma(index_t i) { - return sigma_[i]; - } - - double omega(index_t i) { - return omega_.get(i); - } - - // The set functions - - void set_mu(index_t i, Vector& mu) { - DEBUG_ASSERT(i < number_of_gaussians()); - DEBUG_ASSERT(mu.length() == dimension()); - mu_[i].Copy(mu); - return; - } - - void set_mu(index_t i, index_t length, const double *mu) { - DEBUG_ASSERT(i < number_of_gaussians()); - DEBUG_ASSERT(length == dimension()); - mu_[i].Copy(mu, length); - return; - } - - void set_sigma(index_t i, Matrix& sigma) { - DEBUG_ASSERT(i < number_of_gaussians()); - DEBUG_ASSERT(sigma.n_rows() == dimension()); - DEBUG_ASSERT(sigma.n_cols() == dimension()); - sigma_[i].Copy(sigma); - return; - } - - void set_omega(Vector& omega) { - DEBUG_ASSERT(omega.length() == number_of_gaussians()); - omega_.Copy(omega); - return; - } - - void set_omega(index_t length, const double *omega) { - DEBUG_ASSERT(length == number_of_gaussians()); - omega_.Copy(omega, length); - return; - } - - - /** - * This function outputs the parameters of the model - * to an arraylist of doubles - * - * @code - * ArrayList results; - * mog.OutputResults(&results); - * @endcode - */ - void OutputResults(ArrayList *results) { - - // Initialize the size of the output array - (*results).Init(number_of_gaussians_ * (1 + dimension_*(1 + dimension_))); - - // Copy values to the array from the private variables of the class - for (index_t i = 0; i < number_of_gaussians_; i++) { - (*results)[i] = omega(i); - for (index_t j = 0; j < dimension_; j++) { - (*results)[number_of_gaussians_ + i*dimension_ + j] = mu(i).get(j); - for (index_t k = 0; k < dimension_; k++) { - (*results)[number_of_gaussians_*(1 + dimension_) - + i*dimension_*dimension_ + j*dimension_ - + k] = sigma(i).get(j, k); - } - } - } - } - - /** - * This function prints the parameters of the model - * - * @code - * mog.Display(); - * @endcode - */ - void Display(){ - - // Output the model parameters as the omega, mu and sigma - printf(" Omega : [ "); - for (index_t i = 0; i < number_of_gaussians_; i++) { - printf("%lf ", omega(i)); - } - printf("]\n"); - printf(" Mu : \n["); - for (index_t i = 0; i < number_of_gaussians_; i++) { - for (index_t j = 0; j < dimension_ ; j++) { - printf("%lf ", mu(i).get(j)); - } - printf(";"); - if (i == (number_of_gaussians_ - 1)) { - printf("\b]\n"); - } - } - printf("Sigma : "); - for (index_t i = 0; i < number_of_gaussians_; i++) { - printf("\n["); - for (index_t j = 0; j < dimension_ ; j++) { - for(index_t k = 0; k < dimension_ ; k++) { - printf("%lf ",sigma(i).get(j, k)); - } - printf(";"); - } - printf("\b]"); - } - printf("\n"); - } - - /** - * This function calculates the parameters of the model - * using the Maximum Likelihood function via the - * Expectation Maximization (EM) Algorithm. - * - * @code - * MoG mog; - * Matrix data = "the data on which you want to fit the model"; - * ArrayList results; - * mog.ExpectationMaximization(data, &results); - * @endcode - */ - void ExpectationMaximization(Matrix& data_points); - - /** - * This function computes the loglikelihood of model. - * This function is used by the 'ExpectationMaximization' - * function. - * - */ - long double Loglikelihood(Matrix& data_points, ArrayList& means, - ArrayList& covars, Vector& weights); - - /** - * This function computes the k-means of the data and stores - * the calculated means and covariances in the ArrayList - * of Vectors and Matrices passed to it. It sets the weights - * uniformly. - * - * This function is used to obtain a starting point for - * the optimization - */ - void KMeans(Matrix& data, ArrayList *means, - ArrayList *covars, Vector *weights, index_t value_of_k); -}; - -#endif diff --git a/fastlib/u/pram/mog_em/faster/mog_em_main.cc b/fastlib/u/pram/mog_em/faster/mog_em_main.cc deleted file mode 100644 index 6e64a9bf87..0000000000 --- a/fastlib/u/pram/mog_em/faster/mog_em_main.cc +++ /dev/null @@ -1,72 +0,0 @@ -/** - * @author Parikshit Ram (pram@cc.gatech.edu) - * @file mog_l2e_main.cc - * - * This program test drives the L2 estimation - * of a Gaussian Mixture model. - * - * PARAMETERS TO BE INPUT: - * - * --data - * This is the file that contains the data on which - * the model is to be fit - * - * --mog_em/K - * This is the number of gaussians we want to fit - * on the data, defaults to '1' - * - * --output - * This file will contain the parameters estimated, - * defaults to 'ouotput.csv' - * - */ - -#include "mog.h" - - -int main(int argc, char* argv[]) { - - fx_init(argc, argv); - - ////// READING PARAMETERS AND LOADING DATA ////// - - const char *data_filename = fx_param_str_req(NULL, "data"); - - Matrix data_points; - data::Load(data_filename, &data_points); - - ////// MIXTURE OF GAUSSIANS USING EM ////// - - MoGEM mog; - - struct datanode* mog_em_module = fx_submodule(NULL, "mog_em", "mog_em"); - fx_param_int(mog_em_module, "K", 1); - fx_format_param(mog_em_module, "D", "%d", data_points.n_rows()); - - ////// Timing the initialization of the mixture model ////// - fx_timer_start(mog_em_module, "model_init"); - mog.Init(mog_em_module); - fx_timer_stop(mog_em_module, "model_init"); - - ////// Computing the parameters of the model using the EM algorithm ////// - ArrayList results; - - fx_timer_start(mog_em_module, "EM"); - mog.ExpectationMaximization(data_points); - fx_timer_stop(mog_em_module, "EM"); - - mog.Display(); - mog.OutputResults(&results); - - ////// OUTPUT RESULTS ////// - - const char *output_filename = fx_param_str(NULL, "output", "output.csv"); - - FILE *output_file = fopen(output_filename, "w"); - - ot::Print(results, output_file); - fclose(output_file); - fx_done(); - - return 1; -} diff --git a/fastlib/u/pram/mog_em/faster/phi.h b/fastlib/u/pram/mog_em/faster/phi.h deleted file mode 100644 index e7f9a7c2ae..0000000000 --- a/fastlib/u/pram/mog_em/faster/phi.h +++ /dev/null @@ -1,142 +0,0 @@ -/** - * @author Parikshit Ram (pram@cc.gatech.edu) - * @file phi.h - * - * This file computes the Gaussian probability - * density function - */ -#include "fastlib/fastlib.h" -#include "fastlib/fastlib_int.h" -#include - -/** - * Calculates the multivariate Gaussian probability density function - * - * Example use: - * @code - * Vector x, mean; - * Matrix cov; - * .... - * long double f = phi(x, mean, cov); - * @endcode - */ - -long double phi(Vector& x , Vector& mean , Matrix& cov) { - - long double det, f; - double exponent; - index_t dim; - Matrix inv; - Vector diff, tmp; - - dim = x.length(); - la::InverseInit(cov, &inv); - det = la::Determinant(cov); - - if( det < 0){ - det = -det; - } - la::SubInit(mean,x,&diff); - la::MulInit(inv, diff, &tmp); - exponent = la::Dot(diff, tmp); - long double tmp1, tmp2, tmp3; - tmp1 = 1; - tmp2 = dim; - tmp2 = tmp2/2; - tmp2 = pow((2*(math::PI)),tmp2); - tmp1 = tmp1/tmp2; - tmp3 = 1; - tmp2 = sqrt(det); - tmp3 = tmp3/tmp2; - tmp2 = -exponent; - tmp2 = tmp2 / 2; - f = (tmp1*tmp3*exp(tmp2)); - - return f; -} - -/** - * Calculates the univariate Gaussian probability density function - * - * Example use: - * @code - * double x, mean, var; - * .... - * long double f = phi(x, mean, var); - * @endcode - */ - -long double phi(double x, double mean, double var) { - - long double f; - - f = exp(-1.0*((x-mean)*(x-mean)/(2*var)))/sqrt(2*math::PI*var); - return f; -} - -/** - * Calculates the multivariate Gaussian probability density function - * and also the gradients with respect to the mean and the variance - * - * Example use: - * @code - * Vector x, mean, g_mean, g_cov; - * ArrayList d_cov; // the dSigma - * .... - * long double f = phi(x, mean, cov, d_cov, &g_mean, &g_cov); - * @endcode - */ - -long double phi(Vector& x, Vector& mean, Matrix& cov, ArrayList& d_cov, Vector *g_mean, Vector *g_cov){ - - long double det, f; - double exponent; - index_t dim; - Matrix inv; - Vector diff, tmp; - - dim = x.length(); - la::InverseInit(cov, &inv); - det = la::Determinant(cov); - - if( det < 0){ - det = -det; - } - la::SubInit(mean,x,&diff); - la::MulInit(inv, diff, &tmp); - exponent = la::Dot(diff, tmp); - long double tmp1, tmp2, tmp3; - tmp1 = 1; - tmp2 = dim; - tmp2 = tmp2/2; - tmp2 = pow((2*(math::PI)),tmp2); - tmp1 = tmp1/tmp2; - tmp3 = 1; - tmp2 = sqrt(det); - tmp3 = tmp3/tmp2; - tmp2 = -exponent; - tmp2 = tmp2 / 2; - f = (tmp1*tmp3*exp(tmp2)); - - // Calculating the g_mean values which would be a (1 X dim) vector - la::ScaleInit(f,tmp,g_mean); - - // Calculating the g_cov values which would be a (1 X (dim*(dim+1)/2)) vector - double *g_cov_tmp; - g_cov_tmp = (double*)malloc(d_cov.size()*sizeof(double)); - for(index_t i = 0; i < d_cov.size(); i++){ - Vector tmp_d; - Matrix inv_d; - long double tmp_d_cov_d_r; - - la::MulInit(d_cov[i],tmp,&tmp_d); - tmp_d_cov_d_r = la::Dot(tmp_d,tmp); - la::MulInit(inv,d_cov[i],&inv_d); - for(index_t j = 0; j < dim; j++) - tmp_d_cov_d_r += inv_d.get(j,j); - g_cov_tmp[i] = f*tmp_d_cov_d_r/2; - } - g_cov->Copy(g_cov_tmp,d_cov.size()); - - return f; -} diff --git a/fastlib/u/pram/mog_l2e/faster/build.py b/fastlib/u/pram/mog_l2e/faster/build.py deleted file mode 100644 index a0bc847cdf..0000000000 --- a/fastlib/u/pram/mog_l2e/faster/build.py +++ /dev/null @@ -1,26 +0,0 @@ - -librule( - name = "mog_l2e", # this line can be safely omitted - sources = ["mog.cc"], # files that must be compiled - headers = ["mog.h","phi.h"],# include files part of the 'lib' - deplibs = ["fastlib:fastlib"] # depends on fastlib core - #tests = ["mog_l2e_tests.cc"] - ) - -binrule( - name = "mog_l2e_main", # the executable name - sources = ["mog_l2e_main.cc"], # compile main.cc - headers = ["../opt/optimizers.h"], # no extra headers - deplibs = [":mog_l2e","fastlib:fastlib"] # - ) - -# to build: -# 1. make sure have environment variables set up: -# $ source /full/path/to/fastlib/script/fl-env /full/path/to/fastlib -# (you might want to put this in bashrc) -# 2. fl-build main -# - this automatically will assume --mode=check, the default -# - type fl-build --help for help -# 3. ./main -# - to build same target again, type: make -# - to force recompilation, type: make clean diff --git a/fastlib/u/pram/mog_l2e/faster/mog.cc b/fastlib/u/pram/mog_l2e/faster/mog.cc deleted file mode 100644 index b0719e41e0..0000000000 --- a/fastlib/u/pram/mog_l2e/faster/mog.cc +++ /dev/null @@ -1,502 +0,0 @@ -/** - * @author Parikshit Ram (pram@cc.gatech.edu) - * @file mog.cc - * - * Implementation for L2 loss function, and - * also some initial points generator - * - */ - -#include "mog.h" -#include "phi.h" - -long double MoGL2E::L2Error(const Matrix& data, Vector *gradients) { - - long double reg, fit, l2e; - index_t number_of_points = data.n_cols(); - - - if (gradients != NULL) { - Vector g_reg, g_fit; - reg = RegularizationTerm_(&g_reg); - fit = GoodnessOfFitTerm_(data, &g_fit); - DEBUG_ASSERT(gradients->length() == (number_of_gaussians()* - (dimension()+1)*(dimension()+2)/2 - 1) - - ); - gradients->SetAll(0.0); - la::AddTo(g_reg, gradients); - la::AddExpert((-2.0/number_of_points), g_fit, gradients); - } - else { - reg = RegularizationTerm_(); - fit = GoodnessOfFitTerm_(data); - } - l2e = reg - 2*fit / number_of_points; - return l2e; -} - -long double MoGL2E::RegularizationTerm_(Vector *g_reg){ - Matrix phi_mu, sum_covar; - Vector x, y; - long double reg, tmpVal; - index_t num_gauss, dim; - - Vector df_dw, g_omega; - ArrayList g_mu, g_sigma; - ArrayList > dp_d_mu, dp_d_sigma; - - - num_gauss = number_of_gaussians(); - dim = dimension(); - - phi_mu.Init(num_gauss, num_gauss); - sum_covar.Init(dim, dim); - x.Copy(omega()); - - if (g_reg != NULL) { - g_mu.Init(num_gauss); - g_sigma.Init(num_gauss); - dp_d_mu.Init(num_gauss); - dp_d_sigma.Init(num_gauss); - for(index_t k = 0; k < num_gauss; k++){ - dp_d_mu[k].Init(num_gauss); - dp_d_sigma[k].Init(num_gauss); - } - } - else { - g_mu.Init(0); - g_sigma.Init(0); - dp_d_mu.Init(0); - dp_d_sigma.Init(0); - df_dw.Init(0); - g_omega.Init(0); - } - - for(index_t k = 1; k < num_gauss; k++) { - for(index_t j = 0; j < k; j++) { - la::AddOverwrite(sigma(k), sigma(j), &sum_covar); - - if (g_reg != NULL) { - ArrayList tmp_d_cov; - Vector tmp_dp_d_sigma; - - tmp_d_cov.Init(dim*(dim+1)); - for(index_t i = 0; i < (dim*(dim + 1) / 2); i++){ - tmp_d_cov[i].Copy(d_sigma(k)[i]); - tmp_d_cov[(dim*(dim+1)/2)+i].Copy(d_sigma(j)[i]); - } - - //tmpVal = phi(mu(k),mu(j),sum_covar, - // tmp_d_cov,&dp_d_mu[j][k],&tmp_dp_d_sigma); - tmpVal = phi(mu(k),mu(j),sum_covar,tmp_d_cov, &dp_d_mu[k][j], - &tmp_dp_d_sigma); - - phi_mu.set(j, k, tmpVal); - phi_mu.set(k, j, tmpVal); - - // la::ScaleInit(-1.0, dp_d_mu[j][k], &dp_d_mu[k][j]); - la::ScaleInit(-1.0, dp_d_mu[k][j], &dp_d_mu[j][k]); - - double *tmp_dp, *tmp_dp_1, *tmp_dp_2; - tmp_dp = tmp_dp_d_sigma.ptr(); - tmp_dp_1 = (double*)malloc((tmp_dp_d_sigma.length()/2) * sizeof(double)); - tmp_dp_2 = (double*)malloc((tmp_dp_d_sigma.length()/2) * sizeof(double)); - for(index_t i = 0; i < (tmp_dp_d_sigma.length()/2); i++){ - tmp_dp_1[i] = tmp_dp[i]; - tmp_dp_2[i] = tmp_dp[(dim*(dim + 1) / 2) + i]; - } - dp_d_sigma[j][k].Copy(tmp_dp_1, (dim*(dim + 1) / 2)); - dp_d_sigma[k][j].Copy(tmp_dp_2, (dim*(dim + 1) / 2)); - } - else { - tmpVal = phi(mu(k), mu(j), sum_covar); - phi_mu.set(j, k, tmpVal); - phi_mu.set(k, j, tmpVal); - } - } - } - - for(index_t k = 0; k < num_gauss; k++) { - la::ScaleOverwrite(2, sigma(k), &sum_covar); - - if (g_reg != NULL) { - Vector junk; - tmpVal = phi(mu(k), mu(k), sum_covar, - d_sigma(k), &junk, &dp_d_sigma[k][k]); - phi_mu.set(k, k, tmpVal); - dp_d_mu[k][k].Init(dim); - dp_d_mu[k][k].SetZero(); - } - else { - tmpVal = phi(mu(k), mu(k), sum_covar); - phi_mu.set(k, k, tmpVal); - - } - } - - // Calculating the reg value - la::MulInit( x, phi_mu, &y ); - reg = la::Dot( x, y ); - - if (g_reg != NULL) { - // Calculating the g_omega values - a vector of size K-1 - la::ScaleInit(2.0,y,&df_dw); - la::MulInit(d_omega(),df_dw,&g_omega); - - // Calculating the g_mu values - K vectors of size D - for(index_t k = 0; k < num_gauss; k++){ - g_mu[k].Init(dim); - g_mu[k].SetZero(); - for(index_t j = 0; j < num_gauss; j++) { - la::AddExpert(x.get(j), dp_d_mu[j][k], &g_mu[k]); - } - la::Scale((2.0 * x.get(k)), &g_mu[k]); - } - - // Calculating the g_sigma values - K vectors of size D(D+1)/2 - for(index_t k = 0; k < num_gauss; k++){ - g_sigma[k].Init((dim*(dim + 1)) / 2); - g_sigma[k].SetZero(); - for(index_t j = 0; j < num_gauss; j++) { - la::AddExpert(x.get(j), dp_d_sigma[j][k], &g_sigma[k]); - } - la::Scale((2.0 * x.get(k)), &g_sigma[k]); - } - - // Making the single gradient vector of size K*(D+1)*(D+2)/2 - 1 - double *tmp_g_reg; - tmp_g_reg = (double*)malloc(((num_gauss*(dim + 1)*(dim + 2) / 2) - 1) - *sizeof(double)); - index_t j = 0; - for(index_t k = 0; k < g_omega.length(); k++) { - tmp_g_reg[k] = g_omega.get(k); - } - j = g_omega.length(); - for(index_t k = 0; k < num_gauss; k++){ - for(index_t i = 0; i < dim; i++){ - tmp_g_reg[j + k*(dim) + i] = g_mu[k].get(i); - } - for(index_t i = 0; i < (dim*(dim+1)/2); i++){ - tmp_g_reg[j + num_gauss*dim - + k*(dim*(dim+1) / 2) - + i] = g_sigma[k].get(i); - } - } - g_reg->Copy(tmp_g_reg, ((num_gauss*(dim+1)*(dim+2) / 2) - 1)); - } - - return reg; -} - -long double MoGL2E::GoodnessOfFitTerm_(const Matrix& data, Vector *g_fit) { - long double fit; - Matrix phi_x; - Vector weights, x, y, identity_vector; - index_t num_gauss, num_points, dim; - long double tmpVal; - Vector g_omega,tmp_g_omega; - ArrayList g_mu, g_sigma; - - num_gauss = number_of_gaussians(); - num_points = data.n_cols(); - dim = data.n_rows(); - phi_x.Init(num_gauss, num_points); - weights.Copy(omega()); - x.Init(data.n_rows()); - identity_vector.Init(num_points); - identity_vector.SetAll(1); - - if(g_fit != NULL) { - g_mu.Init(num_gauss); - g_sigma.Init(num_gauss); - } - else { - g_mu.Init(0); - g_sigma.Init(0); - g_omega.Init(0); - tmp_g_omega.Init(0); - } - - for(index_t k = 0; k < num_gauss; k++) { - if (g_fit != NULL) { - g_mu[k].Init(dim); - g_mu[k].SetZero(); - g_sigma[k].Init((dim * (dim+1) / 2)); - g_sigma[k].SetZero(); - } - for(index_t i = 0; i < num_points; i++) { - if (g_fit != NULL) { - Vector tmp_g_mu, tmp_g_sigma; - x.CopyValues(data.GetColumnPtr(i)); - tmpVal = phi(x, mu(k), sigma(k), - d_sigma(k), &tmp_g_mu, &tmp_g_sigma); - phi_x.set(k, i, tmpVal); - la::AddTo(tmp_g_mu, &g_mu[k]); - la::AddTo(tmp_g_sigma, &g_sigma[k]); - } - else { - x.CopyValues(data.GetColumnPtr(i)); - phi_x.set(k, i, phi(x, mu(k), sigma(k))); - } - } - if (g_fit != NULL) { - la::Scale(weights.get(k), &g_mu[k]); - la::Scale(weights.get(k), &g_sigma[k]); - } - } - - la::MulInit(weights, phi_x, &y); - fit = la::Dot(y, identity_vector); - - if (g_fit != NULL) { - // Calculating the g_omega - la::MulInit(phi_x, identity_vector, &tmp_g_omega); - la::MulInit(d_omega(), tmp_g_omega, &g_omega); - - // Making the single gradient vector of size K*(D+1)*(D+2)/2 - double *tmp_g_fit; - tmp_g_fit = (double*)malloc(((num_gauss * (dim+1)*(dim+2) / 2) - 1) - *sizeof(double)); - index_t j = 0; - for(index_t k = 0; k < g_omega.length(); k++) - tmp_g_fit[k] = g_omega.get(k); - j = g_omega.length(); - for(index_t k = 0; k < num_gauss; k++){ - for(index_t i = 0; i < dim; i++){ - tmp_g_fit[j + k*dim + i] = g_mu[k].get(i); - } - for(index_t i = 0; i < (dim * (dim+1) / 2); i++){ - tmp_g_fit[j + num_gauss*dim - + k*(dim * (dim+1) / 2) - + i] = g_sigma[k].get(i); - } - } - g_fit->Copy(tmp_g_fit, ((num_gauss*(dim+1)*(dim+2) / 2) - 1)); - } - return fit; -} - -void MoGL2E::MultiplePointsGenerator(double **points, - index_t number_of_points, - const Matrix& d, - index_t number_of_components) { - - index_t dim, n, i, j, x; - - dim = d.n_rows(); - n = d.n_cols(); - - for( i = 0; i < number_of_points; i++) { - for(j = 0; j < number_of_components - 1; j++) { - points[i][j] = (rand() % 20001)/1000 - 10; - } - } - - for(i = 0; i < number_of_points; i++){ - for(j = 0; j < number_of_components; j++){ - Vector tmp_mu; - tmp_mu.Init(dim); - tmp_mu.CopyValues(d.GetColumnPtr((rand() % n))); - for(x = 0; x < dim; x++) - points[i][number_of_components - 1 + j * dim + x] = tmp_mu.get(x); - } - } - - for(i = 0; i < number_of_points; i++) - for(j = 0; j < number_of_components; j++) - for(x = 0 ; x < (dim * (dim + 1) / 2); x++) - points[i][(number_of_components * (dim + 1) - 1) - + (j * (dim * (dim + 1) / 2)) + x] = (rand() % 501)/100; - - return; -} - -void MoGL2E::InitialPointGenerator(double *theta, const Matrix& data, - index_t k_comp) { - - ArrayList means; - ArrayList covars; - Vector weights; - double temp, noise; - index_t dim; - - weights.Init(k_comp); - means.Init(k_comp); - covars.Init(k_comp); - dim = data.n_rows(); - - for (index_t i = 0; i < k_comp; i++) { - means[i].Init(dim); - covars[i].Init(dim, dim); - } - - KMeans_(data, &means, &covars, &weights, k_comp); - - for(index_t k = 0; k < k_comp - 1; k++){ - temp = weights[k] / weights[k_comp - 1]; - noise = (double)(rand() % 10000) / (double)1000; - theta[k] = noise - 5; - } - for(index_t k = 0; k < k_comp; k++){ - for(index_t j = 0; j < dim; j++) - theta[k_comp - 1 + k * dim + j] = means[k].get(j); - - Matrix U, U_tran; - la::CholeskyInit(covars[k], &U); - la::TransposeInit(U, &U_tran); - for(index_t j = 0; j < dim; j++) { - for(index_t i = 0; i < j + 1; i++) { - noise = (rand() % 501) / 100; - theta[k_comp - 1 + k_comp * dim - + k * dim * (dim + 1) / 2 - + j * (j + 1) / 2 + i] = U_tran.get(j, i) + noise; - } - } - } - return; -} - -void MoGL2E::KMeans_(const Matrix& data, ArrayList *means, - ArrayList *covars, Vector *weights, - index_t value_of_k){ - - ArrayList mu, mu_old; - double* tmpssq; - double* sig; - double* sig_best; - index_t *y; - Vector x, diff; - Matrix ssq; - index_t i, j, k, n, t, dim; - double score, score_old, sum; - - n = data.n_cols(); - dim = data.n_rows(); - mu.Init(value_of_k); - mu_old.Init(value_of_k); - tmpssq = (double*)malloc(value_of_k * sizeof( double )); - sig = (double*)malloc(value_of_k * sizeof( double )); - sig_best = (double*)malloc(value_of_k * sizeof( double )); - ssq.Init(n, value_of_k); - - for( i = 0; i < value_of_k; i++){ - mu[i].Init(dim); - mu_old[i].Init(dim); - } - x.Init(dim); - y = (index_t*)malloc(n * sizeof(index_t)); - diff.Init(dim); - - score_old = 999999; - - // putting 5 random restarts to obtain the k-means - for(i = 0; i < 5; i++){ - t = -1; - for (k = 0; k < value_of_k; k++){ - t = (t + 1 + (rand()%((n - 1 - (value_of_k - k)) - (t + 1)))); - mu[k].CopyValues(data.GetColumnPtr(t)); - for(j = 0; j < n; j++){ - x.CopyValues( data.GetColumnPtr(j)); - la::SubOverwrite(mu[k], x, &diff); - ssq.set( j, k, la::Dot(diff, diff)); - } - } - min_element(ssq, y); - - do{ - for(k = 0; k < value_of_k; k++){ - mu_old[k].CopyValues(mu[k]); - } - - for(k = 0; k < value_of_k; k++){ - index_t p = 0; - mu[k].SetZero(); - for(j = 0; j < n; j++){ - x.CopyValues(data.GetColumnPtr(j)); - if(y[j] == k){ - la::AddTo(x, &mu[k]); - p++; - } - } - - if(p == 0){ - } - else{ - double sc = 1 ; - sc = sc / p; - la::Scale(sc , &mu[k]); - } - for(j = 0; j < n; j++){ - x.CopyValues(data.GetColumnPtr(j)); - la::SubOverwrite(mu[k], x, &diff); - ssq.set(j, k, la::Dot(diff, diff)); - } - } - min_element(ssq, y); - - sum = 0; - for(k = 0; k < value_of_k; k++) { - la::SubOverwrite(mu[k], mu_old[k], &diff); - sum += la::Dot(diff, diff); - } - }while(sum != 0); - - for(k = 0; k < value_of_k; k++){ - index_t p = 0; - tmpssq[k] = 0; - for(j = 0; j < n; j++){ - if(y[j] == k){ - tmpssq[k] += ssq.get(j, k); - p++; - } - } - sig[k] = sqrt(tmpssq[k] / p); - } - - score = 0; - for(k = 0; k < value_of_k; k++){ - score += tmpssq[k]; - } - score = score / n; - - if (score < score_old) { - score_old = score; - for(k = 0; k < value_of_k; k++){ - (*means)[k].CopyValues(mu[k]); - sig_best[k] = sig[k]; - } - } - } - - for(k = 0; k < value_of_k; k++){ - x.SetAll(sig_best[k]); - (*covars)[k].SetDiagonal(x); - } - double tmp = 1; - weights->SetAll(tmp / value_of_k); - return; -} - -void MoGL2E::min_element( Matrix& element, index_t *indices ){ - - index_t last = element.n_cols() - 1; - index_t first, lowest; - index_t i; - - for( i = 0; i < element.n_rows(); i++ ){ - - first = lowest = 0; - if(first == last){ - indices[ i ] = last; - } - while(++first <= last){ - if( element.get( i , first ) < element.get( i , lowest ) ){ - lowest = first; - } - } - indices[ i ] = lowest; - } - return; -} - diff --git a/fastlib/u/pram/mog_l2e/faster/mog.h b/fastlib/u/pram/mog_l2e/faster/mog.h deleted file mode 100644 index 477d39054e..0000000000 --- a/fastlib/u/pram/mog_l2e/faster/mog.h +++ /dev/null @@ -1,595 +0,0 @@ -/** - * @author Parikshit Ram (pram@cc.gatech.edu) - * @file mog.h - * - * Defines a Gaussian Mixture model and - * estimates the parameters of the model - * - */ - -#ifndef MOGL2E_H -#define MOGL2E_H - -#include - - -/** - * A Gaussian mixture model class. - * - * This class uses L2 loss function to - * estimate the parameters of a gaussian mixture - * model on a given data. - * - * The parameters are converted for optimization - * to maintain the following facts: - * - the weights sum to one - * - for this, the weights were parameterized using - * the logistic function - * - the covariance matrix is always positive definite - * - for this, the Cholesky decomposition is used - * - * Example use: - * - * @code - * MoGL2E mog; - * ArrayList results; - * double *params; - * - * mog.MakeModel(number_of_gaussians, dimension, params); - * mog.L2Error(data); - * mog.OutputResults(&results); - * @endcode - */ -class MoGL2E { - - private: - - // The parameters of the Mixture model - ArrayList mu_; - ArrayList sigma_; - Vector omega_; - index_t number_of_gaussians_; - index_t dimension_; - - // The differential for the paramterization - // for optimization - Matrix d_omega_; - ArrayList > d_sigma_; - - public: - - MoGL2E() { - mu_.Init(0); - sigma_.Init(0); - d_sigma_.Init(0); - d_omega_.Init(0, 0); - } - - ~MoGL2E() { - } - - void Init(index_t num_gauss, index_t dimension) { - - // Destruct everything to initialize afresh - mu_.Clear(); - sigma_.Clear(); - d_sigma_.Clear(); - // Initialize the private variables - number_of_gaussians_ = num_gauss; - dimension_ = dimension; - - // Resize the ArrayList of Vectors and Matrices - mu_.Resize(number_of_gaussians_); - sigma_.Resize(number_of_gaussians_); - } - - void Resize_d_sigma_() { - d_sigma_.Resize(number_of_gaussians()); - for(index_t i =0; i < number_of_gaussians(); i++) { - d_sigma_[i].Init(dimension()*(dimension()+1)/2); - } - } - - /** - * - * This function uses the parameters used for optimization - * and converts it into athe parameters of a Gaussian - * mixture model. This is to be used when you do not want - * the gradient values. - * - * Example use: - * - * @code - * MoGL2E mog; - * mog.MakeModel(number_of_gaussians, dimension, - * parameters_for_optimization); - * @endcode - */ - - void MakeModel(index_t num_mods, index_t dimension, double* theta) { - double *temp_mu; - Matrix lower_triangle_matrix, upper_triangle_matrix; - double sum, s_min = 0.01; - - Init(num_mods, dimension); - temp_mu = (double*) malloc (dimension * sizeof(double)) ; - lower_triangle_matrix.Init(dimension, dimension); - upper_triangle_matrix.Init(dimension, dimension); - - // calculating the omega values - sum = 0; - double *temp_array; - temp_array = (double*) malloc (num_mods * sizeof(double)); - for(index_t i = 0; i < num_mods - 1; i++) { - temp_array[i] = exp(theta[i]) ; - sum += temp_array[i] ; - } - temp_array[num_mods - 1] = 1 ; - ++sum ; - la::Scale(num_mods, (1.0 / sum), temp_array); - set_omega(dimension, temp_array); - - // calculating the mu values - for(index_t k = 0; k < num_mods; k++) { - for(index_t j = 0; j < dimension; j++) { - temp_mu[j] = theta[num_mods + k*dimension + j - 1]; - } - set_mu(k, dimension, temp_mu); - } - - // calculating the sigma values - // using a lower triangular matrix and its transpose - // to obtain a positive definite symmetric matrix - Matrix sigma_temp; - sigma_temp.Init(dimension, dimension); - for(index_t k = 0; k < num_mods; k++) { - lower_triangle_matrix.SetAll(0.0); - for(index_t j = 0; j < dimension; j++) { - for(index_t i = 0; i < j; i++) { - lower_triangle_matrix.set(j, i, - theta[(num_mods - 1) - + num_mods*dimension - + k*(dimension*(dimension + 1) / 2) - + (j*(j + 1) / 2) + i]); - } - lower_triangle_matrix.set(j, j, - theta[(num_mods - 1) - + num_mods*dimension - + k*(dimension*(dimension + 1) / 2) - + (j*(j + 1) / 2) + j] + s_min); - - } - la::TransposeOverwrite(lower_triangle_matrix, &upper_triangle_matrix); - la::MulOverwrite(lower_triangle_matrix, upper_triangle_matrix, &sigma_temp); - set_sigma(k, sigma_temp); - } - } - - void MakeModel(datanode *mog_l2e_module, double* theta) { - index_t num_gauss = fx_param_int_req(mog_l2e_module, "K"); - index_t dimension = fx_param_int_req(mog_l2e_module, "D"); - MakeModel(num_gauss, dimension, theta); - } - - /** - * - * This function uses the parameters used for optimization - * and converts it into athe parameters of a Gaussian - * mixture model. This is to be used when you want - * the gradient values. - * - * Example use: - * - * @code - * MoGL2E mog; - * mog.MakeModelWithGradients(number_of_gaussians, dimension, - * parameters_for_optimization); - * @endcode - */ - - void MakeModelWithGradients(index_t num_mods, index_t dimension, double* theta) { - double *temp_mu; - Matrix lower_triangle_matrix, upper_triangle_matrix; - double sum, s_min = 0.01; - - Init(num_mods, dimension); - temp_mu = (double*) malloc (dimension * sizeof(double)); - lower_triangle_matrix.Init(dimension, dimension); - upper_triangle_matrix.Init(dimension, dimension); - - // calculating the omega values - sum = 0; - double *temp_array; - temp_array = (double*) malloc (num_mods * sizeof(double)); - for(index_t i = 0; i < num_mods - 1; i++) { - temp_array[i] = exp(theta[i]) ; - sum += temp_array[i] ; - } - temp_array[num_mods - 1] = 1 ; - ++sum ; - la::Scale(num_mods, (1.0 / sum), temp_array); - set_omega(num_mods, temp_array); - - // calculating the d_omega values - Matrix d_omega_temp; - d_omega_temp.Init(num_mods - 1, num_mods); - d_omega_temp.SetAll(0.0); - for(index_t i = 0; i < num_mods - 1; i++) { - for(index_t j = 0; j < i; j++) { - d_omega_temp.set(i,j,-(omega(i)*omega(j))); - d_omega_temp.set(j,i,-(omega(i)*omega(j))); - } - d_omega_temp.set(i,i,omega(i)*(1-omega(i))); - } - for(index_t i = 0; i < num_mods - 1; i++) { - d_omega_temp.set(i, num_mods - 1, -(omega(i)*omega(num_mods - 1))); - } - set_d_omega(d_omega_temp); - - // calculating the mu values - for(index_t k = 0; k < num_mods; k++) { - for(index_t j = 0; j < dimension; j++) { - temp_mu[j] = theta[num_mods + k*dimension + j - 1]; - } - set_mu(k, dimension, temp_mu); - } - // d_mu is not computed because it is implicitly known - // since no parameterization is applied on them - - // using a lower triangular matrix and its transpose - // to obtain a positive definite symmetric matrix - - // initializing the d_sigma values - - Matrix d_sigma_temp; - d_sigma_temp.Init(dimension, dimension); - Resize_d_sigma_(); - - // calculating the sigma values - Matrix sigma_temp; - sigma_temp.Init(dimension, dimension); - for(index_t k = 0; k < num_mods; k++) { - lower_triangle_matrix.SetAll(0.0); - for(index_t j = 0; j < dimension; j++) { - for(index_t i = 0; i < j; i++) { - lower_triangle_matrix.set( j, i, - theta[(num_mods - 1) - + num_mods*dimension - + k*(dimension*(dimension + 1) / 2) - + (j*(j + 1) / 2) + i]) ; - } - lower_triangle_matrix.set(j, j, - theta[(num_mods - 1) - + num_mods*dimension - + k*(dimension*(dimension + 1) / 2) - + (j*(j + 1) / 2) + j] + s_min); - } - la::TransposeOverwrite(lower_triangle_matrix, &upper_triangle_matrix); - la::MulOverwrite(lower_triangle_matrix, upper_triangle_matrix, &sigma_temp); - set_sigma(k, sigma_temp); - - // calculating the d_sigma values - for(index_t i = 0; i < dimension; i++){ - for(index_t in = 0; in < i+1; in++){ - Matrix d_sigma_d_r,d_sigma_d_r_t,temp_matrix_1,temp_matrix_2; - d_sigma_d_r.Init(dimension, dimension); - d_sigma_d_r_t.Init(dimension, dimension); - d_sigma_d_r.SetAll(0.0); - d_sigma_d_r_t.SetAll(0.0); - d_sigma_d_r.set(i,in,1.0); - d_sigma_d_r_t.set(in,i,1.0); - - la::MulInit(d_sigma_d_r,upper_triangle_matrix,&temp_matrix_1); - la::MulInit(lower_triangle_matrix,d_sigma_d_r_t,&temp_matrix_2); - la::AddOverwrite(temp_matrix_1,temp_matrix_2,&d_sigma_temp); - set_d_sigma(k, (i*(i+1)/2)+in, d_sigma_temp); - } - } - } - } - - ////// THE GET FUNCTIONS ////// - ArrayList& mu() { - return mu_; - } - - ArrayList& sigma() { - return sigma_; - } - - Vector& omega() { - return omega_; - } - - index_t number_of_gaussians() { - return number_of_gaussians_; - } - - index_t dimension() { - return dimension_; - } - - Vector& mu(index_t i) { - return mu_[i] ; - } - - Matrix& sigma(index_t i) { - return sigma_[i]; - } - - double omega(index_t i) { - return omega_.get(i); - } - - Matrix& d_omega(){ - return d_omega_; - } - - ArrayList >& d_sigma(){ - return d_sigma_; - } - - ArrayList& d_sigma(index_t i){ - return d_sigma_[i]; - } - - ////// THE SET FUNCTIONS ////// - - void set_mu(index_t i, Vector& mu) { - DEBUG_ASSERT(i < number_of_gaussians()); - DEBUG_ASSERT(mu.length() == dimension()); - mu_[i].Copy(mu); - return; - } - - void set_mu(index_t i, index_t length, const double *mu) { - DEBUG_ASSERT(i < number_of_gaussians()); - DEBUG_ASSERT(length == dimension()); - mu_[i].Copy(mu, length); - return; - } - - void set_sigma(index_t i, Matrix& sigma) { - DEBUG_ASSERT(i < number_of_gaussians()); - DEBUG_ASSERT(sigma.n_rows() == dimension()); - DEBUG_ASSERT(sigma.n_cols() == dimension()); - sigma_[i].Copy(sigma); - return; - } - - void set_omega(Vector& omega) { - DEBUG_ASSERT(omega.length() == number_of_gaussians()); - omega_.Copy(omega); - return; - } - - void set_omega(index_t length, const double *omega) { - DEBUG_ASSERT(length == number_of_gaussians()); - omega_.Copy(omega, length); - return; - } - - void set_d_omega(Matrix& d_omega) { - d_omega_.Destruct(); - d_omega_.Copy(d_omega); - return; - } - - void set_d_sigma(index_t i, index_t j, Matrix& d_sigma_i_j) { - d_sigma_[i][j].Copy(d_sigma_i_j); - return; - } - - /** - * This function outputs the parameters of the model - * to an arraylist of doubles - * - * @code - * ArrayList results; - * mog.OutputResults(&results); - * @endcode - */ - void OutputResults(ArrayList *results) { - - // Initialize the size of the output array - (*results).Init(number_of_gaussians_ * (1 + dimension_*(1 + dimension_))); - - // Copy values to the array from the private variables of the class - for (index_t i = 0; i < number_of_gaussians_; i++) { - (*results)[i] = omega(i); - for (index_t j = 0; j < dimension_; j++) { - (*results)[number_of_gaussians_ + i*dimension_ + j] = mu(i).get(j); - for (index_t k = 0; k < dimension_; k++) { - (*results)[number_of_gaussians_*(1 + dimension_) - + i*dimension_*dimension_ + j*dimension_ - + k] = sigma(i).get(j, k); - } - } - } - } - - /** - * This function prints the parameters of the model - * - * @code - * mog.Display(); - * @endcode - */ - void Display(){ - - // Output the model parameters as the omega, mu and sigma - printf(" Omega : [ "); - for (index_t i = 0; i < number_of_gaussians_; i++) { - printf("%lf ", omega(i)); - } - printf("]\n"); - printf(" Mu : \n["); - for (index_t i = 0; i < number_of_gaussians_; i++) { - for (index_t j = 0; j < dimension_ ; j++) { - printf("%lf ", mu(i).get(j)); - } - printf(";"); - if (i == (number_of_gaussians_ - 1)) { - printf("\b]\n"); - } - } - printf("Sigma : "); - for (index_t i = 0; i < number_of_gaussians_; i++) { - printf("\n["); - for (index_t j = 0; j < dimension_ ; j++) { - for(index_t k = 0; k < dimension_ ; k++) { - printf("%lf ",sigma(i).get(j, k)); - } - printf(";"); - } - printf("\b]"); - } - printf("\n"); - } - - - /** - * This function calculates the L2 error and - * the gradient of the error with respect to the - * parameters given the data and the parameterized - * mixture - * - * Example use: - * - * @code - * const Matrix data; - * MoGL2E mog; - * index_t num_gauss, dimension; - * double *params; // get the parameters - * - * mog.MakeModel(num_gauss, dimension, params); - * mog.L2Error(data); - * @endcode - */ - long double L2Error(const Matrix&, Vector* = NULL); - - /** - * Calculates the regularization value for a - * Gaussian mixture and its gradient with - * respect to the parameters - * - * Used by the 'L2Error' function to calculate - * the regularization part of the error - */ - long double RegularizationTerm_(Vector* = NULL); - - /** - * Calculates the goodness-of-fit value for a - * Gaussian mixture and its gradient with - * respect to the parameters - * - * Used by the 'L2Error' function to calculate - * the goodness-of-fit part of the error - */ - long double GoodnessOfFitTerm_(const Matrix&, Vector* = NULL); - - /** - * This function computes multiple number of starting points - * required for the Nelder Mead method - * - * Example use: - * @code - * double **p; - * index_t n, num_gauss; - * const Matrix data; - * - * MoGL2E::MultiplePointsGeneratot(p, n, data, num_gauss); - * @endcode - */ - static void MultiplePointsGenerator(double**, index_t, - const Matrix&, index_t); - - /** - * This function parameterizes the starting point obtained - * from the 'k_means" for optimization purposes using the - * Quasi Newton method - * - * Example use: - * @code - * double *p; - * index_t num_gauss; - * const Matrix data; - * - * MoGL2E::InitialPointGeneratot(p, data, num_gauss); - * @endcode - */ - static void InitialPointGenerator(double*, const Matrix&, index_t); - - /** - * This function computes the k-means of the data and stores - * the calculated means and covariances in the ArrayList - * of Vectors and Matrices passed to it. It sets the weights - * uniformly. - * - * This function is used to obtain a starting point for - * the optimization - * - * Example use: - * - * @code - * const Matrix data; - * ArrayList *means; - * ArrayList *covars; - * Vector *weights; - * index_t num_gauss; - * - * ... - * MoGL2E::KMeans(data, means, covars, weights, num_gauss); - *@endcode - */ - static void KMeans_(const Matrix&, ArrayList*, - ArrayList*, Vector*, index_t); - - /** - * This function returns the indices of the minimum - * element in each row of a matrix - */ - static void min_element(Matrix&, index_t*); - - /** - * This is the function which would be used for - * optimization. It creates its own object of - * class MoGL2E and returns the L2 error - * and the gradient which are computed by - * the functions of the class - * - */ - static long double L2ErrorForOpt(Vector& params, - const Matrix& data, - Vector *gradient) { - - MoGL2E model; - index_t dimension = data.n_rows(); - index_t num_gauss; - - num_gauss = (params.length() + 1)*2 / ((dimension+1)*(dimension+2)); - // This check added here to see if - // the gradient is actually demanded here - if (gradient != NULL) { - model.MakeModelWithGradients(num_gauss, dimension, params.ptr()); - return model.L2Error(data, gradient); - } - else { - model.MakeModel(num_gauss, dimension, params.ptr()); - return model.L2Error(data); - } - } - - /** - * This is the function which should be used for - * optimization when there is no need to compute - * any gradients - * - */ - static long double L2ErrorForOpt(Vector& params, const Matrix& data) { - return L2ErrorForOpt(params, data, NULL); - } - -}; - -#endif diff --git a/fastlib/u/pram/mog_l2e/faster/mog_l2e_c_expt_data.csv b/fastlib/u/pram/mog_l2e/faster/mog_l2e_c_expt_data.csv deleted file mode 100644 index ecf2d67940..0000000000 --- a/fastlib/u/pram/mog_l2e/faster/mog_l2e_c_expt_data.csv +++ /dev/null @@ -1,1000 +0,0 @@ --0.6165,-0.7845,-0.94595 --2.3738,-1.5512,-2.151 -0.17863,0.15363,0.11381 -0.41,0.2685,0.47045 --1.634,-1.8045,-1.284 -1.6973,1.0077,1.1101 -1.6948,1.2375,1.1921 --0.053636,0.075703,-0.16084 -0.46646,0.37428,0.88056 -0.2489,0.15923,0.10354 --0.2661,-0.67076,-0.74904 -1.0344,0.81231,0.65549 --0.83848,-0.6146,-0.75169 -3.1115,2.2803,2.1457 --0.19439,0.049159,-0.18603 -0.16238,0.085079,-0.14036 -1.5204,1.1411,0.57399 -0.084489,-0.044184,-0.10485 --0.13632,-0.19165,-0.57118 --1.1863,-0.92949,-0.87861 -0.4196,-0.0028355,0.45413 --1.9044,-1.234,-0.59965 -1.0181,1.074,0.97021 -2.3139,1.4096,1.6465 --0.98593,-0.82848,-0.42251 -1.2228,1.0583,1.0334 -1.7872,1.2369,1.6017 --2.2714,-1.0872,-1.457 --2.0537,-1.9257,-1.539 -0.81401,0.24299,0.26575 --0.56992,-0.62323,-0.68515 -0.9834,1.3369,0.71901 -1.1624,0.92815,1.0735 -1.0146,0.5602,0.67127 -1.8389,1.2694,0.7353 -0.9529,0.55691,1.1478 -1.6972,1.461,1.4487 --1.7138,-1.169,-1.6175 --0.028204,0.22983,-0.046001 --0.22336,0.060864,-0.023443 --2.2862,-1.6373,-1.8103 -0.36671,0.2167,0.2094 --1.5057,-0.99296,-0.92167 -2.0169,1.1388,1.6003 --1.1474,-0.85908,-1.2146 -0.75357,0.48921,0.21084 -0.31258,-0.097472,-0.072763 --1.3139,-0.6149,-0.75809 --3.0937,-2.465,-1.8456 --0.084356,-0.2743,0.42902 --1.4404,-1.3434,-0.89 -0.87574,0.92474,0.93992 -0.72364,0.28869,0.38718 -2.4121,1.1274,1.4528 -0.84271,0.82526,0.42803 --0.91726,-0.18944,-0.34326 -0.54206,0.57629,0.79468 --1.4382,-0.94344,-0.59875 --0.027807,-0.28088,-0.18462 --0.068725,-0.27625,-0.059383 -6.1558e-05,0.3746,0.30391 --0.45302,0.040057,-0.354 -1.5606,0.88436,1.0752 --2.6708,-1.5849,-1.648 -0.61026,0.48438,0.58992 -1.2765,0.76108,0.66035 -1.0418,0.46053,1.0187 -0.82357,0.65182,0.87367 -0.057456,-0.51468,-0.82615 -0.965,0.18219,0.19044 -0.81081,1.1697,0.66233 --0.36435,-0.27163,-0.83624 --0.53798,0.4321,0.34407 --0.4217,-0.36313,-0.24602 --2.1024,-1.3881,-1.2375 --0.33351,0.052651,-0.46196 -0.16881,0.061304,0.15467 -0.44867,0.14858,0.7442 -2.0573,1.8462,1.7614 --0.50022,-0.60787,-0.20115 -0.88824,0.85475,0.86278 -1.1388,0.62494,0.7129 -1.341,1.1455,0.67375 --1.4139,-0.71077,-0.26736 -0.3022,-0.045687,-0.26492 -0.33903,0.39471,0.41694 --1.4363,-0.66974,-0.76903 --1.0576,-1.0453,-0.23254 -1.5425,1.1675,1.0001 --0.18742,-0.13965,0.29061 -0.55567,0.0068724,0.1141 -0.1254,0.0021451,0.11894 --0.90568,-0.66958,-0.41933 --0.79751,-0.87665,-0.92733 -0.6323,-0.16193,0.41558 --1.3538,-1.2049,-0.51138 -1.1134,0.76134,0.78804 -0.81089,0.03075,1.1317 --1.1711,-0.41788,-0.87152 --0.37855,-0.44234,0.48325 --1.6928,-1.7889,-1.3703 --3.1388,-2.1174,-2.0619 -1.4057,1.4166,0.84815 --0.73917,-0.49044,-1.0632 -0.46657,0.36911,0.24448 -0.33358,0.22043,0.39534 -0.030594,0.073841,0.27692 --1.4308,-0.71191,-1.3751 --1.3499,-0.86962,-1.4605 --0.53364,-0.13566,-0.41636 --1.6901,-1.0036,-1.0949 --1.5049,-0.99121,-0.32246 -2.0986,1.5236,1.3769 -0.079447,-0.24494,0.010732 --1.7349,-1.4766,-1.01 --0.058758,-0.044247,-0.19293 --1.6081,-0.9942,-1.3881 --1.923,-1.5905,-1.8654 --0.37213,-0.0076584,0.16398 -1.3589,0.96469,1.0819 -0.18335,0.95775,0.87105 -0.93561,0.76644,0.55131 --1.6644,-1.5388,-0.98019 --0.65646,-0.33299,0.17833 --0.37403,-0.10419,-0.03334 --1.729,-1.3406,-1.2306 --1.8805,-1.2172,-1.7291 -1.3272,0.72748,1.2068 -0.016026,0.017311,0.20987 --0.91947,-0.50239,-0.81324 -1.1483,1.1498,1.0583 -0.33012,0.46117,0.91751 --1.4106,-1.7722,-1.1277 -1.9092,1.3954,1.4036 -0.4126,0.53442,0.73576 -2.1078,1.4421,1.4399 -1.6219,1.3731,0.81305 --0.97505,-0.43224,-0.75139 --1.8413,-0.86412,-0.91452 --0.10394,0.3039,-0.21133 --0.47118,-0.03093,0.16734 --1.2024,-1.328,-0.91784 -0.70943,0.18452,0.42195 -2.1214,1.6626,1.6328 --0.77885,-0.83074,-0.65092 --1.2068,-1.0119,-1.0539 --0.35108,-0.031409,-0.037199 -0.94495,0.65373,1.0238 --1.2174,-0.51031,-0.25788 --1.7121,-1.5819,-1.5091 --0.17084,0.028979,0.16302 --0.093058,-0.56151,-0.52208 -0.69165,0.034571,0.70329 --0.84871,-0.49217,-0.54815 --0.21331,-0.18895,-0.097177 --0.61962,-0.76897,-0.043775 --0.11306,-0.1666,-0.70512 -2.1879,1.322,1.4741 --0.86437,-0.86543,-0.99435 --1.9203,-1.2403,-1.74 -0.66897,0.0047117,0.49389 --1.2878,-0.78708,-0.9679 -0.051136,-0.58182,-0.28244 --0.89437,-0.45182,-0.53615 -0.76306,0.62759,0.43177 -0.78798,0.771,0.45344 --0.2903,-0.40973,-0.014944 --2.9279,-1.7994,-2.1735 -0.18893,-0.19723,-0.051554 -2.2703,1.83,1.7874 -1.4515,0.34804,0.55254 --2.2524,-1.457,-1.5178 --0.11211,-0.30021,0.030943 --0.97151,-0.9014,-0.69827 --1.4602,-0.9545,-0.2426 --1.7592,-1.3083,-1.6153 -0.41161,0.5778,0.67332 --0.61185,-0.452,-0.20605 -0.079529,0.36323,-0.084818 --0.5243,-0.50413,-0.57551 --0.66269,-0.43317,-0.42841 -0.5287,0.48376,0.39842 -1.038,1.0514,0.8002 -3.0103,2.2521,1.676 --1.9344,-1.4134,-0.86415 --1.4574,-1.4167,-1.2703 -1.4791,0.80481,0.97277 --0.55555,-0.27971,-0.26511 --1.9686,-1.6531,-1.1837 -0.44972,0.39698,0.48407 -2.2137,1.8544,1.6979 -1.0089,0.76607,0.31256 -2.7897,1.9622,2.2075 -0.71908,0.61657,0.99208 -2.6574,2.1916,1.5281 --0.48431,0.10929,-0.62964 --1.6244,-1.4256,-1.2367 --0.3009,-0.14365,-0.16234 -1.6964,1.342,0.97836 --1.5908,-1.1707,-1.2791 -0.9054,1.3806,0.86051 --0.85714,-0.32671,-0.86043 -0.78556,0.27917,0.66483 --1.5675,-0.82699,-0.97641 -0.12256,0.2973,0.19656 --2.8569,-1.7265,-1.423 --0.70276,-1.0034,-0.87575 -0.65852,0.91951,1.0505 --0.4575,-0.80393,-0.16986 -1.7624,1.5458,1.2702 --0.89971,-0.95465,-0.63641 --3.3139,-2.1538,-1.8241 --1.7554,-0.90901,-1.0128 -1.5045,1.2804,1.2494 --0.16137,-0.099309,0.0079014 -0.54048,0.088341,0.25739 -1.3457,0.88818,1.2897 --3.0221,-2.3158,-1.8694 --0.91881,-1.1369,-0.29942 --1.0038,-0.96252,-0.89628 --1.4511,-0.81527,-0.77327 --0.25951,-0.0090492,0.090271 -2.1678,1.3592,1.5078 --0.054784,-0.018723,0.34659 -1.7494,1.3383,1.4256 --0.99224,-0.61941,-0.97926 -0.010724,0.085805,-0.095744 --1.1158,-0.13089,-0.76685 -0.83652,-0.12037,0.44881 --0.35803,-0.1421,-0.35758 -0.6843,0.55729,-0.10792 -0.95227,0.85437,0.52711 --0.11162,-0.25344,0.28327 -1.2673,1.1389,0.86183 -3.2912,2.308,3.0507 -0.74773,0.77101,0.12611 --0.0168,0.28206,-0.070105 -1.3014,1.2946,1.1809 -0.079728,0.035041,0.478 --1.5778,-0.68017,-1.0815 -0.69194,0.54368,0.35396 --0.0071333,-0.44037,0.20862 --0.39367,-0.3154,-0.2729 -1.8192,1.093,1.4121 -2.6558,1.2934,2.0026 --0.74476,-0.63759,-0.46414 -0.1474,-0.086305,0.35019 --1.1511,-0.56933,-0.49691 -0.96977,0.76801,0.31844 --3.3701,-2.0407,-2.3685 -1.4111,1.0537,1.1552 -0.31198,0.16948,-0.36431 -0.37293,0.22828,0.027717 -1.7294,1.2733,0.51035 --0.39146,0.086534,-0.34231 --0.18975,0.11539,-0.082974 --1.8107,-1.6539,-1.2894 --2.371,-1.5881,-1.7811 --1.0027,-0.75489,-1.5943 -0.40032,0.44851,0.77779 --0.77134,-0.62007,-0.67577 --1.9006,-0.95704,-0.77859 -1.5288,0.99314,0.6403 --1.0149,-1.1424,-0.58114 --0.016084,0.41402,0.28368 --0.0011644,0.13349,-0.090856 --0.3555,-0.07142,0.51236 -0.56521,0.17608,0.90014 --0.37628,-0.0038747,0.054593 --2.3716,-2.3069,-1.8389 --1.4665,-0.67072,-0.74024 -0.34646,0.23696,0.43421 --1.7909,-1.7192,-1.5578 --0.49481,-0.7134,-0.53647 --1.3417,-0.85633,-0.46208 --1.674,-1.08,-0.83529 --1.4554,-1.3039,-1.0101 --0.57246,-0.53035,-0.67265 -0.24751,0.59592,0.16736 --0.16549,-0.25414,0.090411 -1.5166,1.0494,1.1465 --0.34973,0.0036321,-0.1834 --2.1628,-1.2091,-1.1774 -0.013873,0.051512,-0.49274 -0.10172,-0.4235,0.25804 -0.45113,-0.19239,0.12803 -0.71236,0.61881,0.41783 -1.8216,1.0238,1.3506 --0.78076,-0.36301,-0.29362 -0.37171,-0.16688,0.41067 --0.01878,0.12733,0.30194 --0.827,-0.37507,-0.15046 -3.0447,2.2024,2.0526 --0.36716,-0.56031,-0.55612 --2.0089,-1.4826,-1.5823 -2.5228,1.8636,1.6974 -0.46397,-0.16642,0.51771 --1.5949,-1.3067,-1.6088 -0.88413,0.27769,0.38743 -1.8097,1.5456,1.4192 --1.2771,-0.34841,-0.46539 -0.19265,0.34802,-0.079423 --0.19816,-0.36363,-0.24021 --1.6581,-1.0667,-1.0768 -1.6871,1.0881,1.152 --0.021991,-0.27499,0.0070854 -0.76423,0.62905,0.5282 --1.0211,-0.66635,-0.88949 --0.93432,-0.98547,-0.86437 -0.44804,0.098974,0.24378 -0.15223,0.019695,0.47094 -2.6341,2.0047,1.9904 --0.39209,-0.64899,-0.37306 -3.1534,1.9791,2.1865 -2.15,1.3267,1.5617 --2.7722,-1.6004,-1.2888 --2.3951,-1.1047,-1.3913 --0.81741,-0.12541,0.016696 --0.26483,0.096233,0.00042214 -0.012733,0.10828,0.27256 -1.1928,0.83872,0.99168 --1.0294,-1.1623,-0.34252 --1.0283,-0.83213,-1.0164 --0.28673,-0.20292,-0.46253 --0.029166,0.049592,0.11099 -0.39748,-0.034696,0.43411 -1.5083,0.83126,1.012 -0.88602,0.77726,0.6045 --2.495,-2.072,-1.3995 -0.99387,0.44493,0.42506 -1.1565,0.8752,1.0527 -0.90693,1.0891,1.3295 -1.8672,0.95911,1.2891 -0.46619,0.51005,0.13368 --0.95916,-0.90033,-0.036454 --0.21282,-0.24136,-0.41904 --3.4904,-2.5756,-2.3713 -0.67454,0.84582,0.8237 -0.16667,0.37573,0.55311 --0.84245,-1.2187,-0.80501 --0.9331,-0.74945,-0.4896 --1.5402,-0.88694,-1.5105 --0.068027,-0.52072,-0.18421 -0.54065,0.30758,0.13111 --0.47084,-0.45232,-0.85186 --0.71246,-0.33788,-0.12141 --0.051277,-0.30043,0.29935 --0.24907,-0.14638,-0.094752 --1.3643,-1.0939,-1.303 -1.8422,0.83185,1.8174 -0.62839,0.31361,0.27668 -1.8256,1.1117,1.4689 --0.70937,-0.57495,-0.5543 --1.5944,-1.1845,-0.74429 -1.1511,0.30499,0.72375 -0.058718,0.37358,0.011855 --1.0778,-0.33529,-0.58505 --0.12703,-0.12559,-0.12991 --2.8631,-2.1867,-1.6275 -1.5448,1.1238,1.2838 --1.3984,-1.0804,-0.89229 --0.98125,-0.65272,-0.83962 -1.9091,0.77286,0.88822 --1.2959,-0.37432,-0.53178 --0.58841,-0.30354,0.052591 --0.72139,-0.27631,-0.65655 -2.3085,2.0691,1.3736 -0.1153,-0.54992,0.3696 --1.5407,-1.2825,-1.1006 --1.6027,-1.0447,-1.3118 -2.4737,1.8561,1.3877 -2.7613,1.724,2.1938 -2.3303,1.688,2.0667 --1.79,-1.6004,-0.83711 --0.30434,-0.26636,-0.045708 --0.28352,-0.28622,-0.20034 -0.43825,0.59186,1.0117 --0.81569,-0.7215,-0.24828 --1.3934,-1.2294,-1.5486 --0.6368,-0.70831,-0.52934 -1.5422,1.1419,1.7953 -3.3815,2.0904,2.0507 -0.32679,0.7124,0.45824 --0.38,-0.085501,-0.31053 -1,0.78305,1.0969 --0.69492,-0.52238,-0.67936 -2.6544,1.9154,1.8685 -1.5775,1.4905,1.0029 --1.7496,-1.8807,-1.4732 --0.95473,-0.26049,-0.21346 -1.9111,1.1945,1.3116 -0.5531,0.37984,0.37483 -0.5602,0.6534,0.20168 --2.4333,-1.4903,-2.0353 -0.32475,-0.26915,0.16627 -0.97718,0.21167,0.65776 --0.90757,-0.44728,-0.47233 --1.4289,-1.2567,-1.6105 --0.26455,-0.67822,-0.14757 --1.5022,-1.1389,-0.99806 --0.10196,-0.191,0.24747 -0.39792,-0.081034,0.19342 -1.9572,1.0033,1.2828 -0.25631,0.26421,0.030353 --0.77249,-1.1113,-1.0179 -2.3291,1.9967,1.6419 -1.1761,1.0087,1.2915 -0.32889,0.1416,0.71704 -0.95723,0.64902,0.26976 --0.72412,-0.77286,-0.47506 -1.2205,0.51855,0.72612 -0.38268,0.37604,0.33125 -0.89073,0.88508,0.93413 --1.4927,-0.63355,-1.1864 -2.1887,1.4609,1.198 -0.61915,0.61101,0.56674 --2.7323,-1.2766,-1.5946 -0.66977,1.1494,0.61317 -1.8162,1.1308,1.1446 -0.91006,1.3054,1.105 -1.9679,1.3001,1.1479 -1.8811,1.075,1.1673 --1.2961,-0.71666,-0.62557 --3.286,-2.2674,-2.1703 -2.5493,2.1016,2.3089 -0.55697,0.5824,0.43449 -0.028966,-0.45232,-0.14282 --0.57861,-1.3193,-0.80776 --2.1876,-1.3346,-1.605 -0.31551,-0.091122,0.38435 --1.9589,-1.066,-1.6311 --1.1962,-0.3378,-0.74927 --0.29736,-0.50204,-1.0496 -1.0773,1.0454,1.0632 -0.5355,0.41529,0.55637 --1.9175,-1.4929,-1.1011 -2.112,1.9269,1.3092 -0.046656,-0.1254,-0.038926 -2.6658,2.201,1.9726 --1.7231,-0.69844,-1.5322 --1.1154,-1.4008,-1.485 --1.0936,0.14899,-0.64633 --0.15278,0.30838,0.41924 --1.3925,-0.6345,-0.23483 --1.3739,-1.1753,-0.96986 --3.3908,-2.4024,-2.8405 --1.1946,-1.2366,-0.87551 -0.36677,-0.13477,0.23891 --0.262,-0.45218,-0.29693 --0.23889,0.015721,-0.054343 --0.16673,0.44702,-0.46022 -0.24013,0.57518,-0.13394 --0.71433,-0.63921,-0.30254 --1.0049,-1.352,-0.97276 -0.72425,0.56855,0.050147 --0.59991,-0.63516,-0.57581 -0.32657,-0.31822,-0.18239 --1.3675,-0.80074,-0.69376 --0.20814,0.034394,-0.096955 -1.0611,0.98818,0.90572 --1.2692,-0.95092,-0.75047 -0.19819,0.0086655,-0.20184 --0.33656,-0.29335,-0.2225 --0.10755,-0.12681,-0.12454 --0.51104,-0.28397,-0.13016 --2.9611,-1.5163,-1.3197 --0.20458,-0.1038,-0.034625 -1.9858,1.5592,1.3983 -0.92896,1.2703,0.85247 --0.5375,-0.47171,-0.57883 --0.9427,-0.42368,-1.072 -0.35482,0.33272,0.41026 --0.54659,-0.63326,-0.58798 --0.7532,-1.288,-0.65678 -0.078941,-0.67055,-0.1672 -1.7869,1.1192,1.0503 --3.5916,-2.6476,-2.4518 -0.83355,0.44693,0.7375 --1.4367,-1.4159,-1.0812 -1.3458,0.99154,0.98346 --3.4547,-2.3043,-2.6367 --0.31901,-0.43787,0.085971 -0.082762,0.28754,0.47733 --0.60517,-0.91527,-1.3202 --0.2892,-0.52012,-0.90398 --2.1565,-1.5546,-1.3918 --1.6053,-1.4957,-1.4772 --1.1616,-0.42041,-1.0278 -0.52251,0.81338,1.2673 --0.83533,-0.50062,-0.80944 -2.1911,1.0739,1.0098 -0.19963,0.33749,0.28962 --2.6549,-2.5983,-2.2839 --0.64732,-0.60659,-0.8261 --0.92935,0.3386,-0.72539 -0.14725,0.2347,-0.025811 --0.31445,-0.56578,-0.18044 --0.3977,-0.002443,-0.61421 --1.0456,-0.80294,-0.76976 --0.091975,0.25234,0.036278 --2.058,-1.5216,-1.5463 -0.87272,1.0069,1.0155 --1.8863,-0.98545,-1.0072 --0.94289,-0.58106,0.21578 --0.20825,-0.23388,-0.53198 -0.35358,0.32026,0.313 --0.10922,-0.13298,0.13327 -2.4773,1.6737,1.5238 -2.3117,1.7975,1.8058 -0.89281,0.36925,1.014 -0.13085,-0.1544,0.24037 --1.151,-0.79116,-0.53514 --0.65751,-0.67202,-0.58744 --2.0038,-1.8275,-1.436 --0.53379,-0.10072,-0.4293 --0.67115,-0.5409,-0.53112 -2.496,1.2334,1.5265 -1.0735,0.61552,0.9836 -0.092624,0.01966,0.17427 --0.41725,-0.997,-0.52547 -0.11804,-0.33262,-0.16348 -1.092,0.19532,0.49806 -3.188,2.5225,1.9596 -0.46589,0.276,0.52301 -1.2304,1.1822,1.2891 -0.96827,0.83397,0.42454 -0.79065,0.68759,1.0794 -1.4275,0.77142,0.76853 -1.7949,1.3169,1.3082 -0.062925,-0.3629,0.012532 --0.44772,-0.52737,-0.44973 -0.32311,0.019301,0.1135 -1.4205,1.034,0.65669 -1.7329,0.64093,1.0029 --0.77347,-0.9528,-0.49006 -1.3001,0.95128,1.4479 --0.24534,0.27943,0.0015306 --0.47881,-0.21651,0.17127 -0.77174,0.39404,0.37528 -1.3285,0.89567,0.53145 --0.81274,-0.53334,-0.75773 --2.1358,-0.8674,-1.4318 --0.071754,-0.071367,0.12257 -0.78818,0.82615,0.24901 -0.119,0.057309,0.038197 -2.2483,1.2969,1.1437 --0.47143,-0.22884,-1.085 -1.1333,1.0971,0.95383 --1.1185,-1.2735,-1.1791 --1.8002,-1.5661,-1.0153 -0.95013,0.59277,0.54633 --1.9848,-1.2191,-0.98185 --1.8536,-1.5519,-1.0611 --0.86229,-0.78886,-0.043184 --2.1215,-1.2642,-1.5809 -0.79605,0.13888,0.083899 --0.39529,0.048226,0.10652 --1.8438,-1.0007,-1.2943 --1.2662,-1.0635,-1.0423 --1.406,-0.76256,-0.75919 --0.10207,0.32425,0.1865 --3.4413,-2.2627,-2.2175 --0.9896,-0.41639,-0.27536 --1.983,-1.3199,-1.0997 -0.46982,0.32704,-0.015685 -0.85306,0.56247,0.69314 -0.20976,-0.15912,-0.12332 --0.14457,-0.32674,-0.45541 --3.7554,-2.5832,-2.5437 -0.039982,0.32847,0.14539 --1.2489,-1.0384,-1.0681 --0.37836,0.19049,0.043316 --0.46687,-0.56786,-0.2046 --1.6508,-0.93486,-0.91214 -0.8267,0.16756,0.28948 -0.3417,-0.030041,-0.23273 --0.50009,-0.48719,-0.56571 -1.2714,0.93913,0.73073 -2.2494,2.1117,1.7525 --1.5794,-1.0489,-0.8724 --0.036957,-0.15063,0.54813 --1.5829,-0.9291,-1.0348 -1.0701,0.36813,0.58839 -0.71285,0.4592,0.40555 --0.73721,-0.36945,-0.71263 --0.797,-0.63633,-0.45386 --1.0737,-0.78705,-0.79099 -1.3195,0.959,1.0775 --0.3542,-0.11447,0.05111 --0.21355,0.36469,-0.33967 --1.7935,-0.62089,-0.78061 -0.44555,0.51766,0.14294 -3.8342,2.2116,2.2752 -0.41288,0.39356,0.10433 --2.0278,-1.5625,-1.5353 -0.35172,-0.077008,-0.30096 --2.0463,-1.1901,-1.0951 -0.21175,0.29256,0.016755 --2.413,-1.7128,-1.3967 -1.025,0.58731,1.233 -1.6273,0.84525,1.112 -2.2118,0.95534,1.2199 -1.972,0.85553,1.3554 --1.0804,-1.098,-1.1858 -0.63089,0.30584,0.40866 -1.2985,0.94327,0.91089 --1.5308,-0.97925,-1.0747 -0.28755,-0.18091,-0.12422 -1.0872,0.95837,0.52951 --1.8359,-1.1282,-1.2301 --1.3582,-0.48768,-0.57907 -1.1091,0.60469,0.62787 --0.0090232,-0.0082117,-0.41713 -0.74751,0.35223,0.59295 -1.9444,1.5512,1.7182 -0.68701,0.80237,0.27838 --1.1217,-0.61631,-1.5375 -1.0718,1.5789,1.2972 --0.23785,-0.21184,-0.15692 --1.1633,-0.66644,-1.292 -2.9845,1.4463,1.6732 -0.11423,-0.088033,0.36069 --1.3359,-1.4908,-1.2689 -0.90607,0.58809,0.534 -2.3973,1.242,1.5135 -0.84606,0.37495,0.50162 -1.1261,0.49693,0.53656 -0.15001,0.055656,-0.24595 --0.22601,0.13365,0.14384 -1.2412,1.3229,1.2145 --0.27757,-0.059545,0.10202 -0.10757,-0.097103,0.71807 --0.75057,-0.45978,-0.46484 --0.97697,-0.90457,-0.73866 --0.38251,-0.54952,-0.076576 --0.0074963,1.5641,-1.0968 -2.0089,3.7252,0.34778 -2.5053,4.0152,1.1607 -1.2613,3.0145,-0.11883 -1.626,3.4975,0.40149 -0.57467,2.5748,-0.5559 -0.27223,2.325,-1.1491 --0.98857,0.89059,-2.1303 -0.015729,1.7306,-1.0353 --1.5757,0.47897,-2.6461 -2.7193,3.4125,0.91031 --0.23575,1.8681,-1.0475 --1.0439,1.2157,-1.5633 --1.412,0.93564,-1.9779 -1.2746,3.0667,0.24769 -0.63882,2.4497,-0.74904 -1.2673,2.8636,0.0038115 -1.5297,3.1853,0.45137 --0.14927,1.7386,-1.1457 -2.2053,3.19,0.60563 -0.24205,2.1513,-1.0363 -1.1459,2.6334,-0.27667 --2.4571,0.81176,-2.9678 -0.24818,2.0973,-1.1623 --0.68993,1.2342,-1.6321 --1.0427,1.2388,-2.2123 --3.0384,0.43028,-3.404 --2.5802,0.7054,-2.6449 --0.074594,1.629,-1.2421 --0.12287,1.9453,-1.4686 --1.6956,0.91454,-1.9247 --1.0748,1.9479,-1.6296 -1.3501,3.0198,0.20284 --0.26028,2.4283,-0.017615 --0.094446,1.8989,-0.89622 -1.2898,2.8009,0.22531 -2.0783,3.8643,0.35455 --1.5934,0.88532,-1.8017 -2.5843,3.6608,0.55713 -0.21486,1.9106,-0.808 --0.40333,1.6474,-1.0436 -2.3518,3.4843,0.50179 -0.94974,3.0819,-0.24525 --0.49364,1.4036,-1.129 --0.37632,1.7927,-0.73797 --0.91834,1.3559,-1.3499 --1.2906,0.20859,-2.3015 -1.0214,3.0068,-0.29591 --0.010456,2.2622,-1.1662 --4.0117,-0.87305,-4.0119 --0.21314,1.0561,-0.98488 -0.82306,2.269,-0.21786 -1.0734,2.9048,-0.27158 --0.23799,2.0682,-0.67876 --0.82922,1.2574,-1.4447 -0.52128,2.71,0.11204 --0.78233,1.37,-1.9389 -0.82483,2.5663,-0.097424 --2.7874,-0.33868,-3.3896 -0.74397,3.0046,-0.49214 -2.282,3.6065,0.91681 -1.0441,2.1622,-0.4001 -0.79206,1.6932,-0.51636 --1.1592,1.2855,-2.0126 --0.76816,1.5099,-0.9792 -1.864,3.3787,0.30019 --0.68778,1.3926,-0.76961 --2.4976,0.28985,-2.9103 --1.3206,1.0322,-2.3795 -1.3147,2.9161,-0.26973 -0.058436,2.3221,-0.75942 -0.58954,2.5109,-0.1946 -0.8512,2.341,-0.66614 -2.7425,3.69,1.4654 -1.0178,3.1331,-0.16499 --3.2956,-0.89372,-3.2541 -1.9678,3.3589,0.16748 -1.9821,3.3536,0.77271 --0.64691,1.3878,-1.8322 --0.89547,1.0318,-1.5318 -1.4583,3.0299,0.21971 --0.69709,1.6679,-1.2821 --0.57352,2.1475,-0.72833 -1.9949,3.2238,0.12565 -0.39986,1.9922,0.16466 -2.6807,3.8377,0.72368 --1.1397,1.413,-1.3705 --0.79912,0.9744,-1.6151 -2.4355,3.8825,0.59875 --0.919,1.6668,-1.6283 --2.0274,0.58908,-2.1728 --1.0774,1.2514,-1.8375 -0.2245,2.246,-0.21247 -0.53923,2.1695,-0.58379 -0.25464,2.1586,-1.0186 --0.85909,1.6467,-1.5282 --1.4158,0.93224,-1.8805 -1.6945,2.82,0.028351 -3.4034,4.7775,1.7043 -3.2289,4.3375,1.2141 -3.2795,4.5926,1.5435 --0.38492,1.9098,-0.75276 -0.71665,2.2116,-0.60899 --0.16987,2.4017,-0.85621 --0.0026924,1.9906,-0.43284 --0.61662,1.3429,-1.6849 --0.27766,1.5546,-1.1834 -1.4043,2.9345,0.41183 -0.66785,2.6497,-0.75984 --1.9453,0.78394,-2.6254 -0.39007,2.0815,-1.2207 -3.7721,4.4592,1.2659 --0.076611,2.2881,-0.95275 -0.67343,2.2482,-1.2191 --2.9645,-0.13836,-3.5953 --1.1437,1.7696,-2.0472 --0.65103,1.0542,-1.677 -0.27629,2.2738,-0.43775 -1.2678,2.6634,-0.20776 --2.2685,0.50741,-2.6903 --0.45889,2.0837,-1.2039 --1.0031,1.4533,-0.99194 --1.0608,1.6655,-1.5377 -0.52917,2.0714,-0.67816 -2.0484,3.7681,0.60477 -0.65548,2.3257,-1.0315 -0.9417,2.4616,-1.0971 -1.6025,3.6568,-0.30451 -1.3959,2.6626,0.21203 --1.8762,0.59323,-2.4304 --0.033081,2.0047,-1.1959 -0.19176,2.2118,-0.90641 -3.4321,4.4412,1.4332 -1.2851,3.1189,0.2168 -0.10858,2.1975,-1.2397 -0.51556,2.2542,-0.64292 --2.9341,-0.12474,-2.8156 --3.3237,-0.36751,-3.6139 --0.52862,1.1144,-2.1116 -1.8324,3.2394,0.32047 -0.79391,2.6105,-0.3912 --0.25687,2.4859,-0.2091 --0.050846,2.1395,-0.99325 -2.757,4.1377,0.96629 -1.8607,2.9466,0.019197 --0.50707,1.4758,-1.0576 --0.46702,1.1086,-1.4747 -0.11842,2.3606,-0.34002 -0.61767,2.2567,-0.4994 --1.7431,0.62107,-1.9475 --3.8993,-0.6647,-3.7066 --0.76253,1.5571,-1.4425 -3.1483,4.3842,1.1011 --0.8633,1.359,-1.7863 -2.0454,3.5345,-0.10921 -1.7028,3.4294,-0.15775 -1.0591,2.7454,-0.19058 --0.17302,1.3553,-1.3947 --0.04441,2.1877,-1.2426 --1.4295,1.0314,-1.5831 --1.4795,0.92974,-1.7827 -0.89587,2.3658,-0.59053 -1.2368,3.1492,0.22589 -2.9527,3.4809,0.51724 --0.84716,1.406,-0.99541 -0.83558,2.8438,-0.33657 -2.1743,3.3512,0.65982 -3.0545,3.5135,1.0594 --1.0633,1.1518,-1.9669 --2.1827,0.16688,-2.2939 --0.30389,2.3271,-0.85231 -0.70196,2.262,-0.80812 --0.46074,1.6172,-1.2689 -1.1719,2.9783,-0.48615 --2.4393,1.3131,3.0278 --4.1919,0.32154,2.14 --2.884,0.67302,2.8116 --2.3062,0.61712,3.1546 --0.45794,2.2365,3.8274 --2.2437,0.89172,2.6683 --3.1548,-0.42132,2.3496 --2.0081,1.0154,3.316 --3.6574,-0.17316,2.1668 --2.9222,0.50626,2.4521 -0.24085,2.5638,4.6185 --1.8144,0.060226,2.6847 --3.1462,-0.13026,2.091 --2.146,0.45284,3.1495 --2.9515,0.10653,2.3578 --3.0057,-0.25501,2.1961 --2.3137,0.70411,2.8758 --2.6423,0.27853,1.9894 --1.7993,1.3167,3.7841 -0.25377,2.3319,4.3211 --2.4234,0.8883,3.3827 --2.5006,0.23384,2.5114 --0.75643,1.27,3.8465 --0.82958,1.4993,3.5625 --1.1487,1.7698,4.1092 --1.9435,1.3886,3.1852 --3.6055,-0.28671,1.8443 --1.0274,2.1412,3.9846 --2.3875,0.69726,3.0428 --1.7662,1.1975,2.8763 --2.6746,0.44915,2.1196 --1.3561,1.272,3.5925 --2.3863,0.81495,2.8456 --2.814,0.61679,1.996 --4.019,-0.44685,1.8715 --3.5064,-0.852,1.5273 -0.51787,3.3823,5.0798 -1.004,2.7672,5.3001 --3.4573,0.58689,2.4623 --2.1598,1.2001,2.8015 --1.9104,0.24633,2.7853 --2.6261,0.5693,2.8365 -0.6153,2.8689,5.173 --1.202,1.7882,3.7962 --2.8836,0.57486,2.896 --3.7771,-0.042052,2.1082 --1.8644,1.1815,3.274 --1.9054,1.1895,2.8991 --3.9557,0.16992,1.9112 --1.0379,1.8161,3.9284 --1.9193,1.0014,3.342 --0.11416,2.2954,4.2907 --2.3313,0.96534,2.8068 --1.2659,1.4917,3.8215 --2.9292,0.12168,2.6602 --1.98,0.6965,2.9268 --0.27129,2.2757,4.0148 -0.010834,2.6759,4.4826 --1.8767,1.4824,3.2742 -1.6277,3.7608,5.7578 --2.1222,0.69342,1.8976 --0.16599,2.5066,4.7662 --1.647,0.93619,2.632 --2.4732,0.63763,2.4119 -0.62836,2.3891,4.2134 --1.5908,1.6857,3.1838 --2.3837,0.87428,2.3988 --2.2597,1.1045,3.0302 --1.5337,1.2809,3.7214 --2.009,1.0864,2.7673 --1.9083,0.73419,2.7602 --2.2399,0.43803,2.3513 --3.3707,-0.25379,2.158 --2.0399,1.5221,2.8082 --4.1977,-0.39451,1.5023 --2.2258,0.74821,2.5628 --1.8701,0.93563,2.9273 --1.5203,1.0059,3.3122 --0.69018,2.2939,4.2232 --3.6696,0.15431,1.5653 --3.7288,-0.046977,1.5477 --3.8497,-9.0309,9.8855 --0.76216,5.5497,5.6213 -6.5951,1.0681,7.0362 --3.9972,-8.645,3.2122 -4.1924,-0.07647,-4.5577 --8.508,6.7221,-5.1831 -5.0043,-0.78132,-1.4815 --0.62189,5.6005,1.9512 -8.8983,-0.16512,-1.5992 --9.7205,3.9143,5.3505 --8.916,9.7012,-9.4862 -4.769,-2.9366,3.8559 -2.7113,2.4398,5.0688 -8.6194,0.31788,9.0712 --0.78079,6.3006,-2.2536 -0.2578,-0.21872,-8.8769 --1.5104,4.6292,-2.4932 --1.6817,4.2115,3.1503 --2.2353,6.6882,4.0353 -7.1107,-9.7815,-8.1853 -6.4604,-9.0325,8.9597 -8.2782,0.025347,0.69698 -6.7208,-4.1662,8.2048 -7.3618,-9.7241,-3.8138 -5.5117,5.8836,4.4979 --1.3614,-8.6543,-2.3308 --1.278,-3.7964,7.9775 --5.5139,-3.1999,-8.6312 --9.7363,6.3356,-4.7 --2.4807,-9.9125,2.4912 -6.7712,-0.12368,3.6056 --4.2751,2.269,4.738 --4.3174,-2.5184,8.6596 --3.4584,-6.0338,2.2934 --0.47581,7.9014,4.7661 --5.4803,9.737,2.7305 -9.2401,8.4356,-6.5973 --3.8708,-2.1117,-4.5533 -5.5785,3.2457,6.249 -7.9068,0.8022,-1.9348 --4.9255,-5.7784,3.2017 --7.0849,-3.8934,-4.2788 --3.1701,-9.732,9.2277 -4.6627,-9.9088,1.5311 --9.3227,9.7557,9.3326 -0.88478,6.2359,0.27842 -1.1689,5.4081,7.2845 -3.3937,8.0657,-5.4934 -1.6785,-7.5245,-5.1309 -3.7182,-8.0784,7.9765 -5.3197,1.0294,4.184 -7.9532,-9.8696,9.5029 -9.3358,-7.4861,-0.80871 -8.1159,-8.8844,4.8355 --6.4284,5.2535,3.3793 -9.5698,-8.572,-9.4078 -7.9597,4.3647,-2.9929 --9.4128,-7.1918,-8.3587 --4.3596,2.314,-8.7833 --6.242,-0.56982,5.2019 -2.1751,0.20705,2.5566 --5.8129,-3.0991,0.60934 -9.9547,-8.3048,9.7852 --9.6648,-4.884,-3.9408 --1.2074,0.51144,-6.386 --7.0321,-7.1893,1.385 -2.4289,-7.5906,-0.66856 -5.0874,0.054778,-2.1554 --4.3881,-4.2817,-9.4519 -0.54359,-7.7607,-3.1704 --3.7512,0.00092528,9.527 --6.3652,-2.442,1.5387 -5.5851,-4.5888,5.4128 -6.1902,9.1338,2.5282 -4.4663,-0.83864,4.661 --9.0938,-5.0996,-7.0132 -2.266,6.6091,-1.7072 --3.2957,-3.9365,-8.6203 -1.6773,-9.3356,7.6839 -8.2636,9.7512,6.6399 -0.02545,-0.40447,-3.6958 --1.6498,2.0707,7.9611 -5.9892,0.32498,5.062 -7.8122,9.5452,-6.949 -0.26707,-5.056,4.3083 --2.2055,3.3639,6.8328 -8.6128,-7.0654,5.6692 --4.3454,-1.8976,9.9566 -5.3987,-7.1589,1.7223 -4.5517,-3.1151,-2.7844 -8.2922,0.99864,-2.5218 --7.8776,-9.1514,9.7444 -7.7788,-5.3608,7.7442 -1.9008,-2.0242,-6.2874 --9.7584,-7.5862,-5.1174 --5.2337,-1.1474,-5.0626 --7.5275,-8.971,-6.5237 -7.6157,9.9329,-3.3139 -6.2646,3.8875,-1.8755 -5.2668,2.3004,2.4755 -6.2077,2.3431,7.9601 -3.6451,6.5948,3.5833 -2.496,9.5857,-7.3691 --2.6384,-1.2513,-0.54221 --5.9444,6.9242,9.349 --4.499,-2.0583,-0.024743 --0.36912,-1.5926,-2.0584 --1.9962,7.8398,9.7645 -4.0459,-3.0868,5.3666 --3.5728,6.1683,9.6629 diff --git a/fastlib/u/pram/mog_l2e/faster/mog_l2e_main.cc b/fastlib/u/pram/mog_l2e/faster/mog_l2e_main.cc deleted file mode 100644 index da4fd47981..0000000000 --- a/fastlib/u/pram/mog_l2e/faster/mog_l2e_main.cc +++ /dev/null @@ -1,145 +0,0 @@ -/** - * @author Parikshit Ram (pram@cc.gatech.edu) - * @file mog_l2e_main.cc - * - * This program test drives the L2 estimation - * of a Gaussian Mixture model. - * - * PARAMETERS TO BE INPUT: - * - * --data - * This is the file that contains the data on which - * the model is to be fit - * - * --mog_l2e/K - * This is the number of gaussians we want to fit - * on the data, defaults to '1' - * - * --output - * This file will contain the parameters estimated, - * defaults to 'output.csv' - * - */ - -#include "mog.h" -#include "../opt/optimizers.h" -//#include - - -int main(int argc, char* argv[]) { - - fx_init(argc, argv); - //srand(time(NULL)); - ////// READING PARAMETERS AND LOADING DATA ////// - - const char *data_filename = fx_param_str_req(NULL, "data"); - - Matrix data_points; - data::Load(data_filename, &data_points); - - ////// MIXTURE OF GAUSSIANS USING L2 ESTIMATION ////// - - datanode *mog_l2e_module = fx_submodule(NULL, "mog_l2e", "mog_l2e"); - index_t number_of_gaussians = fx_param_int(mog_l2e_module, "K", 1); - fx_format_param(mog_l2e_module, "D", "%d", data_points.n_rows()); - index_t dimension = fx_param_int_req(mog_l2e_module, "D");; - - ////// RUNNING AN OPTIMIZER TO MINIMIZE THE L2 ERROR ////// - - datanode *opt_module = fx_submodule(NULL, "opt", "opt"); - const char *opt_method = fx_param_str(opt_module, "method", "QuasiNewton"); - index_t param_dim = (number_of_gaussians*(dimension+1)*(dimension+2)/2 - 1); - fx_param_int(opt_module, "param_space_dim", param_dim); - - index_t optim_flag = (strcmp(opt_method, "NelderMead") == 0 ? 1 : 0); - MoGL2E mog; - - - if (optim_flag == 1) { - - ////// OPTIMIZER USING NELDER MEAD METHOD ////// - - NelderMead opt; - - ////// Initializing the optimizer ////// - fx_timer_start(opt_module, "init_opt"); - opt.Init(MoGL2E::L2ErrorForOpt, data_points, opt_module); - fx_timer_stop(opt_module, "init_opt"); - - ////// Getting starting points for the optimization ////// - double **pts; - pts = (double**)malloc((param_dim+1)*sizeof(double*)); - for(index_t i = 0; i < param_dim+1; i++) { - pts[i] = (double*)malloc(param_dim*sizeof(double)); - } - - fx_timer_start(opt_module, "get_init_pts"); - MoGL2E::MultiplePointsGenerator(pts, param_dim+1, - data_points, number_of_gaussians); - fx_timer_stop(opt_module, "get_init_pts"); - - ////// The optimization ////// - - fx_timer_start(opt_module, "optimizing"); - opt.Eval(pts); - fx_timer_stop(opt_module, "optimizing"); - - ////// Making model with the optimal parameters ////// - mog.MakeModel(mog_l2e_module, pts[0]); - - } - else { - - ////// OPTIMIZER USING QUASI NEWTON METHOD ////// - - QuasiNewton opt; - - ////// Initializing the optimizer ////// - fx_timer_start(opt_module, "init_opt"); - opt.Init(MoGL2E::L2ErrorForOpt, data_points, opt_module); - fx_timer_stop(opt_module, "init_opt"); - - ////// Getting starting point for the optimization ////// - double *pt; - pt = (double*)malloc(param_dim*sizeof(double)); - - //index_t rs = 0; - //while ( rs < 5) { - - fx_timer_start(opt_module, "get_init_pt"); - MoGL2E::InitialPointGenerator(pt, data_points, number_of_gaussians); - fx_timer_stop(opt_module, "get_init_pt"); - - ////// The optimization ////// - - fx_timer_start(opt_module, "optimizing"); - opt.Eval(pt); - fx_timer_stop(opt_module, "optimizing"); - - ////// Making model with optimal parameters ////// - mog.MakeModel(mog_l2e_module, pt); - //printf("minimum achieved: %Lf\n", mog.L2Error(data_points)); - //} - - } - - long double error = mog.L2Error(data_points); - NOTIFY("Minimum L2 error achieved: %Lf", error); - mog.Display(); - - ArrayList results; - mog.OutputResults(&results); - - - ////// OUTPUT RESULTS ////// - - const char *output_filename = fx_param_str(NULL, "output", "output.csv"); - - FILE *output_file = fopen(output_filename, "w"); - - ot::Print(results, output_file); - fclose(output_file); - fx_done(); - - return 1; -} diff --git a/fastlib/u/pram/mog_l2e/faster/phi.h b/fastlib/u/pram/mog_l2e/faster/phi.h deleted file mode 100644 index bdddb8720f..0000000000 --- a/fastlib/u/pram/mog_l2e/faster/phi.h +++ /dev/null @@ -1,156 +0,0 @@ -/** - * @author Parikshit Ram (pram@cc.gatech.edu) - * @file phi.h - * - * This file computes the Gaussian probability - * density function - */ -#include "fastlib/fastlib.h" -#include "fastlib/fastlib_int.h" -#include - -/** - * Calculates the multivariate Gaussian probability density function - * - * Example use: - * @code - * Vector x, mean; - * Matrix cov; - * .... - * long double f = phi(x, mean, cov); - * @endcode - */ - -long double phi(Vector& x , Vector& mean , Matrix& cov) { - - long double det, f; - double exponent; - index_t dim; - Matrix inv; - Vector diff, tmp; - - dim = x.length(); - la::InverseInit(cov, &inv); - det = la::Determinant(cov); - - if( det < 0){ - det = -det; - } - la::SubInit(mean,x,&diff); - la::MulInit(inv, diff, &tmp); - exponent = la::Dot(diff, tmp); - long double tmp1, tmp2, tmp3; - tmp1 = 1; - tmp2 = dim; - tmp2 = tmp2/2; - tmp2 = pow((2*(math::PI)),tmp2); - tmp1 = tmp1/tmp2; - tmp3 = 1; - tmp2 = sqrt(det); - tmp3 = tmp3/tmp2; - tmp2 = -exponent; - tmp2 = tmp2 / 2; - f = (tmp1*tmp3*exp(tmp2)); - - return f; -} - -/** - * Calculates the univariate Gaussian probability density function - * - * Example use: - * @code - * double x, mean, var; - * .... - * long double f = phi(x, mean, var); - * @endcode - */ - -long double phi(double x, double mean, double var) { - - long double f; - - f = exp(-1.0*((x-mean)*(x-mean)/(2*var)))/sqrt(2*math::PI*var); - return f; -} - -/** - * Calculates the multivariate Gaussian probability density function - * and also the gradients with respect to the mean and the variance - * - * Example use: - * @code - * Vector x, mean, g_mean, g_cov; - * ArrayList d_cov; // the dSigma - * .... - * long double f = phi(x, mean, cov, d_cov, &g_mean, &g_cov); - * @endcode - */ - -long double phi(Vector& x, Vector& mean, Matrix& cov, ArrayList& d_cov, Vector *g_mean, Vector *g_cov){ - - long double det, f; - double exponent; - index_t dim; - Matrix inv; - Vector diff, tmp; - - dim = x.length(); - la::InverseInit(cov, &inv); - det = la::Determinant(cov); - - if( det < 0){ - det = -det; - } - la::SubInit(mean,x,&diff); - la::MulInit(inv, diff, &tmp); - exponent = la::Dot(diff, tmp); - long double tmp1, tmp2, tmp3; - tmp1 = 1; - tmp2 = dim; - tmp2 = tmp2/2; - tmp2 = pow((2*(math::PI)),tmp2); - tmp1 = tmp1/tmp2; - tmp3 = 1; - tmp2 = sqrt(det); - tmp3 = tmp3/tmp2; - tmp2 = -exponent; - tmp2 = tmp2 / 2; - f = (tmp1*tmp3*exp(tmp2)); - - // Calculating the g_mean values which would be a (1 X dim) vector - la::ScaleInit(f,tmp,g_mean); - - // Calculating the g_cov values which would be a (1 X (dim*(dim+1)/2)) vector - double *g_cov_tmp; - g_cov_tmp = (double*)malloc(d_cov.size()*sizeof(double)); - for(index_t i = 0; i < d_cov.size(); i++){ - Vector tmp_d; - // Matrix inv_d; - Matrix inv_d, tmp_mat_1, tmp_mat_2; - double tmp_d_cov_d_r; - - la::MulInit(d_cov[i],inv,&tmp_mat_1); - la::MulInit(inv, tmp_mat_1, &tmp_mat_2); - la::MulInit(tmp_mat_2, diff, &tmp_d); - tmp_d_cov_d_r = la::Dot(diff, tmp_d); - - // la::MulInit(d_cov[i], tmp, &tmp_d); - // tmp_d_cov_d_r = la::Dot(tmp_d,tmp); - - la::MulInit(inv,d_cov[i],&inv_d); - - double trace = 0; - for(index_t j = 0; j < dim; j++) { - trace += inv_d.get(j,j); - } - - tmp_d_cov_d_r -= trace; - //printf("trace = %lf\n", trace); - - g_cov_tmp[i] = f*tmp_d_cov_d_r/2; - } - g_cov->Copy(g_cov_tmp,d_cov.size()); - - return f; -}