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.
- {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/PKG-INFO +1 -1
- {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet/core.py +37 -35
- {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet/mutation.py +4 -0
- {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet.egg-info/PKG-INFO +1 -1
- {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/pyproject.toml +1 -1
- {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/LICENSE +0 -0
- {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/README.md +0 -0
- {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet/__init__.py +0 -0
- {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet/activation.py +0 -0
- {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet/connection.py +0 -0
- {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet/core_mit_plot_simple.py +0 -0
- {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet/enums.py +0 -0
- {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet/io.py +0 -0
- {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet/layer.py +0 -0
- {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet/neuron.py +0 -0
- {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet/serialization.py +0 -0
- {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet/utils.py +0 -0
- {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet/visualize.py +0 -0
- {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet.egg-info/SOURCES.txt +0 -0
- {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet.egg-info/dependency_links.txt +0 -0
- {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet.egg-info/requires.txt +0 -0
- {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/evonet.egg-info/top_level.txt +0 -0
- {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/setup.cfg +0 -0
- {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/tests/test_activation.py +0 -0
- {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/tests/test_core.py +0 -0
- {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/tests/test_nnet_io_and_forward.py +0 -0
- {evonet-0.1.0.dev16 → evonet-0.1.0.dev18}/tests/test_recurrent_dynamics.py +0 -0
|
@@ -161,41 +161,43 @@ class Nnet:
|
|
|
161
161
|
return new_neurons
|
|
162
162
|
|
|
163
163
|
weight = connection_init_value(connection_init)
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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
|
|
|
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
|