File size: 1,403 Bytes
cf8ab7a
f586f77
 
cf8ab7a
f586f77
cf8ab7a
 
 
f586f77
cf8ab7a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import type { ModelSpec, ParamSpec } from "@elvis/ui";

import spec from "../../../backend/src/models.json";
import generated from "../../../backend/src/sklearn_params.json";

// The models students can choose, from the spec shared with the Python backend:
// models.json picks the settings shown first, sklearn_params.json has the rest.
// JSON imports type "kind" as string, so the specs' shape is checked by
// backend/tests/test_models.py rather than here.
const allParams = generated.models as unknown as Record<string, ParamSpec[]>;

export const MODELS: ModelSpec[] = spec.models.map((model) => {
  const shown = new Set(model.params.map((p) => p.name));
  const library = allParams[model.id] ?? [];
  const described = new Map(library.map((p) => [p.name, p.description]));
  return {
    ...(model as unknown as ModelSpec),
    // The panel's settings take their description from scikit-learn's too
    params: (model.params as unknown as ParamSpec[]).map((p) => ({ ...p, description: p.description ?? described.get(p.name) })),
    // Arguments models.json always passes (e.g. max_iter) start at that value
    otherParams: library
      .filter((p) => !shown.has(p.name))
      .map((p) => (p.name in model.fixed ? { ...p, default: model.fixed[p.name as keyof typeof model.fixed] } as ParamSpec : p)),
    libraryDefaults: Object.fromEntries(library.map((p) => [p.name, p.default])),
  };
});