Skip to content

Instantly share code, notes, and snippets.

@malakhov-dmitrii
Created December 7, 2019 11:10
Show Gist options
  • Save malakhov-dmitrii/b3826a0f1c4ddf80d6c592a21014b39b to your computer and use it in GitHub Desktop.
Save malakhov-dmitrii/b3826a0f1c4ddf80d6c592a21014b39b to your computer and use it in GitHub Desktop.
const adjustParams = (period) => {
const iter = 10;
const incr = 1 / iter;
let bestAlpha = 0.0;
let bestError = -1;
let alpha = bestAlpha;
let bestGamma = 0.0;
let gamma = bestGamma;
let bestDelta = 0.0;
let delta = bestDelta;
while (alpha < 1) {
while (gamma < 1) {
while (delta < 1) {
const pred = this.predict(data, alpha, delta, gamma, period);
const error = this.computeMeanSquaredError(data, pred);
if (error < bestError || bestError === -1) {
bestAlpha = alpha;
bestGamma = gamma;
bestDelta = delta;
bestError = error;
}
delta += incr;
}
delta = 0;
gamma += incr;
}
gamma = 0;
alpha += incr;
}
alpha = bestAlpha;
gamma = bestGamma;
delta = bestDelta;
return {
alpha,
gamma,
delta,
bestError,
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment