Skip to content

Commit

Permalink
Merge pull request #29 from parea-ai/PAI-835-make-scores-accessible-a…
Browse files Browse the repository at this point in the history
…fter-experiment-is-done

feat: add individual experiment scores
  • Loading branch information
joschkabraun authored Mar 14, 2024
2 parents b04a39f + 4bb3134 commit 284f108
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/experiment/experiment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,11 @@ export class Experiment {
).parent_trace_stats,
);
}

get avgScores(): { [key: string]: number } {
if (!this.experimentStats) {
return {};
}
return this.experimentStats.avgScores;
}
}
12 changes: 12 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,18 @@ export class ExperimentStatsSchema {
this.parent_trace_stats = parent_trace_stats;
}

get avgScores(): { [key: string]: number } {
const accumulators: { [key: string]: number } = {};
const counts: { [key: string]: number } = {};
for (const traceStat of this.parent_trace_stats) {
for (const score of traceStat.scores || []) {
accumulators[score.name] = (accumulators[score.name] || 0.0) + score.score;
counts[score.name] = (counts[score.name] || 0) + 1;
}
}
return Object.fromEntries(Object.entries(accumulators).map(([name, value]) => [name, value / counts[name]]));
}

cumulativeAvgScore(): number {
const scores = this.parent_trace_stats.flatMap((traceStat) => traceStat.scores?.map((score) => score.score) || []);
return scores.length > 0 ? scores.reduce((acc, curr) => acc + curr, 0) / scores.length : 0.0;
Expand Down

0 comments on commit 284f108

Please sign in to comment.