From dd1cd2f574de48d9bc7d572c03f5ff1470f51164 Mon Sep 17 00:00:00 2001 From: Xie Yuheng Date: Mon, 20 May 2024 21:14:27 +0800 Subject: [PATCH] [system-a] target test -- always test with `samplingObjective` --- TODO.md | 6 +++--- src/system-a/targets/line.test.ts | 14 -------------- src/system-a/targets/plane.test.ts | 26 -------------------------- src/system-a/targets/quad.test.ts | 17 ----------------- 4 files changed, 3 insertions(+), 60 deletions(-) diff --git a/TODO.md b/TODO.md index b8e400f..105b2d9 100644 --- a/TODO.md +++ b/TODO.md @@ -1,8 +1,8 @@ # system-a -[system-a] extract test function for target `testLine` -[system-a] extract test function for target `testQuad` -[system-a] extract test function for target `testPlane` +[system-a] extract test function for target `testGradientDescentByLine` +[system-a] extract test function for target `testGradientDescentByQuad` +[system-a] extract test function for target `testGradientDescentByPlane` [system-a] test `gradientDescentLonely` by targets [system-a] `velocityRepresentation` -- takes `options: { velocityAccumulationFactor }` diff --git a/src/system-a/targets/line.test.ts b/src/system-a/targets/line.test.ts index 976d779..c147b22 100644 --- a/src/system-a/targets/line.test.ts +++ b/src/system-a/targets/line.test.ts @@ -18,20 +18,6 @@ test("line -- gradientDescentNaked", () => { const xs = [2, 1, 4, 3] const ys = [1.8, 1.2, 4.2, 3.3] - const objective = l2Loss(line)(xs, ys) - - const rs = gradientDescentNaked({ learningRate: 0.01 })(objective, [0, 0], { - revs: 1000, - }) - - assertTensorAlmostEqual(rs, [1, 0], 10e-1) - assertTensorAlmostEqual(rs, [1.05, 0], 10e-6) -}) - -test("line -- gradientDescentNaked & samplingObjective ", () => { - const xs = [2, 1, 4, 3] - const ys = [1.8, 1.2, 4.2, 3.3] - const objective = samplingObjective(l2Loss(line), xs, ys, { batchSize: 4, }) diff --git a/src/system-a/targets/plane.test.ts b/src/system-a/targets/plane.test.ts index 4b88219..26fbee4 100644 --- a/src/system-a/targets/plane.test.ts +++ b/src/system-a/targets/plane.test.ts @@ -33,32 +33,6 @@ test("plane -- gradientDescentNaked", () => { ] const ys = [13.99, 15.99, 18, 22.4, 30.2, 37.94] - const objective = l2Loss(plane)(xs, ys) - - const rs = gradientDescentNaked({ learningRate: 0.001 })( - objective, - [[0, 0], 0], - { - revs: 1000, - }, - ) - - assertTensorAlmostEqual(rs, [[3.98, 2.04], 5.78], 10e-3) - - assertTensorAlmostEqual(plane([2, 3.91])([3.98, 2.04], 5.78), 22.4, 1) -}) - -test("plane -- gradientDescentNaked & samplingObjective", () => { - const xs = [ - [1, 2.05], - [1, 3], - [2, 2], - [2, 3.91], - [3, 6.13], - [4, 8.09], - ] - const ys = [13.99, 15.99, 18, 22.4, 30.2, 37.94] - const objective = samplingObjective(l2Loss(plane), xs, ys, { batchSize: 4, }) diff --git a/src/system-a/targets/quad.test.ts b/src/system-a/targets/quad.test.ts index 8be4653..a2026be 100644 --- a/src/system-a/targets/quad.test.ts +++ b/src/system-a/targets/quad.test.ts @@ -21,23 +21,6 @@ test("quad -- gradientDescentNaked", () => { const xs = [-1, 0, 1, 2, 3] const ys = [2.55, 2.1, 4.35, 10.2, 18.25] - const objective = l2Loss(quad)(xs, ys) - - const rs = gradientDescentNaked({ learningRate: 0.001 })( - objective, - [0, 0, 0], - { - revs: 1000, - }, - ) - - assertTensorAlmostEqual(rs, [1.478, 0.99, 2.05], 10e-3) -}) - -test("quad -- gradientDescentNaked & samplingObjective", () => { - const xs = [-1, 0, 1, 2, 3] - const ys = [2.55, 2.1, 4.35, 10.2, 18.25] - const objective = samplingObjective(l2Loss(quad), xs, ys, { batchSize: 4, })