Testing Monitor object.
| 7 | |
| 8 | |
| 9 | class TestMonitor: |
| 10 | """ |
| 11 | Testing Monitor object. |
| 12 | """ |
| 13 | |
| 14 | network = Network() |
| 15 | |
| 16 | inpt = Input(75) |
| 17 | network.add_layer(inpt, name="X") |
| 18 | _if = IFNodes(25) |
| 19 | network.add_layer(_if, name="Y") |
| 20 | conn = Connection(inpt, _if, w=torch.rand(inpt.n, _if.n)) |
| 21 | network.add_connection(conn, source="X", target="Y") |
| 22 | |
| 23 | inpt_mon = Monitor(inpt, state_vars=["s"]) |
| 24 | network.add_monitor(inpt_mon, name="X") |
| 25 | _if_mon = Monitor(_if, state_vars=["s", "v"]) |
| 26 | network.add_monitor(_if_mon, name="Y") |
| 27 | |
| 28 | network.run(inputs={"X": torch.bernoulli(torch.rand(100, inpt.n))}, time=100) |
| 29 | |
| 30 | assert inpt_mon.get("s").size() == torch.Size([100, 1, inpt.n]) |
| 31 | assert _if_mon.get("s").size() == torch.Size([100, 1, _if.n]) |
| 32 | assert _if_mon.get("v").size() == torch.Size([100, 1, _if.n]) |
| 33 | |
| 34 | del network.monitors["X"], network.monitors["Y"] |
| 35 | |
| 36 | inpt_mon = Monitor(inpt, state_vars=["s"], time=500) |
| 37 | network.add_monitor(inpt_mon, name="X") |
| 38 | _if_mon = Monitor(_if, state_vars=["s", "v"], time=500) |
| 39 | network.add_monitor(_if_mon, name="Y") |
| 40 | |
| 41 | network.run(inputs={"X": torch.bernoulli(torch.rand(500, inpt.n))}, time=500) |
| 42 | |
| 43 | assert inpt_mon.get("s").size() == torch.Size([500, 1, inpt.n]) |
| 44 | assert _if_mon.get("s").size() == torch.Size([500, 1, _if.n]) |
| 45 | assert _if_mon.get("v").size() == torch.Size([500, 1, _if.n]) |
| 46 | |
| 47 | |
| 48 | class TestNetworkMonitor: |
no test coverage detected