示例#1
0
文件: group.py 项目: imclab/dana
 def test_1(self):
     G = Group(5, 'V = I; I')
     Z = np.ones(5)
     DenseConnection(Z, G('I'), 1)
     DenseConnection(Z, G('I'), 2)
     G.run()
     assert np_equal(3 * np.ones(5), G('V'))
示例#2
0
 def test_2(self):
     kernel = np.ones(3) * np.NaN
     C = DenseConnection(np.ones(3),
                         np.ones(3),
                         kernel,
                         equation='dW/dt = 1')
     C.evaluate(dt=.1)
     assert np_equal(C.weights, np.zeros((3, 3)))
示例#3
0
 def test_1(self):
     kernel = np.ones(1)
     C = DenseConnection(np.ones(3),
                         np.ones(3),
                         kernel,
                         equation='dW/dt = 1')
     C.evaluate(dt=.1)
     assert np_equal(C.weights, np.identity(3) * 1.1)
示例#4
0
文件: learning.py 项目: B-Rich/dana
 def test_3(self):
     kernel = np.ones(3)
     kernel[1] = np.NaN
     C = DenseConnection(np.ones(3), np.ones(3), kernel,
                         equation = 'dW/dt = 1')
     C.evaluate(dt=.1)
     assert np_equal(C.weights, np.array([[0,1,0],
                                          [1,0,1],
                                          [0,1,0]])*1.1)
示例#5
0
 def test_3(self):
     kernel = np.ones(3)
     kernel[1] = np.NaN
     C = DenseConnection(np.ones(3),
                         np.ones(3),
                         kernel,
                         equation='dW/dt = 1')
     C.evaluate(dt=.1)
     assert np_equal(C.weights,
                     np.array([[0, 1, 0], [1, 0, 1], [0, 1, 0]]) * 1.1)
示例#6
0
 def test_4(self):
     src = np.ones((3, ))
     dst = zeros((3, ), 'V=I; I')
     kernel = np.ones(1)
     C = DenseConnection(src, dst('I'), kernel, equation='dW/dt = post.I')
     dst.run(dt=0.1)
     assert np_equal(C.weights, np.identity(3) * 1.1)
示例#7
0
 def test_5(self):
     n = 10
     Z = np.random.random(n)
     K = np.random.random(n)
     Z1 = DenseConnection(Z,Z,K,toric=True).output()
     Z2 = SharedConnection(Z,Z,K,toric=True,fft=False).output()
     Z3 = SharedConnection(Z,Z,K,toric=True,fft=True).output()
     Z4 = convolve(Z, K[::-1], mode='wrap')
     assert np_equal(Z1,Z4)
     assert np_equal(Z2,Z4)
     assert np_equal(Z3,Z4)
示例#8
0
 def test_7(self):
     n = 9
     Z = np.random.random(n)
     K = np.random.random(n//2)
     Z1 = DenseConnection(Z,Z,K,toric=False).output()
     Z2 = SharedConnection(Z,Z,K,toric=False,fft=False).output()
     Z3 = SharedConnection(Z,Z,K,toric=False,fft=True).output()
     Z4 = convolve(Z, K[::-1], mode='constant')
     assert np_equal(Z1,Z4)
     assert np_equal(Z2,Z4)
     assert np_equal(Z3,Z4)
示例#9
0
 def test_12(self):
     n = 10
     Z = np.random.random((n,n))
     K = np.random.random((2*n,2*n))
     Z1 = DenseConnection(Z,Z,K,toric=False).output()
     Z2 = SparseConnection(Z,Z,K,toric=False).output()
     Z3 = SharedConnection(Z,Z,K,toric=False,fft=False).output()
     Z4 = SharedConnection(Z,Z,K,toric=False,fft=True).output()
     Z5 = convolve(Z, K[::-1,::-1], mode='constant')
     assert np_equal(Z1,Z5)
     assert np_equal(Z2,Z5)
     assert np_equal(Z3,Z5)
     assert np_equal(Z4,Z5)
示例#10
0
 def test_1(self):
     n = 9
     Z = np.random.random((n,n))
     K = np.random.random((n//2,n//2))
     Z1 = DenseConnection(Z,Z,K,toric=True).output()
     Z2 = SparseConnection(Z,Z,K,toric=True).output()
     Z3 = SharedConnection(Z,Z,K,toric=True,fft=False).output()
     Z4 = SharedConnection(Z,Z,K,toric=True,fft=True).output()
     Z5 = convolve(Z, K[::-1,::-1], mode='wrap')
     assert np_equal(Z1,Z5)
     assert np_equal(Z2,Z5)
     assert np_equal(Z3,Z5)
     assert np_equal(Z4,Z5)
示例#11
0
 def test_6(self):
     n = 10
     Z = np.random.random((n,n))
     K = np.random.random((2*n,2*n))
     Z1 = DenseConnection(Z,Z,K,toric=True).output()
     Z2 = SparseConnection(Z,Z,K,toric=True).output()
     Z3 = SharedConnection(Z,Z,K,toric=True,fft=False).output()
     Z4 = SharedConnection(Z,Z,K,toric=True,fft=True).output()
     K_ = K[5:15,5:15]
     Z5 = convolve(Z, K_[::-1,::-1], mode='wrap')
     assert np_equal(Z1,Z5)
     assert np_equal(Z2,Z5)
     assert np_equal(Z3,Z5)
     assert np_equal(Z4,Z5)
示例#12
0
    def test_3(self):
        net = Network(Clock(0.0, 1.0, 0.001))
        src = Group((1, ), 'dV/dt=1')
        src[...] = 1
        dst = Group((1, ), 'I')
        dst[...] = 0
        kernel = np.ones(1)
        C = DenseConnection(src('V'), dst('I'), kernel)
        net.append(src)
        net.append(dst)
        V, I = [], []

        @net.clock.every(0.1, order=-1)
        def do(t):
            V.append(src['V'][0])
            I.append(dst['I'][0])

        net.run(time=1.0, dt=0.1)
        assert np_equal(
            np.array(V),
            [1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0])
        assert np_equal(
            np.array(I),
            [0.0, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9])
示例#13
0
文件: learning.py 项目: B-Rich/dana
 def test_2(self):
     kernel = np.ones(3)*np.NaN
     C = DenseConnection(np.ones(3), np.ones(3), kernel,
                          equation = 'dW/dt = 1')
     C.evaluate(dt=.1)
     assert np_equal(C.weights, np.zeros((3,3)))
示例#14
0
文件: learning.py 项目: B-Rich/dana
 def test_1(self):
     kernel = np.ones(1)
     C = DenseConnection(np.ones(3), np.ones(3), kernel,
                          equation = 'dW/dt = 1')
     C.evaluate(dt=.1)
     assert np_equal(C.weights, np.identity(3)*1.1)