예제 #1
0
def test_learn_bias():
    import time
    import math

    start_time = time.time()
    net = nef.Network('LB test')

    net.make_input('input', values=math.sin)

    make(net, 'learn_bias', neurons=100)

    net.connect('input', 'learn_bias.input')

    in_probe = net.make_probe('input')
    output_probe = net.make_probe('learn_bias.output')

    build_time = time.time()
    print "build time: ", build_time - start_time

    net.run(10)

    print "sim time: ", time.time() - build_time

    import matplotlib.pyplot as plt
    plt.subplot(211)
    plt.title('input')
    plt.plot(in_probe.get_data())
    plt.subplot(212)
    plt.title('output')
    plt.plot(output_probe.get_data())
    plt.tight_layout()
    plt.show()
예제 #2
0
def test_array():

    neurons = 40

    net = nef.Network('Array Test', seed=50)
    net.make_input('in', np.arange(-1, 1, .34), zero_after_time=1.0)
    net.make_array('A', neurons=neurons, array_size=1, dimensions=6)
    net.make('A2', neurons=neurons, array_size=2, dimensions=3)
    net.make('B', neurons=neurons, array_size=3, dimensions=2)
    net.make('B2', neurons=neurons, array_size=6, dimensions=1)

    net.connect('in', 'A')
    net.connect('in', 'A2')
    net.connect('in', 'B')
    net.connect('in', 'B2')
    net.connect('A2', 'B')

    timesteps = 200
    dt_step = 0.01
    t = np.linspace(dt_step, timesteps * dt_step, timesteps)
    pstc = 0.01

    Ip = net.make_probe('in', dt_sample=dt_step, pstc=pstc)
    Ap = net.make_probe('A', dt_sample=dt_step, pstc=pstc)
    A2p = net.make_probe('A2', dt_sample=dt_step, pstc=pstc)
    Bp = net.make_probe('B', dt_sample=dt_step, pstc=pstc)
    B2p = net.make_probe('B2', dt_sample=dt_step, pstc=pstc)

    print "starting simulation"
    net.run(timesteps * dt_step)

    # plot the results
    plt.ioff()
    plt.close()
    plt.subplot(5, 1, 1)
    plt.ylim([-1.5, 1.5])
    plt.plot(t, Ip.get_data(), 'x')
    plt.title('Input')
    plt.subplot(5, 1, 2)
    plt.ylim([-1.5, 1.5])
    plt.plot(Ap.get_data())
    plt.title('A, array_size=1, dim=6')
    plt.subplot(5, 1, 3)
    plt.ylim([-1.5, 1.5])
    plt.plot(A2p.get_data())
    plt.title('A2, array_size=2, dim=3')
    plt.subplot(5, 1, 4)
    plt.ylim([-1.5, 1.5])
    plt.plot(Bp.get_data())
    plt.title('B, array_size=3, dim=2')
    plt.subplot(5, 1, 5)
    plt.ylim([-1.5, 1.5])
    plt.plot(B2p.get_data())
    plt.title('B2, array_size=6, dim=1')
    plt.tight_layout()
    plt.show()
예제 #3
0
def test_gate():
    import numpy as np
    import matplotlib.pyplot as plt
    import math

    import nengo_theano as nef

    net = nef.Network('Gate Test')
    net.make_input('in1', values=.5)
    net.make_input('in2', values=math.sin)

    net.make('A', neurons=300, dimensions=1)

    make(net=net, name='gate', gated='A', neurons=100, pstc=.01)

    net.connect('in1', 'A', pstc=1e-6)
    net.connect('in2', 'gate', pstc=1e-6)

    timesteps = 1000
    dt_step = 0.01
    t = np.linspace(dt_step, timesteps * dt_step, timesteps)
    pstc = 0.01

    I1p = net.make_probe('in1', dt_sample=dt_step, pstc=pstc)
    I2p = net.make_probe('in2', dt_sample=dt_step, pstc=pstc)
    gate_probe = net.make_probe('A', dt_sample=dt_step, pstc=pstc)
    gated_probe1 = net.make_probe('gate', dt_sample=dt_step, pstc=pstc)
    gated_probe2 = net.make_probe('gate:addOne', dt_sample=dt_step, pstc=pstc)

    print "starting simulation"
    net.run(timesteps * dt_step)

    # plot the results
    plt.ioff()
    plt.close()
    plt.subplot(3, 1, 1)
    plt.title('Input')
    plt.plot(t, I1p.get_data(), 'x')
    plt.plot(t, I2p.get_data(), 'x')
    plt.subplot(3, 1, 2)
    plt.plot(gate_probe.get_data())
    plt.title('A')
    plt.subplot(3, 1, 3)
    plt.title('Gate')
    plt.plot(gated_probe1.get_data())
    plt.plot(gated_probe2.get_data())
    plt.tight_layout()
    plt.show()
예제 #4
0
def test_cleanup():
    raise nose.SkipTest()

    net = nef.Network('Cleanup', seed=3)

    D = 128
    M = 50000
    N1 = 100
    N2 = 50
    index = 0

    def make_vector():
        v = np.random.normal(size=(D, ))

        norm = np.linalg.norm(v)
        v = v / norm
        return v

    print 'making words...'
    words = [make_vector() for i in range(M)]
    words = np.array(words)
    print '...done'

    net.make_array('A', N1, D)
    net.make_array('B', N1, D)

    net.make_array('C', N2, M)  #,intercept=(0.6,0.9))
    print 'made'

    net.connect('A', 'C', words.T, pstc=0.1)
    net.connect('C', 'B', words, pstc=0.1)

    net.make_input('input', words[index])
    net.connect('input', 'A', pstc=0.1)

    net.run(0.001)

    import time
    start = time.time()

    for i in range(5000):
        #print i,net.ensemble['A'].origin['X'].value.get_value()
        print i, words[index, :4],
        print net.nodes['C'].accumulator[0.1].projected_value.get_value()[:4]

        net.run(0.001)
        print(time.time() - start) / (i + 1)
예제 #5
0
def test_abs_val():

    net = nef.Network('Abs val test')

    import numpy as np
    input = np.array([-.2, .5, -.8])
    net.make_input('input', values=input)

    make_abs_val(net, 'abs_val', neurons=50, dimensions=3, intercept=(.2, 1))

    net.connect('input', 'abs_val.input')

    im_probe = net.make_probe('abs_val.input')
    av0_pos_probe = net.make_probe('abs_val.abs_pos0')
    av0_neg_probe = net.make_probe('abs_val.abs_neg0')
    av1_pos_probe = net.make_probe('abs_val.abs_pos1')
    av1_neg_probe = net.make_probe('abs_val.abs_neg1')
    av2_pos_probe = net.make_probe('abs_val.abs_pos2')
    av2_neg_probe = net.make_probe('abs_val.abs_neg2')
    av_probe = net.make_probe('abs_val.output')

    net.run(1)

    import matplotlib.pyplot as plt
    a = 'input = ', input
    plt.subplot(411)
    plt.title(a)
    plt.plot(im_probe.get_data())
    plt.subplot(412)
    plt.title('abs_val_neg')
    plt.plot(av0_pos_probe.get_data())
    plt.plot(av1_pos_probe.get_data())
    plt.plot(av2_pos_probe.get_data())
    plt.legend(['input0', 'input1', 'input2'])
    plt.subplot(413)
    plt.title('abs_val_neg')
    plt.plot(av0_neg_probe.get_data())
    plt.plot(av1_neg_probe.get_data())
    plt.plot(av2_neg_probe.get_data())
    plt.legend(['input0', 'input1', 'input2'])
    input[np.abs(input) <= .2] = 0
    b = 'answer = ', np.abs(input)
    plt.subplot(414)
    plt.title(b)
    plt.plot(av_probe.get_data())
    plt.tight_layout()
    plt.show()
예제 #6
0
def test_thalamus():
    import numpy as np
    import matplotlib.pyplot as plt
    import math

    import nengo_theano as nef

    net = nef.Network('Thalamus Test')

    def func(x):
        return [abs(math.sin(x)), .5, 0]

    net.make_input('in', values=func)
    make(net=net, name='Thalamus', neurons=300, dimensions=3, inhib_scale=3)

    net.connect('in', 'Thalamus.input', pstc=1e-6)

    timesteps = 1000
    dt_step = 0.01
    t = np.linspace(dt_step, timesteps * dt_step, timesteps)
    pstc = 0.01

    Ip = net.make_probe('in', dt_sample=dt_step, pstc=pstc)
    Thp = net.make_probe('Thalamus.Thalamus:addOne',
                         dt_sample=dt_step,
                         pstc=pstc)
    Thp2 = net.make_probe('Thalamus.Thalamus', dt_sample=dt_step, pstc=pstc)

    print "starting simulation"
    net.run(timesteps * dt_step)

    # plot the results
    plt.ioff()
    plt.close()
    plt.subplot(3, 1, 1)
    plt.plot(t, Ip.get_data(), 'x')
    plt.title('Input')
    plt.subplot(3, 1, 2)
    plt.plot(Thp.get_data())
    plt.title('Thalamus.output')
    plt.subplot(3, 1, 3)
    plt.plot(Thp2.get_data())
    plt.title('Thalamus.output')
    plt.tight_layout()
    plt.show()
예제 #7
0
def test_TRN():
    import time

    start_time = time.time()
    net = nef.Network('TRN test')
 
    def cx_func(x):
        return [math.sin(x), -math.sin(x), math.cos(x)]

    net.make_input('input_cortex', values=[.2, .5, -.3])
    net.make_input('input_thalamus', values=[.5,.6,1])
    net.make_input('input_error', values=[0, 0])

    make(net, 'TRN', neurons=100, dimensions=3, 
        dim_fb_err=2) #, mode='direct')

    net.connect('input_cortex', 
                'TRN.input_cortex')
    net.connect('input_thalamus', 
                'TRN.input_thalamus')#, weight=2)
    net.connect('input_error', 
                'TRN.input_error')

    output_probe = net.make_probe('TRN.output')
    avout_probe = net.make_probe('TRN.abs_val_deriv.output')
    int_probe = net.make_probe('TRN.integrator')

    build_time = time.time()
    print "build time: ", build_time - start_time

    net.run(1)

    print "sim time: ", time.time() - build_time

    import matplotlib.pyplot as plt
    plt.subplot(311); plt.title('output')
    plt.plot(output_probe.get_data())
    plt.subplot(312); plt.title('TRN abs val output')
    plt.plot(avout_probe.get_data()); plt.ylim([-1,1])
    plt.subplot(313); plt.title('TRN integrator')
    plt.plot(int_probe.get_data())
    plt.tight_layout()
    plt.show()
예제 #8
0
def test_basalganglia():
    import numpy as np
    import matplotlib.pyplot as plt
    import math

    import nengo_theano as nef
    from .. import templates

    net = nef.Network('BG Test')

    def func(x):
        return [math.sin(x), .5, .2]

    net.make_input('in', value=func)
    templates.basalganglia.make(net=net, name='BG', neurons=300, dimensions=3)

    net.connect('in', 'BG.input', pstc=.01)

    timesteps = 1000
    dt_step = 0.01
    t = np.linspace(dt_step, timesteps * dt_step, timesteps)
    pstc = 0.01

    Ip = net.make_probe('in', dt_sample=dt_step, pstc=pstc)
    BGp = net.make_probe('BG.output', dt_sample=dt_step, pstc=pstc)

    print "starting simulation"
    net.run(timesteps * dt_step)

    # plot the results
    plt.ioff()
    plt.close()
    plt.subplot(2, 1, 1)
    plt.plot(t, Ip.get_data(), 'x')
    plt.title('Input')
    plt.subplot(2, 1, 2)
    plt.plot(BGp.get_data())
    plt.title('BG.output')
    plt.tight_layout()
    plt.show()
예제 #9
0
def test_dot():

    net = nef.Network('Dot product test')

    import numpy as np
    matrix = np.array([[.1, .2], [.3, .4], [.5, .6]])
    vector = np.array([.4, .5])
    net.make_input('input_matrix', values=matrix.flatten())
    net.make_input('input_vector', values=vector)

    make(net,
         'dot_product',
         neurons=1,
         dimensions1=3,
         dimensions2=2,
         mode='direct')

    net.connect('input_matrix', 'dot_product.input_matrix')
    net.connect('input_vector', 'dot_product.input_vector')

    im_probe = net.make_probe('dot_product.input_matrix')
    iv_probe = net.make_probe('dot_product.input_vector')
    row_probe = net.make_probe('dot_product.row_mult0')
    dot_probe = net.make_probe('dot_product.output')

    net.run(1)

    import matplotlib.pyplot as plt
    plt.subplot(311)
    plt.title('matrix input')
    plt.plot(im_probe.get_data())
    plt.subplot(312)
    plt.title('vector input')
    plt.plot(iv_probe.get_data())
    a = 'answer: ', np.dot(matrix, vector)
    plt.subplot(313)
    plt.title(a)
    plt.plot(dot_probe.get_data())
    plt.tight_layout()
    plt.show()
예제 #10
0
def test_cortical_action():

    net = nef.Network('Cortical action test')

    import numpy as np
    input = np.array([-.2, .5, -.8])
    action_vals = np.array([-.4, .35, .78])

    net.make_input('input', values=input)

    make(net, 'ca0', neurons=200, dimensions=3, 
        action_vals=action_vals) #, mode='direct')
    ca1_a_vals = make(net, 'ca1', neurons=100, 
        dimensions=3, mode='direct')

    net.connect('input', 'ca0.input')
    net.connect('input', 'ca1.input')

    im_probe = net.make_probe('input')
    ca0_probe = net.make_probe('ca0.output')
    ca1_probe = net.make_probe('ca1.output')

    net.run(1)

    import matplotlib.pyplot as plt
    a = 'input = ', input
    plt.subplot(311); plt.title(a)
    plt.plot(im_probe.get_data())
    b = 'answer = ', input * action_vals
    plt.subplot(312); plt.title(b)
    plt.plot(ca0_probe.get_data())
    c = 'answer = ', input * ca1_a_vals 
    plt.subplot(313); plt.title(c)
    plt.plot(ca1_probe.get_data())
    plt.tight_layout()
    plt.show()
#======================
N1 = 100 # number of neurons
d1 = 1 # number of actions 
d2 = 1 # number of dimensions in each primitive
d3 = d2 # number of dimensions in the goal / actual states 
inhib_scale = 10 # weighting on inhibitory matrix
tau_inhib=0.005 # pstc for inhibitory connection

testing = 1 # set testing = True
N2 = N1; mode = 'spiking'
if (testing): N2 = 1; mode = 'direct'

# Create the network object
#======================
start_time = time.time()
net = nef.Network('Actor Explorer') 

# Create function input
#======================
# default competitor value found from trial and error
net.make_input('default_competitor', values=[1.5]) 

class TrainingInput(nef.SimpleNode):
    def init(self):
        self.input_vals = arange(-1, 1, .2)
        self.period_length = 2
        self.choose_time = 0.0
    def origin_ILinput(self):
        if (self.t >= self.choose_time):
            self.index = random.randint(0,9) # choose an input randomly from the set
            if (self.index < 5): # specify the correct response for this input
  3. connect with T = (array_size * neurons x array_size x neurons)
  4. connect with T = (array_size x neurons x array_size x neurons)
"""

import math
import numpy as np
import matplotlib.pyplot as plt

import nengo_theano as nef

neurons = 100
dimensions = 1
array_size = 3
inhib_scale = 10

net = nef.Network('WeightMatrix Test')
net.make_input('in1', math.sin, zero_after_time=2.5)
net.make('A', neurons=neurons, dimensions=dimensions, intercept=(.1, 1))
net.make('B', neurons=neurons, dimensions=dimensions)  # for test 1
net.make('B2', neurons=neurons, dimensions=dimensions,
         array_size=array_size)  # for test 2
net.make('B3', neurons=neurons, dimensions=dimensions,
         array_size=array_size)  # for test 3
net.make('B4', neurons=neurons, dimensions=dimensions,
         array_size=array_size)  # for test 4

# setup inhibitory scaling matrix
weight_matrix_1 = [[1] * neurons * 1] * neurons * 1  # for test 1
weight_matrix_2 = [[[1] * neurons] * 1] * neurons * array_size  # for test 1
weight_matrix_3 = [[[1] * neurons * 1] * neurons] * array_size  # for test 3
weight_matrix_4 = [[[[1] * neurons] * 1] * neurons] * array_size  # for test 4
예제 #13
0
"""This is a test file to test the SimpleNode object"""

import math
import random

import numpy as np
import matplotlib.pyplot as plt

import nengo_theano as nef

net = nef.Network('SimpleNode Test')


class TrainingInput(nef.simplenode.SimpleNode):
    def init(self):
        self.input_vals = np.arange(-1, 1, .2)
        self.period_length = 2
        self.choose_time = 0.0

    def origin_test1(self):
        if (self.t >= self.choose_time):
            # choose an input randomly from the set
            self.index = random.randint(0, 9)
            if (self.index < 5):
                # specify the correct response for this input
                self.correct_response = [.5]
            else:
                self.correct_response = [-.5]

            # update the time to next change the input again
            self.choose_time = self.t + self.period_length
예제 #14
0
"""This is a test file to test the func parameter on the connect method"""

import math
import matplotlib.pyplot as plt
import numpy as np
import time

import nengo_theano as nef

start_time = time.time()

net = nef.Network('Function Test')
net.make_input('in', values=math.sin)
net.make('A', neurons=250, dimensions=1)
net.make('B', neurons=250, dimensions=3)


# function example for testing
def square(x):
    return [-x[0] * x[0], -x[0], x[0]]


net.connect('in', 'A')
net.connect('A', 'B', func=square, pstc=0.1)

timesteps = 500
dt_step = 0.01
t = np.linspace(dt_step, timesteps * dt_step, timesteps)
pstc = 0.03

Ip = net.make_probe('in', dt_sample=dt_step, pstc=pstc)
예제 #15
0
"""This test file is for checking the run time of the theano code."""

import math
import time

import nengo_theano as nef

net = nef.Network('Runtime Test', seed=123)
net.make_input('in', value=math.sin)
net.make('A', 1000, 1)
net.make('B', 1000, 1)
net.make('C', 1000, 1)
net.make('D', 1000, 1)


# some functions to use in our network
def pow(x):
    return [xval**2 for xval in x]


def mult(x):
    return [xval * 2 for xval in x]


net.connect('in', 'A')
net.connect('A', 'B')
net.connect('A', 'C', func=pow)
net.connect('A', 'D', func=mult)
net.connect('D', 'B', func=pow)  # throw in some recurrency whynot

start_time = time.time()
예제 #16
0
"""This is a file to test the encoders parameter on ensembles"""

import math
import time

import numpy as np
import matplotlib.pyplot as plt

import nengo_theano as nef

build_time_start = time.time()

timesteps = 10000
dt_step = 0.001

net = nef.Network('Encoder Test', dt=dt_step)
net.make_input('in1', math.sin)
net.make_input('in2', math.cos)
net.make('A', 100, 1)
net.make('B', 100, 1, encoders=[[1]], intercept=(0, 1.0))
net.make('C', 100, 2, radius=1.5)
net.make('D',
         100,
         2,
         encoders=[[1, 1], [1, -1], [-1, -1], [-1, 1]],
         radius=1.5)
net.make('outputC', 1, 1, mode='direct')
net.make('outputD', 1, 1, mode='direct')

net.connect('in1', 'A')
net.connect('A', 'B')
예제 #17
0
"""This is a test file to test the transform parameter on the connect function.
The transform matrix is post * pre dimensions"""

import math

import numpy as np
import matplotlib.pyplot as plt

import nengo_theano as nef


def func(x):
    return [math.sin(x), -math.sin(x)]


net = nef.Network('Transform Test')
net.make_input('in', value=func)
net.make('A', neurons=300, dimensions=3)
net.make('B', neurons=300, array_size=3, dimensions=1)

# define our transform and connect up!
transform = [[0, 1], [1, 0], [1, -1]]
net.connect('in', 'A', transform=transform)
net.connect('in', 'B', transform=transform)

timesteps = 500
dt_step = 0.01
t = np.linspace(dt_step, timesteps * dt_step, timesteps)
pstc = 0.01
Ip = net.make_probe('in', dt_sample=dt_step, pstc=pstc)
Ap = net.make_probe('A', dt_sample=dt_step, pstc=pstc)
예제 #18
0
"""Test of Network.make_subnetwork(), which should allow for easy nesting of
collections of ensembles.
"""

import numpy as np
import matplotlib.pyplot as plt

import nengo_theano as nef

net=nef.Network('Main')

netA=net.make_subnetwork('A')
netB=net.make_subnetwork('B')

net.make('X',50,1)
netA.make('Y',50,1)
netB.make('Z',50,1)
netB.make('W',50,1)

netB.connect('Z','W')     # connection within a subnetwork
net.connect('X','A.Y')    # connection into a subnetwork
net.connect('A.Y','X')    # connection out of a subnetwork
net.connect('A.Y','B.Z')  # connection across subnetworks

netC=netA.make_subnetwork('C')
netC.make('I',50,1)
netC.make('J',50,1)
netC.connect('I','J')       # connection within a subsubnetwork
net.connect('X','A.C.I')    # connection into a subsubnetwork
net.connect('A.C.J','X')    # connection out of a subsubnetwork
net.connect('A.C.J','B.Z')  # connection across subsubnetworks
예제 #19
0
"""This is a file to test the net.write_to_file method
"""

import numpy as np
import matplotlib.pyplot as plt
import math
import time
from neo import hdf5io

import nengo_theano as nef

build_time_start = time.time()

net = nef.Network('Write Out Test')
net.make_input('in', math.sin)
net.make('A', 50, 1)
net.make('B', 5, 1)

net.connect('in', 'A')
net.connect('in', 'B')

timesteps = 100
dt_step = 0.01
t = np.linspace(dt_step, timesteps * dt_step, timesteps)
pstc = 0.01

Ip = net.make_probe('in', dt_sample=dt_step, pstc=pstc)
Ap = net.make_probe('A', dt_sample=dt_step, pstc=pstc)
Bp = net.make_probe('B', dt_sample=dt_step)
BpSpikes = net.make_probe('B', data_type='spikes', dt_sample=dt_step)
예제 #20
0
파일: sequence.py 프로젝트: tcstewar/spa
    def rule2():
        condition(state='B')
        effect(state='C')

    def rule3():
        condition(state='C')
        effect(state='A')


class Sequence(spa.SPA):
    vocab = spa.Vocabulary(8)

    state = spa.Buffer()

    bg = spa.BasalGanglia(Rules)
    thal = spa.Thalamus(bg)

    input = spa.Input(0.1, state='A')


net = nef.Network('Sequence')
model = Sequence(net)

pThal = net.make_probe('thal.rule', dt_sample=0.001, pstc=0.005)

net.run(1)

import matplotlib.pyplot as plt
plt.plot(pThal.get_data())
plt.show()
예제 #21
0
"""This is a test file to test the weight, index_pre, and index_post parameters
on the connect function. 
"""

import math

import numpy as np
import matplotlib.pyplot as plt

import nengo_theano as nef

net = nef.Network('Weight, Index_Pre, and Index_Post Test')
net.make_input('in', value=math.sin)
net.make('A', 300, 1)
net.make('B', 300, 1)
net.make('C', 400, 2)
net.make('D', 800, 3)
net.make('E', 400, 2)
net.make('F', 400, 2)

net.connect('in', 'A', weight=.5)
net.connect('A', 'B', weight=2)
net.connect('A', 'C', index_post=1)
net.connect('A', 'D')
net.connect('C', 'E', index_pre=1)
net.connect('C', 'F', index_pre=1, index_post=0)

timesteps = 500
dt_step = 0.01
t = np.linspace(dt_step, timesteps*dt_step, timesteps)
pstc = 0.01
예제 #22
0
5. creating network array w/ multi-dimensional eval_points

"""

import math

import numpy as np
import matplotlib.pyplot as plt

import nengo_theano as nef

# create the list of evaluation points
eval_points1 = np.arange(-1, 0, .5)
eval_points2 = np.array([[1, 1], [-1, 1], [-1, -1], [1, -1]]).T

net = nef.Network('EvalPoints Test')
net.make_input('in', value=math.sin)

# for test 1
net.make('A1', neurons=300, dimensions=1)
# for test 2
net.make('A2', neurons=300, dimensions=1, eval_points=eval_points1)
# for test 3
net.make('A3', neurons=300, dimensions=1, eval_points=eval_points1)
# for test 4
net.make('A4',
         neurons=300,
         array_size=3,
         dimensions=2,
         eval_points=eval_points2)
예제 #23
0
"""This is a test file to test basic learning
"""

import math
import time

import numpy as np
import matplotlib.pyplot as plt

import nengo_theano as nef

neurons = 30  # number of neurons in all ensembles

start_time = time.time()
net = nef.Network('Learning Test')

import random


class TrainingInput(nef.SimpleNode):
    def init(self):
        self.input_vals = np.arange(-1, 1, .2)
        self.period_length = 10
        self.choose_time = 0.0

    def origin_ILinput(self):
        if (self.t >= self.choose_time):
            # choose an input randomly from the set
            self.index = random.randint(0, 9)
            # specify the correct response for this input
            if (self.index < 5): self.correct_response = [.6]
예제 #24
0
"""This is a test file to test the noise parameter on ensemble"""

import math

import numpy as np
import matplotlib.pyplot as plt

import nengo_theano as nef

net = nef.Network('Noise Test')
net.make_input('in', value=math.sin)
net.make('A', neurons=300, dimensions=1, noise=1)
net.make('A2', neurons=300, dimensions=1, noise=100)
net.make('B', neurons=300, dimensions=2, noise=1000, noise_type='Gaussian')
net.make('C', neurons=100, dimensions=1, array_size=3, noise=10)

net.connect('in', 'A')
net.connect('in', 'A2')
net.connect('in', 'B')
net.connect('in', 'C')

timesteps = 500
dt_step = 0.01
t = np.linspace(dt_step, timesteps * dt_step, timesteps)
pstc = 0.01

Ip = net.make_probe('in', dt_sample=dt_step, pstc=pstc)
Ap = net.make_probe('A', dt_sample=dt_step, pstc=pstc)
A2p = net.make_probe('A2', dt_sample=dt_step, pstc=pstc)
Bp = net.make_probe('B', dt_sample=dt_step, pstc=pstc)
Cp = net.make_probe('C', dt_sample=dt_step, pstc=pstc)
예제 #25
0
"""This is a file to test the fixed_seed parameter, which should make 
identical ensembles.

"""

import numpy as np
import matplotlib.pyplot as plt

import nengo_theano as nef

net = nef.Network('Array Test', fixed_seed=5)
net.make_input('in', [1], zero_after_time=1.0)
net.make('A', 50, 1)
net.make('B', 50, 1)
net.make_array('AB', 50, 2)

net.connect('in', 'A')
net.connect('in', 'B')
net.connect('in', 'AB', index_post=[0, 1])

timesteps = 200
dt_step = 0.01
t = np.linspace(dt_step, timesteps * dt_step, timesteps)
pstc = 0.01

Ip = net.make_probe('in', dt_sample=dt_step, pstc=pstc)
Ap = net.make_probe('A', dt_sample=dt_step, pstc=pstc)
Bp = net.make_probe('B', dt_sample=dt_step, pstc=pstc)
ABp = net.make_probe('AB', dt_sample=dt_step, pstc=pstc)

print "starting simulation"
예제 #26
0
            else:
                row2 = np.array([np.zeros(dimensions), row.imag])
        M.extend(row2)
    return M


def circconv(a, b):
    return np.fft.ifft(np.fft.fft(a) * np.fft.fft(b)).real


D = 16
subD = 8
N = 50
N_C = 200

net = nef.Network('Main', fixed_seed=1)

A = np.random.randn(D)
A /= np.linalg.norm(A)

B = np.random.randn(D)
B /= np.linalg.norm(B)

net.make_input('inA', A)
net.make_input('inB', B)

net.make_array('A', N * subD, D / subD, dimensions=subD)
net.make_array('B', N * subD, D / subD, dimensions=subD)
net.make_array('D', N * subD, D / subD, dimensions=subD)

net.make_array('C',
예제 #27
0
import nengo_theano as nef

net = nef.Network('Scrap')

import math
net.make_input('input', value=1, zero_after_time=5)  #math.sin)
net.make_input('input2', value=1)  #math.sin)

net.make('pop', neurons=100, dimensions=1, intercept=[.05, 1])
net.make('pop2', neurons=100, dimensions=1)

inhib_matrix = [[-1]] * 100

net.connect('input', 'pop')
net.connect('input2', 'pop2')
net.connect('pop', 'pop2', transform=inhib_matrix, pstc=1)

im_probe = net.make_probe('input')
pop_probe = net.make_probe('pop')
pop2_probe = net.make_probe('pop2')

net.run(18)

import matplotlib.pyplot as plt
plt.plot(im_probe.get_data())
plt.plot(pop_probe.get_data())
plt.plot(pop2_probe.get_data())
plt.legend(['input', 'pop', 'pop2'])
plt.tight_layout()
plt.show()
예제 #28
0
"""This is a file to test the direct mode on ensembles"""

import math
import time

import numpy as np
import matplotlib.pyplot as plt

import nengo_theano as nef

build_time_start = time.time()

net = nef.Network('Direct Mode Test')
net.make_input('in', math.sin)
net.make('A', 100, 1)
net.make('B', 1, 1, mode='direct')
net.make('C', 100, 1)
net.make('D', 1, 2, mode='direct')
net.make('E', 1, array_size=2, dimensions=2, mode='direct')

net.connect('in', 'A')
net.connect('A', 'B')
net.connect('B', 'C')
net.connect('B', 'E')
def prod(x): return x[0] * x[1]
net.connect('E', 'D', func=prod)

timesteps = 1000
dt_step = 0.0001

t = np.linspace(dt_step, timesteps*dt_step, timesteps)
예제 #29
0
"""This is a file to create and test the basal ganglia template.
"""

import numpy as np
import matplotlib.pyplot as plt
import math

import nengo_theano as nef
from .. import templates

net = nef.Network('BG Test')


def func(x):
    return [math.sin(x), .5, .2]


net.make_input('in', values=func)
templates.basalganglia.make(net=net, name='BG', dimensions=3)

net.connect('in', 'BG.input')

timesteps = 1000
dt_step = 0.01
t = np.linspace(dt_step, timesteps * dt_step, timesteps)
pstc = 0.01

Ip = net.make_probe('in', dt_sample=dt_step, pstc=pstc)
BGp = net.make_probe('BG.output', dt_sample=dt_step, pstc=pstc)

print "starting simulation"
예제 #30
0
def test_probe(simcls=None, show=False):

    build_time_start = time.time()

    net = nef.Network('Probe Test')
    net.make_input('in', math.sin)
    net.make('A', 50, 1)
    net.make('B', 5, 1)

    net.connect('in', 'A')
    net.connect('in', 'B')

    timesteps = 100
    dt_step = 0.01
    t = np.linspace(dt_step, timesteps*dt_step, timesteps)
    pstc = 0.01

    Ip = net.make_probe('in', dt_sample=dt_step, pstc=pstc)
    Ap = net.make_probe('A', dt_sample=dt_step, pstc=pstc)
    Bp = net.make_probe('B', dt_sample=dt_step)
    BpSpikes = net.make_probe('B', data_type='spikes', dt_sample=dt_step)

    build_time_end = time.time()

    print "Starting simulation"
    if simcls is None:
        net.run(timesteps * dt_step)
    else:
        sim = simcls(net)
        sim.run(timesteps * dt_step)

    sim_time_end = time.time()
    print "\nBuild time: %0.10fs" % (build_time_end - build_time_start)
    print "Sim time: %0.10fs" % (sim_time_end - build_time_end)

    assert Ip.get_data().shape == (100, 1), Ip.get_data().shape
    assert Ap.get_data().shape == (100, 1)
    assert Bp.get_data().shape == (100, 1)
    assert BpSpikes.get_data().shape == (100, 1, 5)

    ip_mse = np.mean((Ip.get_data() - np.sin(t)) ** 2)
    print 'Ip MSE', ip_mse
    assert ip_mse < 0.15  # getting .124 May 9 2013

    ap_mse = np.mean((Ap.get_data() - np.sin(t)) ** 2)
    print 'Ap MSE', ap_mse
    assert ap_mse < 0.15  # getting .127 May 9 2013

    plt.ioff(); plt.close(); 
    plt.subplot(3,1,1)
    plt.plot(Ip.get_data(), 'x'); plt.title('Input')
    plt.plot(np.sin(t))
    plt.subplot(3,1,2)
    plt.plot(Ap.get_data()); plt.title('A')
    plt.plot(np.sin(t))
    plt.subplot(3,1,3); plt.hold(1)
    plt.plot(Bp.get_data())
    for row in BpSpikes.get_data().T: 
        plt.plot(row[0]); 
    plt.title('B')
    if show:
        plt.show()
    else:
        plt.close()