def test_update(self): net = WTNetwork([[1, 0], [-1, 1]], [0.5, 0.0]) self.assertEqual(WTNetwork.split_threshold, net.theta) xs = [0, 0] self.assertEqual([0, 0], net.update(xs)) self.assertEqual([0, 0], xs) xs = [1, 0] self.assertEqual([1, 0], net.update(xs)) self.assertEqual([1, 0], xs) xs = [0, 1] self.assertEqual([0, 1], net.update(xs)) self.assertEqual([0, 1], xs) xs = [1, 1] self.assertEqual([1, 1], net.update(xs)) self.assertEqual([1, 1], xs) net.theta = WTNetwork.negative_threshold xs = [0, 0] self.assertEqual([0, 0], net.update(xs)) self.assertEqual([0, 0], xs) xs = [1, 0] self.assertEqual([1, 0], net.update(xs)) self.assertEqual([1, 0], xs) xs = [0, 1] self.assertEqual([0, 1], net.update(xs)) self.assertEqual([0, 1], xs) xs = [1, 1] self.assertEqual([1, 0], net.update(xs)) self.assertEqual([1, 0], xs) net.theta = WTNetwork.positive_threshold xs = [0, 0] self.assertEqual([0, 1], net.update(xs)) self.assertEqual([0, 1], xs) xs = [1, 0] self.assertEqual([1, 0], net.update(xs)) self.assertEqual([1, 0], xs) xs = [0, 1] self.assertEqual([0, 1], net.update(xs)) self.assertEqual([0, 1], xs) xs = [1, 1] self.assertEqual([1, 1], net.update(xs)) self.assertEqual([1, 1], xs)
def test_update_pin(self): net = WTNetwork([[1, 0], [-1, 1]], [0.5, 0.0]) net.theta = WTNetwork.negative_threshold xs = [1, 1] self.assertEqual([1, 0], net.update(xs, pin=[0])) net.theta = WTNetwork.positive_threshold xs = [0, 0] self.assertEqual([0, 0], net.update(xs, pin=[1]))
def test_update_values(self): net = WTNetwork([[1, 0], [-1, 1]], [0.5, 0.0], theta=WTNetwork.negative_threshold) xs = [1, 1] self.assertEqual([1, 1], net.update(xs, values={1: 1})) net.theta = WTNetwork.positive_threshold xs = [0, 0] self.assertEqual([1, 1], net.update(xs, values={0: 1}))