Skip to content

Commit

Permalink
[system-a] target test -- always test with samplingObjective
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed May 20, 2024
1 parent bd73b64 commit dd1cd2f
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 60 deletions.
6 changes: 3 additions & 3 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -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 }`
Expand Down
14 changes: 0 additions & 14 deletions src/system-a/targets/line.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down
26 changes: 0 additions & 26 deletions src/system-a/targets/plane.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down
17 changes: 0 additions & 17 deletions src/system-a/targets/quad.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down

0 comments on commit dd1cd2f

Please sign in to comment.