Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concrete Values #996

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
07b4bcb
Made a mess but learned a lot.
zaneenders Sep 28, 2024
fd65bc2
Remove idk var.
zaneenders Sep 28, 2024
46980f8
Fix rebase.
zaneenders Sep 29, 2024
453e508
Fix apx-out not displaying.
zaneenders Sep 29, 2024
e9e2148
Diff displaying locally again.
zaneenders Sep 29, 2024
53dfc0f
Remove extra data.
zaneenders Sep 29, 2024
73d4c9c
Formatting.
zaneenders Sep 30, 2024
8067d17
Breaking out compute-true-error for now.
zaneenders Oct 2, 2024
0d970e5
Garbage code but we have contact.
zaneenders Oct 2, 2024
7e7415f
Consolidate.
zaneenders Oct 3, 2024
a747be8
Define true-error for all single points.
zaneenders Oct 3, 2024
b8f59c2
Surface true-error to Odyssey.
zaneenders Oct 3, 2024
4971728
Expending node to get all variables for current spec.
zaneenders Oct 3, 2024
46c8d19
Multi-variable seems to be working for Odyssey. Still lots of shortcu…
zaneenders Oct 3, 2024
b51de3a
Touch ups for Odyssey consumption.
zaneenders Oct 3, 2024
251ede8
Fix ulp-err name.
zaneenders Oct 3, 2024
929c98e
Fix err rename to ulp-errs.
zaneenders Oct 7, 2024
d608f41
Better localize test but found an exact +nan.0.
zaneenders Oct 9, 2024
0b85f73
Putting on invalid rival inputs.
zaneenders Oct 10, 2024
caf5761
Formatting and unfinished Test.
zaneenders Oct 10, 2024
8577c40
Remove big float hack.
zaneenders Oct 10, 2024
7aac4d5
Fix +inf.0 and -inf.0 for exact.
zaneenders Oct 10, 2024
3678897
Flag to not compute true error.
zaneenders Oct 10, 2024
4bf275f
PR touch up.
zaneenders Oct 10, 2024
f8f66c5
Split out core local error from Odyssey.
zaneenders Oct 14, 2024
066c6e2
Simplified true-error.
zaneenders Oct 18, 2024
a8d7578
Using eval-progs-real for true err.
zaneenders Oct 18, 2024
2960f11
Starting on if statements.
zaneenders Oct 19, 2024
ffb5013
No longer crashing on if statements.
zaneenders Oct 21, 2024
f98df25
Filtering more input values.
zaneenders Oct 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 61 additions & 2 deletions infra/testApi.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { strict as assert } from 'node:assert'; // use strict equality everywhe
const SAMPLE_SIZE = 8000
const FPCoreFormula = '(FPCore (x) (- (sqrt (+ x 1)) (sqrt x)))'
const FPCoreFormula2 = '(FPCore (x) (- (sqrt (+ x 1))))'
const FPCoreFormula3 = '(FPCore (x) (if (<= (- (sqrt (+ x 1.0)) (sqrt x)) 0.05) (* 0.5 (sqrt (/ 1.0 x))) (fma (fma (- 0.125) x 0.5) x (- 1.0 (sqrt x)))))'
const eval_sample = [[[1], -1.4142135623730951]]

// improve endpoint
Expand Down Expand Up @@ -88,7 +89,7 @@ assert.deepEqual(sample.points[1], sample2.points[1])
const explainBody = {
method: 'POST',
body: JSON.stringify({
formula: FPCoreFormula, sample: sample2.points
formula: FPCoreFormula, sample: sample.points
})
}
const explain = await (await fetch(makeEndpoint("/api/explanations"), explainBody)).json()
Expand Down Expand Up @@ -142,7 +143,7 @@ assert.deepEqual(calculateAsyncResult.points, [[[1], -1.4142135623730951]])
// Local error endpoint
const localErrorBody = {
method: 'POST', body: JSON.stringify({
formula: FPCoreFormula, sample: sample2.points
formula: FPCoreFormula, sample: sample.points
})
}
const localError = await (await fetch(makeEndpoint("/api/localerror"), localErrorBody)).json()
Expand All @@ -164,6 +165,64 @@ const localError2 = await (await fetch(makeEndpoint("/api/localerror"), {
})).json()
// Test that different sample points produce different job ids ensuring that different results are served for these inputs.
assert.notEqual(localError1.job, localError2.job)
// Assert local error works for default example.
const ignoredValue = 1e+308
'(FPCore (1e-100) (- (sqrt (+ x 1)) (sqrt x)))'
const localError5 = await (await fetch(makeEndpoint("/api/localerror"), {
method: 'POST', body: JSON.stringify({
formula: FPCoreFormula, sample: [[[1e-100], ignoredValue]], seed: 5
})
})).json()
const rootMinusNode = localError5.tree
const leftSQRT = localError5.tree['children'][0]
const rightSQRT = localError5.tree['children'][1]
const plusNode = localError5.tree['children'][0]['children'][0]
const xNode = localError5.tree['children'][0]['children'][0]['children'][0]
const oneNode = localError5.tree['children'][0]['children'][0]['children'][1]

// node, name, approx_value, avg_error, exact_value, true_error_value, ulps_error
assertCheckNode(rootMinusNode, '-', '1.0', '0.0', '1.0', '-1e-50', 1)
assertCheckNode(leftSQRT, 'sqrt', '1.0', '0.0', '1.0', '5e-101', 1)
assertCheckNode(rightSQRT, 'sqrt', '1e-50', '0.0', '1e-50', '2.379726195519099e-68', 1)
assertCheckNode(plusNode, '+', '1.0', '0.0', '1.0', '1e-100', 1)
assertCheckNode(xNode, 'x', '1e-100', '0.0', '1e-100', '0', 1)
assertCheckNode(oneNode, '1.0', '1.0', '0.0', '1.0', '-0.0', 1)

// '(FPCore (1e100) (- (sqrt (+ x 1)) (sqrt x)))'
const localError6 = await (await fetch(makeEndpoint("/api/localerror"), {
method: 'POST', body: JSON.stringify({
formula: FPCoreFormula, sample: [[[1e100], ignoredValue]], seed: 5
})
})).json()
const rootMinusNode6 = localError6.tree
const leftSQRT6 = localError6.tree['children'][0]
const rightSQRT6 = localError6.tree['children'][1]
const plusNode6 = localError6.tree['children'][0]['children'][0]
const xNode6 = localError6.tree['children'][0]['children'][0]['children'][0]
const oneNode6 = localError6.tree['children'][0]['children'][0]['children'][1]
// node, name, approx_value, avg_error, exact_value, true_error_value, ulps_error
assertCheckNode(rootMinusNode6, '-', '0.0', '61.7', '5e-51', '-7.78383463033115e-68', 3854499065107888000)
assertCheckNode(leftSQRT6, 'sqrt', '1e+50', '0.0', '1e+50', '-6.834625285603891e+33', 1)
assertCheckNode(rightSQRT6, 'sqrt', '1e+50', '0.0', '1e+50', '-6.834625285603891e+33', 1)
assertCheckNode(plusNode6, '+', '1e+100', '0.0', '1e+100', '1.0', 1)
assertCheckNode(xNode6, 'x', '1e+100', '0.0', '1e+100', '0', 1)
assertCheckNode(oneNode6, '1.0', '1.0', '0.0', '1.0', '-0.0', 1)

function assertCheckNode(node, name, approx, avg_error, exact_value, true_error_value, ulps_error) {
assert.equal(node['e'], name)
assert.equal(node['approx-value'][0], approx)
assert.equal(node['avg-error'], avg_error)
assert.equal(node['exact-value'][0], exact_value)
assert.equal(node['true-error-value'][0], true_error_value)
assert.equal(node['ulps-error'][0], ulps_error)
}

// TODO if statements
// const localError7 = await (await fetch(makeEndpoint("/api/localerror"), {
// method: 'POST', body: JSON.stringify({
// formula: FPCoreFormula3, sample: [[[1e100], ignoredValue]], seed: 5
// })
// })).json()

// Alternatives endpoint
const altBody = {
Expand Down
12 changes: 3 additions & 9 deletions src/core/explain.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,10 @@
[else #t]))

(define (actual-errors expr pcontext)

(define errs
(match-define (cons subexprs pt-errorss)
(parameterize ([*pcontext* pcontext])
(first (compute-local-errors (list (all-subexpressions expr)) (*context*)))))

(define pruned (make-hash))
(for ([(k v) (in-hash errs)])
(hash-set! pruned k (hash-ref v 'errs)))
(define idk (flip-lists (hash->list pruned)))
(match-define (cons subexprs pt-errorss) idk)
(flip-lists (hash->list (first (compute-local-errors (list (all-subexpressions expr))
(*context*)))))))

(define pt-worst-subexpr
(append* (reap [sow]
Expand Down
Loading
Loading