Skip to content

oracular / predict

Function: predict() ​

ts
function predict(
   state, 
   intent, 
   at, 
   opts?
): Prediction;

Defined in: predict.ts:29

The intent's current estimate at time at: the Beta mean p, its standard deviation, the lower confidence bound that shouldReveal tests, and the cooldown status. Read-only: the stored state is decayed to at for the reading but not changed.

Parameters ​

ParameterTypeDescription
stateEngineStateThe current state. Not mutated.
intentstringName of an intent declared in the config.
atnumberThe time to evaluate at, in the same unit as your durations.
opts?RevealOptionsOverrides for threshold, z, cooldown and bound, resolved as call → intent → engine → defaults. z and bound set lower; cooldown sets revealed and suppressedUntil; threshold only matters to shouldReveal.

Returns ​

Prediction

The prediction. p, sd, lower and confidence are in [0, 1]; evidence is α + β.

Throws ​

RangeError when intent is not declared in the config.

Throws ​

TypeError when state is not an engine state, at is not finite, or opts is malformed.

Example ​

ts
const { p, lower, suppressedUntil } = predict(state, 'upgrade', Date.now());
if (suppressedUntil !== null) scheduleNextCheck(suppressedUntil);

Released under the MIT License.