mx polymorphism

Value: [1e-3 to 2e-2]
This commit is contained in:
Quinn Dougherty 2022-05-09 15:19:56 -04:00
parent 964eba4461
commit 814a5f2c58

View File

@ -120,6 +120,20 @@ module Helpers = {
} }
let mixture = (args: array<expressionValue>): DistributionOperation.outputType => let mixture = (args: array<expressionValue>): DistributionOperation.outputType =>
switch args {
| [EvArray(distributions)] =>
switch parseDistributionArray(distributions) {
| Ok(distrs) => mixtureWithDefaultWeights(distrs)
| Error(err) => err->ArgumentError->GenDistError
}
| [EvArray(distributions), EvArray(weights)] =>
switch (parseDistributionArray(distributions), parseNumberArray(weights)) {
| (Ok(distrs), Ok(wghts)) => mixtureWithGivenWeights(distrs, wghts)
| (Error(err), Ok(_)) => err->ArgumentError->GenDistError
| (Ok(_), Error(err)) => err->ArgumentError->GenDistError
| (Error(err1), Error(err2)) => `${err1}|${err2}`->ArgumentError->GenDistError
}
| _ =>
switch E.A.last(args) { switch E.A.last(args) {
| Some(EvArray(b)) => { | Some(EvArray(b)) => {
let weights = parseNumberArray(b) let weights = parseNumberArray(b)
@ -139,6 +153,7 @@ module Helpers = {
} }
| _ => GenDistError(ArgumentError("Last argument of mx must be array or distribution")) | _ => GenDistError(ArgumentError("Last argument of mx must be array or distribution"))
} }
}
} }
module SymbolicConstructors = { module SymbolicConstructors = {