time-to-botec/squiggle/node_modules/@quri/squiggle-lang/benchmark/generators.ts
NunoSempere b6addc7f05 feat: add the node modules
Necessary in order to clearly see the squiggle hotwiring.
2022-12-03 12:44:49 +00:00

49 lines
1.5 KiB
TypeScript

export let generateFloatRange = (min: number, max: number): number =>
Math.random() * (max - min) + min;
export let generateIntRange = (min: number, max: number): number =>
Math.floor(generateFloatRange(min, max));
export let generateIntMin = (min: number): number => generateIntRange(min, 100);
export let generateInt = (): number => generateIntMin(-100);
let generatePositiveInt = (): number => generateIntMin(1);
export let generateNormal = (): string =>
`normal(${generateInt()}, ${generatePositiveInt()})`;
export let generateBeta = (): string =>
`beta(${generatePositiveInt()}, ${generatePositiveInt()})`;
export let generateLognormal = (): string =>
`lognormal(${generateInt()}, ${generatePositiveInt()})`;
export let generateExponential = (): string =>
`exponential(${generatePositiveInt()})`;
export let generateUniform = (): string => {
let a = generateInt();
let b = generateIntMin(a + 1);
return `uniform(${a}, ${b})`;
};
export let generateCauchy = (): string => {
return `cauchy(${generateInt()}, ${generatePositiveInt()})`;
};
export let generateTriangular = (): string => {
let a = generateInt();
let b = generateIntMin(a + 1);
let c = generateIntMin(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,
uniform: generateUniform,
};