last CR comments
This commit is contained in:
parent
99d1c345c5
commit
b3c0adcd30
|
@ -13,7 +13,7 @@ open Expect
|
||||||
open TestHelpers
|
open TestHelpers
|
||||||
|
|
||||||
module Internals = {
|
module Internals = {
|
||||||
let epsilon = 1e1
|
let epsilon = 5e1
|
||||||
|
|
||||||
let mean = GenericDist_Types.Constructors.UsingDists.mean
|
let mean = GenericDist_Types.Constructors.UsingDists.mean
|
||||||
|
|
||||||
|
@ -21,12 +21,12 @@ module Internals = {
|
||||||
`${algebraicOp} has`->expect->toEqual("failed")
|
`${algebraicOp} has`->expect->toEqual("failed")
|
||||||
|
|
||||||
let distributions = list{
|
let distributions = list{
|
||||||
normalMake(0.0, 1e0),
|
normalMake(4e0, 1e0),
|
||||||
betaMake(2e0, 4e0),
|
betaMake(2e0, 4e0),
|
||||||
exponentialMake(1.234e0),
|
exponentialMake(1.234e0),
|
||||||
uniformMake(7e0, 1e1),
|
uniformMake(7e0, 1e1),
|
||||||
// cauchyMake(1e0, 1e0),
|
// cauchyMake(1e0, 1e0),
|
||||||
lognormalMake(1e0, 1e0),
|
lognormalMake(2e0, 1e0),
|
||||||
triangularMake(1e0, 1e1, 5e1),
|
triangularMake(1e0, 1e1, 5e1),
|
||||||
Ok(floatMake(1e1)),
|
Ok(floatMake(1e1)),
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ let algebraicPower = algebraicPower(~env)
|
||||||
|
|
||||||
let {testOperationMean, distributions, pairsOfDifferentDistributions, epsilon} = module(Internals)
|
let {testOperationMean, distributions, pairsOfDifferentDistributions, epsilon} = module(Internals)
|
||||||
|
|
||||||
describe("Means invariant", () => {
|
describe("Means are invariant", () => {
|
||||||
describe("for addition", () => {
|
describe("for addition", () => {
|
||||||
let testAdditionMean = testOperationMean(algebraicAdd, "algebraicAdd", \"+.", ~epsilon)
|
let testAdditionMean = testOperationMean(algebraicAdd, "algebraicAdd", \"+.", ~epsilon)
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,21 @@
|
||||||
open Jest
|
open Jest
|
||||||
open Expect
|
open Expect
|
||||||
|
|
||||||
|
/*
|
||||||
|
This encodes the expression for percent error
|
||||||
|
The test says "the percent error of received against expected is bounded by epsilon"
|
||||||
|
|
||||||
|
However, the semantics are degraded by catching some numerical instability:
|
||||||
|
when expected is too small, the return of this function might blow up to infinity.
|
||||||
|
So we capture that by taking the max of abs(expected) against a 1.
|
||||||
|
|
||||||
|
A sanity check of this function would be welcome, in general it is a better way of approaching
|
||||||
|
squiggle-lang tests than toBeSoCloseTo.
|
||||||
|
*/
|
||||||
let expectErrorToBeBounded = (received, expected, ~epsilon) => {
|
let expectErrorToBeBounded = (received, expected, ~epsilon) => {
|
||||||
let distance = Js.Math.abs_float(received -. expected)
|
let distance = Js.Math.abs_float(received -. expected)
|
||||||
let expectedAbs = Js.Math.abs_float(expected)
|
let expectedAbs = Js.Math.abs_float(expected)
|
||||||
let normalizingDenom = Js.Math.max_float(
|
let normalizingDenom = Js.Math.max_float(expectedAbs, 1e0)
|
||||||
expectedAbs,
|
|
||||||
epsilon < 1.0 ? epsilon ** 2.0 : epsilon ** -2.0,
|
|
||||||
)
|
|
||||||
let error = distance /. normalizingDenom
|
let error = distance /. normalizingDenom
|
||||||
error->expect->toBeLessThan(epsilon)
|
error->expect->toBeLessThan(epsilon)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user