-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb6bc25
commit 9f136a0
Showing
12 changed files
with
278 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Binary file added
BIN
+970 Bytes
tests/python/tests/kml/catboost/kml/catboost_multiclass_tutorial_ht_catnum.kml
Binary file not shown.
Binary file added
BIN
+624 Bytes
tests/python/tests/kml/catboost/kml/catboost_tiny_1float_1hot_10trees.kml
Binary file not shown.
77 changes: 77 additions & 0 deletions
77
tests/python/tests/kml/catboost/php/catboost_multiclass_tutorial_ht_catnum.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
/** @return shape(features_map:float[], ans:float[])[] */ | ||
function getInput() { | ||
return [ | ||
shape([ | ||
"features_map" => [ | ||
"year" => 1996, | ||
"count" => 197, | ||
"season" => 1 | ||
], | ||
"ans" => [ | ||
-0.4315705250918395, | ||
-0.07602514583990287, | ||
0.5075956709317426 | ||
] | ||
]), | ||
shape([ | ||
"features_map" => [ | ||
"year" => 1968, | ||
"count" => 37, | ||
"season" => 1 | ||
], | ||
"ans" => [ | ||
-0.7547556359399779, | ||
-0.9511000859169567, | ||
1.7058557218569348 | ||
] | ||
]), | ||
shape([ | ||
"features_map" => [ | ||
"year" => 2002, | ||
"count" => 77, | ||
"season" => 0 | ||
], | ||
"ans" => [ | ||
-0.1531870128758389, | ||
0.3682398885336728, | ||
-0.21505287565783404 | ||
] | ||
]), | ||
shape([ | ||
"features_map" => [ | ||
"year" => 1948, | ||
"count" => 59, | ||
"season" => 0 | ||
], | ||
"ans" => [ | ||
-0.04081236490074001, | ||
-0.7956756034401067, | ||
0.8364879683408469 | ||
] | ||
]) | ||
]; | ||
} | ||
|
||
const eps = 1e-5; | ||
|
||
function ensure($x) | ||
{ | ||
if (!$x) { | ||
die(1); | ||
} | ||
} | ||
|
||
function main() | ||
{ | ||
$input = getInput(); | ||
foreach ($input as $row) { | ||
$predictions = kml_catboost_predict_ht_multi("catboost_multiclass_tutorial_ht_catnum", $row['features_map']); | ||
ensure(count($predictions) == count($row['ans'])); | ||
for ($i = 0; $i < count($predictions); $i++) { | ||
ensure(abs($predictions[$i] - $row['ans'][$i]) < eps); | ||
} | ||
} | ||
} | ||
main(); |
71 changes: 71 additions & 0 deletions
71
tests/python/tests/kml/catboost/php/catboost_tiny_1float_1hot_10trees.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
/** @return shape(float_features:float[], cat_features:string[], ans:float)[] */ | ||
function getInput() { | ||
return [ | ||
shape([ | ||
"float_features" => [ | ||
1 | ||
], | ||
"cat_features" => [ | ||
"a" | ||
], | ||
"ans" => 0.7363564860973357 | ||
]), | ||
shape([ | ||
"float_features" => [ | ||
2 | ||
], | ||
"cat_features" => [ | ||
"a" | ||
], | ||
"ans" => 1.4672203311538694 | ||
]), | ||
shape([ | ||
"float_features" => [ | ||
3 | ||
], | ||
"cat_features" => [ | ||
"a" | ||
], | ||
"ans" => -2.276542165549472 | ||
]), | ||
shape([ | ||
"float_features" => [ | ||
3 | ||
], | ||
"cat_features" => [ | ||
"b" | ||
], | ||
"ans" => -0.9489540606737137 | ||
]), | ||
shape([ | ||
"float_features" => [ | ||
5 | ||
], | ||
"cat_features" => [ | ||
"b" | ||
], | ||
"ans" => -0.9489540606737137 | ||
]), | ||
]; | ||
} | ||
|
||
const eps = 1e-5; | ||
|
||
function ensure($x) | ||
{ | ||
if (!$x) { | ||
die(1); | ||
} | ||
} | ||
|
||
function main() | ||
{ | ||
$input = getInput(); | ||
foreach ($input as $row) { | ||
$prediction = kml_catboost_predict_vectors("catboost_tiny_1float_1hot_10trees", $row['float_features'], $row['cat_features']); | ||
ensure(abs($prediction - $row['ans']) < eps); | ||
} | ||
} | ||
main(); |
20 changes: 20 additions & 0 deletions
20
tests/python/tests/kml/catboost/php/unrelated_to_inference.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
function ensure($x) { | ||
if (!$x) { | ||
die(1); | ||
} | ||
} | ||
|
||
function main() { | ||
$model_name = "catboost_tiny_1float_1hot_10trees"; | ||
|
||
ensure(kml_model_exists($model_name)); | ||
ensure(["x", "y"] === kml_get_feature_names($model_name)); | ||
ensure("val_1" == kml_get_custom_property($model_name, "property_1")); | ||
ensure("val_2, val_3" === kml_get_custom_property($model_name, "property_2")); | ||
ensure(null === kml_get_custom_property($model_name, "property_absent")); | ||
ensure(null === kml_xgboost_predict_matrix("absent_model", [])); | ||
} | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import os | ||
|
||
from python.lib.testcase import KphpCompilerAutoTestCase | ||
|
||
|
||
class TestKML(KphpCompilerAutoTestCase): | ||
def compile_and_check_success(self, php_script_path, kml_dir): | ||
kml_dir = os.path.join(self.test_dir, kml_dir) | ||
args = ["--kml-dir={}".format(kml_dir)] | ||
|
||
once_runner = self.make_kphp_once_runner(php_script_path) | ||
|
||
self.assertTrue(once_runner.compile_with_kphp({})) | ||
self.assertTrue(once_runner.run_with_kphp(args=args), "Got KPHP runtime error") | ||
|
||
def test_xgboost_tiny_ht_direct_int_keys_to_fvalue(self): | ||
self.compile_and_check_success(php_script_path="xgboost/php/xgb_tiny_ht_direct_int_keys_to_fvalue.php", | ||
kml_dir="xgboost/kml") | ||
self.compile_and_check_success(php_script_path="xgboost/php/xgb_tiny_ht_direct_int_keys_to_fvalue.php", | ||
kml_dir="xgboost") # Traverse directories recursively | ||
|
||
def test_xgb_tiny_ht_remap_str_keys_to_fvalue(self): | ||
self.compile_and_check_success(php_script_path="xgboost/php/xgb_tiny_ht_remap_str_keys_to_fvalue.php", | ||
kml_dir="xgboost/kml") | ||
|
||
def test_catboost_tiny_1float_1hot_10trees(self): | ||
self.compile_and_check_success(php_script_path="catboost/php/catboost_tiny_1float_1hot_10trees.php", | ||
kml_dir="catboost/kml") | ||
|
||
def test_catboost_multiclass_tutorial_ht_catnum(self): | ||
self.compile_and_check_success(php_script_path="catboost/php/catboost_multiclass_tutorial_ht_catnum.php", | ||
kml_dir="catboost/kml") | ||
|
||
def test_unrelated_to_inference(self): | ||
self.compile_and_check_success(php_script_path="catboost/php/unrelated_to_inference.php", | ||
kml_dir="catboost/kml") |
Binary file added
BIN
+197 Bytes
tests/python/tests/kml/xgboost/kml/xgb_tiny_ht_direct_int_keys_to_fvalue.kml
Binary file not shown.
Binary file added
BIN
+220 Bytes
tests/python/tests/kml/xgboost/kml/xgb_tiny_ht_remap_str_keys_to_fvalue.kml
Binary file not shown.
36 changes: 36 additions & 0 deletions
36
tests/python/tests/kml/xgboost/php/xgb_tiny_ht_direct_int_keys_to_fvalue.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
const eps = 1e-5; | ||
|
||
function ensure($x) | ||
{ | ||
if (!$x) { | ||
die(1); | ||
} | ||
} | ||
|
||
function main() | ||
{ | ||
$inputs = array( | ||
array("0" => 1, "1" => 1), | ||
array("0" => 2, "1" => 2), | ||
array("0" => 100, "1" => 100), | ||
array("0" => 4, "1" => -10), | ||
array("0" => 5, "1" => -555), | ||
); | ||
$expected = array( | ||
0.745589, | ||
0.437018, | ||
0.437018, | ||
0.156840, | ||
0.156840, | ||
); | ||
|
||
$ans = kml_xgboost_predict_matrix("xgb_tiny_ht_direct_int_keys_to_fvalue", $inputs); | ||
|
||
$length = count($expected); | ||
ensure($length == count($ans)); | ||
for ($i = 0; $i < $length; $i++) { | ||
ensure(abs($expected[$i] - $ans[$i]) < eps); | ||
} | ||
} | ||
main(); |
36 changes: 36 additions & 0 deletions
36
tests/python/tests/kml/xgboost/php/xgb_tiny_ht_remap_str_keys_to_fvalue.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
const eps = 1e-5; | ||
|
||
function ensure($x) | ||
{ | ||
if (!$x) { | ||
die(1); | ||
} | ||
} | ||
|
||
function main() | ||
{ | ||
$inputs = array( | ||
array("height" => 1, "weight" => 1, "useless_feature" => 0.1), | ||
array("height" => 2, "weight" => 2, "useless_feature" => 0.12), | ||
array("height" => 100, "weight" => 100, "useless_feature" => 0.123), | ||
array("height" => 4, "weight" => -10, "useless_feature" => 0.1234), | ||
array("height" => 5, "weight" => -555, "useless_feature" => 0.12345), | ||
); | ||
$expected = array( | ||
0.745589, | ||
0.437018, | ||
0.437018, | ||
0.156840, | ||
0.156840, | ||
); | ||
|
||
$ans = kml_xgboost_predict_matrix("xgb_tiny_ht_remap_str_keys_to_fvalue", $inputs); | ||
|
||
$length = count($expected); | ||
ensure($length == count($ans)); | ||
for ($i = 0; $i < $length; $i++) { | ||
ensure(abs($expected[$i] - $ans[$i]) < eps); | ||
} | ||
} | ||
main(); |