First pass at file renaming
This commit is contained in:
parent
5a5a3e1ddc
commit
98779c127b
|
@ -6,12 +6,12 @@ let makeTest = (~only=false, str, item1, item2) =>
|
|||
? Only.test(str, () => expect(item1) -> toEqual(item2))
|
||||
: test(str, () => expect(item1) -> toEqual(item2))
|
||||
|
||||
describe("DistTypes", () =>
|
||||
describe("PointSetTypes", () =>
|
||||
describe("Domain", () => {
|
||||
let makeComplete = (yPoint, expectation) =>
|
||||
makeTest(
|
||||
"With input: " ++ Js.Float.toString(yPoint),
|
||||
DistTypes.Domain.yPointToSubYPoint(Complete, yPoint),
|
||||
PointSetTypes.Domain.yPointToSubYPoint(Complete, yPoint),
|
||||
expectation,
|
||||
)
|
||||
let makeSingle = (direction: [#left | #right], excludingProbabilityMass, yPoint, expectation) =>
|
||||
|
@ -19,7 +19,7 @@ describe("DistTypes", () =>
|
|||
"Excluding: " ++
|
||||
(Js.Float.toString(excludingProbabilityMass) ++
|
||||
(" and yPoint: " ++ Js.Float.toString(yPoint))),
|
||||
DistTypes.Domain.yPointToSubYPoint(
|
||||
PointSetTypes.Domain.yPointToSubYPoint(
|
||||
direction == #left
|
||||
? LeftLimited({xPoint: 3.0, excludingProbabilityMass: excludingProbabilityMass})
|
||||
: RightLimited({xPoint: 3.0, excludingProbabilityMass: excludingProbabilityMass}),
|
||||
|
@ -28,7 +28,7 @@ describe("DistTypes", () =>
|
|||
expectation,
|
||||
)
|
||||
let makeDouble = (domain, yPoint, expectation) =>
|
||||
makeTest("Excluding: limits", DistTypes.Domain.yPointToSubYPoint(domain, yPoint), expectation)
|
||||
makeTest("Excluding: limits", PointSetTypes.Domain.yPointToSubYPoint(domain, yPoint), expectation)
|
||||
|
||||
describe("With Complete Domain", () => {
|
||||
makeComplete(0.0, Some(0.0))
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
open Jest
|
||||
open Expect
|
||||
|
||||
let shape: DistTypes.xyShape = {xs: [1., 4., 8.], ys: [8., 9., 2.]}
|
||||
let shape: PointSetTypes.xyShape = {xs: [1., 4., 8.], ys: [8., 9., 2.]}
|
||||
|
||||
// let makeTest = (~only=false, str, item1, item2) =>
|
||||
// only
|
||||
|
@ -131,7 +131,7 @@ let shape: DistTypes.xyShape = {xs: [1., 4., 8.], ys: [8., 9., 2.]}
|
|||
|
||||
// describe("Discrete", () => {
|
||||
// open Discrete;
|
||||
// let shape: DistTypes.xyShape = {
|
||||
// let shape: PointSetTypes.xyShape = {
|
||||
// xs: [|1., 4., 8.|],
|
||||
// ys: [|0.3, 0.5, 0.2|],
|
||||
// };
|
||||
|
@ -209,7 +209,7 @@ let shape: DistTypes.xyShape = {xs: [1., 4., 8.], ys: [8., 9., 2.]}
|
|||
|
||||
// describe("Mixed", () => {
|
||||
// open Distributions.Mixed;
|
||||
// let discreteShape: DistTypes.xyShape = {
|
||||
// let discreteShape: PointSetTypes.xyShape = {
|
||||
// xs: [|1., 4., 8.|],
|
||||
// ys: [|0.3, 0.5, 0.2|],
|
||||
// };
|
||||
|
@ -309,7 +309,7 @@ let shape: DistTypes.xyShape = {xs: [1., 4., 8.], ys: [8., 9., 2.]}
|
|||
|
||||
// describe("Distplus", () => {
|
||||
// open DistPlus;
|
||||
// let discreteShape: DistTypes.xyShape = {
|
||||
// let discreteShape: PointSetTypes.xyShape = {
|
||||
// xs: [|1., 4., 8.|],
|
||||
// ys: [|0.3, 0.5, 0.2|],
|
||||
// };
|
||||
|
@ -382,7 +382,7 @@ let shape: DistTypes.xyShape = {xs: [1., 4., 8.], ys: [8., 9., 2.]}
|
|||
// let variance = stdev ** 2.0;
|
||||
// let numSamples = 10000;
|
||||
// open Distributions.Shape;
|
||||
// let normal: SymbolicTypes.symbolicDist = `Normal({mean, stdev});
|
||||
// let normal: SymbolicDistTypes.symbolicDist = `Normal({mean, stdev});
|
||||
// let normalShape = ExpressionTree.toShape(numSamples, `SymbolicDist(normal));
|
||||
// let lognormal = SymbolicDist.Lognormal.fromMeanAndStdev(mean, stdev);
|
||||
// let lognormalShape = ExpressionTree.toShape(numSamples, `SymbolicDist(lognormal));
|
||||
|
|
|
@ -28,7 +28,7 @@ let evalParams: ExpressionTypes.ExpressionTree.evaluationParams = {
|
|||
evaluateNode: ExpressionTreeEvaluator.toLeaf,
|
||||
};
|
||||
|
||||
let shape1: DistTypes.xyShape = {xs: [|1., 4., 8.|], ys: [|0.2, 0.4, 0.8|]};
|
||||
let shape1: PointSetTypes.xyShape = {xs: [|1., 4., 8.|], ys: [|0.2, 0.4, 0.8|]};
|
||||
|
||||
describe("XYShapes", () => {
|
||||
describe("logScorePoint", () => {
|
||||
|
|
|
@ -6,14 +6,14 @@ let makeTest = (~only=false, str, item1, item2) =>
|
|||
? Only.test(str, () => expect(item1) -> toEqual(item2))
|
||||
: test(str, () => expect(item1) -> toEqual(item2))
|
||||
|
||||
let shape1: DistTypes.xyShape = {xs: [1., 4., 8.], ys: [0.2, 0.4, 0.8]}
|
||||
let shape1: PointSetTypes.xyShape = {xs: [1., 4., 8.], ys: [0.2, 0.4, 0.8]}
|
||||
|
||||
let shape2: DistTypes.xyShape = {
|
||||
let shape2: PointSetTypes.xyShape = {
|
||||
xs: [1., 5., 10.],
|
||||
ys: [0.2, 0.5, 0.8],
|
||||
}
|
||||
|
||||
let shape3: DistTypes.xyShape = {
|
||||
let shape3: PointSetTypes.xyShape = {
|
||||
xs: [1., 20., 50.],
|
||||
ys: [0.2, 0.5, 0.8],
|
||||
}
|
||||
|
|
16
packages/squiggle-lang/dist/index.js
vendored
16
packages/squiggle-lang/dist/index.js
vendored
File diff suppressed because one or more lines are too long
2
packages/squiggle-lang/dist/report.html
vendored
2
packages/squiggle-lang/dist/report.html
vendored
File diff suppressed because one or more lines are too long
|
@ -1,5 +0,0 @@
|
|||
type t = ExpressionTypes.Program.program
|
||||
|
||||
let last = (r: t) => E.A.last(r) |> E.O.toResult("No rendered lines")
|
||||
// let run = (p:program) => p |> E.A.last |> E.O.fmap(r =>
|
||||
// )
|
|
@ -1,3 +1,3 @@
|
|||
const ProgramEvaluator = require('../distPlus/ProgramEvaluator.gen.js');
|
||||
const ProgramEvaluator = require('../rescript/ProgramEvaluator.gen.js');
|
||||
|
||||
exports.runMePlease = ProgramEvaluator.runAll
|
|
@ -60,7 +60,7 @@ module Internals = {
|
|||
|
||||
type outputs = {
|
||||
graph: ExpressionTypes.ExpressionTree.node,
|
||||
shape: DistTypes.shape,
|
||||
shape: PointSetTypes.shape,
|
||||
}
|
||||
let makeOutputs = (graph, shape): outputs => {graph: graph, shape: shape}
|
||||
|
||||
|
@ -93,7 +93,7 @@ module Internals = {
|
|||
let inputsToLeaf = (inputs: Inputs.inputs) =>
|
||||
MathJsParser.fromString(inputs.squiggleString) |> E.R.bind(_, g => runProgram(inputs, g))
|
||||
|
||||
let outputToDistPlus = (inputs: Inputs.inputs, shape: DistTypes.shape) =>
|
||||
let outputToDistPlus = (inputs: Inputs.inputs, shape: PointSetTypes.shape) =>
|
||||
DistPlus.make(~shape, ~squiggleString=Some(inputs.squiggleString), ())
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
open ExpressionTypes.ExpressionTree
|
||||
// This file exists to manage a dependency cycle. It would be good to refactor later.
|
||||
|
||||
let rec toString: node => string = x =>
|
||||
switch x {
|
||||
|
@ -23,4 +24,4 @@ let rec toString: node => string = x =>
|
|||
|> E.A.fmap(((name, value)) => name ++ (":" ++ toString(value)))
|
||||
|> Js.String.concatMany(_, ",")) ++
|
||||
"}")
|
||||
}
|
||||
}
|
|
@ -18,8 +18,8 @@ type distToFloatOperation = [
|
|||
module ExpressionTree = {
|
||||
type rec hash = array<(string, node)>
|
||||
and node = [
|
||||
| #SymbolicDist(SymbolicTypes.symbolicDist)
|
||||
| #RenderedDist(DistTypes.shape)
|
||||
| #SymbolicDist(SymbolicDistTypes.symbolicDist)
|
||||
| #RenderedDist(PointSetTypes.shape)
|
||||
| #Symbol(string)
|
||||
| #Hash(hash)
|
||||
| #Array(array<node>)
|
||||
|
@ -148,7 +148,7 @@ module ExpressionTree = {
|
|||
| _ => None
|
||||
}
|
||||
|
||||
let _toFloat = (t: DistTypes.shape) =>
|
||||
let _toFloat = (t: PointSetTypes.shape) =>
|
||||
switch t {
|
||||
| Discrete({xyShape: {xs: [x], ys: [1.0]}}) => Some(#SymbolicDist(#Float(x)))
|
||||
| _ => None
|
|
@ -36,8 +36,8 @@ module Function = {
|
|||
|
||||
module Primative = {
|
||||
type t = [
|
||||
| #SymbolicDist(SymbolicTypes.symbolicDist)
|
||||
| #RenderedDist(DistTypes.shape)
|
||||
| #SymbolicDist(SymbolicDistTypes.symbolicDist)
|
||||
| #RenderedDist(PointSetTypes.shape)
|
||||
| #Function(array<string>, node)
|
||||
]
|
||||
|
||||
|
@ -61,8 +61,8 @@ module Primative = {
|
|||
|
||||
module SamplingDistribution = {
|
||||
type t = [
|
||||
| #SymbolicDist(SymbolicTypes.symbolicDist)
|
||||
| #RenderedDist(DistTypes.shape)
|
||||
| #SymbolicDist(SymbolicDistTypes.symbolicDist)
|
||||
| #RenderedDist(PointSetTypes.shape)
|
||||
]
|
||||
|
||||
let isSamplingDistribution: node => bool = x =>
|
|
@ -2,8 +2,8 @@ type node = ExpressionTypes.ExpressionTree.node
|
|||
let getFloat = ExpressionTypes.ExpressionTree.getFloat
|
||||
|
||||
type samplingDist = [
|
||||
| #SymbolicDist(SymbolicTypes.symbolicDist)
|
||||
| #RenderedDist(DistTypes.shape)
|
||||
| #SymbolicDist(SymbolicDistTypes.symbolicDist)
|
||||
| #RenderedDist(PointSetTypes.shape)
|
||||
]
|
||||
|
||||
type rec hashType = array<(string, _type)>
|
||||
|
@ -18,7 +18,7 @@ and _type = [
|
|||
type rec hashTypedValue = array<(string, typedValue)>
|
||||
and typedValue = [
|
||||
| #Float(float)
|
||||
| #RenderedDist(DistTypes.shape)
|
||||
| #RenderedDist(PointSetTypes.shape)
|
||||
| #SamplingDist(samplingDist)
|
||||
| #Array(array<typedValue>)
|
||||
| #Hash(hashTypedValue)
|
|
@ -97,9 +97,9 @@ let toDiscretePointMassesFromTriangulars = (
|
|||
|
||||
let combineShapesContinuousContinuous = (
|
||||
op: ExpressionTypes.algebraicOperation,
|
||||
s1: DistTypes.xyShape,
|
||||
s2: DistTypes.xyShape,
|
||||
): DistTypes.xyShape => {
|
||||
s1: PointSetTypes.xyShape,
|
||||
s2: PointSetTypes.xyShape,
|
||||
): PointSetTypes.xyShape => {
|
||||
let t1n = s1 |> XYShape.T.length
|
||||
let t2n = s2 |> XYShape.T.length
|
||||
|
||||
|
@ -188,7 +188,7 @@ let combineShapesContinuousContinuous = (
|
|||
{xs: outputXs, ys: outputYs}
|
||||
}
|
||||
|
||||
let toDiscretePointMassesFromDiscrete = (s: DistTypes.xyShape): pointMassesWithMoments => {
|
||||
let toDiscretePointMassesFromDiscrete = (s: PointSetTypes.xyShape): pointMassesWithMoments => {
|
||||
let {xs, ys}: XYShape.T.t = s
|
||||
let n = E.A.length(xs)
|
||||
|
||||
|
@ -201,9 +201,9 @@ let toDiscretePointMassesFromDiscrete = (s: DistTypes.xyShape): pointMassesWithM
|
|||
|
||||
let combineShapesContinuousDiscrete = (
|
||||
op: ExpressionTypes.algebraicOperation,
|
||||
continuousShape: DistTypes.xyShape,
|
||||
discreteShape: DistTypes.xyShape,
|
||||
): DistTypes.xyShape => {
|
||||
continuousShape: PointSetTypes.xyShape,
|
||||
discreteShape: PointSetTypes.xyShape,
|
||||
): PointSetTypes.xyShape => {
|
||||
let t1n = continuousShape |> XYShape.T.length
|
||||
let t2n = discreteShape |> XYShape.T.length
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
open Distributions
|
||||
|
||||
type t = DistTypes.continuousShape
|
||||
type t = PointSetTypes.continuousShape
|
||||
let getShape = (t: t) => t.xyShape
|
||||
let interpolation = (t: t) => t.interpolation
|
||||
let make = (~interpolation=#Linear, ~integralSumCache=None, ~integralCache=None, xyShape): t => {
|
||||
|
@ -17,10 +17,10 @@ let shapeMap = (fn, {xyShape, interpolation, integralSumCache, integralCache}: t
|
|||
}
|
||||
let lastY = (t: t) => t |> getShape |> XYShape.T.lastY
|
||||
let oShapeMap = (fn, {xyShape, interpolation, integralSumCache, integralCache}: t): option<
|
||||
DistTypes.continuousShape,
|
||||
PointSetTypes.continuousShape,
|
||||
> => fn(xyShape) |> E.O.fmap(make(~interpolation, ~integralSumCache, ~integralCache))
|
||||
|
||||
let emptyIntegral: DistTypes.continuousShape = {
|
||||
let emptyIntegral: PointSetTypes.continuousShape = {
|
||||
xyShape: {
|
||||
xs: [neg_infinity],
|
||||
ys: [0.0],
|
||||
|
@ -29,7 +29,7 @@ let emptyIntegral: DistTypes.continuousShape = {
|
|||
integralSumCache: Some(0.0),
|
||||
integralCache: None,
|
||||
}
|
||||
let empty: DistTypes.continuousShape = {
|
||||
let empty: PointSetTypes.continuousShape = {
|
||||
xyShape: XYShape.T.empty,
|
||||
interpolation: #Linear,
|
||||
integralSumCache: Some(0.0),
|
||||
|
@ -47,11 +47,11 @@ let stepwiseToLinear = (t: t): t =>
|
|||
let combinePointwise = (
|
||||
~integralSumCachesFn=(_, _) => None,
|
||||
~integralCachesFn: (t, t) => option<t>=(_, _) => None,
|
||||
~distributionType: DistTypes.distributionType=#PDF,
|
||||
~distributionType: PointSetTypes.distributionType=#PDF,
|
||||
fn: (float, float) => float,
|
||||
t1: DistTypes.continuousShape,
|
||||
t2: DistTypes.continuousShape,
|
||||
): DistTypes.continuousShape => {
|
||||
t1: PointSetTypes.continuousShape,
|
||||
t2: PointSetTypes.continuousShape,
|
||||
): PointSetTypes.continuousShape => {
|
||||
// If we're adding the distributions, and we know the total of each, then we
|
||||
// can just sum them up. Otherwise, all bets are off.
|
||||
let combinedIntegralSum = Common.combineIntegralSums(
|
||||
|
@ -130,19 +130,19 @@ let rec scaleBy = (~scale=1.0, t: t): t => {
|
|||
}
|
||||
|
||||
module T = Dist({
|
||||
type t = DistTypes.continuousShape
|
||||
type integral = DistTypes.continuousShape
|
||||
type t = PointSetTypes.continuousShape
|
||||
type integral = PointSetTypes.continuousShape
|
||||
let minX = shapeFn(XYShape.T.minX)
|
||||
let maxX = shapeFn(XYShape.T.maxX)
|
||||
let mapY = mapY
|
||||
let updateIntegralCache = updateIntegralCache
|
||||
let toDiscreteProbabilityMassFraction = _ => 0.0
|
||||
let toShape = (t: t): DistTypes.shape => Continuous(t)
|
||||
let toShape = (t: t): PointSetTypes.shape => Continuous(t)
|
||||
let xToY = (f, {interpolation, xyShape}: t) =>
|
||||
switch interpolation {
|
||||
| #Stepwise => xyShape |> XYShape.XtoY.stepwiseIncremental(f) |> E.O.default(0.0)
|
||||
| #Linear => xyShape |> XYShape.XtoY.linear(f)
|
||||
} |> DistTypes.MixedPoint.makeContinuous
|
||||
} |> PointSetTypes.MixedPoint.makeContinuous
|
||||
|
||||
let truncate = (leftCutoff: option<float>, rightCutoff: option<float>, t: t) => {
|
||||
let lc = E.O.default(neg_infinity, leftCutoff)
|
||||
|
@ -213,7 +213,7 @@ module T = Dist({
|
|||
let combineAlgebraicallyWithDiscrete = (
|
||||
op: ExpressionTypes.algebraicOperation,
|
||||
t1: t,
|
||||
t2: DistTypes.discreteShape,
|
||||
t2: PointSetTypes.discreteShape,
|
||||
) => {
|
||||
let t1s = t1 |> getShape
|
||||
let t2s = t2.xyShape // TODO would like to use Discrete.getShape here, but current file structure doesn't allow for that
|
|
@ -1,6 +1,6 @@
|
|||
open Distributions
|
||||
|
||||
type t = DistTypes.discreteShape
|
||||
type t = PointSetTypes.discreteShape
|
||||
|
||||
let make = (~integralSumCache=None, ~integralCache=None, xyShape): t => {
|
||||
xyShape: xyShape,
|
||||
|
@ -16,13 +16,13 @@ let getShape = (t: t) => t.xyShape
|
|||
let oShapeMap = (fn, {xyShape, integralSumCache, integralCache}: t): option<t> =>
|
||||
fn(xyShape) |> E.O.fmap(make(~integralSumCache, ~integralCache))
|
||||
|
||||
let emptyIntegral: DistTypes.continuousShape = {
|
||||
let emptyIntegral: PointSetTypes.continuousShape = {
|
||||
xyShape: {xs: [neg_infinity], ys: [0.0]},
|
||||
interpolation: #Stepwise,
|
||||
integralSumCache: Some(0.0),
|
||||
integralCache: None,
|
||||
}
|
||||
let empty: DistTypes.discreteShape = {
|
||||
let empty: PointSetTypes.discreteShape = {
|
||||
xyShape: XYShape.T.empty,
|
||||
integralSumCache: Some(0.0),
|
||||
integralCache: Some(emptyIntegral),
|
||||
|
@ -35,13 +35,13 @@ let lastY = (t: t) => t |> getShape |> XYShape.T.lastY
|
|||
let combinePointwise = (
|
||||
~integralSumCachesFn=(_, _) => None,
|
||||
~integralCachesFn: (
|
||||
DistTypes.continuousShape,
|
||||
DistTypes.continuousShape,
|
||||
) => option<DistTypes.continuousShape>=(_, _) => None,
|
||||
PointSetTypes.continuousShape,
|
||||
PointSetTypes.continuousShape,
|
||||
) => option<PointSetTypes.continuousShape>=(_, _) => None,
|
||||
fn,
|
||||
t1: DistTypes.discreteShape,
|
||||
t2: DistTypes.discreteShape,
|
||||
): DistTypes.discreteShape => {
|
||||
t1: PointSetTypes.discreteShape,
|
||||
t2: PointSetTypes.discreteShape,
|
||||
): PointSetTypes.discreteShape => {
|
||||
let combinedIntegralSum = Common.combineIntegralSums(
|
||||
integralSumCachesFn,
|
||||
t1.integralSumCache,
|
||||
|
@ -67,7 +67,7 @@ let reduce = (
|
|||
~integralCachesFn=(_, _) => None,
|
||||
fn,
|
||||
discreteShapes,
|
||||
): DistTypes.discreteShape =>
|
||||
): PointSetTypes.discreteShape =>
|
||||
discreteShapes |> E.A.fold_left(
|
||||
combinePointwise(~integralSumCachesFn, ~integralCachesFn, fn),
|
||||
empty,
|
||||
|
@ -134,8 +134,8 @@ let scaleBy = (~scale=1.0, t: t): t => {
|
|||
}
|
||||
|
||||
module T = Dist({
|
||||
type t = DistTypes.discreteShape
|
||||
type integral = DistTypes.continuousShape
|
||||
type t = PointSetTypes.discreteShape
|
||||
type integral = PointSetTypes.continuousShape
|
||||
let integral = t =>
|
||||
switch (getShape(t) |> XYShape.T.isEmpty, t.integralCache) {
|
||||
| (true, _) => emptyIntegral
|
||||
|
@ -157,7 +157,7 @@ module T = Dist({
|
|||
let toDiscreteProbabilityMassFraction = _ => 1.0
|
||||
let mapY = mapY
|
||||
let updateIntegralCache = updateIntegralCache
|
||||
let toShape = (t: t): DistTypes.shape => Discrete(t)
|
||||
let toShape = (t: t): PointSetTypes.shape => Discrete(t)
|
||||
let toContinuous = _ => None
|
||||
let toDiscrete = t => Some(t)
|
||||
|
||||
|
@ -199,7 +199,7 @@ module T = Dist({
|
|||
|> getShape
|
||||
|> XYShape.XtoY.stepwiseIfAtX(f)
|
||||
|> E.O.default(0.0)
|
||||
|> DistTypes.MixedPoint.makeDiscrete
|
||||
|> PointSetTypes.MixedPoint.makeDiscrete
|
||||
|
||||
let integralXtoY = (f, t) => t |> integral |> Continuous.getShape |> XYShape.XtoY.linear(f)
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
open DistTypes;
|
||||
open PointSetTypes;
|
||||
|
||||
type t = DistTypes.distPlus;
|
||||
type t = PointSetTypes.distPlus;
|
||||
|
||||
let shapeIntegral = shape => Shape.T.Integral.get(shape);
|
||||
let make =
|
||||
|
@ -49,8 +49,8 @@ let shapeFn = (fn, {shape}: t) => fn(shape);
|
|||
|
||||
module T =
|
||||
Distributions.Dist({
|
||||
type t = DistTypes.distPlus;
|
||||
type integral = DistTypes.distPlus;
|
||||
type t = PointSetTypes.distPlus;
|
||||
type integral = PointSetTypes.distPlus;
|
||||
let toShape = toShape;
|
||||
let toContinuous = shapeFn(Shape.T.toContinuous);
|
||||
let toDiscrete = shapeFn(Shape.T.toDiscrete);
|
||||
|
@ -84,7 +84,7 @@ module T =
|
|||
let integral = (t: t) =>
|
||||
updateShape(Continuous(t.integralCache), t);
|
||||
|
||||
let updateIntegralCache = (integralCache: option<DistTypes.continuousShape>, t) =>
|
||||
let updateIntegralCache = (integralCache: option<PointSetTypes.continuousShape>, t) =>
|
||||
update(~integralCache=E.O.default(t.integralCache, integralCache), t);
|
||||
|
||||
let downsample = (i, t): t =>
|
|
@ -5,20 +5,20 @@ module type dist = {
|
|||
let maxX: t => float
|
||||
let mapY: (
|
||||
~integralSumCacheFn: float => option<float>=?,
|
||||
~integralCacheFn: DistTypes.continuousShape => option<DistTypes.continuousShape>=?,
|
||||
~integralCacheFn: PointSetTypes.continuousShape => option<PointSetTypes.continuousShape>=?,
|
||||
~fn: float => float,
|
||||
t,
|
||||
) => t
|
||||
let xToY: (float, t) => DistTypes.mixedPoint
|
||||
let toShape: t => DistTypes.shape
|
||||
let toContinuous: t => option<DistTypes.continuousShape>
|
||||
let toDiscrete: t => option<DistTypes.discreteShape>
|
||||
let xToY: (float, t) => PointSetTypes.mixedPoint
|
||||
let toShape: t => PointSetTypes.shape
|
||||
let toContinuous: t => option<PointSetTypes.continuousShape>
|
||||
let toDiscrete: t => option<PointSetTypes.discreteShape>
|
||||
let normalize: t => t
|
||||
let toDiscreteProbabilityMassFraction: t => float
|
||||
let downsample: (int, t) => t
|
||||
let truncate: (option<float>, option<float>, t) => t
|
||||
|
||||
let updateIntegralCache: (option<DistTypes.continuousShape>, t) => t
|
||||
let updateIntegralCache: (option<PointSetTypes.continuousShape>, t) => t
|
||||
|
||||
let integral: t => integral
|
||||
let integralEndY: t => float
|
||||
|
@ -74,11 +74,11 @@ module Common = {
|
|||
|
||||
let combineIntegrals = (
|
||||
combineFn: (
|
||||
DistTypes.continuousShape,
|
||||
DistTypes.continuousShape,
|
||||
) => option<DistTypes.continuousShape>,
|
||||
t1IntegralCache: option<DistTypes.continuousShape>,
|
||||
t2IntegralCache: option<DistTypes.continuousShape>,
|
||||
PointSetTypes.continuousShape,
|
||||
PointSetTypes.continuousShape,
|
||||
) => option<PointSetTypes.continuousShape>,
|
||||
t1IntegralCache: option<PointSetTypes.continuousShape>,
|
||||
t2IntegralCache: option<PointSetTypes.continuousShape>,
|
||||
) =>
|
||||
switch (t1IntegralCache, t2IntegralCache) {
|
||||
| (None, _)
|
|
@ -1,6 +1,6 @@
|
|||
open Distributions
|
||||
|
||||
type t = DistTypes.mixedShape
|
||||
type t = PointSetTypes.mixedShape
|
||||
let make = (~integralSumCache=None, ~integralCache=None, ~continuous, ~discrete): t => {
|
||||
continuous: continuous,
|
||||
discrete: discrete,
|
||||
|
@ -37,13 +37,13 @@ let updateIntegralCache = (integralCache, t: t): t => {
|
|||
}
|
||||
|
||||
module T = Dist({
|
||||
type t = DistTypes.mixedShape
|
||||
type integral = DistTypes.continuousShape
|
||||
type t = PointSetTypes.mixedShape
|
||||
type integral = PointSetTypes.continuousShape
|
||||
let minX = ({continuous, discrete}: t) =>
|
||||
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): DistTypes.shape => Mixed(t)
|
||||
let toShape = (t: t): PointSetTypes.shape => Mixed(t)
|
||||
|
||||
let updateIntegralCache = updateIntegralCache
|
||||
|
||||
|
@ -103,7 +103,7 @@ module T = Dist({
|
|||
let {continuous, discrete}: t = normalize(t)
|
||||
let c = Continuous.T.xToY(x, continuous)
|
||||
let d = Discrete.T.xToY(x, discrete)
|
||||
DistTypes.MixedPoint.add(c, d) // "add" here just combines the two values into a single MixedPoint.
|
||||
PointSetTypes.MixedPoint.add(c, d) // "add" here just combines the two values into a single MixedPoint.
|
||||
}
|
||||
|
||||
let toDiscreteProbabilityMassFraction = ({discrete, continuous}: t) => {
|
||||
|
@ -170,13 +170,13 @@ module T = Dist({
|
|||
~fn,
|
||||
t: t,
|
||||
): t => {
|
||||
let yMappedDiscrete: DistTypes.discreteShape =
|
||||
let yMappedDiscrete: PointSetTypes.discreteShape =
|
||||
t.discrete
|
||||
|> Discrete.T.mapY(~fn)
|
||||
|> Discrete.updateIntegralSumCache(E.O.bind(t.discrete.integralSumCache, integralSumCacheFn))
|
||||
|> Discrete.updateIntegralCache(E.O.bind(t.discrete.integralCache, integralCacheFn))
|
||||
|
||||
let yMappedContinuous: DistTypes.continuousShape =
|
||||
let yMappedContinuous: PointSetTypes.continuousShape =
|
||||
t.continuous
|
||||
|> Continuous.T.mapY(~fn)
|
||||
|> Continuous.updateIntegralSumCache(
|
|
@ -9,9 +9,9 @@ type assumptions = {
|
|||
}
|
||||
|
||||
let buildSimple = (
|
||||
~continuous: option<DistTypes.continuousShape>,
|
||||
~discrete: option<DistTypes.discreteShape>,
|
||||
): option<DistTypes.shape> => {
|
||||
~continuous: option<PointSetTypes.continuousShape>,
|
||||
~discrete: option<PointSetTypes.discreteShape>,
|
||||
): option<PointSetTypes.shape> => {
|
||||
let continuous =
|
||||
continuous |> E.O.default(Continuous.make(~integralSumCache=Some(0.0), {xs: [], ys: []}))
|
||||
let discrete =
|
|
@ -1,6 +1,6 @@
|
|||
open Distributions
|
||||
|
||||
type t = DistTypes.shape
|
||||
type t = PointSetTypes.shape
|
||||
let mapToAll = ((fn1, fn2, fn3), t: t) =>
|
||||
switch t {
|
||||
| Mixed(m) => fn1(m)
|
||||
|
@ -47,31 +47,31 @@ let combineAlgebraically = (op: ExpressionTypes.algebraicOperation, t1: t, t2: t
|
|||
let combinePointwise = (
|
||||
~integralSumCachesFn: (float, float) => option<float>=(_, _) => None,
|
||||
~integralCachesFn: (
|
||||
DistTypes.continuousShape,
|
||||
DistTypes.continuousShape,
|
||||
) => option<DistTypes.continuousShape>=(_, _) => None,
|
||||
PointSetTypes.continuousShape,
|
||||
PointSetTypes.continuousShape,
|
||||
) => option<PointSetTypes.continuousShape>=(_, _) => None,
|
||||
fn,
|
||||
t1: t,
|
||||
t2: t,
|
||||
) =>
|
||||
switch (t1, t2) {
|
||||
| (Continuous(m1), Continuous(m2)) =>
|
||||
DistTypes.Continuous(
|
||||
PointSetTypes.Continuous(
|
||||
Continuous.combinePointwise(~integralSumCachesFn, ~integralCachesFn, fn, m1, m2),
|
||||
)
|
||||
| (Discrete(m1), Discrete(m2)) =>
|
||||
DistTypes.Discrete(
|
||||
PointSetTypes.Discrete(
|
||||
Discrete.combinePointwise(~integralSumCachesFn, ~integralCachesFn, fn, m1, m2),
|
||||
)
|
||||
| (m1, m2) =>
|
||||
DistTypes.Mixed(
|
||||
PointSetTypes.Mixed(
|
||||
Mixed.combinePointwise(~integralSumCachesFn, ~integralCachesFn, fn, toMixed(m1), toMixed(m2)),
|
||||
)
|
||||
}
|
||||
|
||||
module T = Dist({
|
||||
type t = DistTypes.shape
|
||||
type integral = DistTypes.continuousShape
|
||||
type t = PointSetTypes.shape
|
||||
type integral = PointSetTypes.continuousShape
|
||||
|
||||
let xToY = (f: float) => mapToAll((Mixed.T.xToY(f), Discrete.T.xToY(f), Continuous.T.xToY(f)))
|
||||
|
||||
|
@ -163,7 +163,7 @@ module T = Dist({
|
|||
})
|
||||
|
||||
let pdf = (f: float, t: t) => {
|
||||
let mixedPoint: DistTypes.mixedPoint = T.xToY(f, t)
|
||||
let mixedPoint: PointSetTypes.mixedPoint = T.xToY(f, t)
|
||||
mixedPoint.continuous +. mixedPoint.discrete
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
open DistTypes
|
||||
open PointSetTypes
|
||||
|
||||
let interpolate = (xMin: float, xMax: float, yMin: float, yMax: float, xIntended: float): float => {
|
||||
let minProportion = (xMax -. xIntended) /. (xMax -. xMin)
|
||||
|
@ -126,8 +126,8 @@ module XtoY = {
|
|||
/* Returns a between-points-interpolating function that can be used with PointwiseCombination.combine.
|
||||
Interpolation can either be stepwise (using the value on the left) or linear. Extrapolation can be `UseZero or `UseOutermostPoints. */
|
||||
let continuousInterpolator = (
|
||||
interpolation: DistTypes.interpolationStrategy,
|
||||
extrapolation: DistTypes.extrapolationStrategy,
|
||||
interpolation: PointSetTypes.interpolationStrategy,
|
||||
extrapolation: PointSetTypes.extrapolationStrategy,
|
||||
): interpolator =>
|
||||
switch (interpolation, extrapolation) {
|
||||
| (#Linear, #UseZero) =>
|
||||
|
@ -395,7 +395,7 @@ module Analysis = {
|
|||
let integrateContinuousShape = (
|
||||
~indefiniteIntegralStepwise=(p, h1) => h1 *. p,
|
||||
~indefiniteIntegralLinear=(p, a, b) => a *. p +. b *. p ** 2.0 /. 2.0,
|
||||
t: DistTypes.continuousShape,
|
||||
t: PointSetTypes.continuousShape,
|
||||
): float => {
|
||||
let xs = t.xyShape.xs
|
||||
let ys = t.xyShape.ys
|
||||
|
@ -424,7 +424,7 @@ module Analysis = {
|
|||
})
|
||||
}
|
||||
|
||||
let getMeanOfSquaresContinuousShape = (t: DistTypes.continuousShape) => {
|
||||
let getMeanOfSquaresContinuousShape = (t: PointSetTypes.continuousShape) => {
|
||||
let indefiniteIntegralLinear = (p, a, b) => a *. p ** 3.0 /. 3.0 +. b *. p ** 4.0 /. 4.0
|
||||
let indefiniteIntegralStepwise = (p, h1) => h1 *. p ** 3.0 /. 3.0
|
||||
integrateContinuousShape(~indefiniteIntegralStepwise, ~indefiniteIntegralLinear, t)
|
|
@ -11,7 +11,7 @@ module Internals = {
|
|||
|
||||
type outputs = {
|
||||
continuousParseParams: option<samplingStats>,
|
||||
shape: option<DistTypes.shape>,
|
||||
shape: option<PointSetTypes.shape>,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ module Internals = {
|
|||
ys: array<float>,
|
||||
}
|
||||
|
||||
let jsToDist = (d: distJs): DistTypes.xyShape => {
|
||||
let jsToDist = (d: distJs): PointSetTypes.xyShape => {
|
||||
xs: xsGet(d),
|
||||
ys: ysGet(d),
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ let toShape = (
|
|||
Array.fast_sort(compare, samples)
|
||||
let (continuousPart, discretePart) = E.A.Sorted.Floats.split(samples)
|
||||
let length = samples |> E.A.length |> float_of_int
|
||||
let discrete: DistTypes.discreteShape =
|
||||
let discrete: PointSetTypes.discreteShape =
|
||||
discretePart
|
||||
|> E.FloatFloatMap.fmap(r => r /. length)
|
||||
|> E.FloatFloatMap.toArray
|
|
@ -1,4 +1,4 @@
|
|||
open SymbolicTypes
|
||||
open SymbolicDistTypes
|
||||
|
||||
module Normal = {
|
||||
type t = normal
|
||||
|
@ -317,7 +317,7 @@ module T = {
|
|||
| _ => #NoSolution
|
||||
}
|
||||
|
||||
let toShape = (sampleCount, d: symbolicDist): DistTypes.shape =>
|
||||
let toShape = (sampleCount, d: symbolicDist): PointSetTypes.shape =>
|
||||
switch d {
|
||||
| #Float(v) => Discrete(Discrete.make(~integralSumCache=Some(1.0), {xs: [v], ys: [1.0]}))
|
||||
| _ =>
|
Loading…
Reference in New Issue
Block a user