diff --git a/TODO.md b/TODO.md index bf3a75b..366eaa8 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,7 @@ # system-a +[system-a] `samplingObjective` + # the-book 6: An Apple a Day diff --git a/src/system-a/gradientDescent.ts b/src/system-a/gradientDescent.ts index 2fa82e4..a52c260 100644 --- a/src/system-a/gradientDescent.ts +++ b/src/system-a/gradientDescent.ts @@ -8,15 +8,13 @@ import { } from "./index.js" import { mul, sub } from "./toys/index.js" -export type GradientDescentOptions = { - revs: number - learningRate: number -} - export function gradientDescent( objective: (...ps: Array) => Scalar, ps: Array, - options: GradientDescentOptions, + options: { + revs: number + learningRate: number + }, ): Array { const step = gradientDescentStep(objective, options) const rs = revise(step, options.revs, ps) @@ -27,7 +25,10 @@ export function gradientDescent( export function gradientDescentStep( objective: (...ps: Array) => Scalar, - options: GradientDescentOptions, + options: { + revs: number + learningRate: number + }, ): (ps: Array) => Array { return function step(ps: Array): Array { const gs = gradient(objective, ps) diff --git a/src/system-a/samplingObjective.ts b/src/system-a/samplingObjective.ts new file mode 100644 index 0000000..36b573c --- /dev/null +++ b/src/system-a/samplingObjective.ts @@ -0,0 +1,17 @@ +import { assertTensorArray, type Tensor } from "./Tensor.js" +import type { Expectant, Objective } from "./loss.js" + +export function samplingObjective( + expectant: Expectant, + xs: Tensor, + ys: Tensor, + options: { + batchSize: number + }, +): Objective { + assertTensorArray(xs) + const size = xs.length + return (...ps) => { + throw new Error() + } +}