oracular 0.10.0 → 0.11.0

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/dist/index.js CHANGED
@@ -77,8 +77,8 @@ function lowerBound(alpha, beta, z, bound) {
77
77
  function repeatFactor(n) {
78
78
  return Math.log1p(1 / n) / Math.LN2;
79
79
  }
80
- function laplace(successes, total) {
81
- return (successes + 1) / (total + 2);
80
+ function smoothRate(successes, total, rate) {
81
+ return (successes + 2 * rate) / (total + 2);
82
82
  }
83
83
  function lift(q, b, type = "normalized-difference") {
84
84
  if (type === "absolute-difference") return q - b;
@@ -152,12 +152,13 @@ function signalWeights(state, intent, learning, signal) {
152
152
  }
153
153
  const record2 = getOwn(state.learned, signal) ?? NONE;
154
154
  const nWith = record2.hits + record2.misses;
155
- const qWith = laplace(record2.hits, nWith);
156
155
  const totalEpisodes = state.episodes.hits + state.episodes.misses;
157
156
  const nWithout = Math.max(0, totalEpisodes - nWith);
158
157
  const outcomesWithout = Math.min(nWithout, Math.max(0, state.episodes.hits - record2.hits));
159
- const qWithout = laplace(outcomesWithout, nWithout);
160
- const baseline = learning.lift === "association-rule" ? (record2.hits + outcomesWithout + 2) / (nWith + nWithout + 4) : qWithout;
158
+ const base = totalEpisodes === 0 ? 0 : state.episodes.hits / totalEpisodes;
159
+ const qWith = smoothRate(record2.hits, nWith, base);
160
+ const qWithout = smoothRate(outcomesWithout, nWithout, base);
161
+ const baseline = learning.lift === "association-rule" ? smoothRate(record2.hits + outcomesWithout, nWith + nWithout, base) : qWithout;
161
162
  const score = learningScore(lift(qWith, baseline, learning.lift), learning.lift);
162
163
  const learned = nWith === 0 ? 0 : learning.gain * Math.abs(initial) * score;
163
164
  const nEff = nWith + nWithout === 0 ? 0 : nWith * nWithout / (nWith + nWithout);