FanucWeb/ActiveBOWeb/src/js_funs/online_rbf_policy.js

20 lines
558 B
JavaScript
Raw Normal View History

function rbf(x, centre, sigma) {
return Math.exp(-Math.pow(x - centre, 2) / (2 * Math.pow(sigma, 2)));
}
export function computeRbfCurve(nrPoints, weights) {
const centers = Array.from(
{ length: weights.length },
(_, i) => (i * nrPoints) / (weights.length - 1)
);
const sigma = centers[1] / (2 * Math.sqrt(2 * Math.log(2)));
let policy = Array(nrPoints).fill(0);
for (let x = 0; x < nrPoints; x++) {
for (let i = 0; i < centers.length; i++) {
policy[x] += weights[i] * rbf(x, centers[i], sigma);
}
}
return policy;
}