last workig state.

This commit is contained in:
2025-12-13 14:12:35 +01:00
parent 1761de8acb
commit 841bc7c805
227 changed files with 694550 additions and 251 deletions

View File

@@ -6,6 +6,7 @@ obs, info = env.reset()
for _ in range(1000):
action = env.action_space.sample()
_, reward, terminated, truncated, _ = env.step(action)
if terminated or truncated:
obs, info = env.reset()

View File

@@ -60,7 +60,7 @@ class Sensor(Actor):
if self.sname == "rng":
vec = rng_vector(self.vl)
else:
# place for own sensors (this will be replaced by scapes down the road)
# place for own sensors (this will be replaced by envs down the road)
vec = [0.0] * self.vl
# forward an alle Fanouts
for pid in self.fanout:

View File

@@ -1,4 +1,4 @@
# genotype.py
# genotype.py.old
import json
import math
import random

View File

@@ -1,37 +1,20 @@
import asyncio
import morphology
from experiments.stochastic_hillclimber.actors.trainer import Trainer
from experiments.stochastic_hillclimber.trainer import Trainer
from genotype import construct, save_genotype
def test_genotype_construction():
"""
genotype_data = construct(morphology, hidden_layer_densities=[3, 2])
# Prüfen, ob Cortex, Sensor, Actuator und Neuronen existieren
assert "cortex" in genotype_data
assert len(genotype_data["neurons"]) == 3 + 2 + 1 # 3 in 1. HL, 2 in 2. HL, 1 Output
print("Genotype construction OK")
print("Cortex:", genotype_data["cortex"])
print("---------------------------------")
print("Neurons:", genotype_data["neurons"])
print("---------------------------------")
print("Actuators:", genotype_data["actuator"])
save_genotype("test.json", genotype_data)
"""
trainer = Trainer(
morphology_spec=morphology, # <— wichtig! callable oder "xor_mimic"
hidden_layer_densities=[2], # wie im Buchbeispiel
max_attempts=float("inf"), # MA=inf
eval_limit=float("inf"), # EL=inf
fitness_target=99.9, # FT=99.9
morphology_spec=morphology,
hidden_layer_densities=[2],
max_attempts=float("inf"),
eval_limit=float("inf"),
fitness_target=99.9,
experimental_file="experimental.json",
best_file="best.json",
exoself_steps_per_eval=0, # 0 = Scape/Cortex entscheiden über Halt
exoself_steps_per_eval=0,
)
asyncio.run(trainer.go())

View File

@@ -42,7 +42,7 @@ class Trainer:
geno = construct(
self.morphology_spec,
self.hds,
file_name=self.experimental_file, # <-- schreibt Startnetz nach experimental.json
file_name=self.experimental_file,
add_bias=True
)
fitness, evals, cycles, elapsed = await self._evaluate_with_exoself(geno)
@@ -62,7 +62,7 @@ class Trainer:
print(".........")
if attempt > self.max_attempts or self.eval_acc >= self.eval_limit or self.best_fitness >= self.fitness_target:
# Abschlussausgabe wie im Buch
if self.best_file and os.path.exists(self.best_file):
print_genotype(self.best_file)
print(
@@ -86,7 +86,6 @@ class Trainer:
self.cycle_acc += cycles
self.time_acc += elapsed
# Besser als bisher?
if fitness > self.best_fitness:
self.best_fitness = fitness
if self.best_file and self.experimental_file and os.path.exists(self.experimental_file):
@@ -96,7 +95,6 @@ class Trainer:
attempt += 1
if __name__ == "__main__":
trainer = Trainer(
morphology_spec=morphology,