@hackbuild/agents-views 0.2.12 → 0.2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/yard/scope.js +87 -62
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -176,6 +176,6 @@ Changes are in the repository [CHANGELOG](../../CHANGELOG.md). Code is MIT ([LIC
|
|
|
176
176
|
| `dist/index.js` (main entry, imports external) | 6,346 bytes | 6,663 bytes |
|
|
177
177
|
| `dist/agents-views.iife.js` (single file build) | 6,512 bytes | 6,837 bytes |
|
|
178
178
|
|
|
179
|
-
Measured 2026-12-
|
|
179
|
+
Measured 2026-12-03 by `node tools/lint-packages.mjs` (gzip level 9) from the packed
|
|
180
180
|
tarball. Generated from `tools/size-budget.json`; CI fails when a file moves more than
|
|
181
181
|
5 percent from its row.
|
package/dist/yard/scope.js
CHANGED
|
@@ -2013,6 +2013,8 @@ function micTick(dt) { if (!micAn) return; micAn.getFloatTimeDomainData(micBuf);
|
|
|
2013
2013
|
// ---- yard/io/speech.js
|
|
2014
2014
|
// ---------- speech ----------
|
|
2015
2015
|
const ACTIONS = ['sit', 'down', 'come', 'stay', 'spin', 'speak', 'paw', 'fetch', 'bed'];
|
|
2016
|
+
// the acts the dog offers on its own: not fetch, bed or come
|
|
2017
|
+
const LEARN_OFFER = ACTIONS.filter(a => a !== 'fetch' && a !== 'bed' && a !== 'come');
|
|
2016
2018
|
const SYN = { 'lie': 'down', 'lay': 'down', 'here': 'come', 'come here': 'come', 'roll': 'spin', 'turn': 'spin', 'bark': 'speak', 'shake': 'paw', 'go to bed': 'bed', 'bedtime': 'bed', 'get it': 'fetch', 'ball': 'fetch' };
|
|
2017
2019
|
function handleSpeech(text) {
|
|
2018
2020
|
const s = text.toLowerCase().replace(/[^a-z ]/g, ' ').trim(); if (!s) return;
|
|
@@ -2072,7 +2074,7 @@ const brain = {
|
|
|
2072
2074
|
cur: 'idle', t: 0, sub: '', subT: 0, v: 0.25, a: 0.35,
|
|
2073
2075
|
d: { hunger: 0.35, fatigue: 0.15, play: 0.5, social: 0.4, curiosity: 0.5, prey: 0 },
|
|
2074
2076
|
util: {}, goal: null, goalT: 0, cmd: null, trial: null, sayT: 0, line: '...',
|
|
2075
|
-
W: {}, N: {}, al: {}, offer: {},
|
|
2077
|
+
W: {}, N: {}, al: {}, offer: {}, mem: [], imp: 0, visits: new Map(), barkT: 0, startle: 0, sleepWake: 0,
|
|
2076
2078
|
bond: 0.5, Sp: 0.25, stage: 'awake', hyp: [], pending: null, dwell: 0, done: false, begRel: { n: 2, ok: 1 }, prevD: {}, negT: -99,
|
|
2077
2079
|
speedMul() { return (this.cur === 'sleep' ? 0.6 : 1) * (1 - this.d.fatigue * 0.35) * (this.v < -0.3 ? 0.85 : 1) * (ON('L.organic') ? 1 + 0.08 * PT('activity') : 1); },
|
|
2078
2080
|
init() {
|
|
@@ -2080,6 +2082,8 @@ const brain = {
|
|
|
2080
2082
|
if (saved && saved.W) { this.W = saved.W; this.N = saved.N || {}; this.al = saved.al || {}; this.offer = saved.offer || {}; this.bond = saved.bond ?? 0.5; }
|
|
2081
2083
|
else if (saved && !saved.W) this.W = saved; else this.seed();
|
|
2082
2084
|
for (const c in this.W) this.ensure(c);
|
|
2085
|
+
for (const a of ACTIONS) this.offer[a] ??= 0.15;
|
|
2086
|
+
this.loadLearner();
|
|
2083
2087
|
renderCueButtons(); renderHeat();
|
|
2084
2088
|
},
|
|
2085
2089
|
persist() { store.set('W', { W: this.W, N: this.N, al: this.al, offer: this.offer, bond: this.bond }); },
|
|
@@ -2089,8 +2093,9 @@ const brain = {
|
|
|
2089
2093
|
const prior = { sit: 0.5, come: 0.55, down: 0.3, fetch: 0.35, bed: 0.15, speak: 0.12, spin: 0.08, stay: 0.2, paw: 0.08 };
|
|
2090
2094
|
for (const a of ACTIONS) { this.W[a] = Object.fromEntries(ACTIONS.map(b => [b, b === a ? prior[a] : 0.02 + RNG() * 0.03])); this.ensure(a); }
|
|
2091
2095
|
for (const a of ACTIONS) this.offer[a] = a === 'sit' ? 1 : a === 'down' ? 0.5 : 0.15;
|
|
2096
|
+
this.loadLearner();
|
|
2092
2097
|
},
|
|
2093
|
-
V(c, a) { return (this.W[c] ? this.W[c][a] : 0) - (
|
|
2098
|
+
V(c, a) { return (this.W[c] ? this.W[c][a] : 0) - (this.N[c] ? this.N[c][a] : 0); },
|
|
2094
2099
|
say(s, dur = 2.5) { if (!s) return; this.line = s; this.sayT = dur; },
|
|
2095
2100
|
remember(txt, imp) { this.mem.unshift({ t: now, h: CLOCK.day * 24 + CLOCK.h, txt, imp, ev: EV.n }); if (this.mem.length > 60) this.mem.pop(); this.imp += imp; },
|
|
2096
2101
|
set(b, why = '') {
|
|
@@ -2104,7 +2109,7 @@ const brain = {
|
|
|
2104
2109
|
motor.mode = 'stop'; motor.face = null; motor.ignore = null; dog.postureT.sit = dog.postureT.down = dog.postureT.bow = dog.postureT.reach = 0; dog.pawLift = 0;
|
|
2105
2110
|
if (dog.org) dog.org.inert.capture();
|
|
2106
2111
|
if (prev === 'sleep') { this.stage = 'awake'; SLEEP.wakeUp(); if (dog.org) dog.org.rem = 0; }
|
|
2107
|
-
|
|
2112
|
+
chooseShape(); CHOOSE.setWith(RNG, b, now); this.dwell = CHOOSE.dwellUntil;
|
|
2108
2113
|
}
|
|
2109
2114
|
},
|
|
2110
2115
|
stimulus(kind, s = 1) {
|
|
@@ -2153,40 +2158,66 @@ const brain = {
|
|
|
2153
2158
|
|
|
2154
2159
|
// ---- yard/dog/learning.js
|
|
2155
2160
|
// dog brain: cues and tricks. A cue starts a trial, an offered trick waits for a reward, and the
|
|
2156
|
-
// reward updates the cue to action values through an eligibility trace.
|
|
2161
|
+
// reward updates the cue to action values through an eligibility trace. The table, the trace and the
|
|
2162
|
+
// offer history are the library's CueLearner, stepped on the yard's stream (RNG); brain.W, N, al and
|
|
2163
|
+
// offer are read only copies for the panels, refreshed after every change.
|
|
2164
|
+
let LEARN = null;
|
|
2165
|
+
ENV.dispose(() => LEARN && LEARN.free());
|
|
2166
|
+
const learnShape = () => LEARN.configure({
|
|
2167
|
+
alpha: TV('Ln.alpha'), theta: TV('Ln.theta'), traceSeconds: TV('Ln.trace'), inhibitionDecay: TV('Ln.inhib'), offerRate: TV('Ln.offer'),
|
|
2168
|
+
ignore: TV('Br.ignore'), cueMu: TV('Br.cueMu'), cueTau: TV('Br.cueTau'), noise: ON('L.noise'), refusals: ON('L.organic'),
|
|
2169
|
+
});
|
|
2157
2170
|
Object.assign(brain, {
|
|
2171
|
+
// a fresh learner holding brain.W, N, al and offer as they stand
|
|
2172
|
+
loadLearner() {
|
|
2173
|
+
if (LEARN) LEARN.free();
|
|
2174
|
+
LEARN = new HDRIVE.CueLearner({ rng: () => 0.5, actions: ACTIONS }); learnShape();
|
|
2175
|
+
LEARN.load({ ver: 1, cues: Object.fromEntries(Object.keys(this.W).map(c => [c, { w: this.W[c], n: this.N[c], associability: this.al[c] }])), offer: this.offer });
|
|
2176
|
+
this.syncLearn();
|
|
2177
|
+
},
|
|
2178
|
+
// the copies have no prototype, so a word such as constructor or __proto__ is an ordinary cue
|
|
2179
|
+
syncLearn() {
|
|
2180
|
+
const s = LEARN.toJSON(), W = Object.create(null), N = Object.create(null), al = Object.create(null);
|
|
2181
|
+
for (const c of Object.keys(s.cues)) { const r = s.cues[c]; W[c] = r.w; N[c] = r.n; al[c] = r.associability; }
|
|
2182
|
+
this.W = W; this.N = N; this.al = al;
|
|
2183
|
+
Object.assign(this.offer, s.offer);
|
|
2184
|
+
},
|
|
2158
2185
|
cue(word) {
|
|
2159
2186
|
if (!word) return;
|
|
2160
2187
|
word = word.toLowerCase().slice(0, 18);
|
|
2161
2188
|
const cueEv = EV.emit({ agent: 'dog', kind: 'cue', text: 'heard "' + word + '"' });
|
|
2162
|
-
if (!this.W[word]) {
|
|
2189
|
+
if (!this.W[word]) { learnShape(); LEARN.ensureWith(RNG, word); this.syncLearn(); renderCueButtons(); }
|
|
2163
2190
|
if (this.cur === 'sleep') this.wake('heard "' + word + '"');
|
|
2164
2191
|
const tr = ON('L.organic') ? PT('trainability') : 0;
|
|
2165
2192
|
const distract = this.d.prey * 1.5 + (this.cur === 'chase' ? 1 : 0) + (this.attn > now ? -0.4 : 0) - tr * 0.12;
|
|
2166
2193
|
// everyday non compliance is high (Browne: 44 percent of sit and down ignored); more when he is not watching
|
|
2167
|
-
const watched = HUM.lookingAtDog || (HUM.task && HUM.task.name === 'train');
|
|
2168
|
-
|
|
2194
|
+
const watched = !!(HUM.lookingAtDog || (HUM.task && HUM.task.name === 'train'));
|
|
2195
|
+
// an ignored cue still counts as a trial for massed practice; noise off is the canned path, with no refusals.
|
|
2196
|
+
// then a Gumbel draw per act against a bar raised by distraction; nothing strong: offer something it has been
|
|
2197
|
+
// rewarded for before (free operant history); then the latency
|
|
2198
|
+
learnShape();
|
|
2199
|
+
const res = LEARN.respondWith(RNG, word, now, { distraction: distract, trainability: tr, watched, offerable: LEARN_OFFER });
|
|
2200
|
+
if (res.kind === 'ignored') {
|
|
2169
2201
|
this.trial = { cue: word, action: 'ignored', t0: now, done: now, rewarded: false, ev: cueEv }; dog.earPerk = Math.max(dog.earPerk, 0.5); this.say(pick(['...', 'hm?', '']), 1); renderHeat(word, null); return;
|
|
2170
2202
|
}
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
// nothing strong: offer something it has been rewarded for before (free operant history), or a random guess
|
|
2174
|
-
if (best === 'none' && RNG() < 0.5 && distract < 0.8) { best = ON('L.learn') ? this.sampleOffer() : pick(['sit', 'down', 'spin', 'speak', 'paw', 'come']); this.say('this?', 2); }
|
|
2203
|
+
const best = res.kind === 'act' ? res.action : 'none';
|
|
2204
|
+
if (res.kind === 'act' && res.offered) this.say('this?', 2);
|
|
2175
2205
|
this.trial = { cue: word, action: best, t0: now, done: null, rewarded: false, ev: cueEv };
|
|
2176
2206
|
dog.postureT.sit = dog.postureT.down = dog.postureT.bow = dog.postureT.reach = 0; dog.pawLift = 0; motor.mode = 'stop';
|
|
2177
|
-
const lat =
|
|
2207
|
+
const lat = res.latency;
|
|
2178
2208
|
const go = () => {
|
|
2179
2209
|
this.kindNext = 'cue'; this.causeNext = cueEv;
|
|
2180
2210
|
if (best === 'none') { this.set('confused', 'did not understand "' + word + '"'); this.cmd = { action: 'none', t: 0 }; }
|
|
2181
2211
|
else { this.cmd = { action: best, t: 0, cue: word }; this.set('obey', '"' + word + '" means ' + best + ' (V=' + this.V(word, best).toFixed(2) + ', latency ' + Math.round(lat * 1000) + ' ms)'); }
|
|
2182
|
-
this.trace.unshift({ cue: word, action: best, t: now, done: null }); if (this.trace.length > 8) this.trace.pop();
|
|
2183
2212
|
};
|
|
2184
2213
|
this.pending = null; if (lat > 0.05) { this.pending = { fn: go, at: now + lat, look: V3(YOU.x, 1.5, YOU.z), b: best === 'none' ? 'confused' : 'obey' }; dog.earPerk = 1; } else go();
|
|
2185
2214
|
renderHeat(word, best);
|
|
2186
2215
|
},
|
|
2187
|
-
sampleOffer() {
|
|
2216
|
+
sampleOffer() { learnShape(); return LEARN.sampleOfferWith(RNG, LEARN_OFFER) ?? 'sit'; },
|
|
2188
2217
|
// a trick the dog does on its own (free operant): reward can later attach it to whatever cue the human says
|
|
2189
|
-
offerTrick(a) { this.offered = { a, t: now };
|
|
2218
|
+
offerTrick(a) { this.offered = { a, t: now }; LEARN.offerTrick(a, now); },
|
|
2219
|
+
// the act a cue started finished: its trial in the trace is done, so its credit ages from now
|
|
2220
|
+
trialDone(action) { if (ACTIONS.includes(action)) LEARN.markDone(action, now); },
|
|
2190
2221
|
reward(r, src) {
|
|
2191
2222
|
EV.emit({ agent: 'dog', kind: 'reward', text: (r > 0 ? 'got ' : 'was told off: ') + src + ' (' + (r > 0 ? '+' : '') + r.toFixed(1) + ')', cause: this.trial && now - this.trial.t0 < 25 ? this.trial.ev : null });
|
|
2192
2223
|
this.v = clamp(this.v + 0.3 * r, -1, 1); this.a = clamp(this.a + 0.12 * Math.abs(r), 0, 1);
|
|
@@ -2195,10 +2226,12 @@ Object.assign(brain, {
|
|
|
2195
2226
|
if (ON('L.learn')) this.learnTrace(r, src);
|
|
2196
2227
|
else {
|
|
2197
2228
|
const tr = this.trial;
|
|
2198
|
-
if (tr && !tr.rewarded && tr.action !== 'none' && now - (tr.done || now) < 4.5 && now - tr.t0 < 25) {
|
|
2229
|
+
if (tr && !tr.rewarded && tr.action !== 'none' && tr.action !== 'ignored' && now - (tr.done || now) < 4.5 && now - tr.t0 < 25) {
|
|
2199
2230
|
const row = this.W[tr.cue], alpha = 0.35 * Math.abs(r);
|
|
2200
2231
|
if (r > 0) { row[tr.action] += alpha * (1 - row[tr.action]); for (const a of ACTIONS) if (a !== tr.action) row[a] -= alpha * 0.25 * row[a]; }
|
|
2201
2232
|
else row[tr.action] += alpha * (0 - row[tr.action]);
|
|
2233
|
+
for (const a of ACTIONS) LEARN.prior(tr.cue, a, row[a]);
|
|
2234
|
+
this.syncLearn();
|
|
2202
2235
|
tr.rewarded = true; this.persist(); renderHeat(tr.cue, tr.action);
|
|
2203
2236
|
$('heard').textContent = (r > 0 ? 'learned: ' : 'unlearned: ') + '"' + tr.cue + '" -> ' + tr.action + ' = ' + row[tr.action].toFixed(2);
|
|
2204
2237
|
}
|
|
@@ -2208,32 +2241,21 @@ Object.assign(brain, {
|
|
|
2208
2241
|
// a scolding from the human brings the appeasement set, keyed to the human's posture, not to any misdeed (Horowitz 2009)
|
|
2209
2242
|
if (r < 0 && ON('L.social') && (src === 'no' || src === 'scold') && this.cur !== 'sleep' && (r <= -0.7 || RNG() < 0.2 + 0.25 * PT('fearfulness'))) this.force('appease', 2.5);
|
|
2210
2243
|
},
|
|
2211
|
-
// eligibility traces plus Pearce Kaye Hall associability: credit fades with delay, so a late treat can teach the wrong thing
|
|
2244
|
+
// eligibility traces plus Pearce Kaye Hall associability: credit fades with delay, so a late treat can teach the wrong thing.
|
|
2245
|
+
// spaced beats massed practice (Meyer and Ladewig 2008, Demant 2011): many recent trials damp the learning rate.
|
|
2246
|
+
// the most recent eligible pair takes the credit
|
|
2212
2247
|
learnTrace(r, src) {
|
|
2213
|
-
|
|
2214
|
-
const
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
if (e.cue) {
|
|
2222
|
-
this.ensure(e.cue); const Vv = this.V(e.cue, e.action), al = this.al[e.cue], k = base * al * w * Math.abs(r); const tap = { cue: e.cue, action: e.action, before: Vv, credit: w, r, src, t: now, age };
|
|
2223
|
-
if (lam > Vv) { this.W[e.cue][e.action] = clamp(this.W[e.cue][e.action] + k * (lam - Vv), 0, 1.2); for (const a of ACTIONS) if (a !== e.action) this.W[e.cue][a] *= 1 - k * 0.15; }
|
|
2224
|
-
else this.N[e.cue][e.action] = clamp(this.N[e.cue][e.action] + k * (Vv - lam), 0, 1.2);
|
|
2225
|
-
this.al[e.cue] = clamp((1 - th) * al + th * Math.abs(lam - Vv), 0.05, 1);
|
|
2226
|
-
txt = (r > 0 ? 'learned: ' : 'unlearned: ') + '"' + e.cue + '" -> ' + e.action + ' V=' + this.V(e.cue, e.action).toFixed(2) + ' (credit ' + Math.round(w * 100) + '%)';
|
|
2227
|
-
tap.after = this.V(e.cue, e.action); this.lastLearn = tap;
|
|
2228
|
-
renderHeat(e.cue, e.action);
|
|
2229
|
-
}
|
|
2230
|
-
this.offer[e.action] = clamp((this.offer[e.action] || 0.1) + (r > 0 ? 0.25 : -0.15) * w * TV('Ln.offer'), 0, 3);
|
|
2231
|
-
e.credited = true; any = true;
|
|
2232
|
-
if (this.trial && this.trial.cue === e.cue && this.trial.action === e.action) this.trial.rewarded = true;
|
|
2233
|
-
break; // the most recent eligible pair takes the credit
|
|
2248
|
+
learnShape();
|
|
2249
|
+
const c = LEARN.reward(r, now, PT('trainability'));
|
|
2250
|
+
if (!c) return;
|
|
2251
|
+
this.syncLearn();
|
|
2252
|
+
if (c.cue) {
|
|
2253
|
+
this.lastLearn = { cue: c.cue, action: c.action, before: c.before, credit: c.credit, r, src, t: now, age: c.age, after: c.value };
|
|
2254
|
+
renderHeat(c.cue, c.action);
|
|
2255
|
+
$('heard').textContent = (r > 0 ? 'learned: ' : 'unlearned: ') + '"' + c.cue + '" -> ' + c.action + ' V=' + c.value.toFixed(2) + ' (credit ' + Math.round(c.credit * 100) + '%)';
|
|
2234
2256
|
}
|
|
2235
|
-
if (
|
|
2236
|
-
|
|
2257
|
+
if (this.trial && this.trial.cue === c.cue && this.trial.action === c.action) this.trial.rewarded = true;
|
|
2258
|
+
this.persist();
|
|
2237
2259
|
},
|
|
2238
2260
|
});
|
|
2239
2261
|
|
|
@@ -2287,7 +2309,8 @@ Object.assign(brain, {
|
|
|
2287
2309
|
this.a += ((0.25 + d.play * 0.3 + d.prey * 0.4 - (this.cur === 'sleep' ? 0.25 : 0)) - this.a) * dt * 0.15;
|
|
2288
2310
|
dog.earPerk += ((this.a - 0.4) * 1.2 - dog.earPerk) * dt * 1.5;
|
|
2289
2311
|
dog.hop = Math.max(0, dog.hop - dt * 0.12); this.startle = Math.max(0, this.startle - dt);
|
|
2290
|
-
|
|
2312
|
+
// inhibition decays per minute, faster than excitation
|
|
2313
|
+
if (ON('L.learn') && LEARN) { learnShape(); LEARN.decay(dt); this.syncLearn(); }
|
|
2291
2314
|
// bond: mutual gaze, praise and touch raise it (MacLean and Hare 2015), it decays very slowly
|
|
2292
2315
|
if (ON('L.social')) {
|
|
2293
2316
|
const youH = humHead(tmpV[6]); const hf = headForward(tmpV[7]); const toY = youH.clone().sub(headWorld(dog.eyeL, V3())).normalize();
|
|
@@ -2334,7 +2357,16 @@ Object.assign(brain, {
|
|
|
2334
2357
|
|
|
2335
2358
|
// ---- yard/dog/choice.js
|
|
2336
2359
|
// dog brain: choice. Each behaviour gets a utility from drives, percepts and learning; the choice keeps
|
|
2337
|
-
// one long enough to finish, and records why.
|
|
2360
|
+
// one long enough to finish, and records why. The sampled choice, its dwell and its latencies are the
|
|
2361
|
+
// library's Chooser, stepped on the yard's stream (RNG) so the draw order stays; the yard keeps its
|
|
2362
|
+
// pending switch (it also carries the cue's go function and where the head looks) and the canned
|
|
2363
|
+
// argmax path, whose line is drawn before its dwell.
|
|
2364
|
+
const CHOOSE = new HDRIVE.Chooser({ rng: () => 0.5, options: BEH });
|
|
2365
|
+
ENV.dispose(() => CHOOSE.free());
|
|
2366
|
+
const chooseShape = () => CHOOSE.configure({
|
|
2367
|
+
temperature: TV('Br.temp'), commitment: TV('Br.commit') * (1 + 0.35 * PT('independence')), dwellMu: TV('Br.dwellMu'), dwellTau: TV('Br.dwellTau'),
|
|
2368
|
+
reactMu: TV('Br.reactMu'), reactTau: TV('Br.reactTau'), reactScale: 1 - 0.12 * PT('reactivity'), sample: ON('L.sample'), noise: ON('L.noise'),
|
|
2369
|
+
});
|
|
2338
2370
|
Object.assign(brain, {
|
|
2339
2371
|
utilities() {
|
|
2340
2372
|
const U = this.util, d = this.d, org = ON('L.organic');
|
|
@@ -2396,25 +2428,18 @@ Object.assign(brain, {
|
|
|
2396
2428
|
if (this.pending) { if (now >= this.pending.at) { const p = this.pending; this.pending = null; if (p.fn) p.fn(); else { this.kindNext = p.kind; this.causeNext = p.ev; this.set(p.b, p.why); } } return; }
|
|
2397
2429
|
let best = 'idle', bv = -1; for (const b of BEH) if (U[b] > bv) { bv = U[b]; best = b; }
|
|
2398
2430
|
if (!ON('L.sample')) { U[this.cur] += 0.12; if (U[this.cur] >= bv) best = this.cur; if (best !== this.cur) { this.lastChoice = { at: now, U: Object.assign({}, U), cur: this.cur, best, picked: best, path: 'argmax' }; this.kindNext = 'top'; this.causeNext = this.choiceEv(best, whyOf(best), 'top'); this.set(best, whyOf(best)); } return; }
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
const
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
let tot = ex.reduce((s, x) => s + x[1], 0), r = RNG() * tot, pickB = best; for (const [b, w] of ex) if ((r -= w) <= 0) { pickB = b; break; }
|
|
2412
|
-
this.dwell = now + ORG.exg(TV('Br.dwellMu'), 1, TV('Br.dwellTau'));
|
|
2413
|
-
if (pickB !== this.cur) this.pending = { b: pickB, why: whyOf(pickB) + (pickB !== best ? ', took a lower scored option this time' : ''), at: now + lat(0.6), look: this.causeOf(pickB) };
|
|
2414
|
-
else this.done = false;
|
|
2415
|
-
this.lastChoice = { at: now, U: Object.assign({}, U), cur: this.cur, curU, commit, T, probs: Object.fromEntries(ex.map(([b, w]) => [b, w / tot])), best, picked: pickB, path: 'sample' };
|
|
2416
|
-
if (pickB !== this.cur) { const P = this.pending; P.kind = pickB !== best ? 'sampled' : 'top'; this.lastChoice.lat = P.at - now; P.ev = this.choiceEv(pickB, P.why, P.kind, P.at - now); }
|
|
2417
|
-
}
|
|
2431
|
+
chooseShape();
|
|
2432
|
+
CHOOSE.dwellUntil = this.dwell; if (this.done) CHOOSE.markDone();
|
|
2433
|
+
const d = CHOOSE.updateWith(RNG, now, U, REACTIVE, this.forced && this.forced.until > now ? this.forced.b : undefined);
|
|
2434
|
+
this.dwell = CHOOSE.dwellUntil; this.done = CHOOSE.done;
|
|
2435
|
+
// react: something much better that cannot wait starts after a short heavy tailed latency, while the head already turns to it.
|
|
2436
|
+
// otherwise it chose only because the act is done or its dwell ran out: a sample, so the best option usually but not always wins
|
|
2437
|
+
if (!d.pending) return;
|
|
2438
|
+
CHOOSE.cancel();
|
|
2439
|
+
const b = d.pending.id, kind = d.reason === 'reactive' ? 'react' : d.reason;
|
|
2440
|
+
const P = this.pending = { b, why: whyOf(b) + (kind === 'sampled' ? ', took a lower scored option this time' : ''), at: d.pending.at, look: this.causeOf(b), kind };
|
|
2441
|
+
this.lastChoice = { at: now, U: Object.assign({}, U), cur: this.cur, best: d.best, picked: b, path: kind === 'react' || kind === 'forced' ? 'react' : 'sample', p: d.probability, lat: P.at - now };
|
|
2442
|
+
P.ev = this.choiceEv(b, P.why, kind, P.at - now);
|
|
2418
2443
|
},
|
|
2419
2444
|
// the sense event a choice answers: the newest sighting of the thing causeOf() turns the head to
|
|
2420
2445
|
causeKey(b) { return ({ fetch: 'ball', chase: 'squirrel', greet: 'you', beg: 'you', playbow: 'you', obey: 'you', eat: 'bowl', treat: 'treat', sniff: 'scent', investigate: 'point' })[b] || null; },
|
|
@@ -2561,7 +2586,7 @@ Object.assign(brain, {
|
|
|
2561
2586
|
},
|
|
2562
2587
|
obey(dt, youP, youHead) {
|
|
2563
2588
|
const c = this.cmd, P = dog.postureT; if (!c) { this.done = true; return; } c.t += dt;
|
|
2564
|
-
const finish = (hold = 6) => { if (this.trial && !this.trial.done) { this.trial.done = now;
|
|
2589
|
+
const finish = (hold = 6) => { if (this.trial && !this.trial.done) { this.trial.done = now; this.trialDone(c.action); this.say(pick(LINES.obey), 1.8); } if (c.t > hold) { this.cmd = null; this.done = true; } };
|
|
2565
2590
|
const sitDone = () => NG.active ? (NG.guidance === 'Sit' && this.t > 1.4) : dog.posture.sit > 0.85, downDone = () => NG.active ? (NG.guidance === 'Lie' && this.t > 1.8) : dog.posture.down > 0.85;
|
|
2566
2591
|
switch (c.action) {
|
|
2567
2592
|
case 'sit': motor.mode = 'stop'; P.sit = 1; lookAt(youHead); if (sitDone()) finish(7); break;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hackbuild/agents-views",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.14",
|
|
4
4
|
"description": "Views that bind the agents packages to the hackbuild-ui class layer: the behaviour, utility and drive bars, the cues by acts associations table, the eye inset, and Yard, the dog simulator's stage and rack as one view. Each small view ships as a Vue component and as a custom element.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"@hackbuild/gait": "^0.1.0",
|
|
50
50
|
"@hackbuild/tunables": "^0.1.0",
|
|
51
51
|
"@hackbuild/senses": "0.1.5",
|
|
52
|
-
"@hackbuild/drives": "0.1.
|
|
52
|
+
"@hackbuild/drives": "0.1.8",
|
|
53
53
|
"@hackbuild/cameras": "^0.1.0",
|
|
54
54
|
"@hackbuild/weights": "^0.1.0"
|
|
55
55
|
},
|