Add isNormalized to Continuous

This commit is contained in:
Sam Nolan 2022-04-26 13:25:45 -04:00
parent e47deb8433
commit 350e420884
2 changed files with 6 additions and 3 deletions

View File

@ -14,9 +14,7 @@ describe("Converting from a sample set distribution", () => {
integralSumCache: None,
integralCache: None,
}
let fullShape = Continuous.updateIntegralCache(Some(Continuous.T.integral(c)), c)
let endY = Continuous.T.integralEndY(fullShape)
expect(endY)->toBeCloseTo(1.)
expect(Continuous.isNormalized(c))->toBe(true)
})
})

View File

@ -269,6 +269,11 @@ module T = Dist({
XYShape.Analysis.getVarianceDangerously(t, mean, Analysis.getMeanOfSquares)
})
let isNormalized = (t: t): bool => {
let areaUnderIntegral = t |> updateIntegralCache(Some(T.integral(t))) |> T.integralEndY
areaUnderIntegral -. 1. < 1e-7
}
let downsampleEquallyOverX = (length, t): t =>
t |> shapeMap(XYShape.XsConversion.proportionEquallyOverX(length))