Exemplo n.º 1
0
 def test_correct_example_update_works(self):
     # test two networks with different thresholds
     ntwk = DiscreteTimeSquareLattice(
         shape=(5, 8),
         activation_strength=2,
         inactivation_strength=-2,
         threshold=1.5,
         steepness=1000,
         weight_type='nearest_neighbor_diagonal',
     )
     
     ntwk.vs_matrix = np.array([
         [0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 2, 1, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0],
     ])
     
     correct_next_vs_matrix = np.array([
         [0, 0, 0, 0, 0, 0, 0, 0],
         [0, 2, 2, 2, 0, 0, 0, 0],
         [0, 2, 1,-2, 0, 0, 0, 0],
         [0, 2, 2, 2, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0],
     ])
     
     ntwk.step()
     np.testing.assert_array_equal(ntwk.vs_matrix, correct_next_vs_matrix)
     
     # second network to test
     ntwk = DiscreteTimeSquareLattice(
         shape=(5, 8),
         activation_strength=2,
         inactivation_strength=-2,
         threshold=2.5,
         steepness=1000,
         weight_type='nearest_neighbor_diagonal',
     )
     
     ntwk.vs_matrix = np.array([
         [0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 2, 1, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0],
     ])
     
     correct_next_vs_matrix = np.array([
         [0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 2, 2, 0, 0, 0, 0],
         [0, 0, 1,-2, 0, 0, 0, 0],
         [0, 0, 2, 2, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0],
     ])
     
     ntwk.step()
     np.testing.assert_array_equal(ntwk.vs_matrix, correct_next_vs_matrix)
Exemplo n.º 2
0
 def test_make_weight_matrix_makes_correct_weight_matrices(self):
     # we'll try out a 4 x 5 lattice for the nearest neighbor setting
     # [x x x x x]
     # [x x x x x]
     # [x x x x x]
     # [x x x x x]
     # to vectorize the lattice we read left to right, top to bottom
     correct_matrix = np.array([
       # 00 01 02 03 04   10 11 12 13 14   20 21 22 23 24  30 31 32 33 34
        [0, 1, 0, 0, 0,   1, 1, 0, 0, 0,   0, 0, 0, 0, 0,  0, 0, 0, 0, 0,],  # 00
        [1, 0, 1, 0, 0,   1, 1, 1, 0, 0,   0, 0, 0, 0, 0,  0, 0, 0, 0, 0,],  # 01
        [0, 1, 0, 1, 0,   0, 1, 1, 1, 0,   0, 0, 0, 0, 0,  0, 0, 0, 0, 0,],  # 02
        [0, 0, 1, 0, 1,   0, 0, 1, 1, 1,   0, 0, 0, 0, 0,  0, 0, 0, 0, 0,],  # 03
        [0, 0, 0, 1, 0,   0, 0, 0, 1, 1,   0, 0, 0, 0, 0,  0, 0, 0, 0, 0,],  # 04
             
        [1, 1, 0, 0, 0,   0, 1, 0, 0, 0,   1, 1, 0, 0, 0,  0, 0, 0, 0, 0,],  # 10
        [1, 1, 1, 0, 0,   1, 0, 1, 0, 0,   1, 1, 1, 0, 0,  0, 0, 0, 0, 0,],  # 11
        [0, 1, 1, 1, 0,   0, 1, 0, 1, 0,   0, 1, 1, 1, 0,  0, 0, 0, 0, 0,],  # 12
        [0, 0, 1, 1, 1,   0, 0, 1, 0, 1,   0, 0, 1, 1, 1,  0, 0, 0, 0, 0,],  # 13
        [0, 0, 0, 1, 1,   0, 0, 0, 1, 0,   0, 0, 0, 1, 1,  0, 0, 0, 0, 0,],  # 14
             
        [0, 0, 0, 0, 0,   1, 1, 0, 0, 0,   0, 1, 0, 0, 0,  1, 1, 0, 0, 0,],  # 20
        [0, 0, 0, 0, 0,   1, 1, 1, 0, 0,   1, 0, 1, 0, 0,  1, 1, 1, 0, 0,],  # 21
        [0, 0, 0, 0, 0,   0, 1, 1, 1, 0,   0, 1, 0, 1, 0,  0, 1, 1, 1, 0,],  # 22
        [0, 0, 0, 0, 0,   0, 0, 1, 1, 1,   0, 0, 1, 0, 1,  0, 0, 1, 1, 1,],  # 23
        [0, 0, 0, 0, 0,   0, 0, 0, 1, 1,   0, 0, 0, 1, 0,  0, 0, 0, 1, 1,],  # 24
             
        [0, 0, 0, 0, 0,   0, 0, 0, 0, 0,   1, 1, 0, 0, 0,  0, 1, 0, 0, 0,],  # 30
        [0, 0, 0, 0, 0,   0, 0, 0, 0, 0,   1, 1, 1, 0, 0,  1, 0, 1, 0, 0,],  # 31
        [0, 0, 0, 0, 0,   0, 0, 0, 0, 0,   0, 1, 1, 1, 0,  0, 1, 0, 1, 0,],  # 32
        [0, 0, 0, 0, 0,   0, 0, 0, 0, 0,   0, 0, 1, 1, 1,  0, 0, 1, 0, 1,],  # 33
        [0, 0, 0, 0, 0,   0, 0, 0, 0, 0,   0, 0, 0, 1, 1,  0, 0, 0, 1, 0,],  # 34
     ], dtype=float)
     shape = (4, 5)
     weight_type = 'nearest_neighbor_diagonal'
     
     np.testing.assert_array_equal(DiscreteTimeSquareLattice.make_weight_matrix(shape, weight_type), correct_matrix)