In [17]:
%matplotlib inline
import pylab
import numpy as np

In [94]:
import adapt_fixed_small
reload(adapt_fixed_small)

n_inputs = 1
n_outputs = 1
n_neurons = 256
seed = 3
stim = lambda i: [np.sin(i*2*np.pi/1000)]

adapt = adapt_fixed_small.AdaptiveFixed(n_inputs=n_inputs, 
                                        input_bits=8,
                                        state_bits=8,
                                        extra_bits=4,
                                        decoder_offset=4,
                                        learning_rate=1e-2,
                                        n_outputs=n_outputs, n_neurons=n_neurons, 
                                        seed=seed, smoothing=10)

inputs = []
outputs = []
errors = []
error = np.zeros(1)
for i in range(2000):
    input = np.array(stim(i))*adapt.input_max
    output = adapt.step(input, error)
    error[:] = output - input
    inputs.append(input)
    outputs.append(output)
    errors.append(output-input)

pylab.figure()
pylab.plot(inputs, label='input')
pylab.plot(outputs, label='output')
pylab.plot(errors, label='error')
pylab.legend(loc='best')
pylab.show()



In [93]:
adapt.decoder


Out[93]:
array([[ 33,   0, -34,   0,  26, -57, -12,  35,   2,   4, -19,   0,   0,
          9,  36,  15, -17, -33,  10, -52,  10,   1,  15,  -8,  34,  -2,
          2,  -5,   0,  21,   0,   0, -15, -14,  44,   8,   5,  -4, -21,
         38,   4,  32,   3,  -1,   0, -40, -32,  -8,  13,  -9, -14,   5,
        -23, -30,   2,  33, -52,  30, -47, -46,   4,  28, -34, -10,   0,
        -34,   0, -16,   0,  -6,  -8, -53,   0,  -2, -45,  15,   0,  38,
          1,  24,  63,  -1,  30,  -1, -17,   0,  15,   8, -51, -23,  24,
          0,  -1, -53,  -4, -24,  27,  13, -29,  15, -11,   5, -33,   0,
          7,   3, -10,   0, -67,  -8,  -4, -42, -33, -32,  22, -21, -47,
        -17,   9,   3,   5,  23,  -2, -35,   5,  -2,  16,   0, -29,   0,
          0,  -5, -24, -44,   0,   8, -23,   4,  17, -14,  47,  -3, -58,
        -25,  -3,  21,  -5, -14,  20, -37,   1, -51,   3,   0,   0, -11,
         62, -15,   4,  -4, -53,  10,  30, -54, -16, -13,   0,  17,  36,
          3, -56,   9,  44, -13, -23, -17,   0,   0,  14,   3, -57, -19,
         24,   0,  -8,  18,  -3,   0, -20,  -1,  14,   0,   0,  10,  20,
         25, -11,  36,  49,  15,  24,   0,  30, -25,  36,  -1,  36,   0,
        -31,   9,  11,  -8,  32,   0,  10,  11, -33,  -3,   0, -29, -73,
         11,   6,  13, -18,  17, -35, -43,  13,  63,  62, -37, -46, -25,
        -20,   0, -31, -27,   1,  14,  -1, -32,  -9,  13,  17,  15,   0,
         20,   8,   1,   0, -16, -42,   0, -37, -34]])

In [ ]: