Esempio n. 1
0
 def test_buffer_standalone_noise_ndarray(self):
     B = Buffer(history=3, rate = 1.0, noise=[10.0, 20.0, 30.0])
     B.execute([1,2,3])
     B.execute([4,5,6])
     B.execute([7,8,9])
     val = B.execute([10,11,12])
     assert np.allclose(deque(np.atleast_1d([ 24., 45., 66.], [ 17., 28., 39.], [10, 11, 12])), val)
Esempio n. 2
0
 def test_buffer_initializer_len_3(self):
     B = Buffer(default_variable=[[0.0], [1.0], [2.0]],
                initializer=[[0.0], [1.0], [2.0]],
                history=3)
     assert np.allclose(B.execute(3.0), deque([[1.0], [2.0], np.array([3.])]))
     assert np.allclose(B.execute(4.0), deque([[2.0], np.array([3.]), np.array([4.])]))
     assert np.allclose(B.execute(5.0), deque([np.array([3.]), np.array([4.]), np.array([5.])]))
Esempio n. 3
0
 def test_buffer_standalone_noise_float(self):
     B = Buffer(history=3, rate = 1.0, noise=10.0)
     B.execute([1,2,3])
     B.execute([4,5,6])
     B.execute([7,8,9])
     val = B.execute([10,11,12])
     assert np.allclose(deque(np.atleast_1d([ 24.,  25.,  26.], [ 17.,  18.,  19.], [10, 11, 12])), val)
Esempio n. 4
0
 def test_buffer_standalone_rate_ndarray(self):
     B = Buffer(history=3, rate = np.array([0.1, 0.5, 0.9]))
     B.execute([1,2,3])
     B.execute([4,5,6])
     B.execute([7,8,9])
     val = B.execute([10,11,12])
     assert np.allclose(deque(np.atleast_1d([ 0.04, 1.25, 4.86], [ 0.7,  4. , 8.1], [10, 11, 12])), val)
Esempio n. 5
0
 def test_buffer_standalone_rate_float(self):
     B = Buffer(history=3, rate = 0.1)
     B.execute([1,2,3])
     B.execute([4,5,6])
     B.execute([7,8,9])
     val = B.execute([10,11,12])
     assert np.allclose(deque(np.atleast_1d([ 0.04,  0.05,  0.06], [ 0.7,  0.8,  0.9], [10, 11, 12])), val)
Esempio n. 6
0
 def test_buffer_standalone_rate_list(self, benchmark):
     B = Buffer(history=3, rate = [0.1, 0.5, 0.9])
     B.execute([1,2,3])
     B.execute([4,5,6])
     B.execute([7,8,9])
     val = B.execute([10,11,12])
     assert np.allclose(deque(np.atleast_1d([ 0.04, 1.25, 4.86], [ 0.7,  4. , 8.1], [10, 11, 12])), val)
     if benchmark.enabled:
         benchmark(B.execute, [1, 2, 3])
Esempio n. 7
0
 def test_buffer_standalone_noise_function(self):
     np.random.seed(22)
     B = Buffer(history=3, rate = 1.0, noise=NormalDist(standard_deviation=0.1))
     B.execute([1,2,3])
     B.execute([4,5,6])
     B.execute([7,8,9])
     val = B.execute([10,11,12])
     assert np.allclose(deque(np.atleast_1d([[ 3.8925223, 5.03957263, 6.00262384],
                                             [ 7.00288551, 7.97692328, 9.05877522],
                                             [10, 11, 12]])), val)
Esempio n. 8
0
 def test_buffer_standalone_noise_function(self, benchmark):
     B = Buffer(history=3, rate = 1.0, noise=NormalDist(standard_deviation=0.1))
     B.execute([1, 2, 3])
     B.execute([4, 5, 6])
     B.execute([7, 8, 9])
     val = B.execute([10,11,12])
     assert np.allclose(deque(np.atleast_1d([[4.02430687, 4.91927251, 5.95087965],
                                             [7.09586966, 7.91823773, 8.86077491],
                                             [10, 11, 12]])), val)
     if benchmark.enabled:
         benchmark(B.execute, [1, 2, 3])
Esempio n. 9
0
 def test_buffer_standalone_noise_function_in_array(self):
     B = Buffer(history=3, noise=[10, NormalDist(standard_deviation=0.1), 20])
     np.random.seed(22)
     B.execute([1,2,3])
     B.execute([4,5,6])
     B.execute([7,8,9])
     val = B.execute([10,11,12])
     expected_val = [[24, 5.0800314416734444, 46], [17, 8.040015720836722, 29], [10, 11, 12]]
     for i in range(len(val)):
         for j in range(len(val[i])):
             assert np.allclose(expected_val[i][j], val[i][j])
Esempio n. 10
0
 def test_buffer_standalone_noise_function_in_array(self, benchmark):
     B = Buffer(history=3)
     # Set noise parameter ouside of a constructor to avoid problems
     # with extra copying
     B.parameters.noise.set([10, NormalDist(standard_deviation=0.1), 20])
     B.execute([1, 2, 3])
     B.execute([4, 5, 6])
     B.execute([7, 8, 9])
     val = B.execute([10, 11, 12])
     expected_val = [[24, 4.693117564500052, 46], [17, 7.744647273059847, 29], [10, 11, 12]]
     for v_v, v_e in zip(val, expected_val):
         for v, e in zip(v_v, v_e):
             assert np.allclose(v, e)
     if benchmark.enabled:
         benchmark(B.execute, [1, 2, 3])
Esempio n. 11
0
    def test_buffer_standalone_noise_function_invocation(self):
        class CallCount:
            def __init__(self):
                self.count = 0
            def __call__(self):
                self.count += 1
                return self.count

        counter_f = CallCount()
        # Set noise parameter ouside of a constructor to avoid problems
        # with extra copying. This test fails if noise is passed to constructor
        B = Buffer(history=3)
        B.parameters.noise.set([10, counter_f, 20])
        B.execute([1, 2, 3])
        B.execute([4, 5, 6])
        B.execute([7, 8, 9])
        val = B.execute([10, 11, 12])

        assert counter_f.count == 4
        expected_val = [[24, 12.0, 46], [17, 12.0, 29], [10, 11, 12]]
        for v_v, v_e in zip(val, expected_val):
            for v, e in zip(v_v, v_e):
                assert np.allclose(v, e)
Esempio n. 12
0
 def test_buffer_standalone(self):
     B = Buffer()
     val = B.execute(1.0)
     assert np.allclose(deque(np.atleast_1d(1.0)), val)