diff --git a/packages/squiggle-lang/__tests__/Bandwidth_test.res b/packages/squiggle-lang/__tests__/Bandwidth_test.res index d37e5bb8..4e5c630a 100644 --- a/packages/squiggle-lang/__tests__/Bandwidth_test.res +++ b/packages/squiggle-lang/__tests__/Bandwidth_test.res @@ -4,10 +4,10 @@ open Expect describe("Bandwidth", () => { test("nrd0()", () => { let data = [1., 4., 3., 2.] - expect(Bandwidth.nrd0(data)) -> toEqual(0.7625801874014622) + expect(SampleSetDist_Bandwidth.nrd0(data)) -> toEqual(0.7625801874014622) }) test("nrd()", () => { let data = [1., 4., 3., 2.] - expect(Bandwidth.nrd(data)) -> toEqual(0.8981499984950554) + expect(SampleSetDist_Bandwidth.nrd(data)) -> toEqual(0.8981499984950554) }) }) diff --git a/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/SampleSetDist.res b/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/SampleSetDist.res index 7a63332f..f8dfd84a 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/SampleSetDist.res +++ b/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/SampleSetDist.res @@ -1,3 +1,8 @@ +/* +This is used as a smart constructor. The only way to create a SampleSetDist.t is to call +this constructor. +https://stackoverflow.com/questions/66909578/how-to-make-a-type-constructor-private-in-rescript-except-in-current-module +*/ module T: { @genType type t @@ -16,9 +21,12 @@ module T: { include T -let length = (t: t) => get(t) |> E.A.length +let length = (t: t) => get(t)->E.A.length -// TODO: Refactor to get error in the toPointSetDist function, instead of adding at very end. +/* +TODO: Refactor to get a more precise estimate. Also, this code is just fairly messy, could use +some refactoring. +*/ let toPointSetDist = (~samples: t, ~samplingInputs: SamplingInputs.samplingInputs): result< PointSetTypes.pointSetDist, string, @@ -27,7 +35,7 @@ let toPointSetDist = (~samples: t, ~samplingInputs: SamplingInputs.samplingInput ~samples=get(samples), ~samplingInputs, (), - ).pointSetDist |> E.O.toResult("Failed to convert to PointSetDist") + ).pointSetDist->E.O2.toResult("Failed to convert to PointSetDist") //Randomly get one sample from the distribution let sample = (t: t): float => { diff --git a/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/Bandwidth.res b/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/SampleSetDist_Bandwidth.res similarity index 94% rename from packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/Bandwidth.res rename to packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/SampleSetDist_Bandwidth.res index 6650b862..aef659d1 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/Bandwidth.res +++ b/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/SampleSetDist_Bandwidth.res @@ -1,4 +1,4 @@ -//The math here was taken from https://github.com/jasondavies/science.js/blob/master/src/stats/bandwidth.js +//The math here was taken from https://github.com/jasondavies/science.js/blob/master/src/stats/SampleSetDist_Bandwidth.js let len = x => E.A.length(x) |> float_of_int diff --git a/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/SampleSetDist_ToPointSet.res b/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/SampleSetDist_ToPointSet.res index c8880f7a..59b4fa46 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/SampleSetDist_ToPointSet.res +++ b/packages/squiggle-lang/src/rescript/Distributions/SampleSetDist/SampleSetDist_ToPointSet.res @@ -70,7 +70,7 @@ module Internals = { let formatUnitWidth = w => Jstat.max([w, 1.0]) |> int_of_float let suggestedUnitWidth = (samples, outputXYPoints) => { - let suggestedXWidth = Bandwidth.nrd0(samples) + let suggestedXWidth = SampleSetDist_Bandwidth.nrd0(samples) xWidthToUnitWidth(samples, outputXYPoints, suggestedXWidth) } @@ -97,7 +97,7 @@ let toPointSetDist = ( let pdf = continuousPart |> E.A.length > 5 ? { - let _suggestedXWidth = Bandwidth.nrd0(continuousPart) + let _suggestedXWidth = SampleSetDist_Bandwidth.nrd0(continuousPart) // todo: This does some recalculating from the last step. let _suggestedUnitWidth = Internals.T.suggestedUnitWidth( continuousPart,