Spaces:
Running
Running
Commit ·
6272e72
1
Parent(s): 1a10fd4
fix weight loading structure
Browse files897 unmodified lines89889990090190290390490588 unmodified lines9949959969979989991000100110027 unmodified lines1010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104427 unmodified lines10721073107410751076107710781079108075 unmodified lines1156115711581159116011611162897 unmodified linesGAMMA: 0.95,LR: 0.0005,EPSILON: 1.0,EPS_MIN: 0.05,EPS_DECAY: 0.9985,TARGET_UPDATE_FREQ: 50,trainSteps: 0,totalSteps: 0,88 unmodified linesvar ph = obs.phase_onehot || [1, 0, 0, 0];var sp = obs.spillback_flags || [];var state = new Float32Array(57);for(var i=0;i<12;i++) state[i] = Math.min((ql[i]||0),1.0);for(var i=0;i<12;i++) state[12+i] = Math.min((tp[i]||0),1.0);for(var i=0;i<12;i++) state[24+i] = Math.min((ai[i]||0),1.0);for(var i=0;i<4;i++) state[36+i] = ph[i]||0;state[40] = obs.phase_elapsed_norm||0;state[41] = obs.fairness_score||0;7 unmodified linescomputeReward: function(info, prevInfo) {if (!info) return 0;var r = 0;var cleared = info.step_cleared || 0;r += cleared * 2.0;var nsQ = info.ns_queue || 0;var ewQ = info.ew_queue || 0;var totalQ = nsQ + ewQ;r -= totalQ * 0.15;r -= Math.pow(totalQ, 1.4) * 0.002;r -= Math.abs(nsQ - ewQ) * 0.03;r -= (info.avg_delay || 0) * 0.3;var los = info.los || '';if (los === 'A') r += 1.5;else if (los === 'B') r += 0.8;else if (los === 'C') r += 0.2;else if (los === 'D') r -= 0.2;else if (los === 'E') r -= 0.8;else if (los === 'F') r -= 2.0;r -= (info.step_crashes || 0) * 8.0;r -= (info.spillback_count || 0) * 0.5;var totalQ = (info.ns_queue || 0) + (info.ew_queue || 0);if (this.lastAction === 3) {r += (info.spillback_count || 0) > 3 ? 0.5 : -0.4;}if (this.lastAction === 4) {r += totalQ < 8 ? 0.3 : -0.3;}if (prevInfo && info.phase !== prevInfo.phase && cleared === 0 && totalQ < 3) r -= 0.5;if (cleared === 0 && totalQ > 5) r -= 0.3;var currentTask = document.getElementById('task-sel').value;if (this.lastAction === 1 && totalQ < 6 && currentTask === 'task_suburban_steady') r -= 3.0;return r;},27 unmodified linesthis.totalSteps++;this.rollingReward = 0.95 * this.rollingReward + 0.05 * reward;if(this.trainSteps > 5000) this.LR = 0.0001;if(this.trainSteps > 8000) this.LR = 0.00005;if (this.replay.length >= this.BATCH_SIZE) {this.trainBatch();}75 unmodified linesif (this.lastQVals) {var bestA = 0;for (var i = 1; i < 3; i++) if (this.lastQVals[i] > this.lastQVals[bestA]) bestA = i;var qNames = ['rl-q0','rl-q1','rl-q2','rl-q3','rl-q4'];qNames.forEach(function(id, i) {var e = document.getElementById(id); if (!e) return;897 unmodified lines89889990090190290390490588 unmodified lines9949959969979989991000100110027 unmodified lines1010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105327 unmodified lines10811082108310841085108610871088108975 unmodified lines1165116611671168116911701171897 unmodified linesGAMMA: 0.95,LR: 0.0005,EPSILON: 1.0,EPS_MIN: 0.08,EPS_DECAY: 0.9992,TARGET_UPDATE_FREQ: 50,trainSteps: 0,totalSteps: 0,88 unmodified linesvar ph = obs.phase_onehot || [1, 0, 0, 0];var sp = obs.spillback_flags || [];var state = new Float32Array(57);for(var i=0;i<12;i++) state[i] = Math.min((ql[i]||0)/15.0, 1.0);for(var i=0;i<12;i++) state[12+i] = Math.min((tp[i]||0)/8.0, 1.0);for(var i=0;i<12;i++) state[24+i] = Math.min((ai[i]||0)/5.0, 1.0);for(var i=0;i<4;i++) state[36+i] = ph[i]||0;state[40] = obs.phase_elapsed_norm||0;state[41] = obs.fairness_score||0;7 unmodified linescomputeReward: function(info, prevInfo) {if (!info) return 0;var r = 0;var cleared = info.step_cleared || 0;var nsQ = info.ns_queue || 0;var ewQ = info.ew_queue || 0;var totalQ = nsQ + ewQ;var delay = info.avg_delay || 0;var crashes = info.step_crashes || 0;var spill = info.spillback_count || 0;// Primary signal: throughputr += cleared * 3.0;// Penalise waiting vehicles — mild, linearr -= totalQ * 0.08;// Penalise delay strongly — this is the HCM objectiver -= delay * 0.4;// Penalise imbalance — encourages fair servicer -= Math.abs(nsQ - ewQ) * 0.05;// Safetyr -= crashes * 10.0;// Spillbackr -= spill * 0.3;// LOS bonus/penalty — small, to guide but not dominatevar los = info.los || '';if (los === 'A') r += 1.0;else if (los === 'B') r += 0.5;else if (los === 'C') r += 0.0;else if (los === 'D') r -= 0.5;else if (los === 'E') r -= 1.2;else if (los === 'F') r -= 2.5;// Penalise needless phase switches (action=1) when queues are shortif (this.lastAction === 1 && totalQ < 4) r -= 1.5;return r;},27 unmodified linesthis.totalSteps++;this.rollingReward = 0.95 * this.rollingReward + 0.05 * reward;if(this.trainSteps > 15000) this.LR = 0.0002;if(this.trainSteps > 25000) this.LR = 0.0001;if (this.replay.length >= this.BATCH_SIZE) {this.trainBatch();}75 unmodified linesif (this.lastQVals) {var bestA = 0;for (var i = 1; i < 5; i++) if (this.lastQVals[i] > this.lastQVals[bestA]) bestA = i;var qNames = ['rl-q0','rl-q1','rl-q2','rl-q3','rl-q4'];qNames.forEach(function(id, i) {var e = document.getElementById(id); if (!e) return;
app/viz/dashboard.py+46-37