#global variables
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-s", "--station", dest="workstation",
                  help="spikey workstation to use", default="station309")
parser.add_option("-n", "--num_data_samples", dest="num_data_samples", type="int",
                  help="number of data samples from each class to use", default=200)

options, args = parser.parse_args()

workstation = options.workstation #default: 'station603'
num_data_samples = options.num_data_samples # default: 200
digits = [5,7]

# imports
import numpy
import pyNN.hardware.stage1 as p
import neuclar.network_controller as netcontrol
from  neuclar.network_config import hardware_sparse_config as config
config['network']['decision_pops'] = '2'
import neuclar.data.mnist as mnist
import neuclar.vrconvert as vrconvert

# doing the stuff
p.setup(workStationName=workstation)

# load data
training_data, training_labels = mnist.get_training_data(digits, num_data_samples)
testing_data, testing_labels = mnist.get_training_data(digits, num_data_samples)

# convert data with VRs
training_data_vr = vrconvert.vrconvert(training_data, vrconvert.mnist_samplepoints)
testing_data_vr = vrconvert.vrconvert(testing_data, vrconvert.mnist_samplepoints)

# make data right format
training_patterns = [("mnist_%d"%i, training_data_vr[i], training_labels[i])
                                             for i in range(len(training_labels))]
testing_patterns = [("mnist_%d"%i, testing_data_vr[i], testing_labels[i])
                                             for i in range(len(testing_labels))]
class_ids = list(set(training_labels))

# set up classifier network
bc = netcontrol.BrainController(p, config)
bc.brain.wire_AL_to_MBext()
bc.brain.reinit_random_weights()

# train the network
for tp in training_patterns:
    bc.learn_pattern(tp, class_ids)
test_results = [bc.test_pattern(tp) for tp in testing_patterns]

# assess percent correct
ind_pred = [numpy.argmax(tr) for tr in test_results]
ind_target = [class_ids.index(l) for l in testing_labels]
correct = [i==il for i,il in zip(ind_pred,ind_target)]

num_correct = sum(correct)
num_total = len(correct)
percent_correct = float(num_correct)/float(num_total)

print "Correctly classified %d out of %d (%.2f correct)"%(num_correct, num_total, percent_correct)
print ""
print "Neuromorphic computing rules."

@@ -368,16 +368,132 @@
 lt=200)%0A
+parser.add_option(%22-d%22, %22--digits%22, dest=%22digits_txt%22, help=%22digits to be used%22,%0A                  default=%225,7%22)%0A%0A%0A
 %0Aoptions
@@ -648,19 +648,61 @@
 gits = %5B
-5,7
+int(x) for x in options.digits_txt.split(',')
 %5D%0A%0A# imp

make digits selectable on the command line.