used skip instead of commenting out

This commit is contained in:
Quinn Dougherty 2022-04-20 19:07:25 -04:00
parent 264d970348
commit cc29eb33be
4 changed files with 177 additions and 176 deletions

View File

@ -9,9 +9,7 @@ import * as fc from "fast-check";
describe("Squiggle's parser is whitespace insensitive", () => {
test("when assigning a distribution to a name and calling that name", () => {
/*
* intersperse varying amounts of whitespace in a squiggle string
*/
// intersperse varying amounts of whitespace in a squiggle string
let squiggleString = (
a: string,
b: string,

View File

@ -1,39 +1,37 @@
// import { errorValueToString } from "../../src/js/index";
// import { testRun, expectErrorToBeBounded } from "./TestHelpers";
// import * as fc from "fast-check";
import { testRun, expectErrorToBeBounded } from "./TestHelpers";
import * as fc from "fast-check";
// describe("Mean of mixture is weighted average of means", () => {
// test("mx(beta(a,b), lognormal(m,s), [x,y])", () => {
// fc.assert(
// fc.property(
// fc.float({ min: 1e-1 }), // alpha
// fc.float({ min: 1 }), // beta
// fc.float(), // mu
// fc.float({ min: 1e-1 }), // sigma
// fc.float({ min: 1e-7 }),
// fc.float({ min: 1e-7 }),
// (a, b, m, s, x, y) => {
// let squiggleString = `mean(mixture(beta(${a},${b}), lognormal(${m},${s}), [${x}, ${y}]))`;
// let res = testRun(squiggleString);
// let weightDenom = x + y;
// let betaWeight = x / weightDenom;
// let lognormalWeight = y / weightDenom;
// let betaMean = 1 / (1 + b / a);
// let lognormalMean = m + s ** 2 / 2;
// if (res.tag == "number") {
// expectErrorToBeBounded(
// res.value,
// betaWeight * betaMean + lognormalWeight * lognormalMean,
// 1,
// 2
// );
// } else {
// expect(res.value).toEqual("some error message");
// }
// }
// )
// );
// });
// });
describe("vacuous", () => test("vacuous", () => expect(true).toEqual(true)));
describe("Mean of mixture is weighted average of means", () => {
test.skip("mx(beta(a,b), lognormal(m,s), [x,y])", () => {
fc.assert(
fc.property(
fc.float({ min: 1e-1 }), // alpha
fc.float({ min: 1 }), // beta
fc.float(), // mu
fc.float({ min: 1e-1 }), // sigma
fc.float({ min: 1e-7 }),
fc.float({ min: 1e-7 }),
(a, b, m, s, x, y) => {
let squiggleString = `mean(mixture(beta(${a},${b}), lognormal(${m},${s}), [${x}, ${y}]))`;
let res = testRun(squiggleString);
let weightDenom = x + y;
let betaWeight = x / weightDenom;
let lognormalWeight = y / weightDenom;
let betaMean = 1 / (1 + b / a);
let lognormalMean = m + s ** 2 / 2;
if (res.tag == "number") {
expectErrorToBeBounded(
res.value,
betaWeight * betaMean + lognormalWeight * lognormalMean,
1,
2
);
} else {
expect(res.value).toEqual("some error message");
}
}
)
);
});
});

View File

@ -1,5 +1,5 @@
import { Distribution } from "../../src/js/index";
// import { expectErrorToBeBounded, failDefault } from "./TestHelpers";
import { expectErrorToBeBounded, failDefault } from "./TestHelpers";
import * as fc from "fast-check";
// Beware: float64Array makes it appear in an infinite loop.
@ -14,22 +14,22 @@ let arrayGen = () =>
describe("cumulative density function", () => {
let n = 10000;
// // We should obtain the math here.
// test("'s codomain is bounded above", () => {
// fc.assert(
// fc.property(arrayGen(), fc.float(), (xs_, x) => {
// let xs = Array.from(xs_);
// // Should compute with squiggle strings once interpreter has `sample`
// let dist = new Distribution(
// { tag: "SampleSet", value: xs },
// { sampleCount: n, xyPointLength: 100 }
// );
// let cdfValue = dist.cdf(x).value;
// let epsilon = 5e-7
// expect(cdfValue).toBeLessThanOrEqual(1 + epsilon)
// })
// );
// })
// We should fix this.
test.skip("'s codomain is bounded above", () => {
fc.assert(
fc.property(arrayGen(), fc.float(), (xs_, x) => {
let xs = Array.from(xs_);
// Should compute with squiggle strings once interpreter has `sample`
let dist = new Distribution(
{ tag: "SampleSet", value: xs },
{ sampleCount: n, xyPointLength: 100 }
);
let cdfValue = dist.cdf(x).value;
let epsilon = 5e-7;
expect(cdfValue).toBeLessThanOrEqual(1 + epsilon);
})
);
});
test("'s codomain is bounded below", () => {
fc.assert(
@ -69,50 +69,50 @@ describe("cumulative density function", () => {
});
// I may simply be mistaken about the math here.
// test("at the lowest number in the distribution is within epsilon of 0", () => {
// fc.assert(
// fc.property(arrayGen(), (xs_) => {
// let xs = Array.from(xs_);
// let min = Math.min(...xs);
// // Should compute with squiggle strings once interpreter has `sample`
// let dist = new Distribution(
// { tag: "SampleSet", value: xs },
// { sampleCount: n, xyPointLength: 100 }
// );
// let cdfValue = dist.cdf(min).value;
// let max = Math.max(...xs);
// let epsilon = 5e-3;
// if (max - min < epsilon) {
// expect(cdfValue).toBeGreaterThan(4 * epsilon);
// } else {
// expect(cdfValue).toBeLessThan(4 * epsilon);
// }
// })
// );
// });
test.skip("at the lowest number in the distribution is within epsilon of 0", () => {
fc.assert(
fc.property(arrayGen(), (xs_) => {
let xs = Array.from(xs_);
let min = Math.min(...xs);
// Should compute with squiggle strings once interpreter has `sample`
let dist = new Distribution(
{ tag: "SampleSet", value: xs },
{ sampleCount: n, xyPointLength: 100 }
);
let cdfValue = dist.cdf(min).value;
let max = Math.max(...xs);
let epsilon = 5e-3;
if (max - min < epsilon) {
expect(cdfValue).toBeGreaterThan(4 * epsilon);
} else {
expect(cdfValue).toBeLessThan(4 * epsilon);
}
})
);
});
// I believe this is true, but due to bugs can't get the test to pass.
// test("is <= 1 everywhere with equality when x is higher than the max", () => {
// fc.assert(
// fc.property(arrayGen(), fc.float(), (xs_, x) => {
// let xs = Array.from(xs_);
// let dist = new Distribution(
// { tag: "SampleSet", value: xs },
// { sampleCount: n, xyPointLength: 100 }
// );
// let cdfValue = dist.cdf(x).value;
// let max = Math.max(...xs)
// if (x > max) {
// let epsilon = (x - max) / x
// expect(cdfValue).toBeGreaterThan(1 * (1 - epsilon));
// } else if (typeof cdfValue == "number") {
// expect(Math.round(1e5 * cdfValue) / 1e5).toBeLessThanOrEqual(1);
// } else {
// failDefault()
// }
// })
// );
// });
test.skip("is <= 1 everywhere with equality when x is higher than the max", () => {
fc.assert(
fc.property(arrayGen(), fc.float(), (xs_, x) => {
let xs = Array.from(xs_);
let dist = new Distribution(
{ tag: "SampleSet", value: xs },
{ sampleCount: n, xyPointLength: 100 }
);
let cdfValue = dist.cdf(x).value;
let max = Math.max(...xs);
if (x > max) {
let epsilon = (x - max) / x;
expect(cdfValue).toBeGreaterThan(1 * (1 - epsilon));
} else if (typeof cdfValue == "number") {
expect(Math.round(1e5 * cdfValue) / 1e5).toBeLessThanOrEqual(1);
} else {
failDefault();
}
})
);
});
test("is non-negative everywhere with zero when x is lower than the min", () => {
fc.assert(
@ -133,76 +133,86 @@ describe("cumulative density function", () => {
});
});
// // I no longer believe this is true.
// describe("probability density function", () => {
// let n = 1000;
//
// test("assigns to the max at most the weight of the mean", () => {
// fc.assert(
// fc.property(arrayGen(), (xs_) => {
// let xs = Array.from(xs_);
// let max = Math.max(...xs);
// let mean = xs.reduce((a, b) => a + b, 0.0) / ys.length;
// // Should be from squiggleString once interpreter exposes sampleset
// let dist = new Distribution(
// { tag: "SampleSet", value: xs },
// { sampleCount: n, xyPointLength: 100 }
// );
// let pdfValueMean = dist.pdf(mean).value;
// let pdfValueMax = dist.pdf(max).value;
// if (typeof pdfValueMean == "number" && typeof pdfValueMax == "number") {
// expect(pdfValueMax).toBeLessThanOrEqual(pdfValueMean);
// } else {
// expect(pdfValueMax).toEqual(pdfValueMean);
// }
// })
// );
// });
// });
// I no longer believe this is true.
describe("probability density function", () => {
let n = 1000;
// This should be true, but I can't get it to work.
// describe("mean is mean", () => {
// test("when sampling twice as widely as the input", () => {
// fc.assert(
// fc.property(
// fc.float64Array({ minLength: 10, maxLength: 100000 }),
// (xs_) => {
// let xs = Array.from(xs_);
// let n = xs.length;
// let dist = new Distribution(
// { tag: "SampleSet", value: xs },
// { sampleCount: 2 * n, xyPointLength: 4 * n }
// );
// let mean = dist.mean()
// if (typeof mean.value == "number") {
// expectErrorToBeBounded(mean.value, xs.reduce((a, b) => a + b, 0.0) / n, 5e-1, 1)
// } else {
// failDefault()
// }
// }
// )
// );
// });
//
// test("when sampling half as widely as the input", () => {
// fc.assert(
// fc.property(
// fc.float64Array({ minLength: 10, maxLength: 100000 }),
// (xs_) => {
// let xs = Array.from(xs_);
// let n = xs.length;
// let dist = new Distribution(
// { tag: "SampleSet", value: xs },
// { sampleCount: Math.floor(n / 2), xyPointLength: 4 * n }
// );
// let mean = dist.mean()
// if (typeof mean.value == "number") {
// expectErrorToBeBounded(mean.value, xs.reduce((a, b) => a + b, 0.0) / n, 5e-1, 1)
// } else {
// failDefault()
// }
// }
// )
// );
// });
// });
test.skip("assigns to the max at most the weight of the mean", () => {
fc.assert(
fc.property(arrayGen(), (xs_) => {
let xs = Array.from(xs_);
let max = Math.max(...xs);
let mean = xs.reduce((a, b) => a + b, 0.0) / xs.length;
// Should be from squiggleString once interpreter exposes sampleset
let dist = new Distribution(
{ tag: "SampleSet", value: xs },
{ sampleCount: n, xyPointLength: 100 }
);
let pdfValueMean = dist.pdf(mean).value;
let pdfValueMax = dist.pdf(max).value;
if (typeof pdfValueMean == "number" && typeof pdfValueMax == "number") {
expect(pdfValueMax).toBeLessThanOrEqual(pdfValueMean);
} else {
expect(pdfValueMax).toEqual(pdfValueMean);
}
})
);
});
});
// // This should be true, but I can't get it to work.
describe("mean is mean", () => {
test.skip("when sampling twice as widely as the input", () => {
fc.assert(
fc.property(
fc.float64Array({ minLength: 10, maxLength: 100000 }),
(xs_) => {
let xs = Array.from(xs_);
let n = xs.length;
let dist = new Distribution(
{ tag: "SampleSet", value: xs },
{ sampleCount: 2 * n, xyPointLength: 4 * n }
);
let mean = dist.mean();
if (typeof mean.value == "number") {
expectErrorToBeBounded(
mean.value,
xs.reduce((a, b) => a + b, 0.0) / n,
5e-1,
1
);
} else {
failDefault();
}
}
)
);
});
test.skip("when sampling half as widely as the input", () => {
fc.assert(
fc.property(
fc.float64Array({ minLength: 10, maxLength: 100000 }),
(xs_) => {
let xs = Array.from(xs_);
let n = xs.length;
let dist = new Distribution(
{ tag: "SampleSet", value: xs },
{ sampleCount: Math.floor(n / 2), xyPointLength: 4 * n }
);
let mean = dist.mean();
if (typeof mean.value == "number") {
expectErrorToBeBounded(
mean.value,
xs.reduce((a, b) => a + b, 0.0) / n,
5e-1,
1
);
} else {
failDefault();
}
}
)
);
});
});

View File

@ -7,11 +7,6 @@ import {
// result,
} from "../../src/js/index";
export function testRunR(x: string): any {
//: result<squiggleExpression, errorValue> => {
return run(x, { sampleCount: 1000, xyPointLength: 100 });
}
export function testRun(x: string): squiggleExpression {
let squiggleResult = run(x, { sampleCount: 1000, xyPointLength: 100 });
// return squiggleResult.value