UNPKG

agentfootprint

Version:

The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.

28 lines • 1.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.softmax = void 0; /** * softmax — numerically-stable softmax over raw scores. * * Used by `skillGraph().entryByRelevance(embedder)` to turn per-entry cosine * similarities into a relevance distribution (the surfaced `relevance` %): the * shares sum to 1, so they read as "how much of the match each entry owns". * Internal helper — not a public export (the public surface is `relevance`). * * `temperature > 0` sharpens (<1) or flattens (>1) the distribution; default 1. */ function softmax(scores, temperature = 1) { if (scores.length === 0) return []; const t = temperature > 0 ? temperature : 1; // Subtract the max for numerical stability (exp of large numbers overflows). const max = Math.max(...scores); const exps = scores.map((s) => Math.exp((s - max) / t)); const sum = exps.reduce((a, b) => a + b, 0); // Degenerate guard (all -Infinity / NaN): fall back to a uniform distribution. return sum > 0 && Number.isFinite(sum) ? exps.map((e) => e / sum) : scores.map(() => 1 / scores.length); } exports.softmax = softmax; //# sourceMappingURL=softmax.js.map