moeru-ai/airi · error · Error
The AR-HMM iteration count must be a positive integer.
Error message
The AR-HMM iteration count must be a positive integer.
What it means
EM fitting of the AR-HMM iterates `options.iterations` times; a count below 1 or non-integer makes the loop meaningless or impossible. The library validates this at the entry point before any fitting work.
Source
Thrown at packages/motion-driver-magic/src/ar-hmm.ts:360
for (let row = 0; row < rowCount - 1; row++) {
const values = alpha[row].flatMap((value, state) => parameters.states.map(
(_nextStateModel, nextState) => value + logTransitions[state][nextState] + emissions[row + 1][nextState] + beta[row + 1][nextState],
))
const normalization = logSumExp(values)
for (let state = 0; state < options.stateCount; state++) {
for (let nextState = 0; nextState < options.stateCount; nextState++)
transitionCounts[state][nextState] += Math.exp(values[state * options.stateCount + nextState] - normalization)
}
}
return { gamma, transitionCounts, logLikelihood }
}
/** Creates a linear Gaussian AR-HMM model with deterministic clustering and EM updates. */
export function createArHmmModel(sequence: TrainingSequence, options: FitOptions): ArHmmModel {
if (options.stateCount < 2 || !Number.isInteger(options.stateCount))
throw new Error('The AR-HMM state count must be an integer greater than one.')
if (options.iterations < 1 || !Number.isInteger(options.iterations))
throw new Error('The AR-HMM iteration count must be a positive integer.')
const sourceModel = fitVarParameters(sequence, {
order: options.order,
ridge: options.ridge,
})
const rowCount = sourceModel.trainingFrames.length - options.order
if (rowCount < options.stateCount * (sourceModel.featureCount + 1))
throw new Error('The current motion is too short for this AR-HMM shape.')
const clusterFeatures = createClusterFeatures(sourceModel.trainingFrames, options.order)
const assignments = initializeAssignments(clusterFeatures, options.stateCount)
let expectation = createInitialExpectations(assignments, options.stateCount)
let stateParameters = maximizeParameters(sourceModel, expectation, options)
const logLikelihoods: number[] = []
for (let iteration = 0; iteration < options.iterations; iteration++) {
expectation = expectationStep(sourceModel, stateParameters, options)
logLikelihoods.push(expectation.logLikelihood)
stateParameters = maximizeParameters(sourceModel, expectation, options)View on GitHub (pinned to 9c213115f8)
Solutions
- Pass an integer `iterations >= 1`.
- Coerce computed values: `Math.max(1, Math.round(budget / costPerIteration))`.
- Validate the options object with a schema (integer, minimum 1) before calling.
- Use the documented default iterations instead of a hand-computed value when unsure.
Example fix
// before
createArHmmModel(seq, { stateCount: 3, iterations: 0 })
// after
createArHmmModel(seq, { stateCount: 3, iterations: Math.max(1, Math.round(rawIterations)) }) Defensive patterns
Strategy: validation
Validate before calling
function isValidIterations(n: unknown): n is number {
return typeof n === 'number' && Number.isInteger(n) && n >= 1
} Try / catch
try {
const model = createArHmmModel(seq, options)
} catch (error) {
if (error instanceof Error && error.message.includes('iteration count')) {
return createArHmmModel(seq, { ...options, iterations: 10 })
}
throw error
} Prevention
- Round any computed iteration budget before passing it in.
- Validate options with a schema before calling.
- Replace magic 0 defaults with the library's documented default.
- Type the config as integer (e.g. branded type) so bad values fail at parse time.
When it happens
Trigger: Calling `createArHmmModel(seq, { iterations: 0 })`, negative values, or a non-integer (e.g. 1.5). Also when iterations is computed dynamically (e.g. scaled by a quality factor) without rounding.
Common situations: A 'fast mode' config setting iterations to 0 intending 'auto'; dividing a time budget by per-iteration cost producing a fractional count; JSON config parsed as float (e.g. 3.0 stored as 3 but 2.5 typed by hand).
Related errors
- The AR-HMM state count must be an integer greater than one.
- The current motion is too short for this AR-HMM shape.
- The motion sample rate must be positive.
- The VAR order must be a positive integer.
- mutexAcquireTimeout must be a positive finite number
AI-assisted analysis of moeru-ai/airi@9c213115f8 (2026-09-02).
Data as JSON: /api/errors/4422b0fb0e233992.
Report an issue: GitHub.