2022-05-02 21:15:23 +00:00
|
|
|
open Jest
|
|
|
|
open Expect
|
|
|
|
open TestHelpers
|
|
|
|
|
2022-05-02 22:40:34 +00:00
|
|
|
describe("Scale logarithm", () => {
|
2022-05-06 19:09:00 +00:00
|
|
|
/* These tests may not be important, because scalelog isn't normalized
|
|
|
|
The first one may be failing for a number of reasons.
|
|
|
|
*/
|
|
|
|
Skip.test("mean of the base e scalar logarithm of an exponential(10)", () => {
|
|
|
|
let rate = 10.0
|
|
|
|
let scalelog = DistributionOperation.Constructors.scaleLogarithm(
|
|
|
|
~env,
|
|
|
|
mkExponential(rate),
|
|
|
|
MagicNumbers.Math.e,
|
|
|
|
)
|
|
|
|
|
|
|
|
let meanResult = E.R2.bind(DistributionOperation.Constructors.mean(~env), scalelog)
|
|
|
|
// expected value of log of exponential distribution.
|
|
|
|
let meanAnalytical = Js.Math.log(rate) +. 1.0
|
|
|
|
switch meanResult {
|
|
|
|
| Ok(meanValue) => meanValue->expect->toBeCloseTo(meanAnalytical)
|
|
|
|
| Error(err) => err->expect->toBe(DistributionTypes.OperationError(DivisionByZeroError))
|
|
|
|
}
|
|
|
|
})
|
2022-05-04 15:42:51 +00:00
|
|
|
let low = 10.0
|
|
|
|
let high = 100.0
|
|
|
|
let scalelog = DistributionOperation.Constructors.scaleLogarithm(~env, mkUniform(low, high), 2.0)
|
2022-05-02 21:15:23 +00:00
|
|
|
|
2022-05-04 15:42:51 +00:00
|
|
|
test("mean of the base 2 scalar logarithm of a uniform(10, 100)", () => {
|
|
|
|
//For uniform pdf `_ => 1 / (b - a)`, the expected value of log of uniform is `integral from a to b of x * log(1 / (b -a)) dx`
|
|
|
|
let meanResult = E.R2.bind(DistributionOperation.Constructors.mean(~env), scalelog)
|
|
|
|
let meanAnalytical = -.Js.Math.log2(high -. low) /. 2.0 *. (high ** 2.0 -. low ** 2.0) // -. Js.Math.log2(high -. low)
|
|
|
|
switch meanResult {
|
|
|
|
| Ok(meanValue) => meanValue->expect->toBeCloseTo(meanAnalytical)
|
2022-05-04 16:21:30 +00:00
|
|
|
| Error(err) => err->expect->toEqual(DistributionTypes.OperationError(NegativeInfinityError))
|
2022-05-04 15:42:51 +00:00
|
|
|
}
|
2022-05-02 21:15:23 +00:00
|
|
|
})
|
|
|
|
})
|