{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/LightGBM/issues/469","repository_url":"https://api.github.com/repos/Microsoft/LightGBM","labels_url":"https://api.github.com/repos/Microsoft/LightGBM/issues/469/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/LightGBM/issues/469/comments","events_url":"https://api.github.com/repos/Microsoft/LightGBM/issues/469/events","html_url":"https://github.com/Microsoft/LightGBM/pull/469","id":224760676,"number":469,"title":"[WIP] translate model to if-else","user":{"login":"wxchan","id":13624043,"avatar_url":"https://avatars0.githubusercontent.com/u/13624043?v=3","gravatar_id":"","url":"https://api.github.com/users/wxchan","html_url":"https://github.com/wxchan","followers_url":"https://api.github.com/users/wxchan/followers","following_url":"https://api.github.com/users/wxchan/following{/other_user}","gists_url":"https://api.github.com/users/wxchan/gists{/gist_id}","starred_url":"https://api.github.com/users/wxchan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wxchan/subscriptions","organizations_url":"https://api.github.com/users/wxchan/orgs","repos_url":"https://api.github.com/users/wxchan/repos","events_url":"https://api.github.com/users/wxchan/events{/privacy}","received_events_url":"https://api.github.com/users/wxchan/received_events","type":"User","site_admin":false},"labels":[{"id":482569361,"url":"https://api.github.com/repos/Microsoft/LightGBM/labels/cla-already-signed","name":"cla-already-signed","color":"009800","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2017-04-27T11:58:54Z","updated_at":"2017-04-28T04:22:40Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/Microsoft/LightGBM/pulls/469","html_url":"https://github.com/Microsoft/LightGBM/pull/469","diff_url":"https://github.com/Microsoft/LightGBM/pull/469.diff","patch_url":"https://github.com/Microsoft/LightGBM/pull/469.patch"},"body":"#466 \r\n\r\nchecklist:\r\n\r\n- [ ] multi-threading\r\n- [x] predict type\r\n- [x] multi-class predict\r\n"},"comment":{"url":"https://api.github.com/repos/Microsoft/LightGBM/issues/comments/297903747","html_url":"https://github.com/Microsoft/LightGBM/pull/469#issuecomment-297903747","issue_url":"https://api.github.com/repos/Microsoft/LightGBM/issues/469","id":297903747,"user":{"login":"wxchan","id":13624043,"avatar_url":"https://avatars0.githubusercontent.com/u/13624043?v=3","gravatar_id":"","url":"https://api.github.com/users/wxchan","html_url":"https://github.com/wxchan","followers_url":"https://api.github.com/users/wxchan/followers","following_url":"https://api.github.com/users/wxchan/following{/other_user}","gists_url":"https://api.github.com/users/wxchan/gists{/gist_id}","starred_url":"https://api.github.com/users/wxchan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wxchan/subscriptions","organizations_url":"https://api.github.com/users/wxchan/orgs","repos_url":"https://api.github.com/users/wxchan/repos","events_url":"https://api.github.com/users/wxchan/events{/privacy}","received_events_url":"https://api.github.com/users/wxchan/received_events","type":"User","site_admin":false},"created_at":"2017-04-28T04:22:40Z","updated_at":"2017-04-28T04:22:40Z","body":"current format of output, we can replace the code with current Predict function and produce same result:\r\n\r\n```\r\ndouble PredictTree0(const double* arr) { if ( arr[0] <= 0 ) { return 0.53085714285714281; } else { return 0.53085714285714281; } }\r\n\r\ndouble PredictTree1(const double* arr) { if ( arr[25] <= 1.0674999999999999 ) { if ( arr[25] <= 0.66949999999999998 ) { if ( arr[9] <= 1.1375000000000002 ) { if ( arr[13] <= 1.3005 ) { if ( arr[22] <= 0.79849999999999999 ) { return -0.0030857146246092704; } else { if ( arr[22] <= 1.0605 ) { return -0.020805495108434793; } else { return -0.0038471359557522866; } } } else { if ( arr[21] <= 0.86150000000000015 ) { return -0.015876412489624122; } else { return 0.019545864659995957; } } } else { if ( arr[27] <= 0.83850000000000002 ) { return 0.019963931108928135; } else { return -0.0037267402751869376; } } } else { if ( arr[26] <= 0.77449999999999997 ) { if ( arr[5] <= 0.82050000000000001 ) { if ( arr[14] <= 1.2229999999999999 ) { return -0.025613187487767294; } else { return 0.0090764477187832305; } } else { return 0.012686097690945955; } } else { if ( arr[27] <= 0.90450000000000008 ) { if ( arr[26] <= 0.86550000000000016 ) { if ( arr[25] <= 0.94550000000000001 ) { if ( arr[27] <= 0.79949999999999999 ) { return 0.027430045142431896; } else { return 0.00037963196168188225; } } else { return -0.011909244167854811; } } else { return 0.033515005345244382; } } else { if ( arr[24] <= 1.0265 ) { if ( arr[22] <= 0.99049999999999994 ) { if ( arr[0] <= 1.0044999999999999 ) { return -0.011225249629618723; } else { return -0.040840817228020458; } } else { if ( arr[24] <= 0.82250000000000001 ) { return 0.024790391985467345; } else { return 0.0016312665777546975; } } } else { if ( arr[3] <= 1.6895000000000002 ) { return 0.016862472201139282; } else { return -0.0050087915763422728; } } } } } } else { if ( arr[25] <= 1.5645 ) { if ( arr[22] <= 1.0265 ) { if ( arr[27] <= 1.0474999999999999 ) { if ( arr[5] <= 0.89650000000000007 ) { return -0.023054755169849176; } else { if ( arr[21] <= 0.58250000000000002 ) { return 0.026459740361106859; } else { if ( arr[24] <= 1.2685 ) { return -0.010704762357189547; } else { return 0.015571002071307917; } } } } else { return -0.033873892423290343; } } else { return 0.0029050688747986079; } } else { if ( arr[3] <= 1.8334999999999999 ) { if ( arr[24] <= 1.2565 ) { if ( arr[26] <= 1.0004999999999999 ) { return -0.0074716796022459417; } else { return -0.034881831603262699; } } else { if ( arr[17] <= 1.5245 ) { return -0.024514286372491294; } else { return 0.017127051634031221; } } } else { return -0.05308571536966733; } } } }\r\n\r\ndouble PredictTree2(const double* arr) { if ( arr[25] <= 1.2450000000000001 ) { if ( arr[26] <= 0.80950000000000011 ) { if ( arr[5] <= 1.3494999999999999 ) { if ( arr[24] <= 0.73449999999999993 ) { if ( arr[22] <= 1.0705 ) { if ( arr[22] <= 0.73150000000000004 ) { return 0.01264707751929268; } else { return -0.0098681298654487923; } } else { return 0.013011340232226984; } } else { if ( arr[26] <= 0.72849999999999993 ) { if ( arr[23] <= 1.3315000000000001 ) { return -0.027013526772011014; } else { return 0.014375380019973415; } } else { if ( arr[27] <= 0.83850000000000002 ) { if ( arr[25] <= 0.96550000000000002 ) { return -0.0013600510561473822; } else { return -0.029383326620776837; } } else { return -0.028719829693420216; } } } } else { return 0.020932423025717316; } } else { if ( arr[27] <= 0.90450000000000008 ) { if ( arr[5] <= 0.88149999999999995 ) { if ( arr[25] <= 0.98449999999999993 ) { if ( arr[25] <= 0.66949999999999998 ) { return -0.00061530146274151997; } else { if ( arr[21] <= 1.0625 ) { if ( arr[26] <= 0.86950000000000016 ) { return 0.014936394124275354; } else { return 0.031343334250641765; } } else { return -0.0042954205538199052; } } } else { if ( arr[24] <= 0.68049999999999988 ) { return 0.032849449408791198; } else { if ( arr[26] <= 0.94350000000000001 ) { return -0.02081701218880163; } else { return 0.0071219777994515031; } } } } else { if ( arr[25] <= 0.69049999999999989 ) { return 0.015166935842218295; } else { if ( arr[25] <= 1.0114999999999998 ) { return 0.035250829918393067; } else { return 0.01674711877271795; } } } } else { if ( arr[22] <= 1.0485 ) { if ( arr[24] <= 1.0794999999999999 ) { return -0.025816740649074934; } else { if ( arr[25] <= 0.62349999999999994 ) { return -0.013027819019063552; } else { return 0.0068164612015485957; } } } else { if ( arr[25] <= 0.64749999999999996 ) { return -0.0073851318649833554; } else { return 0.011901040143106676; } } } } } else { if ( arr[27] <= 0.89549999999999996 ) { if ( arr[21] <= 1.0925 ) { if ( arr[21] <= 0.61149999999999993 ) { return 0.011967290253528256; } else { return -0.016260557768785655; } } else { return 0.022262156480021503; } } else { if ( arr[24] <= 1.2484999999999999 ) { if ( arr[22] <= 1.0445 ) { return -0.036910389493118582; } else { return -0.021055382365258824; } } else { if ( arr[3] <= 1.8134999999999999 ) { return -0.0073324029574441578; } else { return -0.034800658630633342; } } } } }\r\n\r\ndouble PredictTree3(const double* arr) { if ( arr[25] <= 1.0674999999999999 ) { if ( arr[25] <= 0.62349999999999994 ) { if ( arr[13] <= 0.94250000000000012 ) { if ( arr[9] <= 1.0065 ) { return -0.016091445113304546; } else { if ( arr[1] <= 0.95750000000000002 ) { return 0.0042105155087150689; } else { return -0.02679562216905473; } } } else { if ( arr[27] <= 0.83650000000000002 ) { if ( arr[25] <= 0.52350000000000008 ) { return 0.00088933590322224005; } else { return 0.024935888667397568; } } else { if ( arr[5] <= 1.3565 ) { return -0.016886498744126101; } else { return 0.01393558048662108; } } } } else { if ( arr[26] <= 0.77449999999999997 ) { if ( arr[5] <= 0.82050000000000001 ) { return -0.018648402715409958; } else { if ( arr[27] <= 0.74750000000000005 ) { return 0.019181893073870134; } else { return -0.011612674155638113; } } } else { if ( arr[27] <= 0.90450000000000008 ) { if ( arr[26] <= 0.86550000000000016 ) { if ( arr[25] <= 0.89549999999999996 ) { if ( arr[27] <= 0.79949999999999999 ) { return 0.024705379148269539; } else { return 0.0027802574627395658; } } else { if ( arr[27] <= 0.84050000000000002 ) { if ( arr[0] <= 1.1685000000000001 ) { return 0.0086605681224196807; } else { return -0.024192525524997802; } } else { return -0.039347421672675069; } } } else { if ( arr[25] <= 0.68649999999999989 ) { if ( arr[13] <= 0.88549999999999995 ) { return -0.0090364048983117649; } else { return 0.029530192630635135; } } else { return 0.027849546508996931; } } } else { if ( arr[9] <= 1.3174999999999999 ) { if ( arr[3] <= 2.0309999999999997 ) { if ( arr[5] <= 0.8125 ) { return -0.0062204765268283422; } else { if ( arr[0] <= 1.746 ) { return 0.014601569256459864; } else { return -0.015405561329103385; } } } else { return -0.01871583659491436; } } else { return 0.017671862238888537; } } } } } else { if ( arr[25] <= 1.5645 ) { if ( arr[22] <= 1.0265 ) { if ( arr[27] <= 1.0285 ) { if ( arr[5] <= 0.98049999999999993 ) { return -0.016386592215251478; } else { return 0.003114845264744405; } } else { if ( arr[24] <= 1.3025 ) { return -0.0381911538910399; } else { if ( arr[7] <= 0.79549999999999987 ) { return -0.024353711355134106; } else { return 0.014312871431006062; } } } } else { return 0.0029286660450065548; } } else { if ( arr[3] <= 1.8334999999999999 ) { return -0.021790739893908721; } else { return -0.044458945736433116; } } } }\r\n\r\nvoid GBDT::PredictRaw(const double* features, double *output) const {\r\n\toutput[0] += PredictTree0(features);\r\n\toutput[0] += PredictTree1(features);\r\n\toutput[0] += PredictTree2(features);\r\n\toutput[0] += PredictTree3(features);\r\n}\r\n\r\nvoid GBDT::Predict(const double* features, double *output) const {\r\n\toutput[0] += PredictTree0(features);\r\n\toutput[0] += PredictTree1(features);\r\n\toutput[0] += PredictTree2(features);\r\n\toutput[0] += PredictTree3(features);\r\n\tif (objective_function_ != nullptr) {\r\n\t\tobjective_function_->ConvertOutput(output, output);\r\n\t}\r\n}\r\n\r\ndouble PredictTree0Leaf(const double* arr) { if ( arr[0] <= 0 ) { return 0; } else { return 1; } }\r\n\r\ndouble PredictTree1Leaf(const double* arr) { if ( arr[25] <= 1.0674999999999999 ) { if ( arr[25] <= 0.66949999999999998 ) { if ( arr[9] <= 1.1375000000000002 ) { if ( arr[13] <= 1.3005 ) { if ( arr[22] <= 0.79849999999999999 ) { return 0; } else { if ( arr[22] <= 1.0605 ) { return 18; } else { return 19; } } } else { if ( arr[21] <= 0.86150000000000015 ) { return 15; } else { return 27; } } } else { if ( arr[27] <= 0.83850000000000002 ) { return 10; } else { return 21; } } } else { if ( arr[26] <= 0.77449999999999997 ) { if ( arr[5] <= 0.82050000000000001 ) { if ( arr[14] <= 1.2229999999999999 ) { return 2; } else { return 25; } } else { return 7; } } else { if ( arr[27] <= 0.90450000000000008 ) { if ( arr[26] <= 0.86550000000000016 ) { if ( arr[25] <= 0.94550000000000001 ) { if ( arr[27] <= 0.79949999999999999 ) { return 3; } else { return 17; } } else { return 9; } } else { return 6; } } else { if ( arr[24] <= 1.0265 ) { if ( arr[22] <= 0.99049999999999994 ) { if ( arr[0] <= 1.0044999999999999 ) { return 4; } else { return 22; } } else { if ( arr[24] <= 0.82250000000000001 ) { return 14; } else { return 29; } } } else { if ( arr[3] <= 1.6895000000000002 ) { return 13; } else { return 16; } } } } } } else { if ( arr[25] <= 1.5645 ) { if ( arr[22] <= 1.0265 ) { if ( arr[27] <= 1.0474999999999999 ) { if ( arr[5] <= 0.89650000000000007 ) { return 1; } else { if ( arr[21] <= 0.58250000000000002 ) { return 12; } else { if ( arr[24] <= 1.2685 ) { return 28; } else { return 30; } } } } else { return 11; } } else { return 8; } } else { if ( arr[3] <= 1.8334999999999999 ) { if ( arr[24] <= 1.2565 ) { if ( arr[26] <= 1.0004999999999999 ) { return 5; } else { return 26; } } else { if ( arr[17] <= 1.5245 ) { return 23; } else { return 24; } } } else { return 20; } } } }\r\n\r\ndouble PredictTree2Leaf(const double* arr) { if ( arr[25] <= 1.2450000000000001 ) { if ( arr[26] <= 0.80950000000000011 ) { if ( arr[5] <= 1.3494999999999999 ) { if ( arr[24] <= 0.73449999999999993 ) { if ( arr[22] <= 1.0705 ) { if ( arr[22] <= 0.73150000000000004 ) { return 0; } else { return 30; } } else { return 29; } } else { if ( arr[26] <= 0.72849999999999993 ) { if ( arr[23] <= 1.3315000000000001 ) { return 12; } else { return 23; } } else { if ( arr[27] <= 0.83850000000000002 ) { if ( arr[25] <= 0.96550000000000002 ) { return 22; } else { return 28; } } else { return 27; } } } } else { return 8; } } else { if ( arr[27] <= 0.90450000000000008 ) { if ( arr[5] <= 0.88149999999999995 ) { if ( arr[25] <= 0.98449999999999993 ) { if ( arr[25] <= 0.66949999999999998 ) { return 2; } else { if ( arr[21] <= 1.0625 ) { if ( arr[26] <= 0.86950000000000016 ) { return 9; } else { return 24; } } else { return 13; } } } else { if ( arr[24] <= 0.68049999999999988 ) { return 7; } else { if ( arr[26] <= 0.94350000000000001 ) { return 25; } else { return 26; } } } } else { if ( arr[25] <= 0.69049999999999989 ) { return 4; } else { if ( arr[25] <= 1.0114999999999998 ) { return 17; } else { return 18; } } } } else { if ( arr[22] <= 1.0485 ) { if ( arr[24] <= 1.0794999999999999 ) { return 3; } else { if ( arr[25] <= 0.62349999999999994 ) { return 6; } else { return 21; } } } else { if ( arr[25] <= 0.64749999999999996 ) { return 5; } else { return 14; } } } } } else { if ( arr[27] <= 0.89549999999999996 ) { if ( arr[21] <= 1.0925 ) { if ( arr[21] <= 0.61149999999999993 ) { return 1; } else { return 19; } } else { return 15; } } else { if ( arr[24] <= 1.2484999999999999 ) { if ( arr[22] <= 1.0445 ) { return 10; } else { return 20; } } else { if ( arr[3] <= 1.8134999999999999 ) { return 11; } else { return 16; } } } } }\r\n\r\ndouble PredictTree3Leaf(const double* arr) { if ( arr[25] <= 1.0674999999999999 ) { if ( arr[25] <= 0.62349999999999994 ) { if ( arr[13] <= 0.94250000000000012 ) { if ( arr[9] <= 1.0065 ) { return 0; } else { if ( arr[1] <= 0.95750000000000002 ) { return 19; } else { return 29; } } } else { if ( arr[27] <= 0.83650000000000002 ) { if ( arr[25] <= 0.52350000000000008 ) { return 12; } else { return 22; } } else { if ( arr[5] <= 1.3565 ) { return 14; } else { return 21; } } } } else { if ( arr[26] <= 0.77449999999999997 ) { if ( arr[5] <= 0.82050000000000001 ) { return 2; } else { if ( arr[27] <= 0.74750000000000005 ) { return 6; } else { return 27; } } } else { if ( arr[27] <= 0.90450000000000008 ) { if ( arr[26] <= 0.86550000000000016 ) { if ( arr[25] <= 0.89549999999999996 ) { if ( arr[27] <= 0.79949999999999999 ) { return 3; } else { return 18; } } else { if ( arr[27] <= 0.84050000000000002 ) { if ( arr[0] <= 1.1685000000000001 ) { return 9; } else { return 26; } } else { return 24; } } } else { if ( arr[25] <= 0.68649999999999989 ) { if ( arr[13] <= 0.88549999999999995 ) { return 8; } else { return 28; } } else { return 20; } } } else { if ( arr[9] <= 1.3174999999999999 ) { if ( arr[3] <= 2.0309999999999997 ) { if ( arr[5] <= 0.8125 ) { return 4; } else { if ( arr[0] <= 1.746 ) { return 16; } else { return 17; } } } else { return 15; } } else { return 10; } } } } } else { if ( arr[25] <= 1.5645 ) { if ( arr[22] <= 1.0265 ) { if ( arr[27] <= 1.0285 ) { if ( arr[5] <= 0.98049999999999993 ) { return 1; } else { return 13; } } else { if ( arr[24] <= 1.3025 ) { return 11; } else { if ( arr[7] <= 0.79549999999999987 ) { return 25; } else { return 30; } } } } else { return 7; } } else { if ( arr[3] <= 1.8334999999999999 ) { return 5; } else { return 23; } } } }\r\n\r\nvoid GBDT::PredictLeafIndex(const double* features, double *output) const {\r\n\toutput[0] = PredictTree0Leaf(features);\r\n\toutput[1] = PredictTree1Leaf(features);\r\n\toutput[2] = PredictTree2Leaf(features);\r\n\toutput[3] = PredictTree3Leaf(features);\r\n}\r\n```"}}
{"actor":{"display_login":"wxchan"}}