Beispiel #1
0
 def test_recurrent_mech_inputs_mismatched_with_default_shorter(self):
     with pytest.raises(MechanismError) as error_text:
         K = KWTA(
             name='K',
             size=6
         )
         K.execute([1, 2, 3, 4, 5])
     assert("does not match required length" in str(error_text.value))
Beispiel #2
0
 def test_kwta_inputs_list_of_strings(self):
     with pytest.raises(KWTAError) as error_text:
         K = KWTA(
             name='K',
             size = 4,
         )
         K.execute(["one", "two", "three", "four"])
     assert("which is not supported for KWTA" in str(error_text.value))
Beispiel #3
0
 def test_kwta_inputs_list_of_ints(self):
     K = KWTA(
         name='K',
         default_variable=[0, 0, 0, 0]
     )
     val = K.execute([10, 12, 0, -1])
     assert(np.allclose(val, [[0.9933071490757153, 0.9990889488055994, 0.0066928509242848554, 0.0024726231566347743]]))
     val = K.execute([1, 2, 3, 0])
     assert(np.allclose(val, [[0.3775406687981454, 0.6224593312018546, 0.8175744761936437, 0.18242552380635635]]))
Beispiel #4
0
 def test_kwta_function_various_spec(self):
     specs = [Logistic, Linear, Linear(slope=3), Logistic(gain=2, offset=-4.2)]
     for s in specs:
         K = KWTA(
             name='K',
             size=5,
             function=s,
             k_value=4
         )
         K.execute([1, 2, 5, -2, .3])
Beispiel #5
0
 def test_kwta_no_inputs(self):
     K = KWTA(
         name='K'
     )
     assert(K.instance_defaults.variable == [[0]])
     val = K.execute([10])
     assert(np.allclose(val, [[0.5]]))
Beispiel #6
0
 def test_kwta_log_gain_offset(self):
     K = KWTA(
         name='K',
         size=2,
         function=Logistic(gain=-.2, offset=4),
         k_value=1
     )
     val = K.execute(input = [.1, -4])
     assert np.allclose(val, [[0.017636340339722684, 0.039165722796764356]])
Beispiel #7
0
 def test_kwta_log_offset(self):
     K = KWTA(
         name='K',
         size=3,
         function=Logistic(offset=-.2),
         k_value=2
     )
     val = K.execute(input=[1, 2, 3])
     assert np.allclose(val, [[0.425557483188341, 0.6681877721681662, 0.84553473491646523]])
Beispiel #8
0
 def test_kwta_log_gain(self):
     K = KWTA(
         name='K',
         size=3,
         function=Logistic(gain=2),
         k_value=2
     )
     val = K.execute(input = [1, 2, 3])
     assert np.allclose(val, [[0.2689414213699951, 0.7310585786300049, 0.9525741268224334]])
Beispiel #9
0
 def test_kwta_linear_slope(self):
     K = KWTA(
         name='K',
         threshold=.5,
         size=5,
         k_value=2,
         function=Linear(slope=2)
     )
     val = K.execute(input=[1, 3, 4, 2, 1])
     assert np.allclose(val, [[-2, 2, 4, 0, -2]])
Beispiel #10
0
 def test_kwta_linear(self): # inhibition would be positive: so instead it is set to zero
     K = KWTA(
         name='K',
         threshold=3,
         size=3,
         k_value=2,
         function=Linear
     )
     val = K.execute(input=[1, 3, 4])
     assert np.allclose(val, [[1, 3, 4]])
Beispiel #11
0
    def test_kwta_matrix_keyword_spec(self):

        for m in MATRIX_KEYWORD_VALUES:
            if m != RANDOM_CONNECTIVITY_MATRIX:
                K = KWTA(
                    name='K',
                    size=4,
                    matrix=m
                )
                val = K.execute([10, 10, 10, 10])
                assert(np.allclose(val, [[.5, .5, .5, .5]]))