Exemple #1
0
labels = np.unique(test_labels)
n_labels = labels.size

# --- test as ANN
codes = forward(test_images, weights, biases)
inds = np.argmax(np.dot(codes, Wc) + bc, axis=1)
labels = np.unique(test_labels)
errors = (test_labels != labels[inds])
print "ANN error:", errors.mean()

# --- find good neuron params for sigmoid
import find_neuron_params

neuron_params_file = 'neuron_params.npz'
if not os.path.exists(neuron_params_file):
    find_neuron_params.find_params(savefile=neuron_params_file, show=False)

neuron_params = dict(np.load(neuron_params_file))
N = neuron_params.pop('N')

# --- create the model
model = nengo.Network()
with model:
    input_images = nengo.Node(output=get_image, label='images')

    # --- make sigmoidal layers
    layers = []
    output = input_images
    for w, b in zip(weights[:-1], biases[:-1]):
        layer = nengo.networks.EnsembleArray(N, b.size, **neuron_params)
        bias = nengo.Node(output=b)
Exemple #2
0
vocab_codes = np.zeros((len(vocab_labels), train_codes.shape[-1]))
for i, label in enumerate(vocab_labels):
    vocab_codes[i] = train_codes[train_labels.flatten() == label].mean(0)

vocab_codes /= norm(vocab_codes, axis=1, keepdims=True)

# --- ANN accuracy on test set
test_codes = forward(test_images, weights, biases)
ann_labels = np.dot(test_codes, vocab_codes.T)
ann_errors = (np.argmax(ann_labels, axis=1) != test_labels)
print("ANN error: %s" % ann_errors.mean())

# --- find good neuron parameters
neuron_params_file = 'neuron_params.npz'
if not os.path.exists(neuron_params_file):
    find_neuron_params.find_params(savefile=neuron_params_file)

# --- load and format neuron params
neuron_params = dict(np.load(neuron_params_file))
N = neuron_params.pop('N')
neuron_params['radius'] = neuron_params['radius'].item()

# --- create the model
model = nengo.Network()
with model:
    input_images = nengo.Node(output=get_image)

    # --- make sigmoidal layers
    layers = []
    output = input_images
    for w, b in zip(weights[:-1], biases[:-1]):
Exemple #3
0
test_images, test_labels = test

# shuffle
rng = np.random.RandomState(92)
inds = rng.permutation(len(test_images))
test_images = test_images[inds]
test_labels = test_labels[inds]

labels = np.unique(test_labels)
n_labels = labels.size

# --- find good neuron params for sigmoid
neuron_params_file = 'neuron_params.npz'
if not os.path.exists(neuron_params_file):
    find_neuron_params.find_params(savefile=neuron_params_file, show=False)

neuron_params = dict(np.load(neuron_params_file))
N = neuron_params.pop('N')
# neuron_params['radius'] = np.array([1,2])

# --- create the model
model = nengo.Network()
with model:
    input_images = nengo.Node(output=get_image, label='images')

    # --- make sigmoidal layers
    layers = []
    output = input_images
    for w, b in zip(weights[:-1], biases[:-1]):
        layer = nengo.networks.EnsembleArray(N, b.size, **neuron_params)