Skip to content

Commit

Permalink
Add prediction in the used programming language
Browse files Browse the repository at this point in the history
  • Loading branch information
Darius Morawiec committed Dec 4, 2017
1 parent 65439b9 commit 68879fc
Show file tree
Hide file tree
Showing 9 changed files with 1,027 additions and 505 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)"
]
},
{
Expand All @@ -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": [
{
Expand All @@ -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"
]
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -143,18 +143,94 @@
" 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",
"output = porter.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('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": {
Expand Down
Loading

0 comments on commit 68879fc

Please sign in to comment.