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.
Files changed (27) hide show
  1. {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/PKG-INFO +1 -1
  2. {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet/core.py +45 -7
  3. {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet.egg-info/PKG-INFO +1 -1
  4. {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/pyproject.toml +1 -1
  5. {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/LICENSE +0 -0
  6. {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/README.md +0 -0
  7. {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet/__init__.py +0 -0
  8. {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet/activation.py +0 -0
  9. {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet/connection.py +0 -0
  10. {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet/core_mit_plot_simple.py +0 -0
  11. {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet/enums.py +0 -0
  12. {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet/io.py +0 -0
  13. {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet/layer.py +0 -0
  14. {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet/mutation.py +0 -0
  15. {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet/neuron.py +0 -0
  16. {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet/serialization.py +0 -0
  17. {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet/utils.py +0 -0
  18. {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet/visualize.py +0 -0
  19. {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet.egg-info/SOURCES.txt +0 -0
  20. {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet.egg-info/dependency_links.txt +0 -0
  21. {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet.egg-info/requires.txt +0 -0
  22. {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/evonet.egg-info/top_level.txt +0 -0
  23. {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/setup.cfg +0 -0
  24. {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/tests/test_activation.py +0 -0
  25. {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/tests/test_core.py +0 -0
  26. {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/tests/test_nnet_io_and_forward.py +0 -0
  27. {evonet-0.1.0.dev23 → evonet-0.1.0.dev24}/tests/test_recurrent_dynamics.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: evonet
3
- Version: 0.1.0.dev23
3
+ Version: 0.1.0.dev24
4
4
  Summary: Evolvable neural network core for integration with EvoLib
5
5
  Author-email: EvoLib <evolib@dismail.de>
6
6
  License: MIT License
@@ -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
- total = len(all_candidates)
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
- # Global connection budget based on density
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
- # Randomly select k connections across all types
274
- selected = random.sample(all_candidates, k)
310
+ sampled = random.sample(remaining_candidates, k)
275
311
 
276
- # Create the selected connections
277
- for src, dst, ctype in selected:
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: evonet
3
- Version: 0.1.0.dev23
3
+ Version: 0.1.0.dev24
4
4
  Summary: Evolvable neural network core for integration with EvoLib
5
5
  Author-email: EvoLib <evolib@dismail.de>
6
6
  License: MIT License
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "evonet"
7
- version = "0.1.0.dev23"
7
+ version = "0.1.0.dev24"
8
8
  description = "Evolvable neural network core for integration with EvoLib"
9
9
  authors = [
10
10
  { name = "EvoLib", email = "evolib@dismail.de" }
File without changes
File without changes
File without changes
File without changes