Skip to content

Commit

Permalink
Uploaded experiment1 first version
Browse files Browse the repository at this point in the history
  • Loading branch information
alandiamond committed Apr 29, 2015
1 parent 63364df commit 5b13577
Show file tree
Hide file tree
Showing 14 changed files with 961 additions and 4 deletions.
41 changes: 39 additions & 2 deletions README.md
@@ -1,2 +1,39 @@
# spinnaker-neuromorphic-classifier
# spinnaker-neuromorphic-classifier
This project demonstrates multivariate classification using neuromorphic hardware,
in this case the SpiNNaker hardware platform [1].
The classifier neural model design is based on that published in [2,3] which is a
bio-inspired design based on the insect olfactory system.

The core requirements to run these programs is Python 2.7 and a SpiNNaker board with
the accompanying software suite made available from MAnchester Universtiy;
The work is demonstrated here in a series of Python/PynNN/sPyNNaker experiments of
increasing complexity/difficulty.
In all these experiments, for those unable to run the program themselves, screenshot(s) of the
relevant raster plots are made available in the "screenshots" subdirectory.

EXPERIMENT 1
This experiment demonstrates a basic ability to use synapse plasticity to learn to
classify ("recognise") 10 digits taken from the standard MNIST dataset.

ACKNOWLEDGEMENTS
This work is supported by a grant from the Human Brain Project (HBP).
The SpiNNaker hardware platform is developed at Manchester University who supplied the board and software suite used in this work.

CITING THIS WORK
To cite the work in this project please contact one of the Github collaborators based at the University of Sussex.

REFERENCES
[1] M. M. Khan, D. R. Lester, L. A. Plana, A. Rast, X. Jin, E. Painkras, and
S. B. Furber, “SpiNNaker: Mapping neural networks onto a massively-
parallel chip multiprocessor,” in Proceedings of the International Joint
Conference on Neural Networks, 2008, pp. 2849–2856

[2] M. Schmuker, T. Pfeil, and M. Nawrot, “A neuromorphic network for
generic multivariate data classification,” Proc. Natl. Acad. Sci., pp. 1–6,
Jan. 2014.

[3] A. Diamond, M. Schmuker, A.Z. Berna, S.Trowell and T. Nowotny
"Classifying chemical sensor data using GPU-accelerated bio-mimetic neuronal networks
based on the insect olfactory system", BMC Neuroscience 2014, 15(Suppl 1):P77
doi:10.1186/1471-2202-15-S1-P77


26 changes: 26 additions & 0 deletions README.md~
@@ -0,0 +1,26 @@
This project demonstrates multivariate classification using neuromorphic hardware,
in this case the SpiNNaker hardware platform [1].
The classifier neural model design is based on that published in [2,3] which is a
bio-inspired design based on the insect olfactory system.

The core requirements to run these programs is Python 2.7 and a SpiNNaker board with
the accompanying software suite made available from MAnchester Universtiy;
The work is demonstrated here in a series of Python/PynNN/sPyNNaker experiments of
increasing complexity/difficulty.
In all these experiments, for those unable to run the program themselves, screenshot(s) of the
relevant raster plots are made available in the "screenshots" subdirectory.

EXPERIMENT 1
This experiment demonstrates a basic ability to use synapse plasticity to learn to
classify ("recognise") 10 digits taken from the standard MNIST dataset.

ACKNOWLEDGEMENTS
This work is supported by a grant from the Human Brain Project (HBP).
The SpiNNaker hardware platform is developed at Manchester University who supplied the board and software suite used in this work.

CITING THIS WORK
To cite the work in this project please contact one of the Github collaborators based at the University of Sussex.

REFERENCES


109 changes: 109 additions & 0 deletions experiment1/BuildAndRunClassifier.py
@@ -0,0 +1,109 @@
import matplotlib.pyplot as plt
import Classifier as classifier
import ModellingUtils as utils
import sys
import os.path
import os

params = eval(open("ModelParams-MNISTClassifier.txt").read())
settings = eval(open("Settings-MNISTClassifier.txt").read())

#clear marker file
if utils.fileExists(settings['RUN_COMPLETE_FILE']):
os.remove(settings['RUN_COMPLETE_FILE'])

#Override default params with any passed args
numArgumentsProvided = len(sys.argv) - 1

if numArgumentsProvided >=1 :
settings['LEARNING'] = eval(sys.argv[1])
if numArgumentsProvided >=2 :
params['NUM_VR'] = int(sys.argv[2])
if numArgumentsProvided >=3 :
params['NUM_CLASSES'] = int(sys.argv[3])
if numArgumentsProvided >=4 :
settings['SPIKE_SOURCE_VR_RESPONSE_PATH'] = sys.argv[4]
if numArgumentsProvided >=5 :
settings['SPIKE_SOURCE_ACTIVE_CLASS_PATH'] = sys.argv[5]
if numArgumentsProvided >=6 :
settings['NUM_OBSERVATIONS'] = int(sys.argv[6])
if numArgumentsProvided >=7 :
settings['OBSERVATION_EXPOSURE_TIME_MS'] = int(sys.argv[7])
if numArgumentsProvided >=8 :
settings['CLASS_LABELS_PATH'] = sys.argv[8]
if numArgumentsProvided >=9 :
settings['CLASSIFICATION_RESULTS_PATH'] = sys.argv[8]

classifier.printParameters('Model Parameters',params)
classifier.printParameters('Classifier Settings',settings)

populationsInput = list()
populationsNoiseSource = list()
populationsRN = list()
populationsPN = list()
populationsAN = list()
projectionsPNAN = list() #keep handle to these for saving learnt weights

totalSimulationTime = settings['OBSERVATION_EXPOSURE_TIME_MS'] * settings['NUM_OBSERVATIONS']
print 'Total Simulation Time will be', totalSimulationTime

DT = 1.0 #ms Integration timestep for simulation

classifier.setupModel(settings, params, DT,totalSimulationTime, populationsInput, populationsNoiseSource, populationsRN,populationsPN,populationsAN,projectionsPNAN)

utils.recordPopulations(populationsInput,settings['RECORD_POP_INPUT'])
utils.recordPopulations(populationsNoiseSource,settings['RECORD_POP_NOISE_SOURCE'])
utils.recordPopulations(populationsRN,settings['RECORD_POP_RN'])
utils.recordPopulations(populationsPN,settings['RECORD_POP_PN'])
utils.recordPopulations(populationsAN,settings['RECORD_POP_AN'])

#run the model for the whole learning or the whole testing period
classifier.run(totalSimulationTime)

if settings['DISPLAY_RASTER_PLOT'] or settings['SAVE_RASTER_PLOT_AS_PNG']:
plt.figure()
plt.xlabel('Time/ms')
plt.ylabel('Neurons')
title = 'Testing'
if settings['LEARNING']:
title = 'Training'
title = title + ' - MNIST Classification - ' + str(params['NUM_VR']) + ' Virtual Receptors (VRs)'
plt.title(title)

indexOffset = 0
indexOffset = 1 + utils.plotAllSpikes(populationsInput, totalSimulationTime, indexOffset,settings['RECORD_POP_INPUT'])
indexOffset = 1 + utils.plotAllSpikes(populationsNoiseSource, totalSimulationTime, indexOffset,settings['RECORD_POP_NOISE_SOURCE'])
indexOffset = 1 + utils.plotAllSpikes(populationsRN, totalSimulationTime, indexOffset,settings['RECORD_POP_RN'])
indexOffset = 1 + utils.plotAllSpikes(populationsPN, totalSimulationTime, indexOffset,settings['RECORD_POP_PN'])
indexOffset = 1 + utils.plotAllSpikes(populationsAN, totalSimulationTime, indexOffset,settings['RECORD_POP_AN'])

#if in the learning stage
if settings['LEARNING']:
#store the weight values learnt via plasticity, these will be reloaded as static weights for test stage
classifier.saveLearntWeightsPNAN(settings,params,projectionsPNAN,len(populationsPN),len(populationsAN))
else:
#save the AN layer spike data from the testing run.
#This data will be interrogated to find the winning class (most active AN pop)
#during the presentation of each test observation
#classifier.saveSpikesAN(settings,populationsAN)
winningClassesByObservation = classifier.calculateWinnersAN(settings,populationsAN)
classLabels = utils.loadListFromCsvFile(settings['CLASS_LABELS_PATH'],True)
scorePercent = classifier.calculateScore(winningClassesByObservation,classLabels)
utils.saveListAsCsvFile(winningClassesByObservation,settings['CLASSIFICATION_RESULTS_PATH'])

#make sure spinnaker shut down before blocking figure is put up
classifier.end()

if settings['SAVE_RASTER_PLOT_AS_PNG']:
filename = 'RasterPlot-Testing.png'
if settings['LEARNING']:
filename = 'RasterPlot-Training.png'
plt.savefig(filename)

#write a marker file to allow invoking programs to know that the Python/Pynn run completed
utils.saveListToFile(['Pynn Run complete'],settings['RUN_COMPLETE_FILE'])

if settings['DISPLAY_RASTER_PLOT']:
plt.show()

print 'PyNN run completed.'
10 changes: 10 additions & 0 deletions experiment1/ClassActivation_SpikeSourceData.csv
@@ -0,0 +1,10 @@
1,4,7,10,13,16,19,22,25,28,31,34,37,40,43,46,49,52,55,58,61,64,67,70,73,76,79,82,85,88,91,94,97,100,103,106,109,112,115,118,121,124,127,130,133,136,139
201,204,207,210,213,216,219,222,225,228,231,234,237,240,243,246,249,252,255,258,261,264,267,270,273,276,279,282,285,288,291,294,297,300,303,306,309,312,315,318,321,324,327,330,333,336,339
401,404,407,410,413,416,419,422,425,428,431,434,437,440,443,446,449,452,455,458,461,464,467,470,473,476,479,482,485,488,491,494,497,500,503,506,509,512,515,518,521,524,527,530,533,536,539
601,604,607,610,613,616,619,622,625,628,631,634,637,640,643,646,649,652,655,658,661,664,667,670,673,676,679,682,685,688,691,694,697,700,703,706,709,712,715,718,721,724,727,730,733,736,739
801,804,807,810,813,816,819,822,825,828,831,834,837,840,843,846,849,852,855,858,861,864,867,870,873,876,879,882,885,888,891,894,897,900,903,906,909,912,915,918,921,924,927,930,933,936,939
1001,1004,1007,1010,1013,1016,1019,1022,1025,1028,1031,1034,1037,1040,1043,1046,1049,1052,1055,1058,1061,1064,1067,1070,1073,1076,1079,1082,1085,1088,1091,1094,1097,1100,1103,1106,1109,1112,1115,1118,1121,1124,1127,1130,1133,1136,1139
1201,1204,1207,1210,1213,1216,1219,1222,1225,1228,1231,1234,1237,1240,1243,1246,1249,1252,1255,1258,1261,1264,1267,1270,1273,1276,1279,1282,1285,1288,1291,1294,1297,1300,1303,1306,1309,1312,1315,1318,1321,1324,1327,1330,1333,1336,1339
1401,1404,1407,1410,1413,1416,1419,1422,1425,1428,1431,1434,1437,1440,1443,1446,1449,1452,1455,1458,1461,1464,1467,1470,1473,1476,1479,1482,1485,1488,1491,1494,1497,1500,1503,1506,1509,1512,1515,1518,1521,1524,1527,1530,1533,1536,1539
1601,1604,1607,1610,1613,1616,1619,1622,1625,1628,1631,1634,1637,1640,1643,1646,1649,1652,1655,1658,1661,1664,1667,1670,1673,1676,1679,1682,1685,1688,1691,1694,1697,1700,1703,1706,1709,1712,1715,1718,1721,1724,1727,1730,1733,1736,1739
1801,1804,1807,1810,1813,1816,1819,1822,1825,1828,1831,1834,1837,1840,1843,1846,1849,1852,1855,1858,1861,1864,1867,1870,1873,1876,1879,1882,1885,1888,1891,1894,1897,1900,1903,1906,1909,1912,1915,1918,1921,1924,1927,1930,1933,1936,1939
1 change: 1 addition & 0 deletions experiment1/ClassLabels.csv
@@ -0,0 +1 @@
0,1,2,3,4,5,6,7,8,9

0 comments on commit 5b13577

Please sign in to comment.