def test_get_latex_result(self): edge_1 = Edge('b', 'a', phase=0.5, attenuation=0.5, delay=2) edge_2 = Edge('c', 'a', phase=-0.5, attenuation=1.5, delay=-1) split_net = self.net 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_latex_result('b'),'1\cdot\exp(j (0.0))\cdot b_{in}(t-0.0)') edge_1 = Edge('a', 'b', phase=1, attenuation=0.4, delay=2) edge_2 = Edge('b', 'c', phase=2, attenuation=0.3, delay=1.2) edge_3 = Edge('c', 'a', phase=3, attenuation=0.2, delay=0) loop_net = Network() loop_net.add_node('a') loop_net.add_node('b') loop_net.add_node('c') loop_net.add_edge(edge_1) loop_net.add_edge(edge_2) loop_net.add_edge(edge_3) loop_net.add_input('a', amplitude=1) loop_net.evaluate(amplitude_cutoff=1e-4) self.assertEqual(loop_net.get_latex_result('b',precision=2),'0.4\cdot\exp(j (1))\cdot a_{in}(t-2)+0.0096\cdot\exp(j (7))\cdot a_{in}(t-5.2)+0.00023\cdot\exp(j (13))\cdot a_{in}(t-8.4)')
# Add nodes net.add_node(name='a') net.add_node(name='b') net.add_node(name='c') net.add_node(name='d') # Add edges net.add_edge(Edge(start='a', end='b', phase=1, attenuation=0.8, delay=1)) net.add_edge(Edge(start='b', end='c', phase=2, attenuation=0.6, delay=2)) net.add_edge(Edge(start='b', end='d', phase=3, attenuation=0.4, delay=3)) # Add input net.add_input(name='a', amplitude=1.0, phase=0) # Visualize the network net.visualize(path='./visualizations/feedforward', format='svg') # Evaluate the network net.evaluate(amplitude_cutoff=1e-3) # Compute output and show results 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')) print('latex string for waves arriving at c:', net.get_latex_result('c')) # render output in a html file net.get_html_result(['c', 'd'], precision=2, path='./visualizations/feedforward.html')
net.add_node(name='b') net.add_node(name='c') net.add_edge(Edge(start='a', end='b', phase=2, attenuation=amp1, delay=1)) net.add_edge(Edge(start='b', end='c', phase=1, attenuation=amp2, delay=2)) net.add_edge( Edge(start='c', end='a', phase=phi3, attenuation=0.5 * amp3, delay=3)) net.add_input('a') net.add_input('b') net.evaluate(amplitude_cutoff=0.001) net.visualize(path='./visualizations/docdemo', format='png') net.visualize(path='./visualizations/docdemo', format='svg') print(net.get_result('b')) print(net.get_latex_result('b', linebreak_limit=1)) net.get_html_result(['c', 'b'], path='./visualizations/docdemo_latex.html') ### Create a testbench with a feed dictionary tb = Testbench(network=net, timestep=0.05, feed_dict={ 'v1': 0.8, 'v2': 0.8, 'v3': 0.9, 'v4': 3 }) x_in_a = np.sin(np.linspace(0, 2 * np.pi, 400)) # create the input signal (Dimensino N) t_in = np.linspace(0, 20, num=401) # create the input time vector (Dimension N+1)