def test_get_eval_result(self): """ creates and evaluates a feed forward combiner """ edge_1 = Edge('b', 'a', phase=SymNum('phi1',default=0.5,product=False), attenuation=0.5, delay=2) edge_2 = Edge('c', 'a', phase=SymNum('phi2',default=0.0,product=False), attenuation=SymNum('amp2',default=1.5,product=True), delay=-1) split_net = Network() split_net.add_node('a') split_net.add_node('b') split_net.add_node('c') split_net.add_edge(edge_1) split_net.add_edge(edge_2) split_net.add_input('b', amplitude=1) split_net.add_input('c', amplitude=1) split_net.evaluate() self.assertEqual(split_net.get_eval_result('a'), [(0.5, 0.5, 2.0), (1.5, 0.0, -1.0)]) self.assertEqual(split_net.get_eval_result('a',feed_dict=None, use_shared_default=True), [(0.5, 0.5, 2.0), (1.5, 0.0, -1.0)]) self.assertEqual(split_net.get_eval_result('a',feed_dict={'phi1':0.6,'phi2':3,'amp2':6}, use_shared_default=True), [(0.5, 0.6, 2.0), (6.0, 3.0, -1.0)])
# print('paths leading to c:', net.get_paths('c')) # print('paths leading to d:', net.get_paths('d')) print('waves arriving at c:', net.get_result('c')) print('waves arriving at d:', net.get_result('d')) net.get_html_result(['c', 'd'], path='./visualizations/symbolicfeedforward.html') # Evaluation without feed dictionary, using the default value of each SymNum waves = [ tuple([ w.eval(feed_dict=None, use_shared_default=False) if hasattr(w, 'eval') else w for w in inner ]) for inner in net.get_result('c') ] print('Waves arriving at c:', waves, '\n') print(net.get_eval_result(name='c', feed_dict=None, use_shared_default=False)) # Evaluation without feed dictionary, with global defaults waves = [ tuple([ w.eval(feed_dict=None, use_shared_default=True) if hasattr(w, 'eval') else w for w in inner ]) for inner in net.get_result('c') ] print('Waves arriving at c:', waves, '\n') print(net.get_eval_result(name='c', feed_dict=None, use_shared_default=True)) # Evaluation with a feed dictionary feed = {'a1': 1, 'a2': 2, 'phi1': 2, 'phi2': 4} waves = [ tuple([