RL-Explorer / web /js /reward-stats.js
AdithyaSK's picture
AdithyaSK HF Staff
Deploy HF RL Explorer
6abb7be verified
Raw History Blame Contribute Delete
496 Bytes
// A reward's scale belongs to its environment. Retain negative and unbounded scores.
export function rewardDistribution(values, bins = 10) {
const xs = values.filter(Number.isFinite);
const min = xs.reduce((a, x) => Math.min(a, x), 0);
const max = xs.reduce((a, x) => Math.max(a, x), 1);
const hist = Array(bins).fill(0);
for (const x of xs) hist[Math.max(0, Math.min(bins - 1, Math.floor((x - min) / (max - min) * bins)))]++;
return { hist, min, max, width: (max - min) / bins };
}