Merge pull request #498 from quantified-uncertainty/mx-polymorph
`mx`/`mixture` polymorphism
This commit is contained in:
commit
7e4ee94b7a
|
@ -119,7 +119,22 @@ module Helpers = {
|
||||||
mixtureWithGivenWeights(distributions, weights)
|
mixtureWithGivenWeights(distributions, weights)
|
||||||
}
|
}
|
||||||
|
|
||||||
let mixture = (args: array<expressionValue>): DistributionOperation.outputType =>
|
let mixture = (args: array<expressionValue>): DistributionOperation.outputType => {
|
||||||
|
let error = (err: string): DistributionOperation.outputType => err->ArgumentError->GenDistError
|
||||||
|
switch args {
|
||||||
|
| [EvArray(distributions)] =>
|
||||||
|
switch parseDistributionArray(distributions) {
|
||||||
|
| Ok(distrs) => mixtureWithDefaultWeights(distrs)
|
||||||
|
| Error(err) => error(err)
|
||||||
|
}
|
||||||
|
| [EvArray(distributions), EvArray(weights)] =>
|
||||||
|
switch (parseDistributionArray(distributions), parseNumberArray(weights)) {
|
||||||
|
| (Ok(distrs), Ok(wghts)) => mixtureWithGivenWeights(distrs, wghts)
|
||||||
|
| (Error(err), Ok(_)) => error(err)
|
||||||
|
| (Ok(_), Error(err)) => error(err)
|
||||||
|
| (Error(err1), Error(err2)) => error(`${err1}|${err2}`)
|
||||||
|
}
|
||||||
|
| _ =>
|
||||||
switch E.A.last(args) {
|
switch E.A.last(args) {
|
||||||
| Some(EvArray(b)) => {
|
| Some(EvArray(b)) => {
|
||||||
let weights = parseNumberArray(b)
|
let weights = parseNumberArray(b)
|
||||||
|
@ -128,16 +143,18 @@ module Helpers = {
|
||||||
)
|
)
|
||||||
switch E.R.merge(distributions, weights) {
|
switch E.R.merge(distributions, weights) {
|
||||||
| Ok(d, w) => mixtureWithGivenWeights(d, w)
|
| Ok(d, w) => mixtureWithGivenWeights(d, w)
|
||||||
| Error(err) => GenDistError(ArgumentError(err))
|
| Error(err) => error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
| Some(EvNumber(_))
|
| Some(EvNumber(_))
|
||||||
| Some(EvDistribution(_)) =>
|
| Some(EvDistribution(_)) =>
|
||||||
switch parseDistributionArray(args) {
|
switch parseDistributionArray(args) {
|
||||||
| Ok(distributions) => mixtureWithDefaultWeights(distributions)
|
| Ok(distributions) => mixtureWithDefaultWeights(distributions)
|
||||||
| Error(err) => GenDistError(ArgumentError(err))
|
| Error(err) => error(err)
|
||||||
|
}
|
||||||
|
| _ => error("Last argument of mx must be array or distribution")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
| _ => GenDistError(ArgumentError("Last argument of mx must be array or distribution"))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user