Embryo-One's picture
Upload 49 files
ed9f15f verified
raw
history blame contribute delete
639 Bytes
/**
* Math Utilities - Mathematical helper functions
*/
/**
* Softmax function for converting logits to probabilities
*/
export function softmax(logits) {
const maxLogit = Math.max(...logits);
const scores = logits.map(l => Math.exp(l - maxLogit));
const sum = scores.reduce((a, b) => a + b);
return scores.map(s => s / sum);
}
/**
* Calculate mean of array
*/
export function mean(array) {
return array.reduce((a, b) => a + b, 0) / array.length;
}
/**
* Clamp value between min and max
*/
export function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}