MCPcopy Create free account
hub / github.com/BindsNET/bindsnet / Monitor

Class Monitor

bindsnet/network/monitors.py:30–130  ·  view source on GitHub ↗

Records state variables of interest.

Source from the content-addressed store, hash-verified

28
29
30class Monitor(AbstractMonitor):
31 # language=rst
32 """
33 Records state variables of interest.
34 """
35
36 def __init__(
37 self,
38 obj: Union[
39 Nodes,
40 AbstractConnection,
41 AbstractMulticompartmentConnection,
42 AbstractFeature,
43 ],
44 state_vars: Iterable[str],
45 time: Optional[int] = None,
46 batch_size: int = 1,
47 device: str = "cpu",
48 sparse: Optional[bool] = False,
49 ):
50 # language=rst
51 """
52 Constructs a ``Monitor`` object.
53
54 :param obj: An object to record state variables from during network simulation.
55 :param state_vars: Iterable of strings indicating names of state variables to record.
56 :param time: If not ``None``, pre-allocate memory for state variable recording.
57 :param device: Allow the monitor to be on different device separate from Network device
58 """
59 super().__init__()
60
61 self.obj = obj
62 self.state_vars = state_vars
63 self.time = time
64 self.batch_size = batch_size
65 self.device = device
66 self.sparse = sparse
67
68 # if time is not specified the monitor variable accumulate the logs
69 if self.time is None:
70 self.device = "cpu"
71
72 self.recording = []
73 self.reset_state_variables()
74
75 def get(self, var: str) -> torch.Tensor:
76 # language=rst
77 """
78 Return recording to user.
79
80 :param var: State variable recording to return.
81 :return: Tensor of shape ``[time, n_1, ..., n_k]``, where ``[n_1, ..., n_k]`` is the shape of the recorded state
82 variable.
83 Note, if time == `None`, get return the logs and empty the monitor variable
84
85 """
86 if self.clean:
87 return_logs = torch.empty(0, device=self.device)

Callers 15

test_add_objectsMethod · 0.90
TestMonitorClass · 0.90
loc1d_mnist.pyFile · 0.90
SOM_LM-SNNs.pyFile · 0.90
conv3d_MNIST.pyFile · 0.90
reservoir.pyFile · 0.90
batch_eth_mnist.pyFile · 0.90
MCC_reservoir.pyFile · 0.90
eth_mnist.pyFile · 0.90
loc2d_mnist.pyFile · 0.90

Calls

no outgoing calls

Tested by 1

test_add_objectsMethod · 0.72