Spaces:
Configuration error
Configuration error
fix: template literal syntax error + align all getElementById calls to actual HTML element IDs + add missing triggerRecalibration/resetMetrics/clearLog globals
Browse files- feedback_optimizer.js +116 -113
feedback_optimizer.js
CHANGED
|
@@ -2,163 +2,166 @@
|
|
| 2 |
// Node #37: Recursive Optimization & Constitutional Convergence
|
| 3 |
// σ=1.0 | L∞=φ⁴⁸ | RDoD≥0.9777
|
| 4 |
|
|
|
|
|
|
|
| 5 |
class FeedbackOptimizer {
|
| 6 |
constructor() {
|
| 7 |
this.metrics = {
|
| 8 |
-
convergenceRate: 0,
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
};
|
| 15 |
-
this.
|
|
|
|
|
|
|
|
|
|
| 16 |
this.logs = [];
|
|
|
|
| 17 |
this.isRunning = false;
|
| 18 |
-
this.
|
| 19 |
-
this.initializeNodes();
|
| 20 |
-
}
|
| 21 |
-
|
| 22 |
-
initializeNodes() {
|
| 23 |
-
const nodes = [
|
| 24 |
-
{ id: '#37', name: 'Feedback Optimizer', status: 'active', coherence: 0.98 },
|
| 25 |
-
{ id: '#12', name: 'Constitutional Guard', status: 'active', coherence: 0.99 },
|
| 26 |
-
{ id: '#23', name: 'API Gateway', status: 'active', coherence: 0.97 },
|
| 27 |
-
{ id: '#45', name: 'Recursive Validator', status: 'active', coherence: 0.96 },
|
| 28 |
-
{ id: '#08', name: 'Convergence Monitor', status: 'active', coherence: 0.95 },
|
| 29 |
-
{ id: '#51', name: 'Optimization Core', status: 'active', coherence: 0.94 }
|
| 30 |
-
];
|
| 31 |
-
nodes.forEach(node => this.nodeMap.set(node.id, node));
|
| 32 |
}
|
| 33 |
|
| 34 |
start() {
|
| 35 |
this.isRunning = true;
|
| 36 |
-
this.addLog('Feedback Optimizer initialized', 'info');
|
| 37 |
-
this.
|
|
|
|
| 38 |
this.renderUI();
|
| 39 |
this.startSimulation();
|
| 40 |
}
|
| 41 |
|
| 42 |
startSimulation() {
|
| 43 |
setInterval(() => {
|
| 44 |
-
if (this.isRunning)
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
this.renderUI();
|
| 48 |
-
}
|
| 49 |
}, 2000);
|
| 50 |
}
|
| 51 |
|
| 52 |
updateMetrics() {
|
| 53 |
-
this.
|
| 54 |
-
this.metrics.
|
| 55 |
-
this.metrics.
|
| 56 |
-
this.metrics.
|
| 57 |
-
this.metrics.
|
| 58 |
-
this.metrics.
|
| 59 |
-
|
|
|
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
if (this.
|
| 66 |
-
this.
|
| 67 |
-
id: `LOOP-${Date.now()}",
|
| 68 |
-
type: types[Math.floor(Math.random() * types.length)],
|
| 69 |
-
depth: Math.floor(Math.random() * 20) + 10,
|
| 70 |
-
convergence: (Math.random() * 0.2 + 0.8).toFixed(4),
|
| 71 |
-
status: statuses[Math.floor(Math.random() * statuses.length)]
|
| 72 |
-
});
|
| 73 |
}
|
| 74 |
-
|
| 75 |
-
// Update existing loops
|
| 76 |
-
this.loops.forEach(loop => {
|
| 77 |
-
loop.convergence = Math.min(parseFloat(loop.convergence) + Math.random() * 0.01, 0.9999).toFixed(4);
|
| 78 |
-
if (parseFloat(loop.convergence) > 0.975) {
|
| 79 |
-
loop.status = 'converged';
|
| 80 |
-
}
|
| 81 |
-
});
|
| 82 |
}
|
| 83 |
|
| 84 |
addLog(message, type = 'info') {
|
|
|
|
| 85 |
const timestamp = new Date().toLocaleTimeString();
|
| 86 |
this.logs.unshift({ timestamp, message, type });
|
| 87 |
if (this.logs.length > 50) this.logs.pop();
|
| 88 |
}
|
| 89 |
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
}
|
| 98 |
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
this.renderLogs();
|
| 103 |
-
this.renderSubstrate();
|
| 104 |
}
|
| 105 |
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
document.getElementById('feedback-loops').textContent = this.metrics.feedbackLoops;
|
| 110 |
-
document.getElementById('constitutional-alignment').textContent = this.metrics.constitutionalAlignment.toFixed(4);
|
| 111 |
-
document.getElementById('substrate-coherence').textContent = this.metrics.substrateCoherence.toFixed(4);
|
| 112 |
-
document.getElementById('recursion-efficiency').textContent = this.metrics.recursionEfficiency.toFixed(4);
|
| 113 |
}
|
| 114 |
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
</div>
|
| 128 |
-
</div>
|
| 129 |
-
`).join('');
|
| 130 |
}
|
| 131 |
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
|
|
|
| 140 |
}
|
| 141 |
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
<div class="node-id">${node.id}</div>
|
| 147 |
-
<div class="node-name">${node.name}</div>
|
| 148 |
-
<div class="node-coherence">${node.coherence}</div>
|
| 149 |
-
</div>
|
| 150 |
-
`).join('');
|
| 151 |
}
|
| 152 |
}
|
| 153 |
|
| 154 |
-
//
|
| 155 |
let optimizer;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
document.addEventListener('DOMContentLoaded', () => {
|
| 157 |
optimizer = new FeedbackOptimizer();
|
| 158 |
optimizer.start();
|
| 159 |
-
|
| 160 |
-
// Event listeners
|
| 161 |
-
document.getElementById('recalibrate-btn')?.addEventListener('click', () => {
|
| 162 |
-
optimizer.recalibrate();
|
| 163 |
-
});
|
| 164 |
-
});
|
|
|
|
| 2 |
// Node #37: Recursive Optimization & Constitutional Convergence
|
| 3 |
// σ=1.0 | L∞=φ⁴⁸ | RDoD≥0.9777
|
| 4 |
|
| 5 |
+
const PHI = 1.6180339887;
|
| 6 |
+
|
| 7 |
class FeedbackOptimizer {
|
| 8 |
constructor() {
|
| 9 |
this.metrics = {
|
| 10 |
+
convergenceRate: 0.9777,
|
| 11 |
+
feedbackGain: PHI,
|
| 12 |
+
recalibrations: 0,
|
| 13 |
+
substrateCoherence: 0.9999,
|
| 14 |
+
systemDrift: 0.0023,
|
| 15 |
+
latencyMs: 47,
|
| 16 |
};
|
| 17 |
+
this.phiCycles = 0;
|
| 18 |
+
this.corrections = 0;
|
| 19 |
+
this.rdodCurrent = 0.9999;
|
| 20 |
+
this.substrateDrift = 0.0023;
|
| 21 |
this.logs = [];
|
| 22 |
+
this.logEventCount = 0;
|
| 23 |
this.isRunning = false;
|
| 24 |
+
this.recalCount = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
}
|
| 26 |
|
| 27 |
start() {
|
| 28 |
this.isRunning = true;
|
| 29 |
+
this.addLog('Feedback Optimizer initialized — σ=1.0 sovereign', 'info');
|
| 30 |
+
this.addLog('φ-Recursive loops active: 4/4', 'success');
|
| 31 |
+
this.addLog('Substrate guardian sync: ONLINE', 'success');
|
| 32 |
this.renderUI();
|
| 33 |
this.startSimulation();
|
| 34 |
}
|
| 35 |
|
| 36 |
startSimulation() {
|
| 37 |
setInterval(() => {
|
| 38 |
+
if (!this.isRunning) return;
|
| 39 |
+
this.updateMetrics();
|
| 40 |
+
this.renderUI();
|
|
|
|
|
|
|
| 41 |
}, 2000);
|
| 42 |
}
|
| 43 |
|
| 44 |
updateMetrics() {
|
| 45 |
+
this.phiCycles++;
|
| 46 |
+
this.metrics.convergenceRate = Math.min(0.9777 + Math.random() * 0.022, 0.9999);
|
| 47 |
+
this.metrics.feedbackGain = +(PHI + (Math.random() - 0.5) * 0.001).toFixed(4);
|
| 48 |
+
this.metrics.substrateCoherence = Math.min(0.9990 + Math.random() * 0.0009, 0.9999);
|
| 49 |
+
this.metrics.systemDrift = +(Math.random() * 0.008).toFixed(4);
|
| 50 |
+
this.metrics.latencyMs = Math.floor(30 + Math.random() * 40);
|
| 51 |
+
this.substrateDrift = this.metrics.systemDrift;
|
| 52 |
+
this.rdodCurrent = +(0.9777 + Math.random() * 0.022).toFixed(4);
|
| 53 |
|
| 54 |
+
if (this.metrics.systemDrift > 0.007) {
|
| 55 |
+
this.corrections++;
|
| 56 |
+
this.addLog(`Auto-correction applied — drift was ${this.metrics.systemDrift.toFixed(4)}`, 'optimize');
|
| 57 |
+
}
|
| 58 |
+
if (this.phiCycles % 10 === 0) {
|
| 59 |
+
this.addLog(`φ-cycle ${this.phiCycles}: RDoD=${this.rdodCurrent} coherence=${this.metrics.substrateCoherence.toFixed(4)}`, 'info');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
}
|
| 62 |
|
| 63 |
addLog(message, type = 'info') {
|
| 64 |
+
this.logEventCount++;
|
| 65 |
const timestamp = new Date().toLocaleTimeString();
|
| 66 |
this.logs.unshift({ timestamp, message, type });
|
| 67 |
if (this.logs.length > 50) this.logs.pop();
|
| 68 |
}
|
| 69 |
|
| 70 |
+
renderUI() {
|
| 71 |
+
// --- Metric cards ---
|
| 72 |
+
this._set('valConvergence', (this.metrics.convergenceRate * 100).toFixed(2) + '%');
|
| 73 |
+
this._set('valFeedbackGain', this.metrics.feedbackGain.toFixed(4));
|
| 74 |
+
this._set('valRecalibrations', this.recalCount);
|
| 75 |
+
this._set('valSubstrates', this.metrics.substrateCoherence.toFixed(4));
|
| 76 |
+
this._set('valDrift', this.metrics.systemDrift.toFixed(4));
|
| 77 |
+
this._set('valLatency', this.metrics.latencyMs + ' ms');
|
| 78 |
+
|
| 79 |
+
// Progress bars
|
| 80 |
+
this._width('convergenceBar', (this.metrics.convergenceRate * 100).toFixed(2));
|
| 81 |
+
this._width('recalBar', Math.max(5, 100 - this.recalCount * 10));
|
| 82 |
+
|
| 83 |
+
// Feedback loop live fields
|
| 84 |
+
this._set('phiCycles', this.phiCycles);
|
| 85 |
+
this._set('substrateDrift', this.substrateDrift.toFixed(4));
|
| 86 |
+
this._set('corrections', this.corrections);
|
| 87 |
+
this._set('rdodCurrent', this.rdodCurrent.toFixed(4));
|
| 88 |
+
|
| 89 |
+
// Header badges
|
| 90 |
+
this._set('convBadge', `→ ${(this.metrics.convergenceRate * 100).toFixed(2)}% Convergence`);
|
| 91 |
+
this._set('loopsBadge', `↻ 4 Loops Active`);
|
| 92 |
+
|
| 93 |
+
// Log feed
|
| 94 |
+
const logEl = document.getElementById('logFeed');
|
| 95 |
+
if (logEl) {
|
| 96 |
+
logEl.innerHTML = this.logs.slice(0, 20).map(log => `
|
| 97 |
+
<div class="log-entry log-${log.type}">
|
| 98 |
+
<span class="log-time">${log.timestamp}</span>
|
| 99 |
+
<span class="log-message">${log.message}</span>
|
| 100 |
+
</div>`).join('');
|
| 101 |
+
}
|
| 102 |
+
this._set('logStatus', `Streaming — ${this.logEventCount} events`);
|
| 103 |
+
|
| 104 |
+
// Footer time
|
| 105 |
+
this._set('footerTime', new Date().toUTCString());
|
| 106 |
}
|
| 107 |
|
| 108 |
+
_set(id, value) {
|
| 109 |
+
const el = document.getElementById(id);
|
| 110 |
+
if (el) el.textContent = value;
|
|
|
|
|
|
|
| 111 |
}
|
| 112 |
|
| 113 |
+
_width(id, pct) {
|
| 114 |
+
const el = document.getElementById(id);
|
| 115 |
+
if (el) el.style.width = pct + '%';
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
}
|
| 117 |
|
| 118 |
+
recalibrate() {
|
| 119 |
+
this.recalCount++;
|
| 120 |
+
this.addLog(`Manual recalibration #${this.recalCount} triggered`, 'optimize');
|
| 121 |
+
const logEl = document.getElementById('recalLog');
|
| 122 |
+
if (logEl) {
|
| 123 |
+
logEl.style.display = 'block';
|
| 124 |
+
logEl.textContent = `Recalibration #${this.recalCount} — ${new Date().toLocaleTimeString()} — convergence boosted to ${(this.metrics.convergenceRate * 1.005).toFixed(4)}`;
|
| 125 |
+
}
|
| 126 |
+
setTimeout(() => {
|
| 127 |
+
this.metrics.convergenceRate = Math.min(this.metrics.convergenceRate * 1.005, 0.9999);
|
| 128 |
+
this.addLog(`Recalibration #${this.recalCount} complete — Convergence: ${(this.metrics.convergenceRate * 100).toFixed(2)}%`, 'success');
|
| 129 |
+
}, 1500);
|
|
|
|
|
|
|
|
|
|
| 130 |
}
|
| 131 |
|
| 132 |
+
reset() {
|
| 133 |
+
this.phiCycles = 0;
|
| 134 |
+
this.corrections = 0;
|
| 135 |
+
this.recalCount = 0;
|
| 136 |
+
this.logs = [];
|
| 137 |
+
this.logEventCount = 0;
|
| 138 |
+
this.metrics.convergenceRate = 0.9777;
|
| 139 |
+
this.addLog('Metrics reset to baseline', 'info');
|
| 140 |
+
this.renderUI();
|
| 141 |
}
|
| 142 |
|
| 143 |
+
clearLog() {
|
| 144 |
+
this.logs = [];
|
| 145 |
+
this.logEventCount = 0;
|
| 146 |
+
this.renderUI();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
}
|
| 148 |
}
|
| 149 |
|
| 150 |
+
// Global instance
|
| 151 |
let optimizer;
|
| 152 |
+
|
| 153 |
+
// Global handlers referenced by HTML onclick attributes
|
| 154 |
+
function triggerRecalibration() {
|
| 155 |
+
optimizer?.recalibrate();
|
| 156 |
+
}
|
| 157 |
+
function resetMetrics() {
|
| 158 |
+
optimizer?.reset();
|
| 159 |
+
}
|
| 160 |
+
function clearLog() {
|
| 161 |
+
optimizer?.clearLog();
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
document.addEventListener('DOMContentLoaded', () => {
|
| 165 |
optimizer = new FeedbackOptimizer();
|
| 166 |
optimizer.start();
|
| 167 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|