Update sync-notebook
This commit is contained in:
		| @@ -15,6 +15,7 @@ if str(lib_dir) not in sys.path: | ||||
|  | ||||
| from datasets import QuadraticFunc | ||||
| from datasets import ConstantGenerator, SinGenerator | ||||
| from datasets import DynamicQuadraticFunc | ||||
|  | ||||
|  | ||||
| class TestQuadraticFunc(unittest.TestCase): | ||||
| @@ -24,20 +25,20 @@ class TestQuadraticFunc(unittest.TestCase): | ||||
|         function = QuadraticFunc([[0, 1], [0.5, 4], [1, 1]]) | ||||
|         print(function) | ||||
|         for x in (0, 0.5, 1): | ||||
|             print("f({:})={:}".format(x, function[x])) | ||||
|             print("f({:})={:}".format(x, function(x))) | ||||
|         thresh = 0.2 | ||||
|         self.assertTrue(abs(function[0] - 1) < thresh) | ||||
|         self.assertTrue(abs(function[0.5] - 4) < thresh) | ||||
|         self.assertTrue(abs(function[1] - 1) < thresh) | ||||
|         self.assertTrue(abs(function(0) - 1) < thresh) | ||||
|         self.assertTrue(abs(function(0.5) - 4) < thresh) | ||||
|         self.assertTrue(abs(function(1) - 1) < thresh) | ||||
|  | ||||
|     def test_none(self): | ||||
|         function = QuadraticFunc() | ||||
|         function.fit([[0, 1], [0.5, 4], [1, 1]], max_iter=3000, verbose=True) | ||||
|         function.fit([[0, 1], [0.5, 4], [1, 1]], max_iter=3000, verbose=False) | ||||
|         print(function) | ||||
|         thresh = 0.2 | ||||
|         self.assertTrue(abs(function[0] - 1) < thresh) | ||||
|         self.assertTrue(abs(function[0.5] - 4) < thresh) | ||||
|         self.assertTrue(abs(function[1] - 1) < thresh) | ||||
|         thresh = 0.15 | ||||
|         self.assertTrue(abs(function(0) - 1) < thresh) | ||||
|         self.assertTrue(abs(function(0.5) - 4) < thresh) | ||||
|         self.assertTrue(abs(function(1) - 1) < thresh) | ||||
|  | ||||
|  | ||||
| class TestConstantGenerator(unittest.TestCase): | ||||
| @@ -59,3 +60,27 @@ class TestSinGenerator(unittest.TestCase): | ||||
|             assert i == idx, "First loop: {:} vs {:}".format(i, idx) | ||||
|         for i, (idx, t, x) in enumerate(dataset): | ||||
|             assert i == idx, "Second loop: {:} vs {:}".format(i, idx) | ||||
|  | ||||
|  | ||||
| class TestDynamicFunc(unittest.TestCase): | ||||
|     """Test DynamicQuadraticFunc.""" | ||||
|  | ||||
|     def test_simple(self): | ||||
|         timestamps = 30 | ||||
|         function = DynamicQuadraticFunc() | ||||
|         function_param = dict() | ||||
|         function_param[0] = SinGenerator( | ||||
|             num=timestamps, num_sin_phase=4, phase_shift=1.0, max_amplitude=1.0 | ||||
|         ) | ||||
|         function_param[1] = ConstantGenerator(constant=0.9) | ||||
|         function_param[2] = SinGenerator( | ||||
|             num=timestamps, num_sin_phase=5, phase_shift=0.4, max_amplitude=0.9 | ||||
|         ) | ||||
|         function.set(function_param) | ||||
|         print(function) | ||||
|  | ||||
|         with self.assertRaises(TypeError) as context: | ||||
|             function(0) | ||||
|  | ||||
|         function.set_timestamp(1) | ||||
|         print(function(2)) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user