Skip to content

Commit

Permalink
XGBoost
Browse files Browse the repository at this point in the history
  • Loading branch information
rchak007 committed May 30, 2024
0 parents commit d1afe62
Show file tree
Hide file tree
Showing 62 changed files with 3,101 additions and 0 deletions.
739 changes: 739 additions & 0 deletions .ipynb_checkpoints/gizaTest1-checkpoint.ipynb

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
1,541 changes: 1,541 additions & 0 deletions GizathonHackathon.md

Large diffs are not rendered by default.

Binary file added Images/hackathonFlowChart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/image-20240520100825088.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/image-20240520101119441.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/image-20240520101328479.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/image-20240520101659807.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/image-20240520101905906.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/image-20240520101937506.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/image-20240520102234001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/image-20240520102237619.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/image-20240520102247386.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/image-20240520102453489.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/image-20240520102649162.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/image-20240520102918909.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/image-20240525115811302.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/image-20240525120809497.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/image-20240525120851866.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/image-20240525121040580.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/image-20240525121117861.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/image-20240525121221062.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/image-20240525121305446.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/image-20240525121429280.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/image-20240525122040197.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/image-20240525122201291.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/image-20240525124048894.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/image-20240525125419274.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/image-20240525125657865.png
Binary file added Images/image-20240525130321177.png
Binary file added Images/image-20240525130917217.png
Binary file added Images/image-20240525130942905.png
Binary file added Images/image-20240525134800752.png
Binary file added Images/image-20240525141136902.png
Binary file added Images/image-20240525141725467.png
Binary file added Images/image-20240525141746844.png
Binary file added Images/image-20240525141819962.png
Binary file added Images/image-20240525141836925.png
Binary file added Images/image-20240525142348171.png
Binary file added Images/image-20240525142544072.png
Binary file added Images/image-20240525142948742.png
Binary file added Images/image-20240525143244923.png
Binary file added Images/image-20240525143545880.png
Binary file added Images/image-20240525143932690.png
Binary file added Images/image-20240525143944209.png
Binary file added Images/image-20240525144141254.png
Binary file added Images/image-20240525144308860.png
Binary file added Images/image-20240530003409871.png
Binary file added Images/image-20240530004110556.png
Binary file added Images/image-20240530005104615.png
Binary file added Images/image-20240530005207866.png
Binary file added Images/image-20240530011707152.png
739 changes: 739 additions & 0 deletions gizaTest1.ipynb

Large diffs are not rendered by default.

Binary file added tmp/cachedir/cache.db
Binary file not shown.
1 change: 1 addition & 0 deletions xgb_diabetes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"model_type": "xgboost", "opt_type": 0, "learner": {"attributes": {}, "feature_names": [], "feature_types": [], "gradient_booster": {"model": {"gbtree_model_param": {"num_parallel_tree": "1", "num_trees": "2"}, "iteration_indptr": [0, 1, 2], "tree_info": [0, 0], "trees": [{"base_weights": [2.1551962e-06, -35.52351, 51.44785, -52.829765, 10.741674, 37.05116, 112.99444, -71.40181, -43.39292, -15.884881, 26.283365, 21.806906, 74.52042, 39.07488, 64.01196, -56.952522, -26.160921, -7.253008, -49.402424, -40.396854, 7.90817, -28.78045, 35.786476, -27.487764, 28.654728, -22.552406, 84.64206, -3.8604815, 75.23053, -66.86708, 4.0107665, -17.541075, 12.952693, -54.664833, -2.3628876, -13.7741785, -20.87677, -12.047309, 21.537113, -9.776771, -1.4604813, 20.830248, 25.867748, 7.1975937, -41.394474, 14.356332, 55.59948, -9.147308, 0.18951875, 89.78801, -10.460482, 3.939519, 82.22582, -9.776771, -21.553297, -3.5473084, 5.552692, -1.1826932, -15.165723, -16.843483, 9.3395195, -15.547309, 4.944158, 1.5632302, -12.247309, -1.965722, 10.353461, -8.589396, 11.130086, 7.089519, -1.8473084, -15.403683, 4.239519, 9.326403, -2.733646, 24.205349, 4.217307, -3.2604814, 28.090105, 6.939519, 26.465866], "categories": [], "categories_nodes": [], "categories_segments": [], "categories_sizes": [], "default_left": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "id": 0, "left_children": [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, -1, 27, 29, -1, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, -1, 51, 53, 55, 57, -1, 59, 61, 63, -1, -1, 65, -1, -1, 67, -1, 69, 71, 73, 75, -1, -1, 77, -1, -1, 79, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], "loss_changes": [648800.9, 168709.69, 124293.125, 23716.688, 24419.168, 66346.64, 14482.875, 6449.4062, 22228.703, 13150.189, 20391.217, 29817.914, 35315.11, 0.0, 8730.457, 17796.484, 0.0, 9058.359, 21902.016, 7590.4355, 8725.924, 387.8042, 22344.129, 5603.8916, 28482.074, 755.4624, 22195.578, 0.0, 2395.4258, 1923.8828, 1366.7615, 6085.4937, 0.0, 11906.922, 10174.322, 3807.5496, 0.0, 0.0, 3870.5864, 0.0, 0.0, 21985.516, 0.0, 1023.4474, 5145.992, 20309.305, 25959.742, 0.0, 0.0, 12630.375, 0.0, 0.0, 438.6836, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], "parents": [2147483647, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 14, 14, 15, 15, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 28, 28, 29, 29, 30, 30, 31, 31, 33, 33, 34, 34, 35, 35, 38, 38, 41, 41, 43, 43, 44, 44, 45, 45, 46, 46, 49, 49, 52, 52], "right_children": [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, -1, 28, 30, -1, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, -1, 52, 54, 56, 58, -1, 60, 62, 64, -1, -1, 66, -1, -1, 68, -1, 70, 72, 74, 76, -1, -1, 78, -1, -1, 80, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], "split_conditions": [0.0056499788, 0.0062067355, 0.07355214, -0.042570855, -0.023450946, 0.036201265, 0.022485405, -0.038719688, -0.051103264, 0.02472964, -0.04354178, -0.03980883, -0.00061173533, 39.07488, 0.016318427, -0.04559945, -26.160921, -0.004221514, 0.045345243, -0.02991782, -0.03321323, 0.0002609183, 0.03799897, -0.026833475, 0.0379505, 0.019913213, 0.19878799, -3.8604815, 0.08540807, -0.07563562, -0.04183994, 0.0030644094, 12.952693, 0.10794366, -0.034521777, 0.009438663, -20.87677, -12.047309, -0.028674295, -9.776771, -1.4604813, 0.01482098, 25.867748, -0.04183994, 0.020446286, 0.034750905, 0.038075905, -9.147308, 0.18951875, -0.071772285, -10.460482, 3.939519, -0.06726771, -9.776771, -21.553297, -3.5473084, 5.552692, -1.1826932, -15.165723, -16.843483, 9.3395195, -15.547309, 4.944158, 1.5632302, -12.247309, -1.965722, 10.353461, -8.589396, 11.130086, 7.089519, -1.8473084, -15.403683, 4.239519, 9.326403, -2.733646, 24.205349, 4.217307, -3.2604814, 28.090105, 6.939519, 26.465866], "split_indices": [2, 8, 2, 8, 2, 9, 5, 4, 4, 8, 3, 8, 8, 0, 4, 4, 0, 8, 5, 2, 3, 2, 7, 6, 3, 0, 5, 0, 2, 9, 0, 9, 0, 3, 8, 4, 0, 0, 6, 0, 0, 8, 0, 0, 4, 2, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "split_type": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "sum_hessian": [353.0, 209.0, 144.0, 152.0, 57.0, 118.0, 26.0, 49.0, 103.0, 21.0, 36.0, 85.0, 33.0, 18.0, 8.0, 28.0, 21.0, 15.0, 88.0, 10.0, 11.0, 5.0, 31.0, 10.0, 75.0, 3.0, 30.0, 1.0, 7.0, 24.0, 4.0, 13.0, 2.0, 79.0, 9.0, 6.0, 4.0, 2.0, 9.0, 4.0, 1.0, 25.0, 6.0, 3.0, 7.0, 50.0, 25.0, 2.0, 1.0, 29.0, 1.0, 1.0, 6.0, 4.0, 20.0, 2.0, 2.0, 10.0, 3.0, 78.0, 1.0, 2.0, 7.0, 4.0, 2.0, 3.0, 6.0, 6.0, 19.0, 1.0, 2.0, 6.0, 1.0, 29.0, 21.0, 15.0, 10.0, 1.0, 28.0, 1.0, 5.0], "tree_param": {"num_deleted": "0", "num_feature": "10", "num_nodes": "81", "size_leaf_vector": "1"}}, {"base_weights": [0.033973694, -23.928804, 39.55442, -39.92107, 3.6668823, 28.630907, 81.78349, -45.921833, -19.072487, -0.1979466, 18.967451, 10.280193, 47.480137, 24.659119, 26.368975, -36.62225, -60.225487, -1.4896207, -37.661182, 23.232634, -8.137161, 33.818333, -5.9450235, -28.651901, 52.621094, 12.051253, -3.281408, -5.3892593, -45.36009, -63.17431, -1.8156382, -15.503915, 15.430917, -44.61493, 7.3433585, -3.5389023, 56.34661, 5.487673, -28.235365, 53.727676, -3.121504, 25.000788, -17.273375, -0.4412842, -11.166572, 20.886992, 59.07768, 5.6961465, -5.458666, -14.175051, 7.9385905, -7.547262, -19.693068, -10.78396, 9.966923, 10.955309, -7.894888, -14.670368, 1.6660401, 3.4066155, -0.102104194, 8.510123, -6.9113336, 4.736274, 22.19846, -7.007573, 4.790467, -4.967204, -18.15296, 19.900429, 0.7423542, -6.6570506, 7.8785605, -7.566439, 4.074084, 11.221738, -3.9727972, 24.584923, 14.716818], "categories": [], "categories_nodes": [], "categories_segments": [], "categories_sizes": [], "default_left": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "id": 1, "left_children": [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, -1, 21, 23, 25, -1, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, -1, -1, 47, 49, 51, 53, 55, -1, 57, 59, 61, 63, 65, 67, 69, 71, -1, 73, -1, -1, 75, 77, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], "loss_changes": [336191.47, 97677.58, 59471.297, 16639.188, 18887.38, 36868.758, 7261.0938, 12160.359, 10729.702, 14698.639, 0.0, 21588.09, 22251.445, 2648.082, 0.0, 18313.352, 6947.1562, 14148.437, 5334.828, 17929.645, 16311.191, 17083.014, 35827.305, 877.0115, 9010.75, 0.0, 0.0, 5340.2256, 8445.039, 2009.5938, 4781.9624, 9398.17, 0.0, 3282.084, 96.34645, 8119.083, 5273.9688, 11256.677, 8043.7695, 9528.148, 5625.47, 0.0, 7944.5674, 0.0, 0.0, 6133.1597, 5377.6875, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], "parents": [2147483647, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 11, 11, 12, 12, 13, 13, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 27, 27, 28, 28, 29, 29, 30, 30, 31, 31, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37, 38, 38, 39, 39, 40, 40, 42, 42, 45, 45, 46, 46], "right_children": [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, -1, 22, 24, 26, -1, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, -1, -1, 48, 50, 52, 54, 56, -1, 58, 60, 62, 64, 66, 68, 70, 72, -1, 74, -1, -1, 76, 78, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], "split_conditions": [0.009961227, -0.0023983933, 0.07355214, 0.03081083, 0.1081111, 0.017293394, -0.052737556, 0.05068012, 0.019186998, -0.016704442, 18.967451, 0.030439656, -0.033245593, -0.060002632, 26.368975, 0.000778808, 0.03333708, 0.00806271, 0.019632837, -0.0018820165, 0.000778808, 0.05068012, -0.06917231, -0.020044709, 0.018583724, 12.051253, -3.281408, -0.045472477, 0.07351515, -0.07626374, 0.001750522, -0.0010776975, 15.430917, -0.0118968515, 0.045340985, 0.0020044427, -0.0010914305, -0.005696818, 0.0024165425, 0.008100982, -0.03603757, 25.000788, 0.05787118, -0.4412842, -11.166572, 0.045345243, -0.0010776975, 5.6961465, -5.458666, -14.175051, 7.9385905, -7.547262, -19.693068, -10.78396, 9.966923, 10.955309, -7.894888, -14.670368, 1.6660401, 3.4066155, -0.102104194, 8.510123, -6.9113336, 4.736274, 22.19846, -7.007573, 4.790467, -4.967204, -18.15296, 19.900429, 0.7423542, -6.6570506, 7.8785605, -7.566439, 4.074084, 11.221738, -3.9727972, 24.584923, 14.716818], "split_indices": [2, 8, 2, 0, 7, 3, 0, 1, 6, 4, 0, 2, 8, 0, 0, 6, 3, 4, 9, 0, 6, 1, 6, 0, 2, 0, 0, 0, 3, 2, 0, 9, 0, 8, 0, 8, 3, 4, 2, 3, 6, 0, 5, 0, 0, 5, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "split_type": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "sum_hessian": [353.0, 220.0, 133.0, 139.0, 81.0, 107.0, 26.0, 107.0, 32.0, 77.0, 4.0, 55.0, 52.0, 3.0, 23.0, 67.0, 40.0, 17.0, 15.0, 19.0, 58.0, 22.0, 33.0, 3.0, 49.0, 2.0, 1.0, 15.0, 52.0, 38.0, 2.0, 14.0, 3.0, 13.0, 2.0, 11.0, 8.0, 35.0, 23.0, 14.0, 8.0, 3.0, 30.0, 1.0, 2.0, 9.0, 40.0, 5.0, 10.0, 51.0, 1.0, 3.0, 35.0, 1.0, 1.0, 2.0, 12.0, 12.0, 1.0, 1.0, 1.0, 4.0, 7.0, 3.0, 5.0, 9.0, 26.0, 18.0, 5.0, 11.0, 3.0, 5.0, 3.0, 24.0, 6.0, 6.0, 3.0, 10.0, 30.0], "tree_param": {"num_deleted": "0", "num_feature": "10", "num_nodes": "79", "size_leaf_vector": "1"}}]}, "name": "gbtree"}, "learner_model_param": {"base_score": "1.5373654E2", "boost_from_average": "1", "num_class": "0", "num_feature": "10", "num_target": "1"}, "objective": {"name": "reg:squarederror", "reg_loss_param": {"scale_pos_weight": "1"}}}, "version": [2, 0, 3]}
6 changes: 6 additions & 0 deletions xgb_diabetes/Scarb.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "xgb_diabetes"
version = "0.1.0"
6 changes: 6 additions & 0 deletions xgb_diabetes/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "xgb_diabetes"
version = "0.1.0"

[cairo]
enable-gas = false
31 changes: 31 additions & 0 deletions xgb_diabetes/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
mod xgb_inference;

fn main(input_vector: Span<i32>) -> i32 {
let tree_0 = xgb_inference::Tree {
base_weights: array![0, -3552351, 5144785, -5282977, 1074167, 3705116, 11299444, -7140181, -4339292, -1588488, 2628337, 2180691, 7452042, 3907488, 6401196, -5695252, -2616092, -725301, -4940242, -4039685, 790817, -2878045, 3578648, -2748776, 2865473, -2255241, 8464206, -386048, 7523053, -6686708, 401077, -1754108, 1295269, -5466483, -236289, -1377418, -2087677, -1204731, 2153711, -977677, -146048, 2083025, 2586775, 719759, -4139447, 1435633, 5559948, -914731, 18952, 8978801, -1046048, 393952, 8222582, -977677, -2155330, -354731, 555269, -118269, -1516572, -1684348, 933952, -1554731, 494416, 156323, -1224731, -196572, 1035346, -858940, 1113009, 708952, -184731, -1540368, 423952, 932640, -273365, 2420535, 421731, -326048, 2809011, 693952, 2646587].span(),
left_children: array![1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 0, 27, 29, 0, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 0, 51, 53, 55, 57, 0, 59, 61, 63, 0, 0, 65, 0, 0, 67, 0, 69, 71, 73, 75, 0, 0, 77, 0, 0, 79, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0].span(),
right_children: array![2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 0, 28, 30, 0, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 0, 52, 54, 56, 58, 0, 60, 62, 64, 0, 0, 66, 0, 0, 68, 0, 70, 72, 74, 76, 0, 0, 78, 0, 0, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0].span(),
split_indices: array![2, 8, 2, 8, 2, 9, 5, 4, 4, 8, 3, 8, 8, 0, 4, 4, 0, 8, 5, 2, 3, 2, 7, 6, 3, 0, 5, 0, 2, 9, 0, 9, 0, 3, 8, 4, 0, 0, 6, 0, 0, 8, 0, 0, 4, 2, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0].span(),
split_conditions: array![565, 621, 7355, -4257, -2345, 3620, 2249, -3872, -5110, 2473, -4354, -3981, -61, 3907488, 1632, -4560, -2616092, -422, 4535, -2992, -3321, 26, 3800, -2683, 3795, 1991, 19879, -386048, 8541, -7564, -4184, 306, 1295269, 10794, -3452, 944, -2087677, -1204731, -2867, -977677, -146048, 1482, 2586775, -4184, 2045, 3475, 3808, -914731, 18952, -7177, -1046048, 393952, -6727, -977677, -2155330, -354731, 555269, -118269, -1516572, -1684348, 933952, -1554731, 494416, 156323, -1224731, -196572, 1035346, -858940, 1113009, 708952, -184731, -1540368, 423952, 932640, -273365, 2420535, 421731, -326048, 2809011, 693952, 2646587].span()
};
let tree_1 = xgb_inference::Tree {
base_weights: array![3397, -2392880, 3955442, -3992107, 366688, 2863091, 8178349, -4592183, -1907249, -19795, 1896745, 1028019, 4748014, 2465912, 2636898, -3662225, -6022549, -148962, -3766118, 2323263, -813716, 3381833, -594502, -2865190, 5262109, 1205125, -328141, -538926, -4536009, -6317431, -181564, -1550392, 1543092, -4461493, 734336, -353890, 5634661, 548767, -2823537, 5372768, -312150, 2500079, -1727338, -44128, -1116657, 2088699, 5907768, 569615, -545867, -1417505, 793859, -754726, -1969307, -1078396, 996692, 1095531, -789489, -1467037, 166604, 340662, -10210, 851012, -691133, 473627, 2219846, -700757, 479047, -496720, -1815296, 1990043, 74235, -665705, 787856, -756644, 407408, 1122174, -397280, 2458492, 1471682].span(),
left_children: array![1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 0, 21, 23, 25, 0, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 0, 0, 47, 49, 51, 53, 55, 0, 57, 59, 61, 63, 65, 67, 69, 71, 0, 73, 0, 0, 75, 77, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0].span(),
right_children: array![2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 0, 22, 24, 26, 0, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 0, 0, 48, 50, 52, 54, 56, 0, 58, 60, 62, 64, 66, 68, 70, 72, 0, 74, 0, 0, 76, 78, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0].span(),
split_indices: array![2, 8, 2, 0, 7, 3, 0, 1, 6, 4, 0, 2, 8, 0, 0, 6, 3, 4, 9, 0, 6, 1, 6, 0, 2, 0, 0, 0, 3, 2, 0, 9, 0, 8, 0, 8, 3, 4, 2, 3, 6, 0, 5, 0, 0, 5, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0].span(),
split_conditions: array![996, -240, 7355, 3081, 10811, 1729, -5274, 5068, 1919, -1670, 1896745, 3044, -3325, -6000, 2636898, 78, 3334, 806, 1963, -188, 78, 5068, -6917, -2004, 1858, 1205125, -328141, -4547, 7352, -7626, 175, -108, 1543092, -1190, 4534, 200, -109, -570, 242, 810, -3604, 2500079, 5787, -44128, -1116657, 4535, -108, 569615, -545867, -1417505, 793859, -754726, -1969307, -1078396, 996692, 1095531, -789489, -1467037, 166604, 340662, -10210, 851012, -691133, 473627, 2219846, -700757, 479047, -496720, -1815296, 1990043, 74235, -665705, 787856, -756644, 407408, 1122174, -397280, 2458492, 1471682].span()
};
let num_trees: u32 = 2;
let base_score: i32 = 15373654;
let opt_type: u8 = 0;
let trees: Span<xgb_inference::Tree> = array![tree_0, tree_1].span();
let mut result: i32 = xgb_inference::accumulate_scores_from_trees(num_trees, trees, input_vector, 0, 0);

if opt_type == 1 {
// Implement logic here
} else {
result = result + base_score;
}

return result;
}
38 changes: 38 additions & 0 deletions xgb_diabetes/src/xgb_inference.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use core::array::ArrayTrait;


#[derive(Copy, Drop)]
pub struct Tree {
pub base_weights: Span<i32>,
pub left_children: Span<u32>,
pub right_children: Span<u32>,
pub split_indices: Span<u32>,
pub split_conditions: Span<i32>
}

pub fn navigate_tree_and_accumulate_score(tree: Tree, features: Span<i32>, node: u32) -> i32 {
if *tree.left_children[node] == 0 {
if *tree.right_children[node] == 0{
return *tree.base_weights[node];
}
}
let mut next_node: u32 = 0;
let feature_index = *tree.split_indices[node];
let threshold = *tree.split_conditions[node];
if *features.at(feature_index) < threshold{
next_node = *tree.left_children[node];
}
else{
next_node = *tree.right_children[node];
}
navigate_tree_and_accumulate_score(tree, features, next_node)
}

pub fn accumulate_scores_from_trees(num_trees: u32, trees: Span<Tree>, features: Span<i32>, index:u32, accumulated_score:i32) -> i32{
if index >= num_trees{
return accumulated_score;
}
let tree: Tree = *trees[index];
let score_from_tree: i32 = navigate_tree_and_accumulate_score(tree, features, 0);
accumulate_scores_from_trees(num_trees, trees, features, index + 1, accumulated_score + score_from_tree)
}
Binary file added zk_xgboost.proof
Binary file not shown.

0 comments on commit d1afe62

Please sign in to comment.