Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

Commit

Permalink
update code to work with python3
Browse files Browse the repository at this point in the history
  • Loading branch information
spencebeecher committed Mar 18, 2017
1 parent ef74076 commit 1f976fa
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 124 deletions.
72 changes: 47 additions & 25 deletions examples/dense_matrix.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"outputs": [],
"source": [
"# make sure you run 'python setup.py install' first!\n",
"import pysparnn\n",
"import pysparnn.cluster_index as ci\n",
"import pysparnn.matrix_distance"
]
},
Expand All @@ -63,7 +63,7 @@
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": true
"collapsed": false
},
"outputs": [],
"source": [
Expand Down Expand Up @@ -94,25 +94,47 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/spencebeecher/anaconda2/lib/python2.7/site-packages/pysparnn/matrix_distance.py:189: RuntimeWarning: divide by zero encountered in true_divide\n",
" magnitude = 1.0 / (a_root_sum_square * self.matrix_root_sum_square)\n"
]
}
],
"source": [
"cp = pysparnn.MultiClusterIndex(train_features, data_to_return)"
"cp = ci.MultiClusterIndex(train_features, data_to_return)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/spencebeecher/anaconda2/lib/python2.7/site-packages/pysparnn/matrix_distance.py:334: RuntimeWarning: divide by zero encountered in true_divide\n",
" magnitude = 1.0 / (a_root_sum_square * self.matrix_root_sum_square)\n",
"/Users/spencebeecher/anaconda2/lib/python2.7/site-packages/pysparnn/matrix_distance.py:336: RuntimeWarning: invalid value encountered in multiply\n",
" return 1 - (dprod * magnitude)\n",
"/Users/spencebeecher/anaconda2/lib/python2.7/site-packages/pysparnn/matrix_distance.py:108: RuntimeWarning: invalid value encountered in less_equal\n",
" dist_filter = (dist_matrix <= max_distance)\n"
]
}
],
"source": [
"dense_cp = pysparnn.MultiClusterIndex(train_features, data_to_return, \n",
" distance_type=pysparnn.matrix_distance.DenseCosineDistance)"
"dense_cp = ci.MultiClusterIndex(train_features, data_to_return, \n",
" distance_type=pysparnn.matrix_distance.DenseCosineDistance)"
]
},
{
Expand All @@ -124,7 +146,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 8,
"metadata": {
"collapsed": false
},
Expand All @@ -135,7 +157,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 9,
"metadata": {
"collapsed": true
},
Expand All @@ -160,7 +182,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 13,
"metadata": {
"collapsed": false
},
Expand All @@ -169,7 +191,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Percent of time sparse returns a top 3 result: 0.2384\n"
"Percent of time sparse returns a top 3 result: 0.2498\n"
]
}
],
Expand All @@ -178,14 +200,14 @@
"\n",
"results = cp.search(test_features, return_distance=False)\n",
"\n",
"print('Percent of time sparse returns a top 3 result:', pysparnn_utils.recall(answers, results).mean())\n",
"print('Percent of time sparse returns a top 3 result: {}'.format(pysparnn_utils.recall(answers, results).mean()))\n",
"\n",
"cp_time = time.time() - t0"
]
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 14,
"metadata": {
"collapsed": false
},
Expand All @@ -194,7 +216,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Percent of time dense returns a top 3 result: 0.2318\n"
"Percent of time dense returns a top 3 result: 0.2458\n"
]
}
],
Expand All @@ -203,25 +225,25 @@
"\n",
"results = dense_cp.search(test_features, return_distance=False)\n",
"\n",
"print('Percent of time dense returns a top 3 result:', pysparnn_utils.recall(answers, results).mean())\n",
"print('Percent of time dense returns a top 3 result: {}'.format(pysparnn_utils.recall(answers, results).mean()))\n",
"\n",
"dense_cp_time = time.time() - t0"
]
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 15,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"4.370408034254829"
"4.979948311566905"
]
},
"execution_count": 13,
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -242,21 +264,21 @@
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 2",
"language": "python",
"name": "python3"
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.0"
"pygments_lexer": "ipython2",
"version": "2.7.12"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 1f976fa

Please sign in to comment.