diff --git a/packages/squiggle-lang/__tests__/Samples__test.res b/packages/squiggle-lang/__tests__/Samples__test.res index c41fce23..9f908ee1 100644 --- a/packages/squiggle-lang/__tests__/Samples__test.res +++ b/packages/squiggle-lang/__tests__/Samples__test.res @@ -10,12 +10,12 @@ describe("Lodash", () => describe("Lodash", () => { makeTest( "split", - SamplesToShape.Internals.T.splitContinuousAndDiscrete([1.432, 1.33455, 2.0]), + SampleSet.Internals.T.splitContinuousAndDiscrete([1.432, 1.33455, 2.0]), ([1.432, 1.33455, 2.0], E.FloatFloatMap.empty()), ) makeTest( "split", - SamplesToShape.Internals.T.splitContinuousAndDiscrete([ + SampleSet.Internals.T.splitContinuousAndDiscrete([ 1.432, 1.33455, 2.0, @@ -32,13 +32,13 @@ describe("Lodash", () => E.A.concatMany([sorted, sorted, sorted, sorted]) |> Belt.SortArray.stableSortBy(_, compare) } - let (_, discrete) = SamplesToShape.Internals.T.splitContinuousAndDiscrete( + let (_, discrete) = SampleSet.Internals.T.splitContinuousAndDiscrete( makeDuplicatedArray(10), ) let toArr = discrete |> E.FloatFloatMap.toArray makeTest("splitMedium", toArr |> Belt.Array.length, 10) - let (c, discrete) = SamplesToShape.Internals.T.splitContinuousAndDiscrete( + let (c, discrete) = SampleSet.Internals.T.splitContinuousAndDiscrete( makeDuplicatedArray(500), ) let toArr = discrete |> E.FloatFloatMap.toArray diff --git a/packages/squiggle-lang/src/rescript/ProgramEvaluator.res b/packages/squiggle-lang/src/rescript/ProgramEvaluator.res index 34fde393..6e2b118d 100644 --- a/packages/squiggle-lang/src/rescript/ProgramEvaluator.res +++ b/packages/squiggle-lang/src/rescript/ProgramEvaluator.res @@ -5,7 +5,7 @@ module Inputs = { sampleCount: option, outputXYPoints: option, kernelWidth: option, - shapeLength: option, + pointSetDistLength: option, } } let defaultRecommendedLength = 100 @@ -21,7 +21,7 @@ module Inputs = { sampleCount: None, outputXYPoints: None, kernelWidth: None, - shapeLength: None, + pointSetDistLength: None, } let make = ( @@ -60,15 +60,15 @@ module Internals = { type outputs = { graph: ASTTypes.AST.node, - shape: PointSetTypes.shape, + pointSetDist: PointSetTypes.pointSetDist, } - let makeOutputs = (graph, shape): outputs => {graph: graph, shape: shape} + let makeOutputs = (graph, pointSetDist): outputs => {graph: graph, pointSetDist: pointSetDist} let makeInputs = (inputs: Inputs.inputs): ASTTypes.AST.samplingInputs => { sampleCount: inputs.samplingInputs.sampleCount |> E.O.default(10000), outputXYPoints: inputs.samplingInputs.outputXYPoints |> E.O.default(10000), kernelWidth: inputs.samplingInputs.kernelWidth, - shapeLength: inputs.samplingInputs.shapeLength |> E.O.default(10000), + pointSetDistLength: inputs.samplingInputs.pointSetDistLength |> E.O.default(10000), } let runNode = (inputs, node) => @@ -93,8 +93,8 @@ module Internals = { let inputsToLeaf = (inputs: Inputs.inputs) => Parser.fromString(inputs.squiggleString) |> E.R.bind(_, g => runProgram(inputs, g)) - let outputToDistPlus = (inputs: Inputs.inputs, shape: PointSetTypes.shape) => - DistPlus.make(~shape, ~squiggleString=Some(inputs.squiggleString), ()) + let outputToDistPlus = (inputs: Inputs.inputs, pointSetDist: PointSetTypes.pointSetDist) => + DistPlus.make(~pointSetDist, ~squiggleString=Some(inputs.squiggleString), ()) } let renderIfNeeded = (inputs: Inputs.inputs, node: ASTTypes.AST.node): result< @@ -179,7 +179,7 @@ let runAll = (squiggleString: string) => { sampleCount: Some(10000), outputXYPoints: Some(10000), kernelWidth: None, - shapeLength: Some(1000), + pointSetDistLength: Some(1000), }, ~squiggleString, ~environment=[]->Belt.Map.String.fromArray, diff --git a/packages/squiggle-lang/src/rescript/interpreter/AST.res b/packages/squiggle-lang/src/rescript/interpreter/AST.res index f5c10ca9..6680db90 100644 --- a/packages/squiggle-lang/src/rescript/interpreter/AST.res +++ b/packages/squiggle-lang/src/rescript/interpreter/AST.res @@ -1,6 +1,7 @@ open ASTTypes.AST let toString = ASTBasic.toString + let envs = (samplingInputs, environment) => { samplingInputs: samplingInputs, environment: environment, @@ -9,9 +10,10 @@ let envs = (samplingInputs, environment) => { let toLeaf = (samplingInputs, environment, node: node) => ASTEvaluator.toLeaf(envs(samplingInputs, environment), node) -let toShape = (samplingInputs, environment, node: node) => + +let toPointSetDist = (samplingInputs, environment, node: node) => switch toLeaf(samplingInputs, environment, node) { - | Ok(#RenderedDist(shape)) => Ok(shape) + | Ok(#RenderedDist(pointSetDist)) => Ok(pointSetDist) | Ok(_) => Error("Rendering failed.") | Error(e) => Error(e) } diff --git a/packages/squiggle-lang/src/rescript/interpreter/ASTEvaluator.res b/packages/squiggle-lang/src/rescript/interpreter/ASTEvaluator.res index 5ac42340..ba2929f0 100644 --- a/packages/squiggle-lang/src/rescript/interpreter/ASTEvaluator.res +++ b/packages/squiggle-lang/src/rescript/interpreter/ASTEvaluator.res @@ -94,7 +94,7 @@ module PointwiseCombination = { let pointwiseCombine = (fn, evaluationParams: evaluationParams, t1: t, t2: t) => switch // TODO: construct a function that we can easily sample from, to construct - // a RenderedDist. Use the xMin and xMax of the rendered shapes to tell the sampling function where to look. + // a RenderedDist. Use the xMin and xMax of the rendered pointSetDists to tell the sampling function where to look. // TODO: This should work for symbolic distributions too! (Render.render(evaluationParams, t1), Render.render(evaluationParams, t2)) { | (Ok(#RenderedDist(rs1)), Ok(#RenderedDist(rs2))) => @@ -195,8 +195,8 @@ module Render = { switch t { | #Function(_) => Error("Cannot render a function") | #SymbolicDist(d) => - Ok(#RenderedDist(SymbolicDist.T.toShape(evaluationParams.samplingInputs.shapeLength, d))) - | #RenderedDist(_) as t => Ok(t) // already a rendered shape, we're done here + Ok(#RenderedDist(SymbolicDist.T.toPointSetDist(evaluationParams.samplingInputs.pointSetDistLength, d))) + | #RenderedDist(_) as t => Ok(t) // already a rendered pointSetDist, we're done here | _ => evaluateAndRetry(evaluationParams, operationToLeaf, t) } } diff --git a/packages/squiggle-lang/src/rescript/interpreter/ASTTypes.res b/packages/squiggle-lang/src/rescript/interpreter/ASTTypes.res index 8314e1bb..5c76df13 100644 --- a/packages/squiggle-lang/src/rescript/interpreter/ASTTypes.res +++ b/packages/squiggle-lang/src/rescript/interpreter/ASTTypes.res @@ -19,7 +19,7 @@ module AST = { type rec hash = array<(string, node)> and node = [ | #SymbolicDist(SymbolicDistTypes.symbolicDist) - | #RenderedDist(PointSetTypes.shape) + | #RenderedDist(PointSetTypes.pointSetDist) | #Symbol(string) | #Hash(hash) | #Array(array) @@ -64,7 +64,7 @@ module AST = { sampleCount: int, outputXYPoints: int, kernelWidth: option, - shapeLength: int, + pointSetDistLength: int, } module SamplingInputs = { @@ -72,13 +72,13 @@ module AST = { sampleCount: option, outputXYPoints: option, kernelWidth: option, - shapeLength: option, + pointSetDistLength: option, } let withDefaults = (t: t): samplingInputs => { sampleCount: t.sampleCount |> E.O.default(10000), outputXYPoints: t.outputXYPoints |> E.O.default(10000), kernelWidth: t.kernelWidth, - shapeLength: t.shapeLength |> E.O.default(10000), + pointSetDistLength: t.pointSetDistLength |> E.O.default(10000), } } @@ -148,7 +148,7 @@ module AST = { | _ => None } - let _toFloat = (t: PointSetTypes.shape) => + let _toFloat = (t: PointSetTypes.pointSetDist) => switch t { | Discrete({xyShape: {xs: [x], ys: [1.0]}}) => Some(#SymbolicDist(#Float(x))) | _ => None diff --git a/packages/squiggle-lang/src/rescript/interpreter/PTypes.res b/packages/squiggle-lang/src/rescript/interpreter/PTypes.res index 2525377f..b710c5b2 100644 --- a/packages/squiggle-lang/src/rescript/interpreter/PTypes.res +++ b/packages/squiggle-lang/src/rescript/interpreter/PTypes.res @@ -37,7 +37,7 @@ module Function = { module Primative = { type t = [ | #SymbolicDist(SymbolicDistTypes.symbolicDist) - | #RenderedDist(PointSetTypes.shape) + | #RenderedDist(PointSetTypes.pointSetDist) | #Function(array, node) ] @@ -62,7 +62,7 @@ module Primative = { module SamplingDistribution = { type t = [ | #SymbolicDist(SymbolicDistTypes.symbolicDist) - | #RenderedDist(PointSetTypes.shape) + | #RenderedDist(PointSetTypes.pointSetDist) ] let isSamplingDistribution: node => bool = x => @@ -126,12 +126,13 @@ module SamplingDistribution = { ) // todo: This bottom part should probably be somewhere else. - let shape = + // todo: REFACTOR: I'm not sure about the SampleSet line. + let pointSetDist = samples - |> E.O.fmap(SamplesToShape.fromSamples(~samplingInputs=evaluationParams.samplingInputs)) - |> E.O.bind(_, r => r.shape) + |> E.O.fmap(r => SampleSet.toPointSetDist(~samplingInputs=evaluationParams.samplingInputs, ~samples=r, ())) + |> E.O.bind(_, r => r.pointSetDist) |> E.O.toResult("No response") - shape |> E.R.fmap(r => #Normalize(#RenderedDist(r))) + pointSetDist |> E.R.fmap(r => #Normalize(#RenderedDist(r))) }) } } diff --git a/packages/squiggle-lang/src/rescript/interpreter/typeSystem/TypeSystem.res b/packages/squiggle-lang/src/rescript/interpreter/typeSystem/TypeSystem.res index 986268b7..2989f1c0 100644 --- a/packages/squiggle-lang/src/rescript/interpreter/typeSystem/TypeSystem.res +++ b/packages/squiggle-lang/src/rescript/interpreter/typeSystem/TypeSystem.res @@ -3,7 +3,7 @@ let getFloat = ASTTypes.AST.getFloat type samplingDist = [ | #SymbolicDist(SymbolicDistTypes.symbolicDist) - | #RenderedDist(PointSetTypes.shape) + | #RenderedDist(PointSetTypes.pointSetDist) ] type rec hashType = array<(string, _type)> @@ -18,7 +18,7 @@ and _type = [ type rec hashTypedValue = array<(string, typedValue)> and typedValue = [ | #Float(float) - | #RenderedDist(PointSetTypes.shape) + | #RenderedDist(PointSetTypes.pointSetDist) | #SamplingDist(samplingDist) | #Array(array) | #Hash(hashTypedValue) diff --git a/packages/squiggle-lang/src/rescript/pointSetDist/Continuous.res b/packages/squiggle-lang/src/rescript/pointSetDist/Continuous.res index 955c2801..0dd0924d 100644 --- a/packages/squiggle-lang/src/rescript/pointSetDist/Continuous.res +++ b/packages/squiggle-lang/src/rescript/pointSetDist/Continuous.res @@ -137,7 +137,7 @@ module T = Dist({ let mapY = mapY let updateIntegralCache = updateIntegralCache let toDiscreteProbabilityMassFraction = _ => 0.0 - let toShape = (t: t): PointSetTypes.shape => Continuous(t) + let toPointSetDist = (t: t): PointSetTypes.pointSetDist => Continuous(t) let xToY = (f, {interpolation, xyShape}: t) => switch interpolation { | #Stepwise => xyShape |> XYShape.XtoY.stepwiseIncremental(f) |> E.O.default(0.0) diff --git a/packages/squiggle-lang/src/rescript/pointSetDist/Discrete.res b/packages/squiggle-lang/src/rescript/pointSetDist/Discrete.res index 98bfcd7c..65828461 100644 --- a/packages/squiggle-lang/src/rescript/pointSetDist/Discrete.res +++ b/packages/squiggle-lang/src/rescript/pointSetDist/Discrete.res @@ -157,7 +157,7 @@ module T = Dist({ let toDiscreteProbabilityMassFraction = _ => 1.0 let mapY = mapY let updateIntegralCache = updateIntegralCache - let toShape = (t: t): PointSetTypes.shape => Discrete(t) + let toPointSetDist = (t: t): PointSetTypes.pointSetDist => Discrete(t) let toContinuous = _ => None let toDiscrete = t => Some(t) diff --git a/packages/squiggle-lang/src/rescript/pointSetDist/DistPlus.res b/packages/squiggle-lang/src/rescript/pointSetDist/DistPlus.res index 2c6c1d05..a9921e36 100644 --- a/packages/squiggle-lang/src/rescript/pointSetDist/DistPlus.res +++ b/packages/squiggle-lang/src/rescript/pointSetDist/DistPlus.res @@ -2,39 +2,39 @@ open PointSetTypes; type t = PointSetTypes.distPlus; -let shapeIntegral = shape => PointSetDist.T.Integral.get(shape); +let pointSetDistIntegral = pointSetDist => PointSetDist.T.Integral.get(pointSetDist); let make = ( - ~shape, + ~pointSetDist, ~squiggleString, ~domain=Complete, ~unit=UnspecifiedDistribution, (), ) : t => { - let integral = shapeIntegral(shape); - {shape, domain, integralCache: integral, unit, squiggleString}; + let integral = pointSetDistIntegral(pointSetDist); + {pointSetDist, domain, integralCache: integral, unit, squiggleString}; }; let update = ( - ~shape=?, + ~pointSetDist=?, ~integralCache=?, ~domain=?, ~unit=?, ~squiggleString=?, t: t, ) => { - shape: E.O.default(t.shape, shape), + pointSetDist: E.O.default(t.pointSetDist, pointSetDist), integralCache: E.O.default(t.integralCache, integralCache), domain: E.O.default(t.domain, domain), unit: E.O.default(t.unit, unit), squiggleString: E.O.default(t.squiggleString, squiggleString), }; -let updateShape = (shape, t) => { - let integralCache = shapeIntegral(shape); - update(~shape, ~integralCache, t); +let updateShape = (pointSetDist, t) => { + let integralCache = pointSetDistIntegral(pointSetDist); + update(~pointSetDist, ~integralCache, t); }; let domainIncludedProbabilityMass = (t: t) => @@ -43,27 +43,27 @@ let domainIncludedProbabilityMass = (t: t) => let domainIncludedProbabilityMassAdjustment = (t: t, f) => f *. Domain.includedProbabilityMass(t.domain); -let toShape = ({shape, _}: t) => shape; +let toPointSetDist = ({pointSetDist, _}: t) => pointSetDist; -let shapeFn = (fn, {shape}: t) => fn(shape); +let pointSetDistFn = (fn, {pointSetDist}: t) => fn(pointSetDist); module T = Distributions.Dist({ type t = PointSetTypes.distPlus; type integral = PointSetTypes.distPlus; - let toShape = toShape; - let toContinuous = shapeFn(PointSetDist.T.toContinuous); - let toDiscrete = shapeFn(PointSetDist.T.toDiscrete); + let toPointSetDist = toPointSetDist; + let toContinuous = pointSetDistFn(PointSetDist.T.toContinuous); + let toDiscrete = pointSetDistFn(PointSetDist.T.toDiscrete); let normalize = (t: t): t => { - let normalizedShape = t |> toShape |> PointSetDist.T.normalize; + let normalizedShape = t |> toPointSetDist |> PointSetDist.T.normalize; t |> updateShape(normalizedShape); }; let truncate = (leftCutoff, rightCutoff, t: t): t => { let truncatedShape = t - |> toShape + |> toPointSetDist |> PointSetDist.T.truncate(leftCutoff, rightCutoff); t |> updateShape(truncatedShape); @@ -71,14 +71,14 @@ module T = let xToY = (f, t: t) => t - |> toShape + |> toPointSetDist |> PointSetDist.T.xToY(f) |> MixedPoint.fmap(domainIncludedProbabilityMassAdjustment(t)); - let minX = shapeFn(PointSetDist.T.minX); - let maxX = shapeFn(PointSetDist.T.maxX); + let minX = pointSetDistFn(PointSetDist.T.minX); + let maxX = pointSetDistFn(PointSetDist.T.maxX); let toDiscreteProbabilityMassFraction = - shapeFn(PointSetDist.T.toDiscreteProbabilityMassFraction); + pointSetDistFn(PointSetDist.T.toDiscreteProbabilityMassFraction); // This bit is kind of awkward, could probably use rethinking. let integral = (t: t) => @@ -88,23 +88,23 @@ module T = update(~integralCache=E.O.default(t.integralCache, integralCache), t); let downsample = (i, t): t => - updateShape(t |> toShape |> PointSetDist.T.downsample(i), t); + updateShape(t |> toPointSetDist |> PointSetDist.T.downsample(i), t); // todo: adjust for limit, maybe? let mapY = ( ~integralSumCacheFn=previousIntegralSum => None, ~integralCacheFn=previousIntegralCache => None, ~fn, - {shape, _} as t: t, + {pointSetDist, _} as t: t, ) : t => - PointSetDist.T.mapY(~integralSumCacheFn, ~fn, shape) + PointSetDist.T.mapY(~integralSumCacheFn, ~fn, pointSetDist) |> updateShape(_, t); // get the total of everything let integralEndY = (t: t) => { PointSetDist.T.Integral.sum( - toShape(t), + toPointSetDist(t), ); }; @@ -112,18 +112,18 @@ module T = let integralXtoY = (f, t: t) => { PointSetDist.T.Integral.xToY( f, - toShape(t), + toPointSetDist(t), ) |> domainIncludedProbabilityMassAdjustment(t); }; // TODO: This part is broken when there is a limit, if this is supposed to be taken into account. let integralYtoX = (f, t: t) => { - PointSetDist.T.Integral.yToX(f, toShape(t)); + PointSetDist.T.Integral.yToX(f, toPointSetDist(t)); }; let mean = (t: t) => { - PointSetDist.T.mean(t.shape); + PointSetDist.T.mean(t.pointSetDist); }; - let variance = (t: t) => PointSetDist.T.variance(t.shape); + let variance = (t: t) => PointSetDist.T.variance(t.pointSetDist); }); diff --git a/packages/squiggle-lang/src/rescript/pointSetDist/Distributions.res b/packages/squiggle-lang/src/rescript/pointSetDist/Distributions.res index 2585f2f5..28c8104b 100644 --- a/packages/squiggle-lang/src/rescript/pointSetDist/Distributions.res +++ b/packages/squiggle-lang/src/rescript/pointSetDist/Distributions.res @@ -10,7 +10,7 @@ module type dist = { t, ) => t let xToY: (float, t) => PointSetTypes.mixedPoint - let toShape: t => PointSetTypes.shape + let toPointSetDist: t => PointSetTypes.pointSetDist let toContinuous: t => option let toDiscrete: t => option let normalize: t => t @@ -39,7 +39,7 @@ module Dist = (T: dist) => { let mapY = T.mapY let xToY = T.xToY let downsample = T.downsample - let toShape = T.toShape + let toPointSetDist = T.toPointSetDist let toDiscreteProbabilityMassFraction = T.toDiscreteProbabilityMassFraction let toContinuous = T.toContinuous let toDiscrete = T.toDiscrete diff --git a/packages/squiggle-lang/src/rescript/pointSetDist/Mixed.res b/packages/squiggle-lang/src/rescript/pointSetDist/Mixed.res index 99a0021b..dcdb2c2f 100644 --- a/packages/squiggle-lang/src/rescript/pointSetDist/Mixed.res +++ b/packages/squiggle-lang/src/rescript/pointSetDist/Mixed.res @@ -43,7 +43,7 @@ module T = Dist({ min(Continuous.T.minX(continuous), Discrete.T.minX(discrete)) let maxX = ({continuous, discrete}: t) => max(Continuous.T.maxX(continuous), Discrete.T.maxX(discrete)) - let toShape = (t: t): PointSetTypes.shape => Mixed(t) + let toPointSetDist = (t: t): PointSetTypes.pointSetDist => Mixed(t) let updateIntegralCache = updateIntegralCache diff --git a/packages/squiggle-lang/src/rescript/pointSetDist/MixedShapeBuilder.res b/packages/squiggle-lang/src/rescript/pointSetDist/MixedShapeBuilder.res index fe853989..89273283 100644 --- a/packages/squiggle-lang/src/rescript/pointSetDist/MixedShapeBuilder.res +++ b/packages/squiggle-lang/src/rescript/pointSetDist/MixedShapeBuilder.res @@ -11,7 +11,7 @@ type assumptions = { let buildSimple = ( ~continuous: option, ~discrete: option, -): option => { +): option => { let continuous = continuous |> E.O.default(Continuous.make(~integralSumCache=Some(0.0), {xs: [], ys: []})) let discrete = diff --git a/packages/squiggle-lang/src/rescript/pointSetDist/PointSetDist.res b/packages/squiggle-lang/src/rescript/pointSetDist/PointSetDist.res index fc4ac9ea..caf0fa1f 100644 --- a/packages/squiggle-lang/src/rescript/pointSetDist/PointSetDist.res +++ b/packages/squiggle-lang/src/rescript/pointSetDist/PointSetDist.res @@ -1,6 +1,6 @@ open Distributions -type t = PointSetTypes.shape +type t = PointSetTypes.pointSetDist let mapToAll = ((fn1, fn2, fn3), t: t) => switch t { | Mixed(m) => fn1(m) @@ -36,12 +36,12 @@ let toMixed = mapToAll(( let combineAlgebraically = (op: ASTTypes.algebraicOperation, t1: t, t2: t): t => switch (t1, t2) { | (Continuous(m1), Continuous(m2)) => - Continuous.combineAlgebraically(op, m1, m2) |> Continuous.T.toShape + Continuous.combineAlgebraically(op, m1, m2) |> Continuous.T.toPointSetDist | (Continuous(m1), Discrete(m2)) | (Discrete(m2), Continuous(m1)) => - Continuous.combineAlgebraicallyWithDiscrete(op, m1, m2) |> Continuous.T.toShape - | (Discrete(m1), Discrete(m2)) => Discrete.combineAlgebraically(op, m1, m2) |> Discrete.T.toShape - | (m1, m2) => Mixed.combineAlgebraically(op, toMixed(m1), toMixed(m2)) |> Mixed.T.toShape + Continuous.combineAlgebraicallyWithDiscrete(op, m1, m2) |> Continuous.T.toPointSetDist + | (Discrete(m1), Discrete(m2)) => Discrete.combineAlgebraically(op, m1, m2) |> Discrete.T.toPointSetDist + | (m1, m2) => Mixed.combineAlgebraically(op, toMixed(m1), toMixed(m2)) |> Mixed.T.toPointSetDist } let combinePointwise = ( @@ -70,12 +70,12 @@ let combinePointwise = ( } module T = Dist({ - type t = PointSetTypes.shape + type t = PointSetTypes.pointSetDist type integral = PointSetTypes.continuousShape let xToY = (f: float) => mapToAll((Mixed.T.xToY(f), Discrete.T.xToY(f), Continuous.T.xToY(f))) - let toShape = (t: t) => t + let toPointSetDist = (t: t) => t let toContinuous = t => None let toDiscrete = t => None diff --git a/packages/squiggle-lang/src/rescript/pointSetDist/PointSetTypes.res b/packages/squiggle-lang/src/rescript/pointSetDist/PointSetTypes.res index ebce1fe3..cd142ddc 100644 --- a/packages/squiggle-lang/src/rescript/pointSetDist/PointSetTypes.res +++ b/packages/squiggle-lang/src/rescript/pointSetDist/PointSetTypes.res @@ -50,15 +50,15 @@ type mixedShape = { integralCache: option, } -type shapeMonad<'a, 'b, 'c> = +type pointSetDistMonad<'a, 'b, 'c> = | Mixed('a) | Discrete('b) | Continuous('c) -type shape = shapeMonad +type pointSetDist = pointSetDistMonad module ShapeMonad = { - let fmap = (t: shapeMonad<'a, 'b, 'c>, (fn1, fn2, fn3)): shapeMonad<'d, 'e, 'f> => + let fmap = (t: pointSetDistMonad<'a, 'b, 'c>, (fn1, fn2, fn3)): pointSetDistMonad<'d, 'e, 'f> => switch t { | Mixed(m) => Mixed(fn1(m)) | Discrete(m) => Discrete(fn2(m)) @@ -68,13 +68,13 @@ module ShapeMonad = { type generationSource = | SquiggleString(string) - | Shape(shape) + | Shape(pointSetDist) type distributionUnit = | UnspecifiedDistribution type distPlus = { - shape: shape, + pointSetDist: pointSetDist, domain: domain, integralCache: continuousShape, unit: distributionUnit, diff --git a/packages/squiggle-lang/src/rescript/sampleSet/KdeLibrary.js b/packages/squiggle-lang/src/rescript/sampleSet/KdeLibrary.js index d95d3829..c901dd96 100644 --- a/packages/squiggle-lang/src/rescript/sampleSet/KdeLibrary.js +++ b/packages/squiggle-lang/src/rescript/sampleSet/KdeLibrary.js @@ -15,7 +15,6 @@ const samplesToContinuousPdf = ( return {xs: pdf.map(r => r.x), ys: pdf.map(r => r.y)}; }; - module.exports = { samplesToContinuousPdf, }; diff --git a/packages/squiggle-lang/src/rescript/sampleSet/SamplesToShape.res b/packages/squiggle-lang/src/rescript/sampleSet/SampleSet.res similarity index 95% rename from packages/squiggle-lang/src/rescript/sampleSet/SamplesToShape.res rename to packages/squiggle-lang/src/rescript/sampleSet/SampleSet.res index d7553da1..03227ed2 100644 --- a/packages/squiggle-lang/src/rescript/sampleSet/SamplesToShape.res +++ b/packages/squiggle-lang/src/rescript/sampleSet/SampleSet.res @@ -11,7 +11,7 @@ module Internals = { type outputs = { continuousParseParams: option, - shape: option, + pointSetDist: option, } } @@ -78,7 +78,7 @@ module Internals = { } } -let toShape = ( +let toPointSetDist = ( ~samples: Internals.T.t, ~samplingInputs: ASTTypes.AST.samplingInputs, (), @@ -127,17 +127,15 @@ let toShape = ( } : None - let shape = MixedShapeBuilder.buildSimple( + let pointSetDist = MixedShapeBuilder.buildSimple( ~continuous=pdf |> E.O.fmap(fst), ~discrete=Some(discrete), ) let samplesParse: Internals.Types.outputs = { continuousParseParams: pdf |> E.O.fmap(snd), - shape: shape, + pointSetDist: pointSetDist, } samplesParse -} - -let fromSamples = (~samplingInputs, samples) => toShape(~samples, ~samplingInputs, ()) +} \ No newline at end of file diff --git a/packages/squiggle-lang/src/rescript/symbolicDist/SymbolicDist.res b/packages/squiggle-lang/src/rescript/symbolicDist/SymbolicDist.res index 0c9b4aa4..aa02f32a 100644 --- a/packages/squiggle-lang/src/rescript/symbolicDist/SymbolicDist.res +++ b/packages/squiggle-lang/src/rescript/symbolicDist/SymbolicDist.res @@ -317,7 +317,7 @@ module T = { | _ => #NoSolution } - let toShape = (sampleCount, d: symbolicDist): PointSetTypes.shape => + let toPointSetDist = (sampleCount, d: symbolicDist): PointSetTypes.pointSetDist => switch d { | #Float(v) => Discrete(Discrete.make(~integralSumCache=Some(1.0), {xs: [v], ys: [1.0]})) | _ =>