used skip instead of commenting out
This commit is contained in:
		
							parent
							
								
									264d970348
								
							
						
					
					
						commit
						cc29eb33be
					
				| 
						 | 
					@ -9,9 +9,7 @@ import * as fc from "fast-check";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
describe("Squiggle's parser is whitespace insensitive", () => {
 | 
					describe("Squiggle's parser is whitespace insensitive", () => {
 | 
				
			||||||
  test("when assigning a distribution to a name and calling that name", () => {
 | 
					  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 = (
 | 
					    let squiggleString = (
 | 
				
			||||||
      a: string,
 | 
					      a: string,
 | 
				
			||||||
      b: string,
 | 
					      b: string,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,39 +1,37 @@
 | 
				
			||||||
// import { errorValueToString } from "../../src/js/index";
 | 
					// import { errorValueToString } from "../../src/js/index";
 | 
				
			||||||
// import { testRun, expectErrorToBeBounded } from "./TestHelpers";
 | 
					import { testRun, expectErrorToBeBounded } from "./TestHelpers";
 | 
				
			||||||
// import * as fc from "fast-check";
 | 
					import * as fc from "fast-check";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// describe("Mean of mixture is weighted average of means", () => {
 | 
					describe("Mean of mixture is weighted average of means", () => {
 | 
				
			||||||
// test("mx(beta(a,b), lognormal(m,s), [x,y])", () => {
 | 
					  test.skip("mx(beta(a,b), lognormal(m,s), [x,y])", () => {
 | 
				
			||||||
//   fc.assert(
 | 
					    fc.assert(
 | 
				
			||||||
//     fc.property(
 | 
					      fc.property(
 | 
				
			||||||
//       fc.float({ min: 1e-1 }), // alpha
 | 
					        fc.float({ min: 1e-1 }), // alpha
 | 
				
			||||||
//       fc.float({ min: 1 }), // beta
 | 
					        fc.float({ min: 1 }), // beta
 | 
				
			||||||
//       fc.float(), // mu
 | 
					        fc.float(), // mu
 | 
				
			||||||
//       fc.float({ min: 1e-1 }), // sigma
 | 
					        fc.float({ min: 1e-1 }), // sigma
 | 
				
			||||||
//       fc.float({ min: 1e-7 }),
 | 
					        fc.float({ min: 1e-7 }),
 | 
				
			||||||
//       fc.float({ min: 1e-7 }),
 | 
					        fc.float({ min: 1e-7 }),
 | 
				
			||||||
//       (a, b, m, s, x, y) => {
 | 
					        (a, b, m, s, x, y) => {
 | 
				
			||||||
//         let squiggleString = `mean(mixture(beta(${a},${b}), lognormal(${m},${s}), [${x}, ${y}]))`;
 | 
					          let squiggleString = `mean(mixture(beta(${a},${b}), lognormal(${m},${s}), [${x}, ${y}]))`;
 | 
				
			||||||
//         let res = testRun(squiggleString);
 | 
					          let res = testRun(squiggleString);
 | 
				
			||||||
//         let weightDenom = x + y;
 | 
					          let weightDenom = x + y;
 | 
				
			||||||
//         let betaWeight = x / weightDenom;
 | 
					          let betaWeight = x / weightDenom;
 | 
				
			||||||
//         let lognormalWeight = y / weightDenom;
 | 
					          let lognormalWeight = y / weightDenom;
 | 
				
			||||||
//         let betaMean = 1 / (1 + b / a);
 | 
					          let betaMean = 1 / (1 + b / a);
 | 
				
			||||||
//         let lognormalMean = m + s ** 2 / 2;
 | 
					          let lognormalMean = m + s ** 2 / 2;
 | 
				
			||||||
//         if (res.tag == "number") {
 | 
					          if (res.tag == "number") {
 | 
				
			||||||
//           expectErrorToBeBounded(
 | 
					            expectErrorToBeBounded(
 | 
				
			||||||
//             res.value,
 | 
					              res.value,
 | 
				
			||||||
//             betaWeight * betaMean + lognormalWeight * lognormalMean,
 | 
					              betaWeight * betaMean + lognormalWeight * lognormalMean,
 | 
				
			||||||
//             1,
 | 
					              1,
 | 
				
			||||||
//             2
 | 
					              2
 | 
				
			||||||
//           );
 | 
					            );
 | 
				
			||||||
//         } else {
 | 
					          } else {
 | 
				
			||||||
//           expect(res.value).toEqual("some error message");
 | 
					            expect(res.value).toEqual("some error message");
 | 
				
			||||||
//         }
 | 
					          }
 | 
				
			||||||
//       }
 | 
					        }
 | 
				
			||||||
//     )
 | 
					      )
 | 
				
			||||||
//   );
 | 
					    );
 | 
				
			||||||
// });
 | 
					  });
 | 
				
			||||||
// });
 | 
					});
 | 
				
			||||||
 | 
					 | 
				
			||||||
describe("vacuous", () => test("vacuous", () => expect(true).toEqual(true)));
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
import { Distribution } from "../../src/js/index";
 | 
					import { Distribution } from "../../src/js/index";
 | 
				
			||||||
// import { expectErrorToBeBounded, failDefault } from "./TestHelpers";
 | 
					import { expectErrorToBeBounded, failDefault } from "./TestHelpers";
 | 
				
			||||||
import * as fc from "fast-check";
 | 
					import * as fc from "fast-check";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Beware: float64Array makes it appear in an infinite loop.
 | 
					// Beware: float64Array makes it appear in an infinite loop.
 | 
				
			||||||
| 
						 | 
					@ -14,22 +14,22 @@ let arrayGen = () =>
 | 
				
			||||||
describe("cumulative density function", () => {
 | 
					describe("cumulative density function", () => {
 | 
				
			||||||
  let n = 10000;
 | 
					  let n = 10000;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  //  // We should obtain the math here.
 | 
					  // We should fix this.
 | 
				
			||||||
  // test("'s codomain is bounded above", () => {
 | 
					  test.skip("'s codomain is bounded above", () => {
 | 
				
			||||||
  //   fc.assert(
 | 
					    fc.assert(
 | 
				
			||||||
  //     fc.property(arrayGen(), fc.float(), (xs_, x) => {
 | 
					      fc.property(arrayGen(), fc.float(), (xs_, x) => {
 | 
				
			||||||
  //       let xs = Array.from(xs_);
 | 
					        let xs = Array.from(xs_);
 | 
				
			||||||
  //       // Should compute with squiggle strings once interpreter has `sample`
 | 
					        // Should compute with squiggle strings once interpreter has `sample`
 | 
				
			||||||
  //       let dist = new Distribution(
 | 
					        let dist = new Distribution(
 | 
				
			||||||
  //         { tag: "SampleSet", value: xs },
 | 
					          { tag: "SampleSet", value: xs },
 | 
				
			||||||
  //         { sampleCount: n, xyPointLength: 100 }
 | 
					          { sampleCount: n, xyPointLength: 100 }
 | 
				
			||||||
  //       );
 | 
					        );
 | 
				
			||||||
  //       let cdfValue = dist.cdf(x).value;
 | 
					        let cdfValue = dist.cdf(x).value;
 | 
				
			||||||
  //       let epsilon = 5e-7
 | 
					        let epsilon = 5e-7;
 | 
				
			||||||
  //       expect(cdfValue).toBeLessThanOrEqual(1 + epsilon)
 | 
					        expect(cdfValue).toBeLessThanOrEqual(1 + epsilon);
 | 
				
			||||||
  //     })
 | 
					      })
 | 
				
			||||||
  //   );
 | 
					    );
 | 
				
			||||||
  // })
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  test("'s codomain is bounded below", () => {
 | 
					  test("'s codomain is bounded below", () => {
 | 
				
			||||||
    fc.assert(
 | 
					    fc.assert(
 | 
				
			||||||
| 
						 | 
					@ -69,50 +69,50 @@ describe("cumulative density function", () => {
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // I may simply be mistaken about the math here.
 | 
					  // I may simply be mistaken about the math here.
 | 
				
			||||||
  // test("at the lowest number in the distribution is within epsilon of 0", () => {
 | 
					  test.skip("at the lowest number in the distribution is within epsilon of 0", () => {
 | 
				
			||||||
  //   fc.assert(
 | 
					    fc.assert(
 | 
				
			||||||
  //     fc.property(arrayGen(), (xs_) => {
 | 
					      fc.property(arrayGen(), (xs_) => {
 | 
				
			||||||
  //       let xs = Array.from(xs_);
 | 
					        let xs = Array.from(xs_);
 | 
				
			||||||
  //       let min = Math.min(...xs);
 | 
					        let min = Math.min(...xs);
 | 
				
			||||||
  //       // Should compute with squiggle strings once interpreter has `sample`
 | 
					        // Should compute with squiggle strings once interpreter has `sample`
 | 
				
			||||||
  //       let dist = new Distribution(
 | 
					        let dist = new Distribution(
 | 
				
			||||||
  //         { tag: "SampleSet", value: xs },
 | 
					          { tag: "SampleSet", value: xs },
 | 
				
			||||||
  //         { sampleCount: n, xyPointLength: 100 }
 | 
					          { sampleCount: n, xyPointLength: 100 }
 | 
				
			||||||
  //       );
 | 
					        );
 | 
				
			||||||
  //       let cdfValue = dist.cdf(min).value;
 | 
					        let cdfValue = dist.cdf(min).value;
 | 
				
			||||||
  //       let max = Math.max(...xs);
 | 
					        let max = Math.max(...xs);
 | 
				
			||||||
  //       let epsilon = 5e-3;
 | 
					        let epsilon = 5e-3;
 | 
				
			||||||
  //       if (max - min < epsilon) {
 | 
					        if (max - min < epsilon) {
 | 
				
			||||||
  //         expect(cdfValue).toBeGreaterThan(4 * epsilon);
 | 
					          expect(cdfValue).toBeGreaterThan(4 * epsilon);
 | 
				
			||||||
  //       } else {
 | 
					        } else {
 | 
				
			||||||
  //         expect(cdfValue).toBeLessThan(4 * epsilon);
 | 
					          expect(cdfValue).toBeLessThan(4 * epsilon);
 | 
				
			||||||
  //       }
 | 
					        }
 | 
				
			||||||
  //     })
 | 
					      })
 | 
				
			||||||
  //   );
 | 
					    );
 | 
				
			||||||
  // });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // I believe this is true, but due to bugs can't get the test to pass.
 | 
					  // 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", () => {
 | 
					  test.skip("is <= 1 everywhere with equality when x is higher than the max", () => {
 | 
				
			||||||
  //    fc.assert(
 | 
					    fc.assert(
 | 
				
			||||||
  //      fc.property(arrayGen(), fc.float(), (xs_, x) => {
 | 
					      fc.property(arrayGen(), fc.float(), (xs_, x) => {
 | 
				
			||||||
  //        let xs = Array.from(xs_);
 | 
					        let xs = Array.from(xs_);
 | 
				
			||||||
  //        let dist = new Distribution(
 | 
					        let dist = new Distribution(
 | 
				
			||||||
  //          { tag: "SampleSet", value: xs },
 | 
					          { tag: "SampleSet", value: xs },
 | 
				
			||||||
  //          { sampleCount: n, xyPointLength: 100 }
 | 
					          { sampleCount: n, xyPointLength: 100 }
 | 
				
			||||||
  //        );
 | 
					        );
 | 
				
			||||||
  //        let cdfValue = dist.cdf(x).value;
 | 
					        let cdfValue = dist.cdf(x).value;
 | 
				
			||||||
  //        let max = Math.max(...xs)
 | 
					        let max = Math.max(...xs);
 | 
				
			||||||
  //        if (x > max) {
 | 
					        if (x > max) {
 | 
				
			||||||
  //          let epsilon = (x - max) / x
 | 
					          let epsilon = (x - max) / x;
 | 
				
			||||||
  //          expect(cdfValue).toBeGreaterThan(1 * (1 - epsilon));
 | 
					          expect(cdfValue).toBeGreaterThan(1 * (1 - epsilon));
 | 
				
			||||||
  //        } else if (typeof cdfValue == "number") {
 | 
					        } else if (typeof cdfValue == "number") {
 | 
				
			||||||
  //          expect(Math.round(1e5 * cdfValue) / 1e5).toBeLessThanOrEqual(1);
 | 
					          expect(Math.round(1e5 * cdfValue) / 1e5).toBeLessThanOrEqual(1);
 | 
				
			||||||
  //        } else {
 | 
					        } else {
 | 
				
			||||||
  //          failDefault()
 | 
					          failDefault();
 | 
				
			||||||
  //        }
 | 
					        }
 | 
				
			||||||
  //      })
 | 
					      })
 | 
				
			||||||
  //    );
 | 
					    );
 | 
				
			||||||
  //  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  test("is non-negative everywhere with zero when x is lower than the min", () => {
 | 
					  test("is non-negative everywhere with zero when x is lower than the min", () => {
 | 
				
			||||||
    fc.assert(
 | 
					    fc.assert(
 | 
				
			||||||
| 
						 | 
					@ -133,76 +133,86 @@ describe("cumulative density function", () => {
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// // I no longer believe this is true.
 | 
					// I no longer believe this is true.
 | 
				
			||||||
// describe("probability density function", () => {
 | 
					describe("probability density function", () => {
 | 
				
			||||||
//  let n = 1000;
 | 
					  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);
 | 
					 | 
				
			||||||
//        }
 | 
					 | 
				
			||||||
//      })
 | 
					 | 
				
			||||||
//    );
 | 
					 | 
				
			||||||
//  });
 | 
					 | 
				
			||||||
// });
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
// This should be true, but I can't get it to work.
 | 
					  test.skip("assigns to the max at most the weight of the mean", () => {
 | 
				
			||||||
// describe("mean is mean", () => {
 | 
					    fc.assert(
 | 
				
			||||||
// test("when sampling twice as widely as the input", () => {
 | 
					      fc.property(arrayGen(), (xs_) => {
 | 
				
			||||||
//   fc.assert(
 | 
					        let xs = Array.from(xs_);
 | 
				
			||||||
//     fc.property(
 | 
					        let max = Math.max(...xs);
 | 
				
			||||||
//       fc.float64Array({ minLength: 10, maxLength: 100000 }),
 | 
					        let mean = xs.reduce((a, b) => a + b, 0.0) / xs.length;
 | 
				
			||||||
//       (xs_) => {
 | 
					        // Should be from squiggleString once interpreter exposes sampleset
 | 
				
			||||||
//         let xs = Array.from(xs_);
 | 
					        let dist = new Distribution(
 | 
				
			||||||
//         let n = xs.length;
 | 
					          { tag: "SampleSet", value: xs },
 | 
				
			||||||
//         let dist = new Distribution(
 | 
					          { sampleCount: n, xyPointLength: 100 }
 | 
				
			||||||
//           { tag: "SampleSet", value: xs },
 | 
					        );
 | 
				
			||||||
//           { sampleCount: 2 * n, xyPointLength: 4 * n }
 | 
					        let pdfValueMean = dist.pdf(mean).value;
 | 
				
			||||||
//         );
 | 
					        let pdfValueMax = dist.pdf(max).value;
 | 
				
			||||||
//         let mean = dist.mean()
 | 
					        if (typeof pdfValueMean == "number" && typeof pdfValueMax == "number") {
 | 
				
			||||||
//         if (typeof mean.value == "number") {
 | 
					          expect(pdfValueMax).toBeLessThanOrEqual(pdfValueMean);
 | 
				
			||||||
//           expectErrorToBeBounded(mean.value, xs.reduce((a, b) => a + b, 0.0) / n, 5e-1, 1)
 | 
					        } else {
 | 
				
			||||||
//         } else {
 | 
					          expect(pdfValueMax).toEqual(pdfValueMean);
 | 
				
			||||||
//           failDefault()
 | 
					        }
 | 
				
			||||||
//         }
 | 
					      })
 | 
				
			||||||
//       }
 | 
					    );
 | 
				
			||||||
//     )
 | 
					  });
 | 
				
			||||||
//   );
 | 
					});
 | 
				
			||||||
// });
 | 
					
 | 
				
			||||||
//
 | 
					// // This should be true, but I can't get it to work.
 | 
				
			||||||
// test("when sampling half as widely as the input", () => {
 | 
					describe("mean is mean", () => {
 | 
				
			||||||
//   fc.assert(
 | 
					  test.skip("when sampling twice as widely as the input", () => {
 | 
				
			||||||
//     fc.property(
 | 
					    fc.assert(
 | 
				
			||||||
//       fc.float64Array({ minLength: 10, maxLength: 100000 }),
 | 
					      fc.property(
 | 
				
			||||||
//       (xs_) => {
 | 
					        fc.float64Array({ minLength: 10, maxLength: 100000 }),
 | 
				
			||||||
//         let xs = Array.from(xs_);
 | 
					        (xs_) => {
 | 
				
			||||||
//         let n = xs.length;
 | 
					          let xs = Array.from(xs_);
 | 
				
			||||||
//         let dist = new Distribution(
 | 
					          let n = xs.length;
 | 
				
			||||||
//           { tag: "SampleSet", value: xs },
 | 
					          let dist = new Distribution(
 | 
				
			||||||
//           { sampleCount: Math.floor(n / 2), xyPointLength: 4 * n }
 | 
					            { tag: "SampleSet", value: xs },
 | 
				
			||||||
//         );
 | 
					            { sampleCount: 2 * n, xyPointLength: 4 * n }
 | 
				
			||||||
//         let mean = dist.mean()
 | 
					          );
 | 
				
			||||||
//         if (typeof mean.value == "number") {
 | 
					          let mean = dist.mean();
 | 
				
			||||||
//           expectErrorToBeBounded(mean.value, xs.reduce((a, b) => a + b, 0.0) / n, 5e-1, 1)
 | 
					          if (typeof mean.value == "number") {
 | 
				
			||||||
//         } else {
 | 
					            expectErrorToBeBounded(
 | 
				
			||||||
//           failDefault()
 | 
					              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();
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,11 +7,6 @@ import {
 | 
				
			||||||
  // result,
 | 
					  // result,
 | 
				
			||||||
} from "../../src/js/index";
 | 
					} 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 {
 | 
					export function testRun(x: string): squiggleExpression {
 | 
				
			||||||
  let squiggleResult = run(x, { sampleCount: 1000, xyPointLength: 100 });
 | 
					  let squiggleResult = run(x, { sampleCount: 1000, xyPointLength: 100 });
 | 
				
			||||||
  // return squiggleResult.value
 | 
					  // return squiggleResult.value
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user