final implementation of shc

This commit is contained in:
2025-09-26 14:18:00 +02:00
parent 0ace1cec3c
commit 90e67652ab
12 changed files with 186 additions and 462 deletions

View File

@@ -1,4 +1,3 @@
# actors/scape.py
from actor import Actor
import math
@@ -14,7 +13,7 @@ class XorScape(Actor):
]
self.index = 0
self.error_acc = 0.0
self.last_actuator = None # <-- wer uns zuletzt "action" geschickt hat
self.last_actuator = None
async def run(self):
while True:
@@ -23,9 +22,8 @@ class XorScape(Actor):
if tag == "sense":
print("SCAPE: got sensed by sensor...")
# Sensor fragt nach Input
_, sid, from_pid = msg
self.last_actuator = from_pid # merken, wer beteiligt ist
self.last_actuator = from_pid
inputs, correct = self.data[self.index]
print("SENSOR input /correct: ", inputs, correct)
await from_pid.send(("percept", inputs))
@@ -33,25 +31,23 @@ class XorScape(Actor):
elif tag == "action":
_, output, from_pid = msg
_, correct = self.data[self.index]
# Calculate RMSE like the Erlang version
step_error = sum((o - c) ** 2 for o, c in zip(output, correct))
step_rmse = math.sqrt(step_error) # This is the key change!
step_rmse = math.sqrt(step_error)
print(f"XOR PATTERN: Input={self.data[self.index][0]} → Network={output} → Expected={correct}")
self.index += 1
if self.index >= len(self.data):
# Episode finished - calculate final fitness
total_rmse = math.sqrt(self.error_acc + step_rmse) # Not step_error!
total_rmse = math.sqrt(self.error_acc + step_rmse)
fitness = 1.0 / (total_rmse + 1e-5)
await from_pid.send(("result", fitness, 1))
self.index = 0
self.error_acc = 0.0
else:
# Continue episode
self.error_acc += step_rmse # Add RMSE, not raw error
self.error_acc += step_rmse
await from_pid.send(("result", 0.0, 0))
elif tag == "terminate":