From 68879fc651051034849de4d1829e02c58b7c06d4 Mon Sep 17 00:00:00 2001 From: Darius Morawiec Date: Mon, 4 Dec 2017 22:14:24 +0100 Subject: [PATCH] Add prediction in the used programming language --- .../c/basics_embedded.ipynb | 90 +- .../DecisionTreeClassifier/c/basics.ipynb | 84 +- .../c/basics_embedded.ipynb | 160 ++-- .../ExtraTreesClassifier/c/basics.ipynb | 787 ++++++++++-------- .../classifier/LinearSVC/c/basics.ipynb | 84 +- .../estimator/classifier/NuSVC/c/basics.ipynb | 87 +- .../c/basics_embedded.ipynb | 148 +++- .../js/basics_embedded.ipynb | 6 +- .../estimator/classifier/SVC/c/basics.ipynb | 86 +- 9 files changed, 1027 insertions(+), 505 deletions(-) diff --git a/examples/estimator/classifier/AdaBoostClassifier/c/basics_embedded.ipynb b/examples/estimator/classifier/AdaBoostClassifier/c/basics_embedded.ipynb index 2880ebd5..3fa177b4 100644 --- a/examples/estimator/classifier/AdaBoostClassifier/c/basics_embedded.ipynb +++ b/examples/estimator/classifier/AdaBoostClassifier/c/basics_embedded.ipynb @@ -92,36 +92,10 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": { "scrolled": false }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "CPU times: user 2.39 ms, sys: 1.6 ms, total: 3.99 ms\n", - "Wall time: 2.81 ms\n" - ] - } - ], - "source": [ - "%%time\n", - "\n", - "from sklearn_porter import Porter\n", - "\n", - "porter = Porter(clf, language='c')\n", - "output = porter.export()\n", - "\n", - "with open('AdaBoostClassifier.c', 'w') as f:\n", - " f.write(output)" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, "outputs": [ { "name": "stdout", @@ -389,14 +363,21 @@ " printf(\"%d\", predict(features));\n", " return 0;\n", "\n", - "}" + "}\n", + "CPU times: user 3.09 ms, sys: 1.99 ms, total: 5.09 ms\n", + "Wall time: 3.47 ms\n" ] } ], "source": [ - "%%bash\n", + "%%time\n", + "\n", + "from sklearn_porter import Porter\n", + "\n", + "porter = Porter(clf, language='c')\n", + "output = porter.export()\n", "\n", - "cat AdaBoostClassifier.c" + "print(output)" ] }, { @@ -406,9 +387,55 @@ "### Run classification in C:" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Save the transpiled estimator:" + ] + }, { "cell_type": "code", "execution_count": 6, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "with open('ada.c', 'w') as f:\n", + " f.write(output)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Compiling:" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "%%bash\n", + "\n", + "gcc ada.c -std=c99 -lm -o ada" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Prediction:" + ] + }, + { + "cell_type": "code", + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -422,8 +449,7 @@ "source": [ "%%bash\n", "\n", - "gcc ./AdaBoostClassifier.c -std=c99 -lm -o AdaBoostClassifier\n", - "./AdaBoostClassifier 1 2 3 4" + "./ada 1 2 3 4" ] } ], diff --git a/examples/estimator/classifier/DecisionTreeClassifier/c/basics.ipynb b/examples/estimator/classifier/DecisionTreeClassifier/c/basics.ipynb index 99999ba8..a3e14a10 100644 --- a/examples/estimator/classifier/DecisionTreeClassifier/c/basics.ipynb +++ b/examples/estimator/classifier/DecisionTreeClassifier/c/basics.ipynb @@ -106,9 +106,9 @@ "\n", "int lChilds[17] = {1, -1, 3, 4, 5, -1, -1, 8, -1, 10, -1, -1, 13, 14, -1, -1, -1};\n", "int rChilds[17] = {2, -1, 12, 7, 6, -1, -1, 9, -1, 11, -1, -1, 16, 15, -1, -1, -1};\n", - "double thresholds[17] = {2.45000004768, -2.0, 1.75, 4.94999980927, 1.65000009537, -2.0, -2.0, 1.54999995232, -2.0, 5.44999980927, -2.0, -2.0, 4.85000038147, 5.94999980927, -2.0, -2.0, -2.0};\n", - "int indices[17] = {2, 2, 3, 2, 3, 2, 2, 3, 2, 2, 2, 2, 2, 0, 2, 2, 2};\n", - "int classes[17][3] = {{50, 50, 50}, {50, 0, 0}, {0, 50, 50}, {0, 49, 5}, {0, 47, 1}, {0, 47, 0}, {0, 0, 1}, {0, 2, 4}, {0, 0, 3}, {0, 2, 1}, {0, 2, 0}, {0, 0, 1}, {0, 1, 45}, {0, 1, 2}, {0, 1, 0}, {0, 0, 2}, {0, 0, 43}};\n", + "double thresholds[17] = {2.45000004768, -2.0, 1.75, 4.94999980927, 1.65000009537, -2.0, -2.0, 1.54999995232, -2.0, 6.94999980927, -2.0, -2.0, 4.85000038147, 3.09999990463, -2.0, -2.0, -2.0};\n", + "int indices[17] = {2, -2, 3, 2, 3, -2, -2, 3, -2, 0, -2, -2, 2, 1, -2, -2, -2};\n", + "int classes[17][3] = {{50, 50, 50}, {50, 0, 0}, {0, 50, 50}, {0, 49, 5}, {0, 47, 1}, {0, 47, 0}, {0, 0, 1}, {0, 2, 4}, {0, 0, 3}, {0, 2, 1}, {0, 2, 0}, {0, 0, 1}, {0, 1, 45}, {0, 1, 2}, {0, 0, 2}, {0, 1, 0}, {0, 0, 43}};\n", "\n", "int findMax(int nums[N_CLASSES]) {\n", " int index = 0;\n", @@ -143,11 +143,15 @@ " return 0;\n", "\n", "}\n", - "\n" + "\n", + "CPU times: user 1.21 ms, sys: 1.05 ms, total: 2.26 ms\n", + "Wall time: 1.43 ms\n" ] } ], "source": [ + "%%time\n", + "\n", "from sklearn_porter import Porter\n", "\n", "porter = Porter(clf, language='c')\n", @@ -155,6 +159,78 @@ "\n", "print(output)" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Run classification in C:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Save the transpiled estimator:" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "with open('tree.c', 'w') as f:\n", + " f.write(output)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Compiling:" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "%%bash\n", + "\n", + "gcc tree.c -std=c99 -lm -o tree" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Prediction:" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2" + ] + } + ], + "source": [ + "%%bash\n", + "\n", + "./tree 1 2 3 4" + ] } ], "metadata": { diff --git a/examples/estimator/classifier/DecisionTreeClassifier/c/basics_embedded.ipynb b/examples/estimator/classifier/DecisionTreeClassifier/c/basics_embedded.ipynb index 925cb7ff..9fdaf4d5 100644 --- a/examples/estimator/classifier/DecisionTreeClassifier/c/basics_embedded.ipynb +++ b/examples/estimator/classifier/DecisionTreeClassifier/c/basics_embedded.ipynb @@ -87,7 +87,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": { "scrolled": false }, @@ -100,69 +100,34 @@ "#include \n", "#include \n", "\n", - "int predict(float atts[4]) {\n", + "#define N_FEATURES 4\n", + "#define N_CLASSES 3\n", "\n", - " int classes[3];\n", - " \n", - " if (features[2] <= 2.45000004768) {\n", - " classes[0] = 50; \n", - " classes[1] = 0; \n", - " classes[2] = 0; \n", - " } else {\n", - " if (features[3] <= 1.75) {\n", - " if (features[2] <= 4.94999980927) {\n", - " if (features[3] <= 1.65000009537) {\n", - " classes[0] = 0; \n", - " classes[1] = 47; \n", - " classes[2] = 0; \n", - " } else {\n", - " classes[0] = 0; \n", - " classes[1] = 0; \n", - " classes[2] = 1; \n", - " }\n", - " } else {\n", - " if (features[3] <= 1.54999995232) {\n", - " classes[0] = 0; \n", - " classes[1] = 0; \n", - " classes[2] = 3; \n", - " } else {\n", - " if (features[0] <= 6.94999980927) {\n", - " classes[0] = 0; \n", - " classes[1] = 2; \n", - " classes[2] = 0; \n", - " } else {\n", - " classes[0] = 0; \n", - " classes[1] = 0; \n", - " classes[2] = 1; \n", - " }\n", - " }\n", - " }\n", - " } else {\n", - " if (features[2] <= 4.85000038147) {\n", - " if (features[1] <= 3.09999990463) {\n", - " classes[0] = 0; \n", - " classes[1] = 0; \n", - " classes[2] = 2; \n", - " } else {\n", - " classes[0] = 0; \n", - " classes[1] = 1; \n", - " classes[2] = 0; \n", - " }\n", - " } else {\n", - " classes[0] = 0; \n", - " classes[1] = 0; \n", - " classes[2] = 43; \n", - " }\n", - " }\n", - " }\n", + "int lChilds[17] = {1, -1, 3, 4, 5, -1, -1, 8, -1, 10, -1, -1, 13, 14, -1, -1, -1};\n", + "int rChilds[17] = {2, -1, 12, 7, 6, -1, -1, 9, -1, 11, -1, -1, 16, 15, -1, -1, -1};\n", + "double thresholds[17] = {0.800000011921, -2.0, 1.75, 4.94999980927, 1.65000009537, -2.0, -2.0, 1.54999995232, -2.0, 6.94999980927, -2.0, -2.0, 4.85000038147, 5.94999980927, -2.0, -2.0, -2.0};\n", + "int indices[17] = {3, -2, 3, 2, 3, -2, -2, 3, -2, 0, -2, -2, 2, 0, -2, -2, -2};\n", + "int classes[17][3] = {{50, 50, 50}, {50, 0, 0}, {0, 50, 50}, {0, 49, 5}, {0, 47, 1}, {0, 47, 0}, {0, 0, 1}, {0, 2, 4}, {0, 0, 3}, {0, 2, 1}, {0, 2, 0}, {0, 0, 1}, {0, 1, 45}, {0, 1, 2}, {0, 1, 0}, {0, 0, 2}, {0, 0, 43}};\n", "\n", + "int findMax(int nums[N_CLASSES]) {\n", " int index = 0;\n", - " for (int i = 0; i < 3; i++) {\n", - " index = classes[i] > classes[index] ? i : index;\n", + " for (int i = 0; i < N_CLASSES; i++) {\n", + " index = nums[i] > nums[index] ? i : index;\n", " }\n", " return index;\n", "}\n", "\n", + "int predict(double features[N_FEATURES], int node) {\n", + " if (thresholds[node] != -2) {\n", + " if (features[indices[node]] <= thresholds[node]) {\n", + " return predict(features, lChilds[node]);\n", + " } else {\n", + " return predict(features, rChilds[node]);\n", + " }\n", + " }\n", + " return findMax(classes[node]);\n", + "}\n", + "\n", "int main(int argc, const char * argv[]) {\n", "\n", " /* Features: */\n", @@ -173,14 +138,19 @@ " }\n", "\n", " /* Prediction: */\n", - " printf(\"%d\", predict(features));\n", + " printf(\"%d\", predict(features, 0));\n", " return 0;\n", "\n", - "}\n" + "}\n", + "\n", + "CPU times: user 1.3 ms, sys: 1.09 ms, total: 2.39 ms\n", + "Wall time: 1.4 ms\n" ] } ], "source": [ + "%%time\n", + "\n", "from sklearn_porter import Porter\n", "\n", "porter = Porter(clf, language='c')\n", @@ -188,6 +158,78 @@ "\n", "print(output)" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Run classification in C:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Save the transpiled estimator:" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "with open('tree.c', 'w') as f:\n", + " f.write(output)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Compiling:" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "%%bash\n", + "\n", + "gcc tree.c -std=c99 -lm -o tree" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Prediction:" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1" + ] + } + ], + "source": [ + "%%bash\n", + "\n", + "./tree 1 2 3 4" + ] } ], "metadata": { diff --git a/examples/estimator/classifier/ExtraTreesClassifier/c/basics.ipynb b/examples/estimator/classifier/ExtraTreesClassifier/c/basics.ipynb index 1c6d42c7..b61a8b3f 100644 --- a/examples/estimator/classifier/ExtraTreesClassifier/c/basics.ipynb +++ b/examples/estimator/classifier/ExtraTreesClassifier/c/basics.ipynb @@ -22,7 +22,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": {}, "outputs": [ { @@ -51,7 +51,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -59,12 +59,13 @@ "text/plain": [ "ExtraTreesClassifier(bootstrap=False, class_weight=None, criterion='gini',\n", " max_depth=None, max_features='auto', max_leaf_nodes=None,\n", + " min_impurity_decrease=0.0, min_impurity_split=None,\n", " min_samples_leaf=1, min_samples_split=2,\n", " min_weight_fraction_leaf=0.0, n_estimators=15, n_jobs=1,\n", " oob_score=False, random_state=0, verbose=0, warm_start=False)" ] }, - "execution_count": 3, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -98,17 +99,17 @@ "#include \n", "#include \n", "\n", - "int predict_00(float atts[]) {\n", + "int predict_0(float features[]) {\n", " int classes[3];\n", " \n", - " if (atts[0] <= 5.5211283675173766) {\n", - " if (atts[1] <= 2.5423691467210121) {\n", - " if (atts[2] <= 2.3285940238943343) {\n", + " if (features[0] <= 5.52112836752) {\n", + " if (features[1] <= 2.54236914672) {\n", + " if (features[2] <= 2.32859402389) {\n", " classes[0] = 1; \n", " classes[1] = 0; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[3] <= 1.4511234333012406) {\n", + " if (features[3] <= 1.4511234333) {\n", " classes[0] = 0; \n", " classes[1] = 8; \n", " classes[2] = 0; \n", @@ -119,7 +120,7 @@ " }\n", " }\n", " } else {\n", - " if (atts[3] <= 0.83878367200965764) {\n", + " if (features[3] <= 0.83878367201) {\n", " classes[0] = 46; \n", " classes[1] = 0; \n", " classes[2] = 0; \n", @@ -130,15 +131,15 @@ " }\n", " }\n", " } else {\n", - " if (atts[3] <= 1.8936930649824477) {\n", - " if (atts[2] <= 5.1807613674845001) {\n", - " if (atts[3] <= 0.2542593119501258) {\n", + " if (features[3] <= 1.89369306498) {\n", + " if (features[2] <= 5.18076136748) {\n", + " if (features[3] <= 0.25425931195) {\n", " classes[0] = 1; \n", " classes[1] = 0; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[3] <= 1.2979109919829468) {\n", - " if (atts[1] <= 3.1466755002784144) {\n", + " if (features[3] <= 1.29791099198) {\n", + " if (features[1] <= 3.14667550028) {\n", " classes[0] = 0; \n", " classes[1] = 8; \n", " classes[2] = 0; \n", @@ -148,24 +149,24 @@ " classes[2] = 0; \n", " }\n", " } else {\n", - " if (atts[3] <= 1.4917742899580739) {\n", + " if (features[3] <= 1.49177428996) {\n", " classes[0] = 0; \n", " classes[1] = 17; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[2] <= 4.6486109417083465) {\n", + " if (features[2] <= 4.64861094171) {\n", " classes[0] = 0; \n", " classes[1] = 7; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[3] <= 1.7802776400056488) {\n", - " if (atts[3] <= 1.5065926898187254) {\n", - " if (atts[2] <= 4.899703297413823) {\n", + " if (features[3] <= 1.78027764001) {\n", + " if (features[3] <= 1.50659268982) {\n", + " if (features[2] <= 4.89970329741) {\n", " classes[0] = 0; \n", " classes[1] = 1; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[2] <= 4.9878533508461969) {\n", + " if (features[2] <= 4.98785335085) {\n", " classes[0] = 0; \n", " classes[1] = 2; \n", " classes[2] = 0; \n", @@ -181,7 +182,7 @@ " classes[2] = 0; \n", " }\n", " } else {\n", - " if (atts[1] <= 3.1244712178243654) {\n", + " if (features[1] <= 3.12447121782) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 5; \n", @@ -218,28 +219,28 @@ " return class_idx;\n", "}\n", "\n", - "int predict_01(float atts[]) {\n", + "int predict_1(float features[]) {\n", " int classes[3];\n", " \n", - " if (atts[3] <= 1.5504955501838129) {\n", - " if (atts[2] <= 2.5923285292922946) {\n", + " if (features[3] <= 1.55049555018) {\n", + " if (features[2] <= 2.59232852929) {\n", " classes[0] = 50; \n", " classes[1] = 0; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[0] <= 5.7051897734310577) {\n", + " if (features[0] <= 5.70518977343) {\n", " classes[0] = 0; \n", " classes[1] = 21; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[1] <= 2.4211563618020882) {\n", - " if (atts[1] <= 2.2376366618358423) {\n", - " if (atts[3] <= 1.0852253511944903) {\n", + " if (features[1] <= 2.4211563618) {\n", + " if (features[1] <= 2.23763666184) {\n", + " if (features[3] <= 1.08522535119) {\n", " classes[0] = 0; \n", " classes[1] = 1; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[2] <= 4.5587103432317777) {\n", + " if (features[2] <= 4.55871034323) {\n", " classes[0] = 0; \n", " classes[1] = 1; \n", " classes[2] = 0; \n", @@ -255,24 +256,24 @@ " classes[2] = 0; \n", " }\n", " } else {\n", - " if (atts[1] <= 2.8877833170885867) {\n", - " if (atts[3] <= 1.2729508337904472) {\n", + " if (features[1] <= 2.88778331709) {\n", + " if (features[3] <= 1.27295083379) {\n", " classes[0] = 0; \n", " classes[1] = 4; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[0] <= 6.5790113411443398) {\n", - " if (atts[2] <= 4.7893806273809885) {\n", + " if (features[0] <= 6.57901134114) {\n", + " if (features[2] <= 4.78938062738) {\n", " classes[0] = 0; \n", " classes[1] = 2; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[0] <= 6.1217669667164261) {\n", + " if (features[0] <= 6.12176696672) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 1; \n", " } else {\n", - " if (atts[2] <= 4.9162291827513958) {\n", + " if (features[2] <= 4.91622918275) {\n", " classes[0] = 0; \n", " classes[1] = 1; \n", " classes[2] = 0; \n", @@ -298,20 +299,20 @@ " }\n", " }\n", " } else {\n", - " if (atts[1] <= 3.1730407214994258) {\n", - " if (atts[3] <= 2.2706219597859412) {\n", - " if (atts[0] <= 5.7034701487511237) {\n", + " if (features[1] <= 3.1730407215) {\n", + " if (features[3] <= 2.27062195979) {\n", + " if (features[0] <= 5.70347014875) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 3; \n", " } else {\n", - " if (atts[2] <= 5.6371861017671403) {\n", - " if (atts[0] <= 6.61522923341691) {\n", - " if (atts[2] <= 5.5676840774650911) {\n", - " if (atts[1] <= 2.9151389085288946) {\n", - " if (atts[0] <= 6.3676007760812388) {\n", - " if (atts[0] <= 6.2352298441972724) {\n", - " if (atts[3] <= 1.652702599886597) {\n", + " if (features[2] <= 5.63718610177) {\n", + " if (features[0] <= 6.61522923342) {\n", + " if (features[2] <= 5.56768407747) {\n", + " if (features[1] <= 2.91513890853) {\n", + " if (features[0] <= 6.36760077608) {\n", + " if (features[0] <= 6.2352298442) {\n", + " if (features[3] <= 1.65270259989) {\n", " classes[0] = 0; \n", " classes[1] = 1; \n", " classes[2] = 0; \n", @@ -341,7 +342,7 @@ " classes[2] = 3; \n", " }\n", " } else {\n", - " if (atts[0] <= 6.7180041929368821) {\n", + " if (features[0] <= 6.71800419294) {\n", " classes[0] = 0; \n", " classes[1] = 1; \n", " classes[2] = 0; \n", @@ -363,9 +364,9 @@ " classes[2] = 6; \n", " }\n", " } else {\n", - " if (atts[3] <= 2.1245702483609095) {\n", - " if (atts[3] <= 1.8196133595321136) {\n", - " if (atts[0] <= 6.5204934295107302) {\n", + " if (features[3] <= 2.12457024836) {\n", + " if (features[3] <= 1.81961335953) {\n", + " if (features[0] <= 6.52049342951) {\n", " classes[0] = 0; \n", " classes[1] = 3; \n", " classes[2] = 0; \n", @@ -398,18 +399,18 @@ " return class_idx;\n", "}\n", "\n", - "int predict_02(float atts[]) {\n", + "int predict_2(float features[]) {\n", " int classes[3];\n", " \n", - " if (atts[3] <= 1.5465266340960862) {\n", - " if (atts[2] <= 4.6071317040414321) {\n", - " if (atts[2] <= 3.3003282579766613) {\n", - " if (atts[3] <= 0.38658752666916157) {\n", + " if (features[3] <= 1.5465266341) {\n", + " if (features[2] <= 4.60713170404) {\n", + " if (features[2] <= 3.30032825798) {\n", + " if (features[3] <= 0.386587526669) {\n", " classes[0] = 41; \n", " classes[1] = 0; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[2] <= 2.1556475054731816) {\n", + " if (features[2] <= 2.15564750547) {\n", " classes[0] = 9; \n", " classes[1] = 0; \n", " classes[2] = 0; \n", @@ -425,13 +426,13 @@ " classes[2] = 0; \n", " }\n", " } else {\n", - " if (atts[1] <= 2.269675323772093) {\n", + " if (features[1] <= 2.26967532377) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 1; \n", " } else {\n", - " if (atts[2] <= 5.4827000154137897) {\n", - " if (atts[2] <= 4.9972260125339991) {\n", + " if (features[2] <= 5.48270001541) {\n", + " if (features[2] <= 4.99722601253) {\n", " classes[0] = 0; \n", " classes[1] = 7; \n", " classes[2] = 0; \n", @@ -448,8 +449,8 @@ " }\n", " }\n", " } else {\n", - " if (atts[3] <= 1.6032070119961934) {\n", - " if (atts[0] <= 6.5187490263266428) {\n", + " if (features[3] <= 1.603207012) {\n", + " if (features[0] <= 6.51874902633) {\n", " classes[0] = 0; \n", " classes[1] = 3; \n", " classes[2] = 0; \n", @@ -459,14 +460,14 @@ " classes[2] = 1; \n", " }\n", " } else {\n", - " if (atts[3] <= 1.8081436115623295) {\n", - " if (atts[1] <= 2.5996223526415174) {\n", + " if (features[3] <= 1.80814361156) {\n", + " if (features[1] <= 2.59962235264) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 2; \n", " } else {\n", - " if (atts[1] <= 3.0266239479308128) {\n", - " if (atts[3] <= 1.7788371596579802) {\n", + " if (features[1] <= 3.02662394793) {\n", + " if (features[3] <= 1.77883715966) {\n", " classes[0] = 0; \n", " classes[1] = 1; \n", " classes[2] = 0; \n", @@ -476,8 +477,8 @@ " classes[2] = 8; \n", " }\n", " } else {\n", - " if (atts[2] <= 5.5827159596680156) {\n", - " if (atts[1] <= 3.1452745616104556) {\n", + " if (features[2] <= 5.58271595967) {\n", + " if (features[1] <= 3.14527456161) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 1; \n", @@ -512,28 +513,28 @@ " return class_idx;\n", "}\n", "\n", - "int predict_03(float atts[]) {\n", + "int predict_3(float features[]) {\n", " int classes[3];\n", " \n", - " if (atts[0] <= 5.1096510251748901) {\n", - " if (atts[3] <= 0.34237436990699954) {\n", + " if (features[0] <= 5.10965102517) {\n", + " if (features[3] <= 0.342374369907) {\n", " classes[0] = 31; \n", " classes[1] = 0; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[3] <= 0.42014141078495837) {\n", + " if (features[3] <= 0.420141410785) {\n", " classes[0] = 3; \n", " classes[1] = 0; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[1] <= 3.3013719233224972) {\n", - " if (atts[2] <= 2.3218753875601132) {\n", + " if (features[1] <= 3.30137192332) {\n", + " if (features[2] <= 2.32187538756) {\n", " classes[0] = 1; \n", " classes[1] = 0; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[0] <= 4.9582561902467441) {\n", - " if (atts[1] <= 2.4726812725055445) {\n", + " if (features[0] <= 4.95825619025) {\n", + " if (features[1] <= 2.47268127251) {\n", " classes[0] = 0; \n", " classes[1] = 1; \n", " classes[2] = 0; \n", @@ -556,26 +557,26 @@ " }\n", " }\n", " } else {\n", - " if (atts[2] <= 5.0059938824178367) {\n", - " if (atts[3] <= 0.59215586323442948) {\n", + " if (features[2] <= 5.00599388242) {\n", + " if (features[3] <= 0.592155863234) {\n", " classes[0] = 14; \n", " classes[1] = 0; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[2] <= 4.8869158585494921) {\n", - " if (atts[2] <= 4.5845956777760826) {\n", + " if (features[2] <= 4.88691585855) {\n", + " if (features[2] <= 4.58459567778) {\n", " classes[0] = 0; \n", " classes[1] = 32; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[1] <= 3.0013521708088704) {\n", - " if (atts[0] <= 6.2818121532768014) {\n", - " if (atts[3] <= 1.3566014997210807) {\n", + " if (features[1] <= 3.00135217081) {\n", + " if (features[0] <= 6.28181215328) {\n", + " if (features[3] <= 1.35660149972) {\n", " classes[0] = 0; \n", " classes[1] = 1; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[3] <= 1.4692521397047558) {\n", + " if (features[3] <= 1.4692521397) {\n", " classes[0] = 0; \n", " classes[1] = 2; \n", " classes[2] = 0; \n", @@ -597,22 +598,22 @@ " }\n", " }\n", " } else {\n", - " if (atts[0] <= 6.024789407414449) {\n", + " if (features[0] <= 6.02478940741) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 3; \n", " } else {\n", - " if (atts[3] <= 1.5357312864913262) {\n", + " if (features[3] <= 1.53573128649) {\n", " classes[0] = 0; \n", " classes[1] = 2; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[1] <= 2.5827080563561564) {\n", + " if (features[1] <= 2.58270805636) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 1; \n", " } else {\n", - " if (atts[0] <= 6.5669079160763015) {\n", + " if (features[0] <= 6.56690791608) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 2; \n", @@ -627,9 +628,9 @@ " }\n", " }\n", " } else {\n", - " if (atts[2] <= 5.1863245386304202) {\n", - " if (atts[1] <= 2.7092082675123628) {\n", - " if (atts[3] <= 1.8776005740851462) {\n", + " if (features[2] <= 5.18632453863) {\n", + " if (features[1] <= 2.70920826751) {\n", + " if (features[3] <= 1.87760057409) {\n", " classes[0] = 0; \n", " classes[1] = 1; \n", " classes[2] = 0; \n", @@ -662,15 +663,15 @@ " return class_idx;\n", "}\n", "\n", - "int predict_04(float atts[]) {\n", + "int predict_4(float features[]) {\n", " int classes[3];\n", " \n", - " if (atts[3] <= 1.3441161325132915) {\n", - " if (atts[1] <= 3.0101406622719056) {\n", - " if (atts[0] <= 5.5513347352769937) {\n", - " if (atts[1] <= 2.4504689497176879) {\n", - " if (atts[0] <= 5.3493399647294266) {\n", - " if (atts[0] <= 4.8750152915599827) {\n", + " if (features[3] <= 1.34411613251) {\n", + " if (features[1] <= 3.01014066227) {\n", + " if (features[0] <= 5.55133473528) {\n", + " if (features[1] <= 2.45046894972) {\n", + " if (features[0] <= 5.34933996473) {\n", + " if (features[0] <= 4.87501529156) {\n", " classes[0] = 1; \n", " classes[1] = 0; \n", " classes[2] = 0; \n", @@ -685,7 +686,7 @@ " classes[2] = 0; \n", " }\n", " } else {\n", - " if (atts[1] <= 2.8545732504476669) {\n", + " if (features[1] <= 2.85457325045) {\n", " classes[0] = 0; \n", " classes[1] = 3; \n", " classes[2] = 0; \n", @@ -706,8 +707,8 @@ " classes[2] = 0; \n", " }\n", " } else {\n", - " if (atts[2] <= 4.5412213265156476) {\n", - " if (atts[3] <= 1.6796973785314397) {\n", + " if (features[2] <= 4.54122132652) {\n", + " if (features[3] <= 1.67969737853) {\n", " classes[0] = 0; \n", " classes[1] = 10; \n", " classes[2] = 0; \n", @@ -717,11 +718,11 @@ " classes[2] = 1; \n", " }\n", " } else {\n", - " if (atts[3] <= 1.8681215891414575) {\n", - " if (atts[3] <= 1.7082770221162646) {\n", - " if (atts[2] <= 5.4587785419790711) {\n", - " if (atts[1] <= 2.6322218231672321) {\n", - " if (atts[1] <= 2.2075641354665572) {\n", + " if (features[3] <= 1.86812158914) {\n", + " if (features[3] <= 1.70827702212) {\n", + " if (features[2] <= 5.45877854198) {\n", + " if (features[1] <= 2.63222182317) {\n", + " if (features[1] <= 2.20756413547) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 1; \n", @@ -731,15 +732,15 @@ " classes[2] = 0; \n", " }\n", " } else {\n", - " if (atts[1] <= 2.9750656646611109) {\n", - " if (atts[0] <= 6.5700013628278997) {\n", - " if (atts[3] <= 1.4378231510535273) {\n", + " if (features[1] <= 2.97506566466) {\n", + " if (features[0] <= 6.57000136283) {\n", + " if (features[3] <= 1.43782315105) {\n", " classes[0] = 0; \n", " classes[1] = 1; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[3] <= 1.5344588928285092) {\n", - " if (atts[0] <= 6.46420655970892) {\n", + " if (features[3] <= 1.53445889283) {\n", + " if (features[0] <= 6.46420655971) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 1; \n", @@ -771,18 +772,18 @@ " classes[2] = 2; \n", " }\n", " } else {\n", - " if (atts[1] <= 2.8407804212030414) {\n", + " if (features[1] <= 2.8407804212) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 3; \n", " } else {\n", - " if (atts[2] <= 6.150836971984635) {\n", - " if (atts[1] <= 3.1337532458575437) {\n", + " if (features[2] <= 6.15083697198) {\n", + " if (features[1] <= 3.13375324586) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 6; \n", " } else {\n", - " if (atts[2] <= 5.8292593574657765) {\n", + " if (features[2] <= 5.82925935747) {\n", " classes[0] = 0; \n", " classes[1] = 1; \n", " classes[2] = 0; \n", @@ -818,14 +819,14 @@ " return class_idx;\n", "}\n", "\n", - "int predict_05(float atts[]) {\n", + "int predict_5(float features[]) {\n", " int classes[3];\n", " \n", - " if (atts[3] <= 1.7676213332657358) {\n", - " if (atts[1] <= 3.4545610617739615) {\n", - " if (atts[2] <= 3.6502854621611109) {\n", - " if (atts[2] <= 3.1891586420402427) {\n", - " if (atts[3] <= 0.95101981363257859) {\n", + " if (features[3] <= 1.76762133327) {\n", + " if (features[1] <= 3.45456106177) {\n", + " if (features[2] <= 3.65028546216) {\n", + " if (features[2] <= 3.18915864204) {\n", + " if (features[3] <= 0.951019813633) {\n", " classes[0] = 29; \n", " classes[1] = 0; \n", " classes[2] = 0; \n", @@ -840,19 +841,19 @@ " classes[2] = 0; \n", " }\n", " } else {\n", - " if (atts[0] <= 5.1755356442982308) {\n", + " if (features[0] <= 5.1755356443) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 1; \n", " } else {\n", - " if (atts[3] <= 1.4533850152404659) {\n", - " if (atts[1] <= 2.6607527474224346) {\n", - " if (atts[3] <= 1.1197721207462903) {\n", + " if (features[3] <= 1.45338501524) {\n", + " if (features[1] <= 2.66075274742) {\n", + " if (features[3] <= 1.11977212075) {\n", " classes[0] = 0; \n", " classes[1] = 4; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[2] <= 5.0340535096243002) {\n", + " if (features[2] <= 5.03405350962) {\n", " classes[0] = 0; \n", " classes[1] = 5; \n", " classes[2] = 0; \n", @@ -868,9 +869,9 @@ " classes[2] = 0; \n", " }\n", " } else {\n", - " if (atts[1] <= 3.2000655596791701) {\n", - " if (atts[1] <= 2.648931143548773) {\n", - " if (atts[0] <= 6.0403355971033852) {\n", + " if (features[1] <= 3.20006555968) {\n", + " if (features[1] <= 2.64893114355) {\n", + " if (features[0] <= 6.0403355971) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 1; \n", @@ -880,20 +881,20 @@ " classes[2] = 0; \n", " }\n", " } else {\n", - " if (atts[0] <= 6.5033636618817878) {\n", - " if (atts[0] <= 5.6045121474787978) {\n", + " if (features[0] <= 6.50336366188) {\n", + " if (features[0] <= 5.60451214748) {\n", " classes[0] = 0; \n", " classes[1] = 2; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[3] <= 1.5280856302044936) {\n", - " if (atts[0] <= 5.9853353459190419) {\n", + " if (features[3] <= 1.5280856302) {\n", + " if (features[0] <= 5.98533534592) {\n", " classes[0] = 0; \n", " classes[1] = 1; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[1] <= 2.8357509785984978) {\n", - " if (atts[2] <= 4.663137085998029) {\n", + " if (features[1] <= 2.8357509786) {\n", + " if (features[2] <= 4.663137086) {\n", " classes[0] = 0; \n", " classes[1] = 1; \n", " classes[2] = 0; \n", @@ -915,8 +916,8 @@ " }\n", " }\n", " } else {\n", - " if (atts[1] <= 3.0563716510809584) {\n", - " if (atts[3] <= 1.6545352601337104) {\n", + " if (features[1] <= 3.05637165108) {\n", + " if (features[3] <= 1.65453526013) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 1; \n", @@ -946,10 +947,10 @@ " classes[2] = 0; \n", " }\n", " } else {\n", - " if (atts[3] <= 1.8121969431622151) {\n", - " if (atts[2] <= 5.5628289586225659) {\n", - " if (atts[2] <= 4.8118490651150063) {\n", - " if (atts[1] <= 3.1684422458572552) {\n", + " if (features[3] <= 1.81219694316) {\n", + " if (features[2] <= 5.56282895862) {\n", + " if (features[2] <= 4.81184906512) {\n", + " if (features[1] <= 3.16844224586) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 2; \n", @@ -986,28 +987,28 @@ " return class_idx;\n", "}\n", "\n", - "int predict_06(float atts[]) {\n", + "int predict_6(float features[]) {\n", " int classes[3];\n", " \n", - " if (atts[3] <= 1.8380720877184731) {\n", - " if (atts[3] <= 0.94908629972759717) {\n", + " if (features[3] <= 1.83807208772) {\n", + " if (features[3] <= 0.949086299728) {\n", " classes[0] = 50; \n", " classes[1] = 0; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[2] <= 3.9259614145650565) {\n", + " if (features[2] <= 3.92596141457) {\n", " classes[0] = 0; \n", " classes[1] = 11; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[0] <= 5.7524397380621881) {\n", - " if (atts[0] <= 5.5675846099678861) {\n", - " if (atts[3] <= 1.3096158726185634) {\n", + " if (features[0] <= 5.75243973806) {\n", + " if (features[0] <= 5.56758460997) {\n", + " if (features[3] <= 1.30961587262) {\n", " classes[0] = 0; \n", " classes[1] = 3; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[0] <= 4.9965273461288433) {\n", + " if (features[0] <= 4.99652734613) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 1; \n", @@ -1023,16 +1024,16 @@ " classes[2] = 0; \n", " }\n", " } else {\n", - " if (atts[3] <= 1.3226210794537889) {\n", + " if (features[3] <= 1.32262107945) {\n", " classes[0] = 0; \n", " classes[1] = 9; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[3] <= 1.5331659525110946) {\n", - " if (atts[1] <= 2.9363041020633207) {\n", - " if (atts[1] <= 2.6271371465694107) {\n", - " if (atts[2] <= 5.2132714648801279) {\n", - " if (atts[0] <= 6.1450817798403774) {\n", + " if (features[3] <= 1.53316595251) {\n", + " if (features[1] <= 2.93630410206) {\n", + " if (features[1] <= 2.62713714657) {\n", + " if (features[2] <= 5.21327146488) {\n", + " if (features[0] <= 6.14508177984) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 1; \n", @@ -1047,17 +1048,17 @@ " classes[2] = 1; \n", " }\n", " } else {\n", - " if (atts[0] <= 6.1049023089068344) {\n", + " if (features[0] <= 6.10490230891) {\n", " classes[0] = 0; \n", " classes[1] = 2; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[3] <= 1.4576934027935942) {\n", + " if (features[3] <= 1.45769340279) {\n", " classes[0] = 0; \n", " classes[1] = 1; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[2] <= 5.0702880434553546) {\n", + " if (features[2] <= 5.07028804346) {\n", " classes[0] = 0; \n", " classes[1] = 1; \n", " classes[2] = 0; \n", @@ -1075,16 +1076,16 @@ " classes[2] = 0; \n", " }\n", " } else {\n", - " if (atts[2] <= 5.1260403107316117) {\n", - " if (atts[1] <= 3.1470031032977439) {\n", - " if (atts[2] <= 4.8079453149979541) {\n", + " if (features[2] <= 5.12604031073) {\n", + " if (features[1] <= 3.1470031033) {\n", + " if (features[2] <= 4.807945315) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 2; \n", " } else {\n", - " if (atts[0] <= 6.1519032927184263) {\n", - " if (atts[0] <= 6.0430469727063381) {\n", - " if (atts[1] <= 2.9580633267166325) {\n", + " if (features[0] <= 6.15190329272) {\n", + " if (features[0] <= 6.04304697271) {\n", + " if (features[1] <= 2.95806332672) {\n", " classes[0] = 0; \n", " classes[1] = 1; \n", " classes[2] = 0; \n", @@ -1099,7 +1100,7 @@ " classes[2] = 1; \n", " }\n", " } else {\n", - " if (atts[2] <= 4.9211956019572716) {\n", + " if (features[2] <= 4.92119560196) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 1; \n", @@ -1142,17 +1143,17 @@ " return class_idx;\n", "}\n", "\n", - "int predict_07(float atts[]) {\n", + "int predict_7(float features[]) {\n", " int classes[3];\n", " \n", - " if (atts[0] <= 4.8350779809500537) {\n", + " if (features[0] <= 4.83507798095) {\n", " classes[0] = 16; \n", " classes[1] = 0; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[2] <= 5.0521211317065813) {\n", - " if (atts[3] <= 1.187984123199987) {\n", - " if (atts[2] <= 2.4198502829763324) {\n", + " if (features[2] <= 5.05212113171) {\n", + " if (features[3] <= 1.1879841232) {\n", + " if (features[2] <= 2.41985028298) {\n", " classes[0] = 34; \n", " classes[1] = 0; \n", " classes[2] = 0; \n", @@ -1162,20 +1163,20 @@ " classes[2] = 0; \n", " }\n", " } else {\n", - " if (atts[3] <= 1.9700979161064909) {\n", - " if (atts[3] <= 1.2103523333737463) {\n", + " if (features[3] <= 1.97009791611) {\n", + " if (features[3] <= 1.21035233337) {\n", " classes[0] = 0; \n", " classes[1] = 5; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[3] <= 1.7922824027484205) {\n", - " if (atts[3] <= 1.3556012588196729) {\n", + " if (features[3] <= 1.79228240275) {\n", + " if (features[3] <= 1.35560125882) {\n", " classes[0] = 0; \n", " classes[1] = 13; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[1] <= 2.3506367699266271) {\n", - " if (atts[2] <= 4.781047702897828) {\n", + " if (features[1] <= 2.35063676993) {\n", + " if (features[2] <= 4.7810477029) {\n", " classes[0] = 0; \n", " classes[1] = 1; \n", " classes[2] = 0; \n", @@ -1185,8 +1186,8 @@ " classes[2] = 1; \n", " }\n", " } else {\n", - " if (atts[0] <= 5.2396924972122507) {\n", - " if (atts[3] <= 1.540099250418558) {\n", + " if (features[0] <= 5.23969249721) {\n", + " if (features[3] <= 1.54009925042) {\n", " classes[0] = 0; \n", " classes[1] = 1; \n", " classes[2] = 0; \n", @@ -1203,9 +1204,9 @@ " }\n", " }\n", " } else {\n", - " if (atts[2] <= 4.8114599180137345) {\n", - " if (atts[0] <= 6.1531159293238975) {\n", - " if (atts[0] <= 5.9178402810269528) {\n", + " if (features[2] <= 4.81145991801) {\n", + " if (features[0] <= 6.15311592932) {\n", + " if (features[0] <= 5.91784028103) {\n", " classes[0] = 0; \n", " classes[1] = 1; \n", " classes[2] = 0; \n", @@ -1233,15 +1234,15 @@ " }\n", " }\n", " } else {\n", - " if (atts[3] <= 1.9630314654063374) {\n", - " if (atts[0] <= 6.3214984808907442) {\n", - " if (atts[0] <= 5.9718572619240069) {\n", + " if (features[3] <= 1.96303146541) {\n", + " if (features[0] <= 6.32149848089) {\n", + " if (features[0] <= 5.97185726192) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 3; \n", " } else {\n", - " if (atts[1] <= 2.7957859024446297) {\n", - " if (atts[3] <= 1.5647405810243964) {\n", + " if (features[1] <= 2.79578590244) {\n", + " if (features[3] <= 1.56474058102) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 1; \n", @@ -1280,35 +1281,35 @@ " return class_idx;\n", "}\n", "\n", - "int predict_08(float atts[]) {\n", + "int predict_8(float features[]) {\n", " int classes[3];\n", " \n", - " if (atts[2] <= 2.0691016397809667) {\n", + " if (features[2] <= 2.06910163978) {\n", " classes[0] = 50; \n", " classes[1] = 0; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[3] <= 2.2998321977443212) {\n", - " if (atts[2] <= 5.7568501553340212) {\n", - " if (atts[3] <= 1.3336353223788777) {\n", + " if (features[3] <= 2.29983219774) {\n", + " if (features[2] <= 5.75685015533) {\n", + " if (features[3] <= 1.33363532238) {\n", " classes[0] = 0; \n", " classes[1] = 28; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[1] <= 2.7958206613730536) {\n", - " if (atts[3] <= 1.6143543486045333) {\n", - " if (atts[2] <= 4.272187437395063) {\n", + " if (features[1] <= 2.79582066137) {\n", + " if (features[3] <= 1.6143543486) {\n", + " if (features[2] <= 4.2721874374) {\n", " classes[0] = 0; \n", " classes[1] = 1; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[3] <= 1.4076716455330911) {\n", + " if (features[3] <= 1.40767164553) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 1; \n", " } else {\n", - " if (atts[1] <= 2.4055632554020563) {\n", - " if (atts[0] <= 6.1686928410480846) {\n", + " if (features[1] <= 2.4055632554) {\n", + " if (features[0] <= 6.16869284105) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 1; \n", @@ -1330,14 +1331,14 @@ " classes[2] = 7; \n", " }\n", " } else {\n", - " if (atts[3] <= 2.0267573938538184) {\n", - " if (atts[3] <= 1.6093679712505249) {\n", - " if (atts[2] <= 4.6346452780257099) {\n", + " if (features[3] <= 2.02675739385) {\n", + " if (features[3] <= 1.60936797125) {\n", + " if (features[2] <= 4.63464527803) {\n", " classes[0] = 0; \n", " classes[1] = 10; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[2] <= 4.9520732824288594) {\n", + " if (features[2] <= 4.95207328243) {\n", " classes[0] = 0; \n", " classes[1] = 6; \n", " classes[2] = 0; \n", @@ -1348,18 +1349,18 @@ " }\n", " }\n", " } else {\n", - " if (atts[1] <= 2.8720874155782443) {\n", + " if (features[1] <= 2.87208741558) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 2; \n", " } else {\n", - " if (atts[0] <= 6.5173975475393169) {\n", - " if (atts[1] <= 3.1451728271597688) {\n", + " if (features[0] <= 6.51739754754) {\n", + " if (features[1] <= 3.14517282716) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 7; \n", " } else {\n", - " if (atts[0] <= 6.1052098155768029) {\n", + " if (features[0] <= 6.10520981558) {\n", " classes[0] = 0; \n", " classes[1] = 1; \n", " classes[2] = 0; \n", @@ -1406,48 +1407,48 @@ " return class_idx;\n", "}\n", "\n", - "int predict_09(float atts[]) {\n", + "int predict_9(float features[]) {\n", " int classes[3];\n", " \n", - " if (atts[2] <= 1.7984751272085284) {\n", + " if (features[2] <= 1.79847512721) {\n", " classes[0] = 48; \n", " classes[1] = 0; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[2] <= 2.743614525085631) {\n", + " if (features[2] <= 2.74361452509) {\n", " classes[0] = 2; \n", " classes[1] = 0; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[3] <= 1.5726279935672078) {\n", - " if (atts[1] <= 2.8580128675676453) {\n", - " if (atts[3] <= 1.0071725081685803) {\n", + " if (features[3] <= 1.57262799357) {\n", + " if (features[1] <= 2.85801286757) {\n", + " if (features[3] <= 1.00717250817) {\n", " classes[0] = 0; \n", " classes[1] = 7; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[3] <= 1.4508596346903717) {\n", - " if (atts[0] <= 5.4788470711552755) {\n", + " if (features[3] <= 1.45085963469) {\n", + " if (features[0] <= 5.47884707116) {\n", " classes[0] = 0; \n", " classes[1] = 2; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[2] <= 4.3105326892188245) {\n", + " if (features[2] <= 4.31053268922) {\n", " classes[0] = 0; \n", " classes[1] = 9; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[3] <= 1.2510118285538396) {\n", + " if (features[3] <= 1.25101182855) {\n", " classes[0] = 0; \n", " classes[1] = 2; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[3] <= 1.3008071595868549) {\n", + " if (features[3] <= 1.30080715959) {\n", " classes[0] = 0; \n", " classes[1] = 2; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[1] <= 2.6182927931585578) {\n", + " if (features[1] <= 2.61829279316) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 1; \n", @@ -1461,8 +1462,8 @@ " }\n", " }\n", " } else {\n", - " if (atts[2] <= 5.0329756375451549) {\n", - " if (atts[2] <= 4.9472819976263134) {\n", + " if (features[2] <= 5.03297563755) {\n", + " if (features[2] <= 4.94728199763) {\n", " classes[0] = 0; \n", " classes[1] = 3; \n", " classes[2] = 0; \n", @@ -1484,10 +1485,10 @@ " classes[2] = 0; \n", " }\n", " } else {\n", - " if (atts[2] <= 6.1966904607047031) {\n", - " if (atts[2] <= 5.7145493422412432) {\n", - " if (atts[3] <= 1.7483953438728816) {\n", - " if (atts[0] <= 5.1244250369354614) {\n", + " if (features[2] <= 6.1966904607) {\n", + " if (features[2] <= 5.71454934224) {\n", + " if (features[3] <= 1.74839534387) {\n", + " if (features[0] <= 5.12442503694) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 1; \n", @@ -1497,13 +1498,13 @@ " classes[2] = 0; \n", " }\n", " } else {\n", - " if (atts[0] <= 5.9635245683145435) {\n", - " if (atts[1] <= 2.9403134736939704) {\n", + " if (features[0] <= 5.96352456831) {\n", + " if (features[1] <= 2.94031347369) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 5; \n", " } else {\n", - " if (atts[1] <= 3.1597595674715184) {\n", + " if (features[1] <= 3.15975956747) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 1; \n", @@ -1544,12 +1545,12 @@ " return class_idx;\n", "}\n", "\n", - "int predict_10(float atts[]) {\n", + "int predict_10(float features[]) {\n", " int classes[3];\n", " \n", - " if (atts[0] <= 4.9792803198265787) {\n", - " if (atts[1] <= 2.4799516418973426) {\n", - " if (atts[2] <= 2.1081189544909256) {\n", + " if (features[0] <= 4.97928031983) {\n", + " if (features[1] <= 2.4799516419) {\n", + " if (features[2] <= 2.10811895449) {\n", " classes[0] = 1; \n", " classes[1] = 0; \n", " classes[2] = 0; \n", @@ -1559,7 +1560,7 @@ " classes[2] = 0; \n", " }\n", " } else {\n", - " if (atts[2] <= 2.3031890773229251) {\n", + " if (features[2] <= 2.30318907732) {\n", " classes[0] = 19; \n", " classes[1] = 0; \n", " classes[2] = 0; \n", @@ -1570,16 +1571,16 @@ " }\n", " }\n", " } else {\n", - " if (atts[2] <= 4.0566901295803843) {\n", - " if (atts[2] <= 3.864595594637342) {\n", - " if (atts[1] <= 2.4493558386314596) {\n", + " if (features[2] <= 4.05669012958) {\n", + " if (features[2] <= 3.86459559464) {\n", + " if (features[1] <= 2.44935583863) {\n", " classes[0] = 0; \n", " classes[1] = 4; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[1] <= 3.1013702094660816) {\n", - " if (atts[0] <= 5.4182674136813782) {\n", - " if (atts[1] <= 2.7351736650965983) {\n", + " if (features[1] <= 3.10137020947) {\n", + " if (features[0] <= 5.41826741368) {\n", + " if (features[1] <= 2.7351736651) {\n", " classes[0] = 0; \n", " classes[1] = 1; \n", " classes[2] = 0; \n", @@ -1605,31 +1606,31 @@ " classes[2] = 0; \n", " }\n", " } else {\n", - " if (atts[3] <= 2.4500323361484484) {\n", - " if (atts[0] <= 7.2381296350332578) {\n", - " if (atts[2] <= 4.9855890272850028) {\n", - " if (atts[3] <= 1.4175185078836599) {\n", + " if (features[3] <= 2.45003233615) {\n", + " if (features[0] <= 7.23812963503) {\n", + " if (features[2] <= 4.98558902729) {\n", + " if (features[3] <= 1.41751850788) {\n", " classes[0] = 0; \n", " classes[1] = 19; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[3] <= 1.9085482831152847) {\n", - " if (atts[3] <= 1.5077226825858063) {\n", + " if (features[3] <= 1.90854828312) {\n", + " if (features[3] <= 1.50772268259) {\n", " classes[0] = 0; \n", " classes[1] = 10; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[1] <= 2.8843708444178024) {\n", + " if (features[1] <= 2.88437084442) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 2; \n", " } else {\n", - " if (atts[3] <= 1.7559926563657857) {\n", + " if (features[3] <= 1.75599265637) {\n", " classes[0] = 0; \n", " classes[1] = 2; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[1] <= 3.0877764696391852) {\n", + " if (features[1] <= 3.08777646964) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 2; \n", @@ -1648,10 +1649,10 @@ " }\n", " }\n", " } else {\n", - " if (atts[3] <= 1.9978145065895823) {\n", - " if (atts[3] <= 1.7865760346812085) {\n", - " if (atts[2] <= 5.0311129249450408) {\n", - " if (atts[0] <= 6.33527863763707) {\n", + " if (features[3] <= 1.99781450659) {\n", + " if (features[3] <= 1.78657603468) {\n", + " if (features[2] <= 5.03111292495) {\n", + " if (features[0] <= 6.33527863764) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 1; \n", @@ -1661,12 +1662,12 @@ " classes[2] = 0; \n", " }\n", " } else {\n", - " if (atts[3] <= 1.5068336243767517) {\n", + " if (features[3] <= 1.50683362438) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 2; \n", " } else {\n", - " if (atts[2] <= 5.7874281257170956) {\n", + " if (features[2] <= 5.78742812572) {\n", " classes[0] = 0; \n", " classes[1] = 1; \n", " classes[2] = 0; \n", @@ -1712,19 +1713,19 @@ " return class_idx;\n", "}\n", "\n", - "int predict_11(float atts[]) {\n", + "int predict_11(float features[]) {\n", " int classes[3];\n", " \n", - " if (atts[1] <= 3.1769571393777749) {\n", - " if (atts[3] <= 0.65371013474073503) {\n", + " if (features[1] <= 3.17695713938) {\n", + " if (features[3] <= 0.653710134741) {\n", " classes[0] = 13; \n", " classes[1] = 0; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[3] <= 1.8469214377642704) {\n", - " if (atts[2] <= 4.7208371488439003) {\n", - " if (atts[0] <= 5.7627729686766793) {\n", - " if (atts[3] <= 1.6360344565374696) {\n", + " if (features[3] <= 1.84692143776) {\n", + " if (features[2] <= 4.72083714884) {\n", + " if (features[0] <= 5.76277296868) {\n", + " if (features[3] <= 1.63603445654) {\n", " classes[0] = 0; \n", " classes[1] = 21; \n", " classes[2] = 0; \n", @@ -1739,17 +1740,17 @@ " classes[2] = 0; \n", " }\n", " } else {\n", - " if (atts[3] <= 1.7208344558505428) {\n", - " if (atts[2] <= 4.9971796261133532) {\n", + " if (features[3] <= 1.72083445585) {\n", + " if (features[2] <= 4.99717962611) {\n", " classes[0] = 0; \n", " classes[1] = 3; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[0] <= 7.1981562798039125) {\n", - " if (atts[2] <= 5.257435716402731) {\n", - " if (atts[0] <= 6.4367447385930507) {\n", - " if (atts[0] <= 6.2970719060390206) {\n", - " if (atts[3] <= 1.5681733276103198) {\n", + " if (features[0] <= 7.1981562798) {\n", + " if (features[2] <= 5.2574357164) {\n", + " if (features[0] <= 6.43674473859) {\n", + " if (features[0] <= 6.29707190604) {\n", + " if (features[3] <= 1.56817332761) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 1; \n", @@ -1792,14 +1793,14 @@ " }\n", " }\n", " } else {\n", - " if (atts[2] <= 3.8047750384801153) {\n", + " if (features[2] <= 3.80477503848) {\n", " classes[0] = 37; \n", " classes[1] = 0; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[3] <= 2.1793218211052987) {\n", - " if (atts[2] <= 5.2771791684203357) {\n", - " if (atts[3] <= 1.8542162920413572) {\n", + " if (features[3] <= 2.17932182111) {\n", + " if (features[2] <= 5.27717916842) {\n", + " if (features[3] <= 1.85421629204) {\n", " classes[0] = 0; \n", " classes[1] = 5; \n", " classes[2] = 0; \n", @@ -1832,14 +1833,14 @@ " return class_idx;\n", "}\n", "\n", - "int predict_12(float atts[]) {\n", + "int predict_12(float features[]) {\n", " int classes[3];\n", " \n", - " if (atts[3] <= 1.7021128663169045) {\n", - " if (atts[1] <= 2.9849618599913255) {\n", - " if (atts[3] <= 1.4970948166731561) {\n", - " if (atts[0] <= 5.6231451775870234) {\n", - " if (atts[0] <= 4.7790295218134444) {\n", + " if (features[3] <= 1.70211286632) {\n", + " if (features[1] <= 2.98496185999) {\n", + " if (features[3] <= 1.49709481667) {\n", + " if (features[0] <= 5.62314517759) {\n", + " if (features[0] <= 4.77902952181) {\n", " classes[0] = 2; \n", " classes[1] = 0; \n", " classes[2] = 0; \n", @@ -1849,12 +1850,12 @@ " classes[2] = 0; \n", " }\n", " } else {\n", - " if (atts[3] <= 1.3284118253233357) {\n", + " if (features[3] <= 1.32841182532) {\n", " classes[0] = 0; \n", " classes[1] = 14; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[1] <= 2.7629100232801327) {\n", + " if (features[1] <= 2.76291002328) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 1; \n", @@ -1866,15 +1867,15 @@ " }\n", " }\n", " } else {\n", - " if (atts[3] <= 1.6376492357878205) {\n", - " if (atts[2] <= 4.602142482827186) {\n", + " if (features[3] <= 1.63764923579) {\n", + " if (features[2] <= 4.60214248283) {\n", " classes[0] = 0; \n", " classes[1] = 3; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[1] <= 2.7219560941499337) {\n", - " if (atts[0] <= 6.0880929809363096) {\n", - " if (atts[3] <= 1.5437156698788206) {\n", + " if (features[1] <= 2.72195609415) {\n", + " if (features[0] <= 6.08809298094) {\n", + " if (features[3] <= 1.54371566988) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 1; \n", @@ -1901,12 +1902,12 @@ " }\n", " }\n", " } else {\n", - " if (atts[3] <= 0.65664750033467612) {\n", + " if (features[3] <= 0.656647500335) {\n", " classes[0] = 48; \n", " classes[1] = 0; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[2] <= 5.3797694299386132) {\n", + " if (features[2] <= 5.37976942994) {\n", " classes[0] = 0; \n", " classes[1] = 15; \n", " classes[2] = 0; \n", @@ -1918,10 +1919,10 @@ " }\n", " }\n", " } else {\n", - " if (atts[2] <= 5.2961110038745645) {\n", - " if (atts[2] <= 4.8192148664349324) {\n", - " if (atts[0] <= 6.0796086876843409) {\n", - " if (atts[1] <= 3.1799571540756144) {\n", + " if (features[2] <= 5.29611100387) {\n", + " if (features[2] <= 4.81921486643) {\n", + " if (features[0] <= 6.07960868768) {\n", + " if (features[1] <= 3.17995715408) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 1; \n", @@ -1958,18 +1959,18 @@ " return class_idx;\n", "}\n", "\n", - "int predict_13(float atts[]) {\n", + "int predict_13(float features[]) {\n", " int classes[3];\n", " \n", - " if (atts[0] <= 7.5141141980731554) {\n", - " if (atts[1] <= 2.7153722801061679) {\n", - " if (atts[0] <= 5.0467466254497211) {\n", - " if (atts[0] <= 4.7200417810678674) {\n", + " if (features[0] <= 7.51411419807) {\n", + " if (features[1] <= 2.71537228011) {\n", + " if (features[0] <= 5.04674662545) {\n", + " if (features[0] <= 4.72004178107) {\n", " classes[0] = 1; \n", " classes[1] = 0; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[2] <= 3.8068991717706888) {\n", + " if (features[2] <= 3.80689917177) {\n", " classes[0] = 0; \n", " classes[1] = 3; \n", " classes[2] = 0; \n", @@ -1980,13 +1981,13 @@ " }\n", " }\n", " } else {\n", - " if (atts[2] <= 4.9043062884719539) {\n", - " if (atts[2] <= 4.6235755435786769) {\n", + " if (features[2] <= 4.90430628847) {\n", + " if (features[2] <= 4.62357554358) {\n", " classes[0] = 0; \n", " classes[1] = 16; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[3] <= 1.7869205517467841) {\n", + " if (features[3] <= 1.78692055175) {\n", " classes[0] = 0; \n", " classes[1] = 1; \n", " classes[2] = 0; \n", @@ -1997,13 +1998,13 @@ " }\n", " }\n", " } else {\n", - " if (atts[0] <= 5.9034846845099169) {\n", + " if (features[0] <= 5.90348468451) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 3; \n", " } else {\n", - " if (atts[0] <= 6.0069964788449255) {\n", - " if (atts[2] <= 5.092356647339539) {\n", + " if (features[0] <= 6.00699647884) {\n", + " if (features[2] <= 5.09235664734) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 1; \n", @@ -2021,8 +2022,8 @@ " }\n", " }\n", " } else {\n", - " if (atts[2] <= 3.9028751327869577) {\n", - " if (atts[3] <= 0.92942217227084012) {\n", + " if (features[2] <= 3.90287513279) {\n", + " if (features[3] <= 0.929422172271) {\n", " classes[0] = 49; \n", " classes[1] = 0; \n", " classes[2] = 0; \n", @@ -2032,18 +2033,18 @@ " classes[2] = 0; \n", " }\n", " } else {\n", - " if (atts[3] <= 1.95141861134337) {\n", - " if (atts[2] <= 5.9202819502434796) {\n", - " if (atts[1] <= 3.0337596705736161) {\n", - " if (atts[1] <= 2.9515778790039278) {\n", - " if (atts[3] <= 1.565131126685861) {\n", - " if (atts[3] <= 1.4106022275635259) {\n", + " if (features[3] <= 1.95141861134) {\n", + " if (features[2] <= 5.92028195024) {\n", + " if (features[1] <= 3.03375967057) {\n", + " if (features[1] <= 2.951577879) {\n", + " if (features[3] <= 1.56513112669) {\n", + " if (features[3] <= 1.41060222756) {\n", " classes[0] = 0; \n", " classes[1] = 10; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[1] <= 2.8239691897096861) {\n", - " if (atts[0] <= 6.3740416107871889) {\n", + " if (features[1] <= 2.82396918971) {\n", + " if (features[0] <= 6.37404161079) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 1; \n", @@ -2064,8 +2065,8 @@ " classes[2] = 2; \n", " }\n", " } else {\n", - " if (atts[3] <= 1.7349329909051114) {\n", - " if (atts[2] <= 5.5073889949611754) {\n", + " if (features[3] <= 1.73493299091) {\n", + " if (features[2] <= 5.50738899496) {\n", " classes[0] = 0; \n", " classes[1] = 8; \n", " classes[2] = 0; \n", @@ -2081,9 +2082,9 @@ " }\n", " }\n", " } else {\n", - " if (atts[1] <= 3.2667907396292932) {\n", - " if (atts[0] <= 6.8510331900259231) {\n", - " if (atts[2] <= 5.3080841532160195) {\n", + " if (features[1] <= 3.26679073963) {\n", + " if (features[0] <= 6.85103319003) {\n", + " if (features[2] <= 5.30808415322) {\n", " classes[0] = 0; \n", " classes[1] = 4; \n", " classes[2] = 0; \n", @@ -2132,16 +2133,16 @@ " return class_idx;\n", "}\n", "\n", - "int predict_14(float atts[]) {\n", + "int predict_14(float features[]) {\n", " int classes[3];\n", " \n", - " if (atts[2] <= 1.5213681480470247) {\n", + " if (features[2] <= 1.52136814805) {\n", " classes[0] = 37; \n", " classes[1] = 0; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[2] <= 3.3733067152396501) {\n", - " if (atts[2] <= 1.928483210061239) {\n", + " if (features[2] <= 3.37330671524) {\n", + " if (features[2] <= 1.92848321006) {\n", " classes[0] = 13; \n", " classes[1] = 0; \n", " classes[2] = 0; \n", @@ -2151,19 +2152,19 @@ " classes[2] = 0; \n", " }\n", " } else {\n", - " if (atts[3] <= 1.4203844512442054) {\n", - " if (atts[0] <= 5.2718002974390057) {\n", + " if (features[3] <= 1.42038445124) {\n", + " if (features[0] <= 5.27180029744) {\n", " classes[0] = 0; \n", " classes[1] = 2; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[3] <= 1.3984442803066099) {\n", + " if (features[3] <= 1.39844428031) {\n", " classes[0] = 0; \n", " classes[1] = 24; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[1] <= 2.815819690150918) {\n", - " if (atts[0] <= 6.5752606285820789) {\n", + " if (features[1] <= 2.81581969015) {\n", + " if (features[0] <= 6.57526062858) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 1; \n", @@ -2180,9 +2181,9 @@ " }\n", " }\n", " } else {\n", - " if (atts[2] <= 5.0733232229961533) {\n", - " if (atts[2] <= 4.7277283044181084) {\n", - " if (atts[3] <= 1.6830983078709849) {\n", + " if (features[2] <= 5.073323223) {\n", + " if (features[2] <= 4.72772830442) {\n", + " if (features[3] <= 1.68309830787) {\n", " classes[0] = 0; \n", " classes[1] = 10; \n", " classes[2] = 0; \n", @@ -2192,13 +2193,13 @@ " classes[2] = 1; \n", " }\n", " } else {\n", - " if (atts[3] <= 1.7955400567946675) {\n", - " if (atts[2] <= 4.9226321104784594) {\n", + " if (features[3] <= 1.79554005679) {\n", + " if (features[2] <= 4.92263211048) {\n", " classes[0] = 0; \n", " classes[1] = 2; \n", " classes[2] = 0; \n", " } else {\n", - " if (atts[1] <= 2.5475161659836072) {\n", + " if (features[1] <= 2.54751616598) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 1; \n", @@ -2209,7 +2210,7 @@ " }\n", " }\n", " } else {\n", - " if (atts[1] <= 3.0302843343947554) {\n", + " if (features[1] <= 3.03028433439) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 7; \n", @@ -2221,10 +2222,10 @@ " }\n", " }\n", " } else {\n", - " if (atts[1] <= 3.110966564102843) {\n", - " if (atts[3] <= 1.8737745337319733) {\n", - " if (atts[0] <= 6.1758400547445209) {\n", - " if (atts[0] <= 5.9332085107091395) {\n", + " if (features[1] <= 3.1109665641) {\n", + " if (features[3] <= 1.87377453373) {\n", + " if (features[0] <= 6.17584005474) {\n", + " if (features[0] <= 5.93320851071) {\n", " classes[0] = 0; \n", " classes[1] = 0; \n", " classes[2] = 1; \n", @@ -2264,7 +2265,7 @@ " return class_idx;\n", "}\n", "\n", - "int predict (float atts[]) {\n", + "int predict (float features[]) {\n", " int n_classes = 3;\n", " int classes[n_classes];\n", " int i;\n", @@ -2272,21 +2273,21 @@ " classes[i] = 0;\n", " }\n", "\n", - " classes[predict_00(atts)]++;\n", - " classes[predict_01(atts)]++;\n", - " classes[predict_02(atts)]++;\n", - " classes[predict_03(atts)]++;\n", - " classes[predict_04(atts)]++;\n", - " classes[predict_05(atts)]++;\n", - " classes[predict_06(atts)]++;\n", - " classes[predict_07(atts)]++;\n", - " classes[predict_08(atts)]++;\n", - " classes[predict_09(atts)]++;\n", - " classes[predict_10(atts)]++;\n", - " classes[predict_11(atts)]++;\n", - " classes[predict_12(atts)]++;\n", - " classes[predict_13(atts)]++;\n", - " classes[predict_14(atts)]++;\n", + " classes[predict_0(features)]++;\n", + " classes[predict_1(features)]++;\n", + " classes[predict_2(features)]++;\n", + " classes[predict_3(features)]++;\n", + " classes[predict_4(features)]++;\n", + " classes[predict_5(features)]++;\n", + " classes[predict_6(features)]++;\n", + " classes[predict_7(features)]++;\n", + " classes[predict_8(features)]++;\n", + " classes[predict_9(features)]++;\n", + " classes[predict_10(features)]++;\n", + " classes[predict_11(features)]++;\n", + " classes[predict_12(features)]++;\n", + " classes[predict_13(features)]++;\n", + " classes[predict_14(features)]++;\n", "\n", " int class_idx = 0;\n", " int class_val = classes[0];\n", @@ -2300,24 +2301,100 @@ "}\n", "\n", "int main(int argc, const char * argv[]) {\n", - " float atts[argc-1];\n", + " float features[argc-1];\n", " int i;\n", " for (i = 1; i < argc; i++) {\n", - " atts[i-1] = atof(argv[i]);\n", + " features[i-1] = atof(argv[i]);\n", " }\n", - " printf(\"%d\", predict(atts));\n", + " printf(\"%d\", predict(features));\n", " return 0;\n", - "}\n" + "}\n", + "CPU times: user 18.7 ms, sys: 1.74 ms, total: 20.4 ms\n", + "Wall time: 20.1 ms\n" ] } ], "source": [ + "%%time\n", + "\n", "from sklearn_porter import Porter\n", "\n", "output = Porter(clf, language='c').export()\n", "\n", "print output" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Run classification in C:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Save the transpiled estimator:" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "with open('forest.c', 'w') as f:\n", + " f.write(output)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Compiling:" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "%%bash\n", + "\n", + "gcc forest.c -std=c99 -lm -o forest" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Prediction:" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2" + ] + } + ], + "source": [ + "%%bash\n", + "\n", + "./forest 1 2 3 4" + ] } ], "metadata": { @@ -2336,7 +2413,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", - "version": "2.7.12" + "version": "2.7.13" } }, "nbformat": 4, diff --git a/examples/estimator/classifier/LinearSVC/c/basics.ipynb b/examples/estimator/classifier/LinearSVC/c/basics.ipynb index d25aae9c..5b039b75 100644 --- a/examples/estimator/classifier/LinearSVC/c/basics.ipynb +++ b/examples/estimator/classifier/LinearSVC/c/basics.ipynb @@ -85,7 +85,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": { "scrolled": false }, @@ -98,8 +98,8 @@ "#include \n", "#include \n", "\n", - "double coefficients[3][4] = {{0.18424209458473811, 0.45123000025163923, -0.80794587716737576, -0.45071660033253858}, {0.052877455748516447, -0.89214995228605254, 0.40398084459610972, -0.9376821661447452}, {-0.85070784319293802, -0.98670214922204336, 1.381010448739191, 1.8654095662423917}};\n", - "double intercepts[3] = {0.10956266406702335, 1.6636707776739579, -1.7096109416521363};\n", + "double coefficients[3][4] = {{0.184242094585, 0.451230000252, -0.807945877167, -0.450716600333}, {0.0528774557485, -0.892149952286, 0.403980844596, -0.937682166145}, {-0.850707843193, -0.986702149222, 1.38101044874, 1.86540956624}};\n", + "double intercepts[3] = {0.109562664067, 1.66367077767, -1.70961094165};\n", "\n", "int predict (float features[]) {\n", " double class_val = -INFINITY;\n", @@ -131,11 +131,15 @@ " printf(\"%d\", predict(features));\n", " return 0;\n", "\n", - "}\n" + "}\n", + "CPU times: user 910 µs, sys: 922 µs, total: 1.83 ms\n", + "Wall time: 996 µs\n" ] } ], "source": [ + "%%time\n", + "\n", "from sklearn_porter import Porter\n", "\n", "porter = Porter(clf, language='c')\n", @@ -143,6 +147,78 @@ "\n", "print(output)" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Run classification in C:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Save the transpiled estimator:" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "with open('linearsvc.c', 'w') as f:\n", + " f.write(output)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Compiling:" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "%%bash\n", + "\n", + "gcc linearsvc.c -std=c99 -lm -o linearsvc" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Prediction:" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2" + ] + } + ], + "source": [ + "%%bash\n", + "\n", + "./linearsvc 1 2 3 4" + ] } ], "metadata": { diff --git a/examples/estimator/classifier/NuSVC/c/basics.ipynb b/examples/estimator/classifier/NuSVC/c/basics.ipynb index 57a8ae34..af1524b8 100644 --- a/examples/estimator/classifier/NuSVC/c/basics.ipynb +++ b/examples/estimator/classifier/NuSVC/c/basics.ipynb @@ -80,12 +80,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ + "\n", "### Transpile classifier:" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": { "scrolled": false }, @@ -109,9 +110,9 @@ "#define KERNEL_COEF 0.0\n", "#define KERNEL_DEGREE 3\n", "\n", - "double vectors[105][4] = {{4.9000000000000004, 3.0, 1.3999999999999999, 0.20000000000000001}, {4.5999999999999996, 3.1000000000000001, 1.5, 0.20000000000000001}, {5.4000000000000004, 3.8999999999999999, 1.7, 0.40000000000000002}, {5.0, 3.3999999999999999, 1.5, 0.20000000000000001}, {4.9000000000000004, 3.1000000000000001, 1.5, 0.10000000000000001}, {5.4000000000000004, 3.7000000000000002, 1.5, 0.20000000000000001}, {4.7999999999999998, 3.3999999999999999, 1.6000000000000001, 0.20000000000000001}, {5.7000000000000002, 4.4000000000000004, 1.5, 0.40000000000000002}, {5.7000000000000002, 3.7999999999999998, 1.7, 0.29999999999999999}, {5.0999999999999996, 3.7999999999999998, 1.5, 0.29999999999999999}, {5.4000000000000004, 3.3999999999999999, 1.7, 0.20000000000000001}, {5.0999999999999996, 3.7000000000000002, 1.5, 0.40000000000000002}, {5.0999999999999996, 3.2999999999999998, 1.7, 0.5}, {4.7999999999999998, 3.3999999999999999, 1.8999999999999999, 0.20000000000000001}, {5.0, 3.0, 1.6000000000000001, 0.20000000000000001}, {5.0, 3.3999999999999999, 1.6000000000000001, 0.40000000000000002}, {5.2000000000000002, 3.5, 1.5, 0.20000000000000001}, {4.7000000000000002, 3.2000000000000002, 1.6000000000000001, 0.20000000000000001}, {4.7999999999999998, 3.1000000000000001, 1.6000000000000001, 0.20000000000000001}, {5.4000000000000004, 3.3999999999999999, 1.5, 0.40000000000000002}, {4.9000000000000004, 3.1000000000000001, 1.5, 0.10000000000000001}, {4.9000000000000004, 3.1000000000000001, 1.5, 0.10000000000000001}, {5.0999999999999996, 3.3999999999999999, 1.5, 0.20000000000000001}, {4.5, 2.2999999999999998, 1.3, 0.29999999999999999}, {5.0, 3.5, 1.6000000000000001, 0.59999999999999998}, {5.0999999999999996, 3.7999999999999998, 1.8999999999999999, 0.40000000000000002}, {4.7999999999999998, 3.0, 1.3999999999999999, 0.29999999999999999}, {5.0999999999999996, 3.7999999999999998, 1.6000000000000001, 0.20000000000000001}, {5.2999999999999998, 3.7000000000000002, 1.5, 0.20000000000000001}, {7.0, 3.2000000000000002, 4.7000000000000002, 1.3999999999999999}, {6.4000000000000004, 3.2000000000000002, 4.5, 1.5}, {6.9000000000000004, 3.1000000000000001, 4.9000000000000004, 1.5}, {5.5, 2.2999999999999998, 4.0, 1.3}, {6.5, 2.7999999999999998, 4.5999999999999996, 1.5}, {5.7000000000000002, 2.7999999999999998, 4.5, 1.3}, {6.2999999999999998, 3.2999999999999998, 4.7000000000000002, 1.6000000000000001}, {4.9000000000000004, 2.3999999999999999, 3.2999999999999998, 1.0}, {6.5999999999999996, 2.8999999999999999, 4.5999999999999996, 1.3}, {5.2000000000000002, 2.7000000000000002, 3.8999999999999999, 1.3999999999999999}, {5.0, 2.0, 3.5, 1.0}, {5.9000000000000004, 3.0, 4.2000000000000002, 1.5}, {6.0, 2.2000000000000002, 4.0, 1.0}, {6.0999999999999996, 2.8999999999999999, 4.7000000000000002, 1.3999999999999999}, {5.5999999999999996, 2.8999999999999999, 3.6000000000000001, 1.3}, {6.7000000000000002, 3.1000000000000001, 4.4000000000000004, 1.3999999999999999}, {5.5999999999999996, 3.0, 4.5, 1.5}, {5.7999999999999998, 2.7000000000000002, 4.0999999999999996, 1.0}, {6.2000000000000002, 2.2000000000000002, 4.5, 1.5}, {5.5999999999999996, 2.5, 3.8999999999999999, 1.1000000000000001}, {5.9000000000000004, 3.2000000000000002, 4.7999999999999998, 1.8}, {6.0999999999999996, 2.7999999999999998, 4.0, 1.3}, {6.2999999999999998, 2.5, 4.9000000000000004, 1.5}, {6.0999999999999996, 2.7999999999999998, 4.7000000000000002, 1.2}, {6.5999999999999996, 3.0, 4.4000000000000004, 1.3999999999999999}, {6.7999999999999998, 2.7999999999999998, 4.7999999999999998, 1.3999999999999999}, {6.7000000000000002, 3.0, 5.0, 1.7}, {6.0, 2.8999999999999999, 4.5, 1.5}, {5.7000000000000002, 2.6000000000000001, 3.5, 1.0}, {5.5, 2.3999999999999999, 3.7999999999999998, 1.1000000000000001}, {5.5, 2.3999999999999999, 3.7000000000000002, 1.0}, {5.7999999999999998, 2.7000000000000002, 3.8999999999999999, 1.2}, {6.0, 2.7000000000000002, 5.0999999999999996, 1.6000000000000001}, {5.4000000000000004, 3.0, 4.5, 1.5}, {6.0, 3.3999999999999999, 4.5, 1.6000000000000001}, {6.7000000000000002, 3.1000000000000001, 4.7000000000000002, 1.5}, {6.2999999999999998, 2.2999999999999998, 4.4000000000000004, 1.3}, {5.5999999999999996, 3.0, 4.0999999999999996, 1.3}, {5.5, 2.5, 4.0, 1.3}, {5.5, 2.6000000000000001, 4.4000000000000004, 1.2}, {6.0999999999999996, 3.0, 4.5999999999999996, 1.3999999999999999}, {5.7999999999999998, 2.6000000000000001, 4.0, 1.2}, {5.0, 2.2999999999999998, 3.2999999999999998, 1.0}, {5.5999999999999996, 2.7000000000000002, 4.2000000000000002, 1.3}, {5.7000000000000002, 3.0, 4.2000000000000002, 1.2}, {5.7000000000000002, 2.8999999999999999, 4.2000000000000002, 1.3}, {6.2000000000000002, 2.8999999999999999, 4.2999999999999998, 1.3}, {5.0999999999999996, 2.5, 3.0, 1.1000000000000001}, {5.7000000000000002, 2.7999999999999998, 4.0999999999999996, 1.3}, {5.7999999999999998, 2.7000000000000002, 5.0999999999999996, 1.8999999999999999}, {6.2999999999999998, 2.8999999999999999, 5.5999999999999996, 1.8}, {4.9000000000000004, 2.5, 4.5, 1.7}, {6.5, 3.2000000000000002, 5.0999999999999996, 2.0}, {6.4000000000000004, 2.7000000000000002, 5.2999999999999998, 1.8999999999999999}, {5.7000000000000002, 2.5, 5.0, 2.0}, {5.7999999999999998, 2.7999999999999998, 5.0999999999999996, 2.3999999999999999}, {6.4000000000000004, 3.2000000000000002, 5.2999999999999998, 2.2999999999999998}, {6.5, 3.0, 5.5, 1.8}, {6.0, 2.2000000000000002, 5.0, 1.5}, {5.5999999999999996, 2.7999999999999998, 4.9000000000000004, 2.0}, {6.2999999999999998, 2.7000000000000002, 4.9000000000000004, 1.8}, {6.2000000000000002, 2.7999999999999998, 4.7999999999999998, 1.8}, {6.0999999999999996, 3.0, 4.9000000000000004, 1.8}, {7.2000000000000002, 3.0, 5.7999999999999998, 1.6000000000000001}, {6.2999999999999998, 2.7999999999999998, 5.0999999999999996, 1.5}, {6.0999999999999996, 2.6000000000000001, 5.5999999999999996, 1.3999999999999999}, {6.4000000000000004, 3.1000000000000001, 5.5, 1.8}, {6.0, 3.0, 4.7999999999999998, 1.8}, {6.9000000000000004, 3.1000000000000001, 5.4000000000000004, 2.1000000000000001}, {6.9000000000000004, 3.1000000000000001, 5.0999999999999996, 2.2999999999999998}, {5.7999999999999998, 2.7000000000000002, 5.0999999999999996, 1.8999999999999999}, {6.7000000000000002, 3.0, 5.2000000000000002, 2.2999999999999998}, {6.2999999999999998, 2.5, 5.0, 1.8999999999999999}, {6.5, 3.0, 5.2000000000000002, 2.0}, {6.2000000000000002, 3.3999999999999999, 5.4000000000000004, 2.2999999999999998}, {5.9000000000000004, 3.0, 5.0999999999999996, 1.8}};\n", - "double coefficients[2][105] = {{4.6863813658892557, 4.6863813658892557, 4.6863813658892557, 4.6863813658892557, 4.6863813658892557, 4.6863813658892557, 4.6863813658892557, 0.0, 4.6863813658892557, 0.0, 4.6863813658892557, 4.6863813658892557, 4.6863813658892557, 4.6863813658892557, 4.6863813658892557, 4.6863813658892557, 4.6863813658892557, 4.6863813658892557, 4.6863813658892557, 4.6863813658892557, 4.6863813658892557, 4.6863813658892557, 4.6863813658892557, 4.6863813658892557, 4.6863813658892557, 4.6863813658892557, 4.6863813658892557, 0.0, 0.0, -0.0, -0.0, -0.0, -4.6863813658892557, -0.0, -0.0, -0.0, -4.6863813658892557, -0.0, -4.6863813658892557, -4.6863813658892557, -4.6863813658892557, -4.6863813658892557, -0.0, -4.6863813658892557, -0.0, -0.0, -4.6863813658892557, -0.0, -4.6863813658892557, -0.0, -4.6863813658892557, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -4.6863813658892557, -4.6863813658892557, -4.6863813658892557, -4.6863813658892557, -0.0, -0.0, -0.0, -0.0, -0.0, -4.6863813658892557, -4.6863813658892557, -4.6863813658892557, -0.0, -4.6863813658892557, -4.6863813658892557, -4.6863813658892557, -4.6863813658892557, -4.6863813658892557, -4.6863813658892557, -4.6863813658892557, -4.6863813658892557, -2.1272220789292948, -2.1272220789292948, -2.1272220789292948, -2.1272220789292948, -2.1272220789292948, -2.1272220789292948, -2.1272220789292948, -2.1272220789292948, -2.1272220789292948, -2.1272220789292948, -2.1272220789292948, -2.1272220789292948, -2.1272220789292948, -2.1272220789292948, -0.0, -2.1272220789292948, -2.1272220789292948, -2.1272220789292948, -2.1272220789292948, -0.0, -2.1272220789292948, -2.1272220789292948, -2.1272220789292948, -2.1272220789292948, -2.1272220789292948, -2.1272220789292948, -2.1272220789292948}, {0.0, 0.0, 2.1272220789292948, 2.1272220789292948, 2.1272220789292948, 2.1272220789292948, 2.1272220789292948, 2.1272220789292948, 2.1272220789292948, 2.1272220789292948, 2.1272220789292948, 2.1272220789292948, 2.1272220789292948, 2.1272220789292948, 2.1272220789292948, 2.1272220789292948, 2.1272220789292948, 2.1272220789292948, 2.1272220789292948, 2.1272220789292948, 2.1272220789292948, 2.1272220789292948, 2.1272220789292948, 0.0, 2.1272220789292948, 2.1272220789292948, 0.0, 2.1272220789292948, 2.1272220789292948, 47.529341773693893, 47.529341773693893, 47.529341773693893, 0.0, 47.529341773693893, 47.529341773693893, 47.529341773693893, 0.0, 47.529341773693893, 0.0, 0.0, 0.0, 0.0, 47.529341773693893, 0.0, 47.529341773693893, 47.529341773693893, 0.0, 47.529341773693893, 0.0, 47.529341773693893, 0.0, 47.529341773693893, 47.529341773693893, 47.529341773693893, 47.529341773693893, 47.529341773693893, 47.529341773693893, 0.0, 0.0, 0.0, 0.0, 47.529341773693893, 47.529341773693893, 47.529341773693893, 47.529341773693893, 47.529341773693893, 0.0, 0.0, 47.529341773693893, 47.529341773693893, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -47.529341773693893, -47.529341773693893, -47.529341773693893, -47.529341773693893, -47.529341773693893, -47.529341773693893, -47.529341773693893, -0.0, -47.529341773693893, -47.529341773693893, -47.529341773693893, -47.529341773693893, -47.529341773693893, -47.529341773693893, -47.529341773693893, -47.529341773693893, -47.529341773693893, -47.529341773693893, -47.529341773693893, -47.529341773693893, -47.529341773693893, -47.529341773693893, -47.529341773693893, -47.529341773693893, -47.529341773693893, -0.0, -47.529341773693893}};\n", - "double intercepts[3] = {0.10061840191760112, 0.051748160156319709, -0.084181689668018464};\n", + "double vectors[105][4] = {{4.9, 3.0, 1.4, 0.2}, {4.6, 3.1, 1.5, 0.2}, {5.4, 3.9, 1.7, 0.4}, {5.0, 3.4, 1.5, 0.2}, {4.9, 3.1, 1.5, 0.1}, {5.4, 3.7, 1.5, 0.2}, {4.8, 3.4, 1.6, 0.2}, {5.7, 4.4, 1.5, 0.4}, {5.7, 3.8, 1.7, 0.3}, {5.1, 3.8, 1.5, 0.3}, {5.4, 3.4, 1.7, 0.2}, {5.1, 3.7, 1.5, 0.4}, {5.1, 3.3, 1.7, 0.5}, {4.8, 3.4, 1.9, 0.2}, {5.0, 3.0, 1.6, 0.2}, {5.0, 3.4, 1.6, 0.4}, {5.2, 3.5, 1.5, 0.2}, {4.7, 3.2, 1.6, 0.2}, {4.8, 3.1, 1.6, 0.2}, {5.4, 3.4, 1.5, 0.4}, {4.9, 3.1, 1.5, 0.1}, {4.9, 3.1, 1.5, 0.1}, {5.1, 3.4, 1.5, 0.2}, {4.5, 2.3, 1.3, 0.3}, {5.0, 3.5, 1.6, 0.6}, {5.1, 3.8, 1.9, 0.4}, {4.8, 3.0, 1.4, 0.3}, {5.1, 3.8, 1.6, 0.2}, {5.3, 3.7, 1.5, 0.2}, {7.0, 3.2, 4.7, 1.4}, {6.4, 3.2, 4.5, 1.5}, {6.9, 3.1, 4.9, 1.5}, {5.5, 2.3, 4.0, 1.3}, {6.5, 2.8, 4.6, 1.5}, {5.7, 2.8, 4.5, 1.3}, {6.3, 3.3, 4.7, 1.6}, {4.9, 2.4, 3.3, 1.0}, {6.6, 2.9, 4.6, 1.3}, {5.2, 2.7, 3.9, 1.4}, {5.0, 2.0, 3.5, 1.0}, {5.9, 3.0, 4.2, 1.5}, {6.0, 2.2, 4.0, 1.0}, {6.1, 2.9, 4.7, 1.4}, {5.6, 2.9, 3.6, 1.3}, {6.7, 3.1, 4.4, 1.4}, {5.6, 3.0, 4.5, 1.5}, {5.8, 2.7, 4.1, 1.0}, {6.2, 2.2, 4.5, 1.5}, {5.6, 2.5, 3.9, 1.1}, {5.9, 3.2, 4.8, 1.8}, {6.1, 2.8, 4.0, 1.3}, {6.3, 2.5, 4.9, 1.5}, {6.1, 2.8, 4.7, 1.2}, {6.6, 3.0, 4.4, 1.4}, {6.8, 2.8, 4.8, 1.4}, {6.7, 3.0, 5.0, 1.7}, {6.0, 2.9, 4.5, 1.5}, {5.7, 2.6, 3.5, 1.0}, {5.5, 2.4, 3.8, 1.1}, {5.5, 2.4, 3.7, 1.0}, {5.8, 2.7, 3.9, 1.2}, {6.0, 2.7, 5.1, 1.6}, {5.4, 3.0, 4.5, 1.5}, {6.0, 3.4, 4.5, 1.6}, {6.7, 3.1, 4.7, 1.5}, {6.3, 2.3, 4.4, 1.3}, {5.6, 3.0, 4.1, 1.3}, {5.5, 2.5, 4.0, 1.3}, {5.5, 2.6, 4.4, 1.2}, {6.1, 3.0, 4.6, 1.4}, {5.8, 2.6, 4.0, 1.2}, {5.0, 2.3, 3.3, 1.0}, {5.6, 2.7, 4.2, 1.3}, {5.7, 3.0, 4.2, 1.2}, {5.7, 2.9, 4.2, 1.3}, {6.2, 2.9, 4.3, 1.3}, {5.1, 2.5, 3.0, 1.1}, {5.7, 2.8, 4.1, 1.3}, {5.8, 2.7, 5.1, 1.9}, {6.3, 2.9, 5.6, 1.8}, {4.9, 2.5, 4.5, 1.7}, {6.5, 3.2, 5.1, 2.0}, {6.4, 2.7, 5.3, 1.9}, {5.7, 2.5, 5.0, 2.0}, {5.8, 2.8, 5.1, 2.4}, {6.4, 3.2, 5.3, 2.3}, {6.5, 3.0, 5.5, 1.8}, {6.0, 2.2, 5.0, 1.5}, {5.6, 2.8, 4.9, 2.0}, {6.3, 2.7, 4.9, 1.8}, {6.2, 2.8, 4.8, 1.8}, {6.1, 3.0, 4.9, 1.8}, {7.2, 3.0, 5.8, 1.6}, {6.3, 2.8, 5.1, 1.5}, {6.1, 2.6, 5.6, 1.4}, {6.4, 3.1, 5.5, 1.8}, {6.0, 3.0, 4.8, 1.8}, {6.9, 3.1, 5.4, 2.1}, {6.9, 3.1, 5.1, 2.3}, {5.8, 2.7, 5.1, 1.9}, {6.7, 3.0, 5.2, 2.3}, {6.3, 2.5, 5.0, 1.9}, {6.5, 3.0, 5.2, 2.0}, {6.2, 3.4, 5.4, 2.3}, {5.9, 3.0, 5.1, 1.8}};\n", + "double coefficients[2][105] = {{4.68638136589, 4.68638136589, 4.68638136589, 4.68638136589, 4.68638136589, 4.68638136589, 4.68638136589, 0.0, 4.68638136589, 0.0, 4.68638136589, 4.68638136589, 4.68638136589, 4.68638136589, 4.68638136589, 4.68638136589, 4.68638136589, 4.68638136589, 4.68638136589, 4.68638136589, 4.68638136589, 4.68638136589, 4.68638136589, 4.68638136589, 4.68638136589, 4.68638136589, 4.68638136589, 0.0, 0.0, -0.0, -0.0, -0.0, -4.68638136589, -0.0, -0.0, -0.0, -4.68638136589, -0.0, -4.68638136589, -4.68638136589, -4.68638136589, -4.68638136589, -0.0, -4.68638136589, -0.0, -0.0, -4.68638136589, -0.0, -4.68638136589, -0.0, -4.68638136589, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -4.68638136589, -4.68638136589, -4.68638136589, -4.68638136589, -0.0, -0.0, -0.0, -0.0, -0.0, -4.68638136589, -4.68638136589, -4.68638136589, -0.0, -4.68638136589, -4.68638136589, -4.68638136589, -4.68638136589, -4.68638136589, -4.68638136589, -4.68638136589, -4.68638136589, -2.12722207893, -2.12722207893, -2.12722207893, -2.12722207893, -2.12722207893, -2.12722207893, -2.12722207893, -2.12722207893, -2.12722207893, -2.12722207893, -2.12722207893, -2.12722207893, -2.12722207893, -2.12722207893, -0.0, -2.12722207893, -2.12722207893, -2.12722207893, -2.12722207893, -0.0, -2.12722207893, -2.12722207893, -2.12722207893, -2.12722207893, -2.12722207893, -2.12722207893, -2.12722207893}, {0.0, 0.0, 2.12722207893, 2.12722207893, 2.12722207893, 2.12722207893, 2.12722207893, 2.12722207893, 2.12722207893, 2.12722207893, 2.12722207893, 2.12722207893, 2.12722207893, 2.12722207893, 2.12722207893, 2.12722207893, 2.12722207893, 2.12722207893, 2.12722207893, 2.12722207893, 2.12722207893, 2.12722207893, 2.12722207893, 0.0, 2.12722207893, 2.12722207893, 0.0, 2.12722207893, 2.12722207893, 47.5293417737, 47.5293417737, 47.5293417737, 0.0, 47.5293417737, 47.5293417737, 47.5293417737, 0.0, 47.5293417737, 0.0, 0.0, 0.0, 0.0, 47.5293417737, 0.0, 47.5293417737, 47.5293417737, 0.0, 47.5293417737, 0.0, 47.5293417737, 0.0, 47.5293417737, 47.5293417737, 47.5293417737, 47.5293417737, 47.5293417737, 47.5293417737, 0.0, 0.0, 0.0, 0.0, 47.5293417737, 47.5293417737, 47.5293417737, 47.5293417737, 47.5293417737, 0.0, 0.0, 47.5293417737, 47.5293417737, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -47.5293417737, -47.5293417737, -47.5293417737, -47.5293417737, -47.5293417737, -47.5293417737, -47.5293417737, -0.0, -47.5293417737, -47.5293417737, -47.5293417737, -47.5293417737, -47.5293417737, -47.5293417737, -47.5293417737, -47.5293417737, -47.5293417737, -47.5293417737, -47.5293417737, -47.5293417737, -47.5293417737, -47.5293417737, -47.5293417737, -47.5293417737, -47.5293417737, -0.0, -47.5293417737}};\n", + "double intercepts[3] = {0.100618401918, 0.0517481601563, -0.084181689668};\n", "int weights[3] = {29, 49, 27};\n", "\n", "int predict (double features[]) {\n", @@ -261,11 +262,15 @@ " return 0;\n", "\n", "}\n", - "\n" + "\n", + "CPU times: user 3.23 ms, sys: 1.68 ms, total: 4.91 ms\n", + "Wall time: 3.52 ms\n" ] } ], "source": [ + "%%time\n", + "\n", "from sklearn_porter import Porter\n", "\n", "porter = Porter(clf, language='c')\n", @@ -273,6 +278,78 @@ "\n", "print(output)" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Run classification in C:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Save the transpiled estimator:" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "with open('nusvc.c', 'w') as f:\n", + " f.write(output)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Compiling:" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "%%bash\n", + "\n", + "gcc nusvc.c -std=c99 -lm -o nusvc" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Prediction:" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0" + ] + } + ], + "source": [ + "%%bash\n", + "\n", + "./nusvc 1 2 3 4" + ] } ], "metadata": { diff --git a/examples/estimator/classifier/RandomForestClassifier/c/basics_embedded.ipynb b/examples/estimator/classifier/RandomForestClassifier/c/basics_embedded.ipynb index 08b0c9bc..27444428 100644 --- a/examples/estimator/classifier/RandomForestClassifier/c/basics_embedded.ipynb +++ b/examples/estimator/classifier/RandomForestClassifier/c/basics_embedded.ipynb @@ -88,7 +88,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": { "scrolled": false }, @@ -101,7 +101,7 @@ "#include \n", "#include \n", "\n", - "int predict_0(float atts[]) {\n", + "int predict_0(float features[]) {\n", " int classes[3];\n", " \n", " if (features[3] <= 0.75) {\n", @@ -155,7 +155,7 @@ " return class_idx;\n", "}\n", "\n", - "int predict_1(float atts[]) {\n", + "int predict_1(float features[]) {\n", " int classes[3];\n", " \n", " if (features[3] <= 0.800000011921) {\n", @@ -215,7 +215,7 @@ " return class_idx;\n", "}\n", "\n", - "int predict_2(float atts[]) {\n", + "int predict_2(float features[]) {\n", " int classes[3];\n", " \n", " if (features[0] <= 5.55000019073) {\n", @@ -287,7 +287,7 @@ " return class_idx;\n", "}\n", "\n", - "int predict_3(float atts[]) {\n", + "int predict_3(float features[]) {\n", " int classes[3];\n", " \n", " if (features[0] <= 5.44999980927) {\n", @@ -371,7 +371,7 @@ " return class_idx;\n", "}\n", "\n", - "int predict_4(float atts[]) {\n", + "int predict_4(float features[]) {\n", " int classes[3];\n", " \n", " if (features[3] <= 0.699999988079) {\n", @@ -425,7 +425,7 @@ " return class_idx;\n", "}\n", "\n", - "int predict_5(float atts[]) {\n", + "int predict_5(float features[]) {\n", " int classes[3];\n", " \n", " if (features[3] <= 0.800000011921) {\n", @@ -491,7 +491,7 @@ " return class_idx;\n", "}\n", "\n", - "int predict_6(float atts[]) {\n", + "int predict_6(float features[]) {\n", " int classes[3];\n", " \n", " if (features[3] <= 0.699999988079) {\n", @@ -551,7 +551,7 @@ " return class_idx;\n", "}\n", "\n", - "int predict_7(float atts[]) {\n", + "int predict_7(float features[]) {\n", " int classes[3];\n", " \n", " if (features[2] <= 2.59999990463) {\n", @@ -617,7 +617,7 @@ " return class_idx;\n", "}\n", "\n", - "int predict_8(float atts[]) {\n", + "int predict_8(float features[]) {\n", " int classes[3];\n", " \n", " if (features[3] <= 0.699999988079) {\n", @@ -689,7 +689,7 @@ " return class_idx;\n", "}\n", "\n", - "int predict_9(float atts[]) {\n", + "int predict_9(float features[]) {\n", " int classes[3];\n", " \n", " if (features[2] <= 2.59999990463) {\n", @@ -749,7 +749,7 @@ " return class_idx;\n", "}\n", "\n", - "int predict_10(float atts[]) {\n", + "int predict_10(float features[]) {\n", " int classes[3];\n", " \n", " if (features[3] <= 0.800000011921) {\n", @@ -821,7 +821,7 @@ " return class_idx;\n", "}\n", "\n", - "int predict_11(float atts[]) {\n", + "int predict_11(float features[]) {\n", " int classes[3];\n", " \n", " if (features[2] <= 2.59999990463) {\n", @@ -887,7 +887,7 @@ " return class_idx;\n", "}\n", "\n", - "int predict_12(float atts[]) {\n", + "int predict_12(float features[]) {\n", " int classes[3];\n", " \n", " if (features[3] <= 0.800000011921) {\n", @@ -947,7 +947,7 @@ " return class_idx;\n", "}\n", "\n", - "int predict_13(float atts[]) {\n", + "int predict_13(float features[]) {\n", " int classes[3];\n", " \n", " if (features[0] <= 5.44999980927) {\n", @@ -1013,7 +1013,7 @@ " return class_idx;\n", "}\n", "\n", - "int predict_14(float atts[]) {\n", + "int predict_14(float features[]) {\n", " int classes[3];\n", " \n", " if (features[2] <= 2.59999990463) {\n", @@ -1061,7 +1061,7 @@ " return class_idx;\n", "}\n", "\n", - "int predict (float atts[]) {\n", + "int predict (float features[]) {\n", " int n_classes = 3;\n", " int classes[n_classes];\n", " int i;\n", @@ -1069,21 +1069,21 @@ " classes[i] = 0;\n", " }\n", "\n", - " classes[predict_0(atts)]++;\n", - " classes[predict_1(atts)]++;\n", - " classes[predict_2(atts)]++;\n", - " classes[predict_3(atts)]++;\n", - " classes[predict_4(atts)]++;\n", - " classes[predict_5(atts)]++;\n", - " classes[predict_6(atts)]++;\n", - " classes[predict_7(atts)]++;\n", - " classes[predict_8(atts)]++;\n", - " classes[predict_9(atts)]++;\n", - " classes[predict_10(atts)]++;\n", - " classes[predict_11(atts)]++;\n", - " classes[predict_12(atts)]++;\n", - " classes[predict_13(atts)]++;\n", - " classes[predict_14(atts)]++;\n", + " classes[predict_0(features)]++;\n", + " classes[predict_1(features)]++;\n", + " classes[predict_2(features)]++;\n", + " classes[predict_3(features)]++;\n", + " classes[predict_4(features)]++;\n", + " classes[predict_5(features)]++;\n", + " classes[predict_6(features)]++;\n", + " classes[predict_7(features)]++;\n", + " classes[predict_8(features)]++;\n", + " classes[predict_9(features)]++;\n", + " classes[predict_10(features)]++;\n", + " classes[predict_11(features)]++;\n", + " classes[predict_12(features)]++;\n", + " classes[predict_13(features)]++;\n", + " classes[predict_14(features)]++;\n", "\n", " int class_idx = 0;\n", " int class_val = classes[0];\n", @@ -1097,18 +1097,22 @@ "}\n", "\n", "int main(int argc, const char * argv[]) {\n", - " float atts[argc-1];\n", + " float features[argc-1];\n", " int i;\n", " for (i = 1; i < argc; i++) {\n", - " atts[i-1] = atof(argv[i]);\n", + " features[i-1] = atof(argv[i]);\n", " }\n", - " printf(\"%d\", predict(atts));\n", + " printf(\"%d\", predict(features));\n", " return 0;\n", - "}\n" + "}\n", + "CPU times: user 11.2 ms, sys: 2.75 ms, total: 14 ms\n", + "Wall time: 12.1 ms\n" ] } ], "source": [ + "%%time\n", + "\n", "from sklearn_porter import Porter\n", "\n", "porter = Porter(clf, language='c')\n", @@ -1116,6 +1120,78 @@ "\n", "print(output)" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Run classification in C:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Save the transpiled estimator:" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "with open('forest.c', 'w') as f:\n", + " f.write(output)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Compiling:" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "%%bash\n", + "\n", + "gcc forest.c -std=c99 -lm -o forest" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Prediction:" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1" + ] + } + ], + "source": [ + "%%bash\n", + "\n", + "./forest 1 2 3 4" + ] } ], "metadata": { diff --git a/examples/estimator/classifier/RandomForestClassifier/js/basics_embedded.ipynb b/examples/estimator/classifier/RandomForestClassifier/js/basics_embedded.ipynb index b5214c61..a425337d 100644 --- a/examples/estimator/classifier/RandomForestClassifier/js/basics_embedded.ipynb +++ b/examples/estimator/classifier/RandomForestClassifier/js/basics_embedded.ipynb @@ -971,14 +971,12 @@ "\n", " }\n", "}\n", - "CPU times: user 8.93 ms, sys: 1.83 ms, total: 10.8 ms\n", - "Wall time: 9.71 ms\n" + "CPU times: user 9.93 ms, sys: 2.45 ms, total: 12.4 ms\n", + "Wall time: 11 ms\n" ] } ], "source": [ - "%%time\n", - "\n", "from sklearn_porter import Porter\n", "\n", "porter = Porter(clf, language='js')\n", diff --git a/examples/estimator/classifier/SVC/c/basics.ipynb b/examples/estimator/classifier/SVC/c/basics.ipynb index 018db4ee..9c20f50a 100644 --- a/examples/estimator/classifier/SVC/c/basics.ipynb +++ b/examples/estimator/classifier/SVC/c/basics.ipynb @@ -22,7 +22,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": {}, "outputs": [ { @@ -52,7 +52,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -64,7 +64,7 @@ " tol=0.001, verbose=False)" ] }, - "execution_count": 3, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -109,9 +109,9 @@ "#define KERNEL_COEF 0.0\n", "#define KERNEL_DEGREE 3\n", "\n", - "double vectors[150][4] = {{5.0999999999999996, 3.5, 1.3999999999999999, 0.20000000000000001}, {4.9000000000000004, 3.0, 1.3999999999999999, 0.20000000000000001}, {4.7000000000000002, 3.2000000000000002, 1.3, 0.20000000000000001}, {4.5999999999999996, 3.1000000000000001, 1.5, 0.20000000000000001}, {5.0, 3.6000000000000001, 1.3999999999999999, 0.20000000000000001}, {5.4000000000000004, 3.8999999999999999, 1.7, 0.40000000000000002}, {4.5999999999999996, 3.3999999999999999, 1.3999999999999999, 0.29999999999999999}, {5.0, 3.3999999999999999, 1.5, 0.20000000000000001}, {4.4000000000000004, 2.8999999999999999, 1.3999999999999999, 0.20000000000000001}, {4.9000000000000004, 3.1000000000000001, 1.5, 0.10000000000000001}, {5.4000000000000004, 3.7000000000000002, 1.5, 0.20000000000000001}, {4.7999999999999998, 3.3999999999999999, 1.6000000000000001, 0.20000000000000001}, {4.7999999999999998, 3.0, 1.3999999999999999, 0.10000000000000001}, {4.2999999999999998, 3.0, 1.1000000000000001, 0.10000000000000001}, {5.7999999999999998, 4.0, 1.2, 0.20000000000000001}, {5.7000000000000002, 4.4000000000000004, 1.5, 0.40000000000000002}, {5.4000000000000004, 3.8999999999999999, 1.3, 0.40000000000000002}, {5.0999999999999996, 3.5, 1.3999999999999999, 0.29999999999999999}, {5.7000000000000002, 3.7999999999999998, 1.7, 0.29999999999999999}, {5.0999999999999996, 3.7999999999999998, 1.5, 0.29999999999999999}, {5.4000000000000004, 3.3999999999999999, 1.7, 0.20000000000000001}, {5.0999999999999996, 3.7000000000000002, 1.5, 0.40000000000000002}, {4.5999999999999996, 3.6000000000000001, 1.0, 0.20000000000000001}, {5.0999999999999996, 3.2999999999999998, 1.7, 0.5}, {4.7999999999999998, 3.3999999999999999, 1.8999999999999999, 0.20000000000000001}, {5.0, 3.0, 1.6000000000000001, 0.20000000000000001}, {5.0, 3.3999999999999999, 1.6000000000000001, 0.40000000000000002}, {5.2000000000000002, 3.5, 1.5, 0.20000000000000001}, {5.2000000000000002, 3.3999999999999999, 1.3999999999999999, 0.20000000000000001}, {4.7000000000000002, 3.2000000000000002, 1.6000000000000001, 0.20000000000000001}, {4.7999999999999998, 3.1000000000000001, 1.6000000000000001, 0.20000000000000001}, {5.4000000000000004, 3.3999999999999999, 1.5, 0.40000000000000002}, {5.2000000000000002, 4.0999999999999996, 1.5, 0.10000000000000001}, {5.5, 4.2000000000000002, 1.3999999999999999, 0.20000000000000001}, {4.9000000000000004, 3.1000000000000001, 1.5, 0.10000000000000001}, {5.0, 3.2000000000000002, 1.2, 0.20000000000000001}, {5.5, 3.5, 1.3, 0.20000000000000001}, {4.9000000000000004, 3.1000000000000001, 1.5, 0.10000000000000001}, {4.4000000000000004, 3.0, 1.3, 0.20000000000000001}, {5.0999999999999996, 3.3999999999999999, 1.5, 0.20000000000000001}, {5.0, 3.5, 1.3, 0.29999999999999999}, {4.5, 2.2999999999999998, 1.3, 0.29999999999999999}, {4.4000000000000004, 3.2000000000000002, 1.3, 0.20000000000000001}, {5.0, 3.5, 1.6000000000000001, 0.59999999999999998}, {5.0999999999999996, 3.7999999999999998, 1.8999999999999999, 0.40000000000000002}, {4.7999999999999998, 3.0, 1.3999999999999999, 0.29999999999999999}, {5.0999999999999996, 3.7999999999999998, 1.6000000000000001, 0.20000000000000001}, {4.5999999999999996, 3.2000000000000002, 1.3999999999999999, 0.20000000000000001}, {5.2999999999999998, 3.7000000000000002, 1.5, 0.20000000000000001}, {5.0, 3.2999999999999998, 1.3999999999999999, 0.20000000000000001}, {7.0, 3.2000000000000002, 4.7000000000000002, 1.3999999999999999}, {6.4000000000000004, 3.2000000000000002, 4.5, 1.5}, {6.9000000000000004, 3.1000000000000001, 4.9000000000000004, 1.5}, {5.5, 2.2999999999999998, 4.0, 1.3}, {6.5, 2.7999999999999998, 4.5999999999999996, 1.5}, {5.7000000000000002, 2.7999999999999998, 4.5, 1.3}, {6.2999999999999998, 3.2999999999999998, 4.7000000000000002, 1.6000000000000001}, {4.9000000000000004, 2.3999999999999999, 3.2999999999999998, 1.0}, {6.5999999999999996, 2.8999999999999999, 4.5999999999999996, 1.3}, {5.2000000000000002, 2.7000000000000002, 3.8999999999999999, 1.3999999999999999}, {5.0, 2.0, 3.5, 1.0}, {5.9000000000000004, 3.0, 4.2000000000000002, 1.5}, {6.0, 2.2000000000000002, 4.0, 1.0}, {6.0999999999999996, 2.8999999999999999, 4.7000000000000002, 1.3999999999999999}, {5.5999999999999996, 2.8999999999999999, 3.6000000000000001, 1.3}, {6.7000000000000002, 3.1000000000000001, 4.4000000000000004, 1.3999999999999999}, {5.5999999999999996, 3.0, 4.5, 1.5}, {5.7999999999999998, 2.7000000000000002, 4.0999999999999996, 1.0}, {6.2000000000000002, 2.2000000000000002, 4.5, 1.5}, {5.5999999999999996, 2.5, 3.8999999999999999, 1.1000000000000001}, {5.9000000000000004, 3.2000000000000002, 4.7999999999999998, 1.8}, {6.0999999999999996, 2.7999999999999998, 4.0, 1.3}, {6.2999999999999998, 2.5, 4.9000000000000004, 1.5}, {6.0999999999999996, 2.7999999999999998, 4.7000000000000002, 1.2}, {6.4000000000000004, 2.8999999999999999, 4.2999999999999998, 1.3}, {6.5999999999999996, 3.0, 4.4000000000000004, 1.3999999999999999}, {6.7999999999999998, 2.7999999999999998, 4.7999999999999998, 1.3999999999999999}, {6.7000000000000002, 3.0, 5.0, 1.7}, {6.0, 2.8999999999999999, 4.5, 1.5}, {5.7000000000000002, 2.6000000000000001, 3.5, 1.0}, {5.5, 2.3999999999999999, 3.7999999999999998, 1.1000000000000001}, {5.5, 2.3999999999999999, 3.7000000000000002, 1.0}, {5.7999999999999998, 2.7000000000000002, 3.8999999999999999, 1.2}, {6.0, 2.7000000000000002, 5.0999999999999996, 1.6000000000000001}, {5.4000000000000004, 3.0, 4.5, 1.5}, {6.0, 3.3999999999999999, 4.5, 1.6000000000000001}, {6.7000000000000002, 3.1000000000000001, 4.7000000000000002, 1.5}, {6.2999999999999998, 2.2999999999999998, 4.4000000000000004, 1.3}, {5.5999999999999996, 3.0, 4.0999999999999996, 1.3}, {5.5, 2.5, 4.0, 1.3}, {5.5, 2.6000000000000001, 4.4000000000000004, 1.2}, {6.0999999999999996, 3.0, 4.5999999999999996, 1.3999999999999999}, {5.7999999999999998, 2.6000000000000001, 4.0, 1.2}, {5.0, 2.2999999999999998, 3.2999999999999998, 1.0}, {5.5999999999999996, 2.7000000000000002, 4.2000000000000002, 1.3}, {5.7000000000000002, 3.0, 4.2000000000000002, 1.2}, {5.7000000000000002, 2.8999999999999999, 4.2000000000000002, 1.3}, {6.2000000000000002, 2.8999999999999999, 4.2999999999999998, 1.3}, {5.0999999999999996, 2.5, 3.0, 1.1000000000000001}, {5.7000000000000002, 2.7999999999999998, 4.0999999999999996, 1.3}, {6.2999999999999998, 3.2999999999999998, 6.0, 2.5}, {5.7999999999999998, 2.7000000000000002, 5.0999999999999996, 1.8999999999999999}, {7.0999999999999996, 3.0, 5.9000000000000004, 2.1000000000000001}, {6.2999999999999998, 2.8999999999999999, 5.5999999999999996, 1.8}, {6.5, 3.0, 5.7999999999999998, 2.2000000000000002}, {7.5999999999999996, 3.0, 6.5999999999999996, 2.1000000000000001}, {4.9000000000000004, 2.5, 4.5, 1.7}, {7.2999999999999998, 2.8999999999999999, 6.2999999999999998, 1.8}, {6.7000000000000002, 2.5, 5.7999999999999998, 1.8}, {7.2000000000000002, 3.6000000000000001, 6.0999999999999996, 2.5}, {6.5, 3.2000000000000002, 5.0999999999999996, 2.0}, {6.4000000000000004, 2.7000000000000002, 5.2999999999999998, 1.8999999999999999}, {6.7999999999999998, 3.0, 5.5, 2.1000000000000001}, {5.7000000000000002, 2.5, 5.0, 2.0}, {5.7999999999999998, 2.7999999999999998, 5.0999999999999996, 2.3999999999999999}, {6.4000000000000004, 3.2000000000000002, 5.2999999999999998, 2.2999999999999998}, {6.5, 3.0, 5.5, 1.8}, {7.7000000000000002, 3.7999999999999998, 6.7000000000000002, 2.2000000000000002}, {7.7000000000000002, 2.6000000000000001, 6.9000000000000004, 2.2999999999999998}, {6.0, 2.2000000000000002, 5.0, 1.5}, {6.9000000000000004, 3.2000000000000002, 5.7000000000000002, 2.2999999999999998}, {5.5999999999999996, 2.7999999999999998, 4.9000000000000004, 2.0}, {7.7000000000000002, 2.7999999999999998, 6.7000000000000002, 2.0}, {6.2999999999999998, 2.7000000000000002, 4.9000000000000004, 1.8}, {6.7000000000000002, 3.2999999999999998, 5.7000000000000002, 2.1000000000000001}, {7.2000000000000002, 3.2000000000000002, 6.0, 1.8}, {6.2000000000000002, 2.7999999999999998, 4.7999999999999998, 1.8}, {6.0999999999999996, 3.0, 4.9000000000000004, 1.8}, {6.4000000000000004, 2.7999999999999998, 5.5999999999999996, 2.1000000000000001}, {7.2000000000000002, 3.0, 5.7999999999999998, 1.6000000000000001}, {7.4000000000000004, 2.7999999999999998, 6.0999999999999996, 1.8999999999999999}, {7.9000000000000004, 3.7999999999999998, 6.4000000000000004, 2.0}, {6.4000000000000004, 2.7999999999999998, 5.5999999999999996, 2.2000000000000002}, {6.2999999999999998, 2.7999999999999998, 5.0999999999999996, 1.5}, {6.0999999999999996, 2.6000000000000001, 5.5999999999999996, 1.3999999999999999}, {7.7000000000000002, 3.0, 6.0999999999999996, 2.2999999999999998}, {6.2999999999999998, 3.3999999999999999, 5.5999999999999996, 2.3999999999999999}, {6.4000000000000004, 3.1000000000000001, 5.5, 1.8}, {6.0, 3.0, 4.7999999999999998, 1.8}, {6.9000000000000004, 3.1000000000000001, 5.4000000000000004, 2.1000000000000001}, {6.7000000000000002, 3.1000000000000001, 5.5999999999999996, 2.3999999999999999}, {6.9000000000000004, 3.1000000000000001, 5.0999999999999996, 2.2999999999999998}, {5.7999999999999998, 2.7000000000000002, 5.0999999999999996, 1.8999999999999999}, {6.7999999999999998, 3.2000000000000002, 5.9000000000000004, 2.2999999999999998}, {6.7000000000000002, 3.2999999999999998, 5.7000000000000002, 2.5}, {6.7000000000000002, 3.0, 5.2000000000000002, 2.2999999999999998}, {6.2999999999999998, 2.5, 5.0, 1.8999999999999999}, {6.5, 3.0, 5.2000000000000002, 2.0}, {6.2000000000000002, 3.3999999999999999, 5.4000000000000004, 2.2999999999999998}, {5.9000000000000004, 3.0, 5.0999999999999996, 1.8}};\n", + "double vectors[150][4] = {{5.1, 3.5, 1.4, 0.2}, {4.9, 3.0, 1.4, 0.2}, {4.7, 3.2, 1.3, 0.2}, {4.6, 3.1, 1.5, 0.2}, {5.0, 3.6, 1.4, 0.2}, {5.4, 3.9, 1.7, 0.4}, {4.6, 3.4, 1.4, 0.3}, {5.0, 3.4, 1.5, 0.2}, {4.4, 2.9, 1.4, 0.2}, {4.9, 3.1, 1.5, 0.1}, {5.4, 3.7, 1.5, 0.2}, {4.8, 3.4, 1.6, 0.2}, {4.8, 3.0, 1.4, 0.1}, {4.3, 3.0, 1.1, 0.1}, {5.8, 4.0, 1.2, 0.2}, {5.7, 4.4, 1.5, 0.4}, {5.4, 3.9, 1.3, 0.4}, {5.1, 3.5, 1.4, 0.3}, {5.7, 3.8, 1.7, 0.3}, {5.1, 3.8, 1.5, 0.3}, {5.4, 3.4, 1.7, 0.2}, {5.1, 3.7, 1.5, 0.4}, {4.6, 3.6, 1.0, 0.2}, {5.1, 3.3, 1.7, 0.5}, {4.8, 3.4, 1.9, 0.2}, {5.0, 3.0, 1.6, 0.2}, {5.0, 3.4, 1.6, 0.4}, {5.2, 3.5, 1.5, 0.2}, {5.2, 3.4, 1.4, 0.2}, {4.7, 3.2, 1.6, 0.2}, {4.8, 3.1, 1.6, 0.2}, {5.4, 3.4, 1.5, 0.4}, {5.2, 4.1, 1.5, 0.1}, {5.5, 4.2, 1.4, 0.2}, {4.9, 3.1, 1.5, 0.1}, {5.0, 3.2, 1.2, 0.2}, {5.5, 3.5, 1.3, 0.2}, {4.9, 3.1, 1.5, 0.1}, {4.4, 3.0, 1.3, 0.2}, {5.1, 3.4, 1.5, 0.2}, {5.0, 3.5, 1.3, 0.3}, {4.5, 2.3, 1.3, 0.3}, {4.4, 3.2, 1.3, 0.2}, {5.0, 3.5, 1.6, 0.6}, {5.1, 3.8, 1.9, 0.4}, {4.8, 3.0, 1.4, 0.3}, {5.1, 3.8, 1.6, 0.2}, {4.6, 3.2, 1.4, 0.2}, {5.3, 3.7, 1.5, 0.2}, {5.0, 3.3, 1.4, 0.2}, {7.0, 3.2, 4.7, 1.4}, {6.4, 3.2, 4.5, 1.5}, {6.9, 3.1, 4.9, 1.5}, {5.5, 2.3, 4.0, 1.3}, {6.5, 2.8, 4.6, 1.5}, {5.7, 2.8, 4.5, 1.3}, {6.3, 3.3, 4.7, 1.6}, {4.9, 2.4, 3.3, 1.0}, {6.6, 2.9, 4.6, 1.3}, {5.2, 2.7, 3.9, 1.4}, {5.0, 2.0, 3.5, 1.0}, {5.9, 3.0, 4.2, 1.5}, {6.0, 2.2, 4.0, 1.0}, {6.1, 2.9, 4.7, 1.4}, {5.6, 2.9, 3.6, 1.3}, {6.7, 3.1, 4.4, 1.4}, {5.6, 3.0, 4.5, 1.5}, {5.8, 2.7, 4.1, 1.0}, {6.2, 2.2, 4.5, 1.5}, {5.6, 2.5, 3.9, 1.1}, {5.9, 3.2, 4.8, 1.8}, {6.1, 2.8, 4.0, 1.3}, {6.3, 2.5, 4.9, 1.5}, {6.1, 2.8, 4.7, 1.2}, {6.4, 2.9, 4.3, 1.3}, {6.6, 3.0, 4.4, 1.4}, {6.8, 2.8, 4.8, 1.4}, {6.7, 3.0, 5.0, 1.7}, {6.0, 2.9, 4.5, 1.5}, {5.7, 2.6, 3.5, 1.0}, {5.5, 2.4, 3.8, 1.1}, {5.5, 2.4, 3.7, 1.0}, {5.8, 2.7, 3.9, 1.2}, {6.0, 2.7, 5.1, 1.6}, {5.4, 3.0, 4.5, 1.5}, {6.0, 3.4, 4.5, 1.6}, {6.7, 3.1, 4.7, 1.5}, {6.3, 2.3, 4.4, 1.3}, {5.6, 3.0, 4.1, 1.3}, {5.5, 2.5, 4.0, 1.3}, {5.5, 2.6, 4.4, 1.2}, {6.1, 3.0, 4.6, 1.4}, {5.8, 2.6, 4.0, 1.2}, {5.0, 2.3, 3.3, 1.0}, {5.6, 2.7, 4.2, 1.3}, {5.7, 3.0, 4.2, 1.2}, {5.7, 2.9, 4.2, 1.3}, {6.2, 2.9, 4.3, 1.3}, {5.1, 2.5, 3.0, 1.1}, {5.7, 2.8, 4.1, 1.3}, {6.3, 3.3, 6.0, 2.5}, {5.8, 2.7, 5.1, 1.9}, {7.1, 3.0, 5.9, 2.1}, {6.3, 2.9, 5.6, 1.8}, {6.5, 3.0, 5.8, 2.2}, {7.6, 3.0, 6.6, 2.1}, {4.9, 2.5, 4.5, 1.7}, {7.3, 2.9, 6.3, 1.8}, {6.7, 2.5, 5.8, 1.8}, {7.2, 3.6, 6.1, 2.5}, {6.5, 3.2, 5.1, 2.0}, {6.4, 2.7, 5.3, 1.9}, {6.8, 3.0, 5.5, 2.1}, {5.7, 2.5, 5.0, 2.0}, {5.8, 2.8, 5.1, 2.4}, {6.4, 3.2, 5.3, 2.3}, {6.5, 3.0, 5.5, 1.8}, {7.7, 3.8, 6.7, 2.2}, {7.7, 2.6, 6.9, 2.3}, {6.0, 2.2, 5.0, 1.5}, {6.9, 3.2, 5.7, 2.3}, {5.6, 2.8, 4.9, 2.0}, {7.7, 2.8, 6.7, 2.0}, {6.3, 2.7, 4.9, 1.8}, {6.7, 3.3, 5.7, 2.1}, {7.2, 3.2, 6.0, 1.8}, {6.2, 2.8, 4.8, 1.8}, {6.1, 3.0, 4.9, 1.8}, {6.4, 2.8, 5.6, 2.1}, {7.2, 3.0, 5.8, 1.6}, {7.4, 2.8, 6.1, 1.9}, {7.9, 3.8, 6.4, 2.0}, {6.4, 2.8, 5.6, 2.2}, {6.3, 2.8, 5.1, 1.5}, {6.1, 2.6, 5.6, 1.4}, {7.7, 3.0, 6.1, 2.3}, {6.3, 3.4, 5.6, 2.4}, {6.4, 3.1, 5.5, 1.8}, {6.0, 3.0, 4.8, 1.8}, {6.9, 3.1, 5.4, 2.1}, {6.7, 3.1, 5.6, 2.4}, {6.9, 3.1, 5.1, 2.3}, {5.8, 2.7, 5.1, 1.9}, {6.8, 3.2, 5.9, 2.3}, {6.7, 3.3, 5.7, 2.5}, {6.7, 3.0, 5.2, 2.3}, {6.3, 2.5, 5.0, 1.9}, {6.5, 3.0, 5.2, 2.0}, {6.2, 3.4, 5.4, 2.3}, {5.9, 3.0, 5.1, 1.8}};\n", "double coefficients[2][150] = {{1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -0.0, -1.0, -0.0, -1.0, -0.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -0.0, -0.0, -1.0, -1.0, -1.0, -0.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -0.0, -0.0, -1.0, -1.0, -1.0, -0.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}, {1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}};\n", - "double intercepts[3] = {0.043376922607421875, 0.11445245146751404, -0.0031709671020507812};\n", + "double intercepts[3] = {0.0433769226074, 0.114452451468, -0.00317096710205};\n", "int weights[3] = {50, 50, 50};\n", "\n", "int predict (double features[]) {\n", @@ -261,11 +261,15 @@ " return 0;\n", "\n", "}\n", - "\n" + "\n", + "CPU times: user 3.21 ms, sys: 1.59 ms, total: 4.79 ms\n", + "Wall time: 3.38 ms\n" ] } ], "source": [ + "%%time\n", + "\n", "from sklearn_porter import Porter\n", "\n", "porter = Porter(clf, language='c')\n", @@ -273,6 +277,76 @@ "\n", "print(output)" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Run classification in C:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Save the transpiled estimator:" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "with open('svc.c', 'w') as f:\n", + " f.write(output)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Compiling:" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [], + "source": [ + "%%bash\n", + "\n", + "gcc svc.c -std=c99 -lm -o svc" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Prediction:" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0" + ] + } + ], + "source": [ + "%%bash\n", + "\n", + "./svc 1 2 3 4" + ] } ], "metadata": {