Skip to content

Commit

Permalink
Merge pull request #30 from Saran-nns/freezefix
Browse files Browse the repository at this point in the history
Freeze fix
  • Loading branch information
Saran-nns authored Aug 6, 2021
2 parents d2ff193 + 27e1e12 commit 24da0eb
Show file tree
Hide file tree
Showing 13 changed files with 343 additions and 59 deletions.
142 changes: 142 additions & 0 deletions .ipynb_checkpoints/Untitled-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from sorn import Simulator\n",
"import numpy as np\n",
"\n",
"# Sample input\n",
"num_features = 10\n",
"time_steps = 200\n",
"inputs = np.random.rand(num_features,time_steps)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Network Initialized\n",
"Number of connections in Wee 3894 , Wei 1580, Wie 8000\n",
"Shapes Wee (200, 200) Wei (40, 200) Wie (200, 40)\n"
]
}
],
"source": [
"# To simulate the network;\n",
"matrices_dict, E, I, R, C = Simulator.simulate_sorn(inputs = inputs, phase='plasticity', \n",
" matrices=None, noise = True, \n",
" time_steps=time_steps,\n",
" _ne = 200, _nu=num_features)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"matrices_dict, E, I, R, C = Simulator.simulate_sorn(inputs = inputs, phase='plasticity', \n",
" matrices=matrices_dict, noise= True, \n",
" time_steps=time_steps,_ne = 200, \n",
" _nu=num_features)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"matrices_dict, E, I, R, C = Simulator.simulate_sorn(inputs = inputs, phase='plasticity', \n",
" matrices=matrices_dict, noise= True, \n",
" time_steps=time_steps,_ne = 200, \n",
" _nu=num_features, freeze=['ip'])"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "'dict' object has no attribute 'Wee'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-6-a4c248d62b08>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mmatrices_dict\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mWee\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;31mAttributeError\u001b[0m: 'dict' object has no attribute 'Wee'"
]
}
],
"source": [
"matrices_dict.Wee"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "'MatrixCollection' object has no attribute 'Wee'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-5-ed9a72c6207e>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 4\u001b[0m matrices_dict, E, I, R, C = Trainer.train_sorn(inputs = inputs, phase='Training', \n\u001b[0;32m 5\u001b[0m \u001b[0mmatrices\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mmatrices_dict\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0m_nu\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mnum_features\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 6\u001b[1;33m time_steps=1)\n\u001b[0m",
"\u001b[1;32mN:\\sorn\\sorn\\sorn.py\u001b[0m in \u001b[0;36mtrain_sorn\u001b[1;34m(self, inputs, phase, matrices, time_steps, noise, freeze, **kwargs)\u001b[0m\n\u001b[0;32m 1135\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1136\u001b[0m Wee, Wei, Wie = (\n\u001b[1;32m-> 1137\u001b[1;33m \u001b[0mmatrix_collection\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mWee\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1138\u001b[0m \u001b[0mmatrix_collection\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mWei\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1139\u001b[0m \u001b[0mmatrix_collection\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mWie\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mAttributeError\u001b[0m: 'MatrixCollection' object has no attribute 'Wee'"
]
}
],
"source": [
"from sorn import Trainer\n",
"inputs = np.random.rand(num_features,1)\n",
"\n",
"matrices_dict, E, I, R, C = Trainer.train_sorn(inputs = inputs, phase='training', \n",
" matrices=matrices_dict,_nu=num_features, \n",
" time_steps=1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.10"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ from sorn import Trainer
inputs = np.random.rand(num_features,1)

# SORN network is frozen during training phase
matrices_dict, Exc_activity, Inh_activity, Rec_activity, num_active_connections = Trainer.train_sorn(inputs = inputs, phase='Training', matrices=matrices_dict,_nu=num_features, time_steps=1)
matrices_dict, Exc_activity, Inh_activity, Rec_activity, num_active_connections = Trainer.train_sorn(inputs = inputs, phase='training', matrices=matrices_dict,_nu=num_features, time_steps=1)
```

To turn off any plasticity mechanisms during simulation or training phase, you can use `freeze` argument.
Expand Down
140 changes: 140 additions & 0 deletions Untitled.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from sorn import Simulator\n",
"import numpy as np\n",
"\n",
"# Sample input\n",
"num_features = 10\n",
"time_steps = 200\n",
"inputs = np.random.rand(num_features,time_steps)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Network Initialized\n",
"Number of connections in Wee 3894 , Wei 1580, Wie 8000\n",
"Shapes Wee (200, 200) Wei (40, 200) Wie (200, 40)\n"
]
}
],
"source": [
"# To simulate the network;\n",
"matrices_dict, E, I, R, C = Simulator.simulate_sorn(inputs = inputs, phase='plasticity', \n",
" matrices=None, noise = True, \n",
" time_steps=time_steps,\n",
" _ne = 200, _nu=num_features)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"matrices_dict, E, I, R, C = Simulator.simulate_sorn(inputs = inputs, phase='plasticity', \n",
" matrices=matrices_dict, noise= True, \n",
" time_steps=time_steps,_ne = 200, \n",
" _nu=num_features)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"from sorn import Trainer\n",
"inputs = np.random.rand(num_features,1)\n",
"\n",
"matrices_dict, E, I, R, C = Trainer.train_sorn(inputs = inputs, phase='training', \n",
" matrices=matrices_dict,_nu=num_features, \n",
" time_steps=1)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Network Initialized\n",
"Number of connections in Wee 3891 , Wei 1580, Wie 8000\n",
"Shapes Wee (200, 200) Wei (40, 200) Wie (200, 40)\n"
]
}
],
"source": [
"matrices_dict, E, I, R, C = Simulator.simulate_sorn(inputs = inputs, phase='plasticity', \n",
" matrices=None, noise = True, time_steps=1, \n",
" _ne = 200, _nu=num_features, \n",
" freeze=['ip'])\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Network Initialized\n",
"Number of connections in Wee 3900 , Wei 1582, Wie 8000\n",
"Shapes Wee (200, 200) Wei (40, 200) Wie (200, 40)\n"
]
}
],
"source": [
"matrices_dict, E, I, R, C = Simulator.simulate_sorn(inputs = inputs, phase='plasticity', \n",
" matrices=None, noise = True, time_steps=1, \n",
" _ne = 200, _nu=num_features, \n",
" freeze=['ip','sp','ss'])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.10"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
2 changes: 1 addition & 1 deletion build/lib/sorn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
from .utils import *

__author__ = "Saranraj Nambusubramaniyan"
__version__ = "0.5.1"
__version__ = "0.5.2"

logging.basicConfig(level=logging.INFO)
Loading

0 comments on commit 24da0eb

Please sign in to comment.