evonet 0.1.0.dev11__tar.gz → 0.1.0.dev13__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {evonet-0.1.0.dev11 → evonet-0.1.0.dev13}/PKG-INFO +1 -1
- {evonet-0.1.0.dev11 → evonet-0.1.0.dev13}/evonet/core.py +4 -4
- {evonet-0.1.0.dev11 → evonet-0.1.0.dev13}/evonet/mutation.py +32 -9
- {evonet-0.1.0.dev11 → evonet-0.1.0.dev13}/evonet.egg-info/PKG-INFO +1 -1
- {evonet-0.1.0.dev11 → evonet-0.1.0.dev13}/pyproject.toml +1 -1
- {evonet-0.1.0.dev11 → evonet-0.1.0.dev13}/LICENSE +0 -0
- {evonet-0.1.0.dev11 → evonet-0.1.0.dev13}/README.md +0 -0
- {evonet-0.1.0.dev11 → evonet-0.1.0.dev13}/evonet/__init__.py +0 -0
- {evonet-0.1.0.dev11 → evonet-0.1.0.dev13}/evonet/activation.py +0 -0
- {evonet-0.1.0.dev11 → evonet-0.1.0.dev13}/evonet/connection.py +0 -0
- {evonet-0.1.0.dev11 → evonet-0.1.0.dev13}/evonet/core_mit_plot_simple.py +0 -0
- {evonet-0.1.0.dev11 → evonet-0.1.0.dev13}/evonet/enums.py +0 -0
- {evonet-0.1.0.dev11 → evonet-0.1.0.dev13}/evonet/io.py +0 -0
- {evonet-0.1.0.dev11 → evonet-0.1.0.dev13}/evonet/layer.py +0 -0
- {evonet-0.1.0.dev11 → evonet-0.1.0.dev13}/evonet/neuron.py +0 -0
- {evonet-0.1.0.dev11 → evonet-0.1.0.dev13}/evonet/serialization.py +0 -0
- {evonet-0.1.0.dev11 → evonet-0.1.0.dev13}/evonet/utils.py +0 -0
- {evonet-0.1.0.dev11 → evonet-0.1.0.dev13}/evonet/visualize.py +0 -0
- {evonet-0.1.0.dev11 → evonet-0.1.0.dev13}/evonet.egg-info/SOURCES.txt +0 -0
- {evonet-0.1.0.dev11 → evonet-0.1.0.dev13}/evonet.egg-info/dependency_links.txt +0 -0
- {evonet-0.1.0.dev11 → evonet-0.1.0.dev13}/evonet.egg-info/requires.txt +0 -0
- {evonet-0.1.0.dev11 → evonet-0.1.0.dev13}/evonet.egg-info/top_level.txt +0 -0
- {evonet-0.1.0.dev11 → evonet-0.1.0.dev13}/setup.cfg +0 -0
- {evonet-0.1.0.dev11 → evonet-0.1.0.dev13}/tests/test_activation.py +0 -0
- {evonet-0.1.0.dev11 → evonet-0.1.0.dev13}/tests/test_core.py +0 -0
- {evonet-0.1.0.dev11 → evonet-0.1.0.dev13}/tests/test_nnet_io_and_forward.py +0 -0
- {evonet-0.1.0.dev11 → evonet-0.1.0.dev13}/tests/test_recurrent_dynamics.py +0 -0
|
@@ -180,7 +180,7 @@ class Nnet:
|
|
|
180
180
|
if RecurrentKind.LATERAL in recurrent:
|
|
181
181
|
full_layer = list(self.layers[layer_idx].neurons)
|
|
182
182
|
for src in full_layer:
|
|
183
|
-
if src != NeuronRole.HIDDEN:
|
|
183
|
+
if src.role != NeuronRole.HIDDEN:
|
|
184
184
|
continue # No recurrence on INPUT or OUTPUT
|
|
185
185
|
for dst in new_neurons:
|
|
186
186
|
if src is not dst:
|
|
@@ -193,7 +193,7 @@ class Nnet:
|
|
|
193
193
|
|
|
194
194
|
if RecurrentKind.INDIRECT in recurrent:
|
|
195
195
|
for src in new_neurons:
|
|
196
|
-
if src != NeuronRole.HIDDEN:
|
|
196
|
+
if src.role != NeuronRole.HIDDEN:
|
|
197
197
|
continue # No recurrence on INPUT or OUTPUT
|
|
198
198
|
for lower_layer in self.layers[1:layer_idx]:
|
|
199
199
|
for dst in lower_layer.neurons:
|
|
@@ -230,12 +230,12 @@ class Nnet:
|
|
|
230
230
|
Args:
|
|
231
231
|
source (Neuron): Source neuron.
|
|
232
232
|
target (Neuron): Target neuron.
|
|
233
|
-
weight (float | None): Initial weight. If None,
|
|
233
|
+
weight (float | None): Initial weight. If None, 0.0 is used.
|
|
234
234
|
conn_type (ConnectionType): Type of connection (e.g. standard, recurrent).
|
|
235
235
|
"""
|
|
236
236
|
|
|
237
237
|
if weight is None:
|
|
238
|
-
weight =
|
|
238
|
+
weight = 0.0
|
|
239
239
|
|
|
240
240
|
conn = Connection(source, target, weight=weight, conn_type=conn_type)
|
|
241
241
|
source.outgoing.append(conn)
|
|
@@ -152,21 +152,44 @@ def mutate_biases(net: Nnet, probability: float = 1.0, std: float = 0.1) -> None
|
|
|
152
152
|
def add_random_connection(
|
|
153
153
|
net: Nnet,
|
|
154
154
|
allowed_recurrent: Optional[Collection[RecurrentKind | str]] = None,
|
|
155
|
+
connection_init: Literal["zero", "random", "near_zero"] = "zero",
|
|
155
156
|
) -> bool:
|
|
156
157
|
"""
|
|
157
158
|
Add a valid connection between two randomly chosen neurons.
|
|
158
159
|
|
|
159
160
|
Rules:
|
|
160
|
-
-
|
|
161
|
-
-
|
|
162
|
-
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
161
|
+
- Disallow connections into INPUT neurons.
|
|
162
|
+
- Disallow duplicate (source, target) pairs.
|
|
163
|
+
- Classify connection type by layer order:
|
|
164
|
+
* src_layer < dst_layer -> STANDARD
|
|
165
|
+
* src_layer >= dst_layer -> RECURRENT
|
|
166
|
+
- Recurrent edges are filtered by `allowed_recurrent`
|
|
167
|
+
(list of 'direct' | 'lateral' | 'indirect').
|
|
168
|
+
|
|
169
|
+
Args:
|
|
170
|
+
net (Nnet): Target network to modify.
|
|
171
|
+
allowed_recurrent (Collection[RecurrentKind | str] | None):
|
|
172
|
+
Allowed recurrent connection kinds. Default: None (no recurrent edges).
|
|
173
|
+
connection_init (Literal["zero", "random", "near_zero"]):
|
|
174
|
+
Weight initialization mode for the new connection.
|
|
175
|
+
- "zero": Weight = 0.0 (neutral; ideal with HELI)
|
|
176
|
+
- "random": Weight ~ N(0, 0.5)
|
|
177
|
+
- "near_zero": Weight ~ U(-0.05, 0.05)
|
|
178
|
+
|
|
179
|
+
Returns:
|
|
180
|
+
bool: True if a connection was added, False otherwise.
|
|
168
181
|
"""
|
|
169
182
|
|
|
183
|
+
# Weight initialization
|
|
184
|
+
if connection_init == "zero":
|
|
185
|
+
weight = 0.0
|
|
186
|
+
elif connection_init == "random":
|
|
187
|
+
weight = np.random.randn() * 0.5
|
|
188
|
+
elif connection_init == "near_zero":
|
|
189
|
+
weight = np.random.uniform(-0.05, 0.05)
|
|
190
|
+
else:
|
|
191
|
+
raise ValueError(f"Unknown init mode: {connection_init}")
|
|
192
|
+
|
|
170
193
|
# normalize to set[RecurrentKind]
|
|
171
194
|
kinds: set[RecurrentKind] = set()
|
|
172
195
|
if allowed_recurrent:
|
|
@@ -223,7 +246,7 @@ def add_random_connection(
|
|
|
223
246
|
else ConnectionType.RECURRENT
|
|
224
247
|
)
|
|
225
248
|
|
|
226
|
-
net.add_connection(src, dst, conn_type=conn_type)
|
|
249
|
+
net.add_connection(src, dst, weight=weight, conn_type=conn_type)
|
|
227
250
|
return True
|
|
228
251
|
|
|
229
252
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|