gepa-ts
Version:
TypeScript implementation of GEPA (Gradient-free Evolution of Prompts and Agents) - Complete port with 100% feature parity
42 lines • 1.55 kB
JavaScript
export class CurrentBestCandidateSelector {
select(state) {
const bestIdx = state.programFullScoresValSet.indexOf(Math.max(...state.programFullScoresValSet));
return [state.programs[bestIdx], [bestIdx]];
}
}
export class ParetoCandidateSelector {
rng;
constructor(rng) {
this.rng = rng || Math.random;
}
select(state) {
// Collect all program indices that are on the Pareto front for ANY instance
const paretoIndices = new Set();
for (const instanceParetoSet of state.programAtParetoFrontValset) {
for (const idx of instanceParetoSet) {
paretoIndices.add(idx);
}
}
if (paretoIndices.size === 0) {
// Fallback to best if no Pareto programs
return new CurrentBestCandidateSelector().select(state);
}
// Convert to array for random selection
const paretoArray = Array.from(paretoIndices);
// Randomly select from Pareto front programs
const randomIdx = Math.floor(this.rng() * paretoArray.length);
const selectedProgramIdx = paretoArray[randomIdx];
return [state.programs[selectedProgramIdx], [selectedProgramIdx]];
}
}
export class RandomCandidateSelector {
rng;
constructor(rng) {
this.rng = rng || Math.random;
}
select(state) {
const randomIdx = Math.floor(this.rng() * state.programs.length);
return [state.programs[randomIdx], [randomIdx]];
}
}
//# sourceMappingURL=candidate-selector.js.map