I believe I have functionality in place for new run
command, but I
could be wrong. Pushing so Sam can review Value: [1e-5 to 9e-3]
This commit is contained in:
parent
f1798e3165
commit
2c452163b6
|
@ -2,9 +2,11 @@ import * as _ from "lodash";
|
||||||
import {
|
import {
|
||||||
genericDist,
|
genericDist,
|
||||||
samplingParams,
|
samplingParams,
|
||||||
|
environment,
|
||||||
evaluatePartialUsingExternalBindings,
|
evaluatePartialUsingExternalBindings,
|
||||||
externalBindings,
|
externalBindings,
|
||||||
expressionValue,
|
expressionValue,
|
||||||
|
recordEV,
|
||||||
errorValue,
|
errorValue,
|
||||||
distributionError,
|
distributionError,
|
||||||
toPointSet,
|
toPointSet,
|
||||||
|
@ -15,6 +17,8 @@ import {
|
||||||
mixedShape,
|
mixedShape,
|
||||||
sampleSetDist,
|
sampleSetDist,
|
||||||
symbolicDist,
|
symbolicDist,
|
||||||
|
defaultEnvironment,
|
||||||
|
defaultSamplingEnv,
|
||||||
} from "../rescript/TypescriptInterface.gen";
|
} from "../rescript/TypescriptInterface.gen";
|
||||||
export {
|
export {
|
||||||
makeSampleSetDist,
|
makeSampleSetDist,
|
||||||
|
@ -50,10 +54,7 @@ import {
|
||||||
} from "../rescript/Distributions/DistributionOperation/DistributionOperation.gen";
|
} from "../rescript/Distributions/DistributionOperation/DistributionOperation.gen";
|
||||||
export type { samplingParams, errorValue, externalBindings as bindings };
|
export type { samplingParams, errorValue, externalBindings as bindings };
|
||||||
|
|
||||||
export let defaultSamplingInputs: samplingParams = {
|
export let defaultSamplingInputs: samplingParams = defaultSamplingEnv;
|
||||||
sampleCount: 10000,
|
|
||||||
xyPointLength: 10000,
|
|
||||||
};
|
|
||||||
|
|
||||||
export type result<a, b> =
|
export type result<a, b> =
|
||||||
| {
|
| {
|
||||||
|
@ -90,8 +91,9 @@ export type squiggleExpression =
|
||||||
| tagged<"symbol", string>
|
| tagged<"symbol", string>
|
||||||
| tagged<"string", string>
|
| tagged<"string", string>
|
||||||
| tagged<"call", string>
|
| tagged<"call", string>
|
||||||
| tagged<"lambda", [string[], internalCode]>
|
| tagged<"lambda", [string[], recordEV, internalCode]>
|
||||||
| tagged<"array", squiggleExpression[]>
|
| tagged<"array", squiggleExpression[]>
|
||||||
|
| tagged<"arrayString", string[]>
|
||||||
| tagged<"boolean", boolean>
|
| tagged<"boolean", boolean>
|
||||||
| tagged<"distribution", Distribution>
|
| tagged<"distribution", Distribution>
|
||||||
| tagged<"number", number>
|
| tagged<"number", number>
|
||||||
|
@ -100,16 +102,16 @@ export type squiggleExpression =
|
||||||
export function run(
|
export function run(
|
||||||
squiggleString: string,
|
squiggleString: string,
|
||||||
bindings?: externalBindings,
|
bindings?: externalBindings,
|
||||||
samplingInputs?: samplingParams
|
samplingInputs?: samplingParams,
|
||||||
|
environ?: environment
|
||||||
): result<squiggleExpression, errorValue> {
|
): result<squiggleExpression, errorValue> {
|
||||||
let b = bindings ? bindings : {};
|
let b = bindings ? bindings : {};
|
||||||
let si: samplingParams = samplingInputs
|
let si: samplingParams = samplingInputs
|
||||||
? samplingInputs
|
? samplingInputs
|
||||||
: defaultSamplingInputs;
|
: defaultSamplingInputs;
|
||||||
|
let e = environ ? environ : defaultEnvironment;
|
||||||
let result: result<expressionValue, errorValue> =
|
let res: result<expressionValue, errorValue> = eval(squiggleString); // , b, e);
|
||||||
evaluateUsingExternalBindings(squiggleString, b);
|
return resultMap(res, (x) => createTsExport(x, si));
|
||||||
return resultMap(result, (x) => createTsExport(x, si));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run Partial. A partial is a block of code that doesn't return a value
|
// Run Partial. A partial is a block of code that doesn't return a value
|
||||||
|
@ -118,7 +120,11 @@ export function runPartial(
|
||||||
bindings: externalBindings,
|
bindings: externalBindings,
|
||||||
_samplingInputs?: samplingParams
|
_samplingInputs?: samplingParams
|
||||||
): result<externalBindings, errorValue> {
|
): result<externalBindings, errorValue> {
|
||||||
return evaluatePartialUsingExternalBindings(squiggleString, bindings);
|
return evaluatePartialUsingExternalBindings(
|
||||||
|
squiggleString,
|
||||||
|
bindings,
|
||||||
|
defaultEnvironment
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createTsExport(
|
function createTsExport(
|
||||||
|
@ -158,6 +164,8 @@ function createTsExport(
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
case "EvArrayString":
|
||||||
|
return tag("arrayString", x.value);
|
||||||
case "EvBool":
|
case "EvBool":
|
||||||
return tag("boolean", x.value);
|
return tag("boolean", x.value);
|
||||||
case "EvCall":
|
case "EvCall":
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
module ExpressionValue = ReducerInterface_ExpressionValue
|
module ExpressionValue = ReducerInterface_ExpressionValue
|
||||||
type expressionValue = ReducerInterface_ExpressionValue.expressionValue
|
type expressionValue = ReducerInterface_ExpressionValue.expressionValue
|
||||||
|
|
||||||
let runGenericOperation = DistributionOperation.run(
|
let defaultEnv: DistributionOperation.env = {
|
||||||
~env={
|
|
||||||
sampleCount: MagicNumbers.Environment.defaultSampleCount,
|
sampleCount: MagicNumbers.Environment.defaultSampleCount,
|
||||||
xyPointLength: MagicNumbers.Environment.defaultXYPointLength,
|
xyPointLength: MagicNumbers.Environment.defaultXYPointLength,
|
||||||
},
|
}
|
||||||
|
|
||||||
|
let runGenericOperation = DistributionOperation.run(
|
||||||
|
~env=defaultEnv,
|
||||||
)
|
)
|
||||||
|
|
||||||
module Helpers = {
|
module Helpers = {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
let defaultEnv: DistributionOperation.env
|
||||||
let dispatch: (
|
let dispatch: (
|
||||||
ReducerInterface_ExpressionValue.functionCall,
|
ReducerInterface_ExpressionValue.functionCall,
|
||||||
ReducerInterface_ExpressionValue.environment,
|
ReducerInterface_ExpressionValue.environment,
|
||||||
|
|
|
@ -49,6 +49,9 @@ type externalBindings = Reducer.externalBindings
|
||||||
@genType
|
@genType
|
||||||
type expressionValue = ReducerInterface_ExpressionValue.expressionValue
|
type expressionValue = ReducerInterface_ExpressionValue.expressionValue
|
||||||
|
|
||||||
|
@genType
|
||||||
|
type recordEV = ReducerInterface_ExpressionValue.record
|
||||||
|
|
||||||
@genType
|
@genType
|
||||||
type errorValue = Reducer_ErrorValue.errorValue
|
type errorValue = Reducer_ErrorValue.errorValue
|
||||||
|
|
||||||
|
@ -72,3 +75,12 @@ let distributionErrorToString = DistributionTypes.Error.toString
|
||||||
|
|
||||||
@genType
|
@genType
|
||||||
type internalCode = ReducerInterface_ExpressionValue.internalCode
|
type internalCode = ReducerInterface_ExpressionValue.internalCode
|
||||||
|
|
||||||
|
@genType
|
||||||
|
let defaultSamplingEnv = ReducerInterface_GenericDistribution.defaultEnv
|
||||||
|
|
||||||
|
@genType
|
||||||
|
type environment = ReducerInterface_ExpressionValue.environment
|
||||||
|
|
||||||
|
@genType
|
||||||
|
let defaultEnvironment = ReducerInterface_ExpressionValue.defaultEnvironment
|
||||||
|
|
Loading…
Reference in New Issue
Block a user