evonet 0.1.0.dev23__tar.gz → 0.1.0.dev24__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.dev23 → evonet-0.1.0.dev24}/PKG-INFO +1 -1
- {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet/core.py +45 -7
- {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet.egg-info/PKG-INFO +1 -1
- {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/pyproject.toml +1 -1
- {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/LICENSE +0 -0
- {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/README.md +0 -0
- {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet/__init__.py +0 -0
- {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet/activation.py +0 -0
- {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet/connection.py +0 -0
- {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet/core_mit_plot_simple.py +0 -0
- {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet/enums.py +0 -0
- {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet/io.py +0 -0
- {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet/layer.py +0 -0
- {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet/mutation.py +0 -0
- {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet/neuron.py +0 -0
- {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet/serialization.py +0 -0
- {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet/utils.py +0 -0
- {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet/visualize.py +0 -0
- {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet.egg-info/SOURCES.txt +0 -0
- {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet.egg-info/dependency_links.txt +0 -0
- {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet.egg-info/requires.txt +0 -0
- {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet.egg-info/top_level.txt +0 -0
- {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/setup.cfg +0 -0
- {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/tests/test_activation.py +0 -0
- {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/tests/test_core.py +0 -0
- {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/tests/test_nnet_io_and_forward.py +0 -0
- {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/tests/test_recurrent_dynamics.py +0 -0
|
@@ -122,6 +122,7 @@ class Nnet:
|
|
|
122
122
|
connection_scope: Literal["adjacent", "crosslayer"] = "adjacent",
|
|
123
123
|
connection_density: float = 1.0,
|
|
124
124
|
max_connections: int = 2**63 - 1,
|
|
125
|
+
require_io_connections: bool = True,
|
|
125
126
|
) -> list[Neuron]:
|
|
126
127
|
"""
|
|
127
128
|
Add one or more neurons to the network.
|
|
@@ -147,6 +148,9 @@ class Nnet:
|
|
|
147
148
|
that should actually be created. Must be in [0, 1].
|
|
148
149
|
max_connections:
|
|
149
150
|
Hard limit for the number of created connections per neuron.
|
|
151
|
+
require_io_connections:
|
|
152
|
+
If True, ensure that each newly added neuron has at least
|
|
153
|
+
one incoming and one outgoing connection (if structurally possible).
|
|
150
154
|
|
|
151
155
|
Returns:
|
|
152
156
|
list[Neuron]: The created neuron objects.
|
|
@@ -260,21 +264,55 @@ class Nnet:
|
|
|
260
264
|
if not all_candidates:
|
|
261
265
|
continue
|
|
262
266
|
|
|
263
|
-
|
|
267
|
+
forced: list[tuple[Neuron, Neuron, ConnectionType]] = []
|
|
268
|
+
|
|
269
|
+
# --------------------------------------------------------------
|
|
270
|
+
# IO enforcement
|
|
271
|
+
# --------------------------------------------------------------
|
|
272
|
+
|
|
273
|
+
if require_io_connections and max_connections > 0:
|
|
274
|
+
incoming_candidates = [
|
|
275
|
+
(src, dst, ctype) for src, dst, ctype in all_candidates if dst is n
|
|
276
|
+
]
|
|
277
|
+
|
|
278
|
+
outgoing_candidates = [
|
|
279
|
+
(src, dst, ctype) for src, dst, ctype in all_candidates if src is n
|
|
280
|
+
]
|
|
281
|
+
|
|
282
|
+
# Enforce incoming if possible
|
|
283
|
+
if incoming_candidates:
|
|
284
|
+
forced.append(random.choice(incoming_candidates))
|
|
285
|
+
|
|
286
|
+
# Enforce outgoing if possible and budget allows
|
|
287
|
+
if outgoing_candidates and len(forced) < max_connections:
|
|
288
|
+
forced.append(random.choice(outgoing_candidates))
|
|
289
|
+
|
|
290
|
+
# --------------------------------------------------------------
|
|
291
|
+
# Remaining
|
|
292
|
+
# --------------------------------------------------------------
|
|
264
293
|
|
|
265
|
-
|
|
294
|
+
total = len(all_candidates)
|
|
266
295
|
k = int(np.ceil(total * connection_density))
|
|
267
|
-
k = min(k, max_connections)
|
|
296
|
+
k = min(k, max_connections - len(forced))
|
|
268
297
|
k = max(k, 0)
|
|
269
298
|
|
|
299
|
+
remaining_candidates = [c for c in all_candidates if c not in forced]
|
|
300
|
+
|
|
301
|
+
# Create forced connections
|
|
302
|
+
for src, dst, ctype in forced:
|
|
303
|
+
self.add_connection(src, dst, weight=weight, conn_type=ctype)
|
|
304
|
+
|
|
305
|
+
k = min(k, len(remaining_candidates))
|
|
306
|
+
|
|
270
307
|
if k == 0:
|
|
271
308
|
continue
|
|
272
309
|
|
|
273
|
-
|
|
274
|
-
selected = random.sample(all_candidates, k)
|
|
310
|
+
sampled = random.sample(remaining_candidates, k)
|
|
275
311
|
|
|
276
|
-
#
|
|
277
|
-
|
|
312
|
+
# --------------------------------------------------------------
|
|
313
|
+
# Create connections
|
|
314
|
+
# --------------------------------------------------------------
|
|
315
|
+
for src, dst, ctype in forced + sampled:
|
|
278
316
|
self.add_connection(src, dst, weight=weight, conn_type=ctype)
|
|
279
317
|
|
|
280
318
|
return new_neurons
|
|
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
|
|
File without changes
|