Merge pull request #357 from quantified-uncertainty/hotfix-negative-multiply
Prevent negative standard deviation in symbolic multiplication
This commit is contained in:
commit
296bc44a0d
|
@ -20,6 +20,7 @@ describe("eval on distribution functions", () => {
|
||||||
})
|
})
|
||||||
describe("unaryMinus", () => {
|
describe("unaryMinus", () => {
|
||||||
testEval("mean(-normal(5,2))", "Ok(-5)")
|
testEval("mean(-normal(5,2))", "Ok(-5)")
|
||||||
|
testEval("-normal(5,2)", "Ok(Normal(-5,2))")
|
||||||
})
|
})
|
||||||
describe("to", () => {
|
describe("to", () => {
|
||||||
testEval("5 to 2", "Error(Math Error: Low value must be less than high value.)")
|
testEval("5 to 2", "Error(Math Error: Low value must be less than high value.)")
|
||||||
|
|
|
@ -52,7 +52,7 @@ module Normal = {
|
||||||
switch operation {
|
switch operation {
|
||||||
| #Add => Some(#Normal({mean: n1 +. n2.mean, stdev: n2.stdev}))
|
| #Add => Some(#Normal({mean: n1 +. n2.mean, stdev: n2.stdev}))
|
||||||
| #Subtract => Some(#Normal({mean: n1 -. n2.mean, stdev: n2.stdev}))
|
| #Subtract => Some(#Normal({mean: n1 -. n2.mean, stdev: n2.stdev}))
|
||||||
| #Multiply => Some(#Normal({mean: n1 *. n2.mean, stdev: n1 *. n2.stdev}))
|
| #Multiply => Some(#Normal({mean: n1 *. n2.mean, stdev: Js.Math.abs_float(n1) *. n2.stdev}))
|
||||||
| _ => None
|
| _ => None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,8 +60,8 @@ module Normal = {
|
||||||
switch operation {
|
switch operation {
|
||||||
| #Add => Some(#Normal({mean: n1.mean +. n2, stdev: n1.stdev}))
|
| #Add => Some(#Normal({mean: n1.mean +. n2, stdev: n1.stdev}))
|
||||||
| #Subtract => Some(#Normal({mean: n1.mean -. n2, stdev: n1.stdev}))
|
| #Subtract => Some(#Normal({mean: n1.mean -. n2, stdev: n1.stdev}))
|
||||||
| #Multiply => Some(#Normal({mean: n1.mean *. n2, stdev: n1.stdev *. n2}))
|
| #Multiply => Some(#Normal({mean: n1.mean *. n2, stdev: n1.stdev *. Js.Math.abs_float(n2)}))
|
||||||
| #Divide => Some(#Normal({mean: n1.mean /. n2, stdev: n1.stdev /. n2}))
|
| #Divide => Some(#Normal({mean: n1.mean /. n2, stdev: n1.stdev /. Js.Math.abs_float(n2)}))
|
||||||
| _ => None
|
| _ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user