evonet 0.1.0.dev16__tar.gz → 0.1.0.dev18__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.dev16 → evonet-0.1.0.dev18}/PKG-INFO +1 -1
  2. {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet/core.py +37 -35
  3. {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet/mutation.py +4 -0
  4. {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet.egg-info/PKG-INFO +1 -1
  5. {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/pyproject.toml +1 -1
  6. {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/LICENSE +0 -0
  7. {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/README.md +0 -0
  8. {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet/__init__.py +0 -0
  9. {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet/activation.py +0 -0
  10. {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet/connection.py +0 -0
  11. {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet/core_mit_plot_simple.py +0 -0
  12. {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet/enums.py +0 -0
  13. {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet/io.py +0 -0
  14. {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet/layer.py +0 -0
  15. {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet/neuron.py +0 -0
  16. {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet/serialization.py +0 -0
  17. {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet/utils.py +0 -0
  18. {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet/visualize.py +0 -0
  19. {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet.egg-info/SOURCES.txt +0 -0
  20. {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet.egg-info/dependency_links.txt +0 -0
  21. {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet.egg-info/requires.txt +0 -0
  22. {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet.egg-info/top_level.txt +0 -0
  23. {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/setup.cfg +0 -0
  24. {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/tests/test_activation.py +0 -0
  25. {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/tests/test_core.py +0 -0
  26. {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/tests/test_nnet_io_and_forward.py +0 -0
  27. {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/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.dev16
3
+ Version: 0.1.0.dev18
4
4
  Summary: Evolvable neural network core for integration with EvoLib
5
5
  Author-email: EvoLib <evolib@dismail.de>
6
6
  License: MIT License
@@ -161,41 +161,43 @@ class Nnet:
161
161
  return new_neurons
162
162
 
163
163
  weight = connection_init_value(connection_init)
164
- possible_pairs: list[tuple[Neuron, Neuron]] = []
165
-
166
- # Connection logic
167
- if connection_scope == "adjacent":
168
- # Previous layer ---> new neurons
169
- if layer_idx > 0:
170
- for src in self.layers[layer_idx - 1].neurons:
171
- for n in new_neurons:
172
- possible_pairs.append((src, n))
173
- # New neurons ---> next layer (only for hidden neurons)
174
- if role == NeuronRole.HIDDEN and layer_idx < len(self.layers) - 1:
175
- for dst in self.layers[layer_idx + 1].neurons:
176
- for n in new_neurons:
177
- possible_pairs.append((n, dst))
178
-
179
- elif connection_scope == "crosslayer":
180
- # All earlier layers ---> new neurons
181
- for i in range(0, layer_idx):
182
- for src in self.layers[i].neurons:
183
- for n in new_neurons:
184
- possible_pairs.append((src, n))
185
- # New neurons ---> all later layers
186
- for j in range(layer_idx + 1, len(self.layers)):
187
- for dst in self.layers[j].neurons:
188
- for n in new_neurons:
189
- possible_pairs.append((n, dst))
190
-
191
- # Density control: subsample of possible pairs
192
- if connection_density < 1.0 and possible_pairs:
193
- k = max(1, int(len(possible_pairs) * connection_density))
194
- possible_pairs = random.sample(possible_pairs, k)
195
-
196
- # Create connections
197
- for src, dst in possible_pairs:
198
- self.add_connection(src, dst, weight=weight)
164
+
165
+ # Build connections for each new neuron
166
+ for n in new_neurons:
167
+
168
+ possible_in: list[Neuron] = []
169
+ possible_out: list[Neuron] = []
170
+
171
+ # ADJACENT connections
172
+ if connection_scope == "adjacent":
173
+ if layer_idx > 0:
174
+ possible_in.extend(self.layers[layer_idx - 1].neurons)
175
+ if role == NeuronRole.HIDDEN and layer_idx < len(self.layers) - 1:
176
+ possible_out.extend(self.layers[layer_idx + 1].neurons)
177
+
178
+ # CROSSLAYER connections
179
+ elif connection_scope == "crosslayer":
180
+ # All earlier layers ---> new neuron
181
+ for i in range(0, layer_idx):
182
+ possible_in.extend(self.layers[i].neurons)
183
+ # New neuron ---> all later layers
184
+ for j in range(layer_idx + 1, len(self.layers)):
185
+ possible_out.extend(self.layers[j].neurons)
186
+
187
+ # Density control per neuron
188
+ if connection_density < 1.0:
189
+ if possible_in:
190
+ k_in = max(1, int(len(possible_in) * connection_density))
191
+ possible_in = random.sample(possible_in, k_in)
192
+ if possible_out:
193
+ k_out = max(1, int(len(possible_out) * connection_density))
194
+ possible_out = random.sample(possible_out, k_out)
195
+
196
+ # Create the actual connections
197
+ for src in possible_in:
198
+ self.add_connection(src, n, weight=weight)
199
+ for dst in possible_out:
200
+ self.add_connection(n, dst, weight=weight)
199
201
 
200
202
  # Recurrent connections
201
203
  if recurrent:
@@ -263,6 +263,8 @@ def add_random_neuron(
263
263
  net: Nnet,
264
264
  activations: list[str] | None = None,
265
265
  connection_init: Literal["zero", "random", "near_zero", "none"] = "zero",
266
+ connection_scope: Literal["adjacent", "crosslayer"] = "adjacent",
267
+ connection_density: float = 1.0,
266
268
  ) -> None:
267
269
  """
268
270
  Insert a new hidden neuron into a random layer.
@@ -292,6 +294,8 @@ def add_random_neuron(
292
294
  activation=random_function_name(activations),
293
295
  role=NeuronRole.HIDDEN,
294
296
  connection_init=connection_init,
297
+ connection_scope=connection_scope,
298
+ connection_density=connection_density,
295
299
  )
296
300
 
297
301
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: evonet
3
- Version: 0.1.0.dev16
3
+ Version: 0.1.0.dev18
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.dev16"
7
+ version = "0.1.0.dev18"
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