Formatter

This commit is contained in:
Ozzie Gooen 2022-09-02 21:53:20 -07:00
parent 93f4c1e0c2
commit b87e952785
6 changed files with 47 additions and 39 deletions

View File

@ -63,9 +63,15 @@ describe("FunctionRegistry Library", () => {
testEvalToBe("SampleSet.fromList([3,5,2,3,5,2,3,5,2,3,3,5])", "Ok(Sample Set Distribution)")
testEvalToBe("SampleSet.fromList([3,5,2,3,5,2,3,5,2,3,3,5])", "Ok(Sample Set Distribution)")
testEvalToBe("SampleSet.fromFn({|| sample(normal(5,2))})", "Ok(Sample Set Distribution)")
testEvalToBe("SampleSet.min(SampleSet.fromDist(normal(50,2)), 2)", "Ok(Sample Set Distribution)")
testEvalToBe(
"SampleSet.min(SampleSet.fromDist(normal(50,2)), 2)",
"Ok(Sample Set Distribution)",
)
testEvalToBe("mean(SampleSet.min(SampleSet.fromDist(normal(50,2)), 2))", "Ok(2)")
testEvalToBe("SampleSet.max(SampleSet.fromDist(normal(50,2)), 10)", "Ok(Sample Set Distribution)")
testEvalToBe(
"SampleSet.max(SampleSet.fromDist(normal(50,2)), 10)",
"Ok(Sample Set Distribution)",
)
testEvalToBe(
"addOne(t)=t+1; SampleSet.toList(SampleSet.map(SampleSet.fromList([1,2,3,4,5,6]), addOne))",
"Ok([2,3,4,5,6,7])",

View File

@ -302,13 +302,15 @@ module T = Dist({
}
let sampleN = (t: t, n: int): array<float> => {
let discreteIntegralSum = discreteIntegralSum(t);
let integralSum = integralSum(t);
let discreteSampleLength:int = (Js.Int.toFloat(n) *. discreteIntegralSum /. integralSum) -> E.Float.toInt
let continuousSampleLength = n - discreteSampleLength;
let continuousSamples = t.continuous ->Continuous.T.normalize-> Continuous.T.sampleN( continuousSampleLength)
let discreteIntegralSum = discreteIntegralSum(t)
let integralSum = integralSum(t)
let discreteSampleLength: int =
(Js.Int.toFloat(n) *. discreteIntegralSum /. integralSum)->E.Float.toInt
let continuousSampleLength = n - discreteSampleLength
let continuousSamples =
t.continuous->Continuous.T.normalize->Continuous.T.sampleN(continuousSampleLength)
let discreteSamples = t.discrete->Discrete.T.normalize->Discrete.T.sampleN(discreteSampleLength)
Js.log3("Samples", continuousSamples, discreteSamples);
Js.log3("Samples", continuousSamples, discreteSamples)
E.A.concat(discreteSamples, continuousSamples)->E.A.shuffle
}
})