Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files
app.py
CHANGED
|
@@ -67,14 +67,17 @@ class SundewDemo:
|
|
| 67 |
self.activations.append(activate)
|
| 68 |
self.energy_saved.append(0.0 if activate else 1.0)
|
| 69 |
|
| 70 |
-
# Update threshold (PI controller)
|
| 71 |
if len(self.activation_history) >= 10:
|
| 72 |
recent_rate = sum(self.activation_history[-10:]) / 10
|
| 73 |
error = self.target_rate - recent_rate
|
| 74 |
self.error_sum += error
|
|
|
|
|
|
|
| 75 |
|
| 76 |
-
# PI update
|
| 77 |
-
|
|
|
|
| 78 |
self.threshold = min(0.95, max(0.05, self.threshold))
|
| 79 |
|
| 80 |
return activate
|
|
|
|
| 67 |
self.activations.append(activate)
|
| 68 |
self.energy_saved.append(0.0 if activate else 1.0)
|
| 69 |
|
| 70 |
+
# Update threshold (PI controller) - FIXED: Correct direction and stronger gains
|
| 71 |
if len(self.activation_history) >= 10:
|
| 72 |
recent_rate = sum(self.activation_history[-10:]) / 10
|
| 73 |
error = self.target_rate - recent_rate
|
| 74 |
self.error_sum += error
|
| 75 |
+
# Prevent integral windup
|
| 76 |
+
self.error_sum = max(-5.0, min(5.0, self.error_sum))
|
| 77 |
|
| 78 |
+
# PI update - FIXED: SUBTRACT error to decrease threshold when rate is too low
|
| 79 |
+
adjustment = 0.05 * error + 0.002 * self.error_sum
|
| 80 |
+
self.threshold -= adjustment # FIXED: Changed += to -=
|
| 81 |
self.threshold = min(0.95, max(0.05, self.threshold))
|
| 82 |
|
| 83 |
return activate
|