time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

index.ts (1589B)


      1 import {
      2   distributions,
      3   generateInt,
      4   generateFloatRange,
      5 } from "./generators.js";
      6 import { test, expectEqual } from "./lib.js";
      7 
      8 // This script is pretty old and it's unclear how useful it is.
      9 // It should probably be converted to the jest test.
     10 
     11 const checkDistributionSame = async (
     12   distribution: string,
     13   operation: (arg: string) => string
     14 ) => {
     15   await expectEqual(
     16     operation(distribution),
     17     operation(`PointSet.fromDist(${distribution})`)
     18   );
     19   await expectEqual(
     20     operation(distribution),
     21     operation(`SampleSet.fromDist(${distribution})`)
     22   );
     23 };
     24 
     25 Object.entries(distributions).map(([key, generator]) => {
     26   const distribution = generator();
     27   test(`mean is the same for ${key} distribution under all distribution types`, async () =>
     28     await checkDistributionSame(distribution, (d: string) => `mean(${d})`));
     29 
     30   test(`cdf is the same for ${key} distribution under all distribution types`, async () => {
     31     const cdf_value = generateInt();
     32     await checkDistributionSame(
     33       distribution,
     34       (d: string) => `cdf(${d}, ${cdf_value})`
     35     );
     36   });
     37 
     38   test(`pdf is the same for ${key} distribution under all distribution types`, async () => {
     39     const pdf_value = generateInt();
     40     await checkDistributionSame(
     41       distribution,
     42       (d: string) => `pdf(${d}, ${pdf_value})`
     43     );
     44   });
     45 
     46   test(`inv is the same for ${key} distribution under all distribution types`, async () => {
     47     const inv_value = generateFloatRange(0, 1);
     48     await checkDistributionSame(
     49       distribution,
     50       (d: string) => `inv(${d}, ${inv_value})`
     51     );
     52   });
     53 });