squiggle/packages/squiggle-lang/benchmark/generators.ts

48 lines
1.4 KiB
TypeScript
Raw Normal View History

2022-04-26 20:38:17 +00:00
export let generateFloatRange = (min: number, max: number): number =>
Math.floor(Math.random() * (max - min) + min);
2022-04-26 18:26:02 +00:00
2022-04-26 20:38:17 +00:00
export let generateFloatMin = (min: number): number =>
generateFloatRange(min, 100);
export let generateFloat = (): number => generateFloatMin(-100);
let generatePositive = (): number => generateFloatMin(1);
2022-04-26 18:26:02 +00:00
export let generateNormal = (): string =>
`normal(${generateFloat()}, ${generatePositive()})`;
export let generateBeta = (): string =>
`beta(${generatePositive()}, ${generatePositive()})`;
export let generateLognormal = (): string =>
`lognormal(${generateFloat()}, ${generatePositive()})`;
export let generateExponential = (): string =>
`exponential(${generatePositive()})`;
export let generateUniform = (): string => {
2022-04-26 20:38:17 +00:00
let a = generateFloat();
let b = generateFloatMin(a + 1);
return `uniform(${a}, ${b})`;
};
export let generateCauchy = (): string => {
2022-04-26 20:38:17 +00:00
return `cauchy(${generateFloat()}, ${generatePositive()})`;
};
export let generateTriangular = (): string => {
2022-04-26 20:38:17 +00:00
let a = generateFloat();
let b = generateFloatMin(a + 1);
let c = generateFloatMin(b + 1);
return `triangular(${a}, ${b}, ${c})`;
};
export let distributions: { [key: string]: () => string } = {
normal: generateNormal,
beta: generateBeta,
lognormal: generateLognormal,
exponential: generateExponential,
triangular: generateTriangular,
cauchy: generateCauchy,
2022-04-26 20:38:17 +00:00
uniform: generateUniform,
};