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

Method test_weights

test/network/test_connections.py:73–164  ·  view source on GitHub ↗
(self, conn_type, shape_a, shape_b, shape_w, *args, **kwargs)

Source from the content-addressed store, hash-verified

71 assert d == torch.device("cuda:0")
72
73 def test_weights(self, conn_type, shape_a, shape_b, shape_w, *args, **kwargs):
74 print("Testing:", conn_type)
75 time = 100
76 weights = [None, torch.Tensor(*shape_w)]
77 wmins = [
78 -np.inf,
79 0,
80 torch.zeros(*shape_w),
81 torch.zeros(*shape_w).masked_fill(
82 torch.bernoulli(torch.rand(*shape_w)) == 1, -np.inf
83 ),
84 ]
85 wmaxes = [
86 np.inf,
87 0,
88 torch.ones(*shape_w),
89 torch.randn(*shape_w).masked_fill(
90 torch.bernoulli(torch.rand(*shape_w)) == 1, np.inf
91 ),
92 ]
93 update_rule = kwargs.get("update_rule", None)
94 for w in weights:
95 for wmin in wmins:
96 for wmax in wmaxes:
97 ### Conditional checks ###
98 # WeightDependentPostPre does not handle infinite ranges
99 if (
100 (torch.tensor(wmin, dtype=torch.float32) == -np.inf).any()
101 or (torch.tensor(wmax, dtype=torch.float32) == np.inf).any()
102 ) and update_rule == WeightDependentPostPre:
103 continue
104
105 # Rmax only supported for Connection & LocalConnection
106 elif (
107 not (conn_type == Connection or conn_type == LocalConnection)
108 and update_rule == Rmax
109 ):
110 return
111
112 # SparseConnection isn't supported for wmin\\wmax
113 elif (conn_type == SparseConnection) and not (
114 (torch.tensor(wmin, dtype=torch.float32) == -np.inf).all()
115 and (torch.tensor(wmax, dtype=torch.float32) == np.inf).all()
116 ):
117 continue
118
119 print(
120 f"- w: {type(w).__name__}, "
121 f"wmin: {type(wmax).__name__}, wmax: {type(wmax).__name__}"
122 )
123 if kwargs.get("update_rule") == Rmax:
124 l_a = SRM0Nodes(
125 shape=shape_a, traces=True, traces_additive=True
126 )
127 l_b = SRM0Nodes(
128 shape=shape_b, traces=True, traces_additive=True
129 )
130 else:

Callers 1

Calls 9

add_layerMethod · 0.95
add_connectionMethod · 0.95
runMethod · 0.95
SRM0NodesClass · 0.90
LIFNodesClass · 0.90
NetworkClass · 0.90
InputClass · 0.90
ConnectionClass · 0.85
getMethod · 0.45

Tested by

no test coverage detected