Skip to content

Commit a171827

Browse files
committed
Fix maia paper and only eval half the positions
1 parent 435b997 commit a171827

2 files changed

Lines changed: 24 additions & 9 deletions

File tree

src/constants/common.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
// The Maia model is only run at multiples of 200 Elo. The intermediate levels
2+
// (200n + 100, e.g. 700, 900, ...) are not selectable; they only appear in the
3+
// "Moves by Rating" graph, where they are linearly interpolated.
14
export const MAIA_MODELS = Array.from(
2-
{ length: 21 },
3-
(_, i) => `maia_kdd_${600 + i * 100}`,
5+
{ length: 11 },
6+
(_, i) => `maia_kdd_${600 + i * 200}`,
47
)
58

69
export const MAIA_RATINGS = MAIA_MODELS.map((m) =>

src/hooks/useAnalysisController/useMoveRecommendations.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useMemo } from 'react'
22
import { Chess } from 'chess.ts'
3-
import { MAIA_MODELS } from 'src/constants/common'
3+
import { MAIA_MODELS, MAIA_RATINGS } from 'src/constants/common'
44
import { GameNode, MaiaEvaluation, StockfishEvaluation } from 'src/types'
55
import { sortStockfishMoves } from './utils'
66

@@ -105,15 +105,27 @@ export const useMoveRecommendations = (
105105
}
106106
}
107107

108+
// Maia is only evaluated at multiples of 200 Elo (MAIA_MODELS). The graph is
109+
// drawn at a finer 100-Elo resolution: evaluated levels use their real policy
110+
// and the intermediate levels (200n + 100) are linearly interpolated from
111+
// their two neighbours.
112+
const probabilityAt = (rating: number, move: string): number =>
113+
(maia[`maia_kdd_${rating}`]?.policy?.[move] || 0) * 100
114+
115+
const minRating = MAIA_RATINGS[0]
116+
const maxRating = MAIA_RATINGS[MAIA_RATINGS.length - 1]
117+
108118
const data = []
109-
for (const rating of MAIA_MODELS) {
110-
const entry: { [key: string]: number } = {
111-
rating: parseInt(rating.replace('maia_kdd_', '')),
112-
}
119+
for (let rating = minRating; rating <= maxRating; rating += 100) {
120+
const entry: { [key: string]: number } = { rating }
121+
const isEvaluated = rating % 200 === 0
113122

114123
for (const move of candidates) {
115-
const probability = (maia[rating]?.policy?.[move[0]] || 0) * 100
116-
entry[move[1]] = probability
124+
entry[move[1]] = isEvaluated
125+
? probabilityAt(rating, move[0])
126+
: (probabilityAt(rating - 100, move[0]) +
127+
probabilityAt(rating + 100, move[0])) /
128+
2
117129
}
118130

119131
data.push(entry)

0 commit comments

Comments
 (0)