{"record":{"id":"6de025e7afc0c0ef","repo":"moeru-ai/airi","slug":"every-motion-frame-must-have-the-same-number-of-va","errorCode":null,"errorMessage":"Every motion frame must have the same number of values.","messagePattern":"Every motion frame must have the same number of values\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/motion-driver-magic/src/shared/var.ts","lineNumber":81,"sourceCode":"    const feature = createAutoregressiveFeature(frames, order, channelCount, frameIndex)\n    const prediction = predictAutoregressiveValues(coefficients, feature)\n    residuals.push(frames[frameIndex].map((value, channel) => value - prediction[channel]))\n  }\n  return residuals\n}\n\n/** Fits the VAR parameters that both public methods use. */\nexport function fitVarParameters(sequence: TrainingSequence, options: VarFitOptions): VarParameters {\n  if (!Number.isFinite(sequence.sampleRateHz) || sequence.sampleRateHz <= 0)\n    throw new Error('The motion sample rate must be positive.')\n  if (options.order < 1 || !Number.isInteger(options.order))\n    throw new Error('The VAR order must be a positive integer.')\n\n  const frames = sequence.frames\n  if (frames.length === 0 || frames[0].length === 0)\n    throw new Error('The motion sequence must contain at least one value.')\n  if (frames.some(frame => frame.length !== frames[0].length))\n    throw new Error('Every motion frame must have the same number of values.')\n\n  const channels = createMotionChannels(frames)\n  if (channels.length === 0)\n    throw new Error('The current motion has no changing channels.')\n  if (frames.length <= options.order + 1)\n    throw new Error('The current motion is too short for this VAR order.')\n\n  const baselineFrame = createBaselineFrame(frames)\n  const trainingFrames = frames.map(frame => channels.map(\n    channel => (frame[channel.valueIndices[0]] - channel.mean) / channel.scale,\n  ))\n  const coefficients = fitCoefficients(trainingFrames, options)\n  const residuals = createResiduals(trainingFrames, coefficients, options.order)\n  const squaredResidualSum = residuals.reduce(\n    (sum, residual) => sum + residual.reduce((channelSum, value) => channelSum + value ** 2, 0),\n    0,\n  )\n","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/moeru-ai/airi/blob/9c213115f8bd0fff9e6eabab02b077ac32da21be/packages/motion-driver-magic/src/shared/var.ts#L63-L99","documentation":"fitVarParameters fits vector-autoregressive parameters to a motion sequence, treating each column of the frame matrix as a channel. It requires a rectangular frame matrix; every frame must supply the same number of scalar values. It throws this error when any frame's length differs from the first frame's length, because ragged input would silently misalign channels.","triggerScenarios":"Calling fitVarParameters (directly or via sourceModel/parameters) with a sequence whose frames array contains arrays of differing lengths, e.g. mixing poses with different joint counts or appending a partial frame.","commonSituations":"Importing motion data from heterogeneous sources where some frames carry extra or missing channels; concatenating clips recorded with different skeletons; hand-building test sequences with typos in frame lengths.","solutions":["Inspect sequence.frames and find frames whose .length differs from frames[0].length; correct or drop them","Normalize all frames through the same extraction pipeline so each frame maps to the same fixed set of values","Pad or trim frames to a fixed dimensionality before fitting (documenting which values are padded)","Add a validation step upstream that rejects ragged frame matrices before calling fitVarParameters"],"exampleFix":"// before\nconst frames = [[0, 1, 2], [0, 1]] // ragged\nfitVarParameters({ frames, ... }, options)\n// after\nconst frames = [[0, 1, 2], [3, 4, 5]] // all frames same length\nfitVarParameters({ frames, ... }, options)","handlingStrategy":"validation","validationCode":"function isRectangular(frames: number[][]): boolean {\n  return frames.length > 0 && frames.every(f => f.length === frames[0].length)\n}\nif (!isRectangular(sequence.frames)) throw new Error('Frames must all have the same length')","typeGuard":"function isNumberMatrix(v: unknown): v is number[][] {\n  return Array.isArray(v) && v.length > 0 && v.every(f => Array.isArray(f) && f.length === v[0].length && f.every(n => typeof n === 'number'))\n}","tryCatchPattern":"try {\n  const params = fitVarParameters(sequence, options)\n} catch (e) {\n  if (e instanceof Error && e.message === 'Every motion frame must have the same number of values.') {\n    // report which frame lengths are present and resample/repair\n  } else throw e\n}","preventionTips":["Build frames through a single extraction function that always emits a fixed-length vector","Assert frame dimensionality in tests for every motion source you ingest","Log frames.filter(f => f.length !== frames[0].length).length in preprocessing pipelines","Reject ragged clips at import time instead of at fit time"],"tags":["validation","motion-data","var"],"backgroundTag":"ragged-motion-frames","analyzedSha":"9c213115f8bd0fff9e6eabab02b077ac32da21be","analyzedAt":"2026-09-02T04:27:24.639Z","contentChangedAt":"2026-09-02T04:27:24.639Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}