mx
polymorphism
Value: [1e-3 to 2e-2]
This commit is contained in:
parent
964eba4461
commit
814a5f2c58
|
@ -120,24 +120,39 @@ module Helpers = {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mixture = (args: array<expressionValue>): DistributionOperation.outputType =>
|
let mixture = (args: array<expressionValue>): DistributionOperation.outputType =>
|
||||||
switch E.A.last(args) {
|
switch args {
|
||||||
| Some(EvArray(b)) => {
|
| [EvArray(distributions)] =>
|
||||||
let weights = parseNumberArray(b)
|
switch parseDistributionArray(distributions) {
|
||||||
let distributions = parseDistributionArray(
|
| Ok(distrs) => mixtureWithDefaultWeights(distrs)
|
||||||
Belt.Array.slice(args, ~offset=0, ~len=E.A.length(args) - 1),
|
| Error(err) => err->ArgumentError->GenDistError
|
||||||
)
|
}
|
||||||
switch E.R.merge(distributions, weights) {
|
| [EvArray(distributions), EvArray(weights)] =>
|
||||||
| Ok(d, w) => mixtureWithGivenWeights(d, w)
|
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) {
|
||||||
|
| Some(EvArray(b)) => {
|
||||||
|
let weights = parseNumberArray(b)
|
||||||
|
let distributions = parseDistributionArray(
|
||||||
|
Belt.Array.slice(args, ~offset=0, ~len=E.A.length(args) - 1),
|
||||||
|
)
|
||||||
|
switch E.R.merge(distributions, weights) {
|
||||||
|
| Ok(d, w) => mixtureWithGivenWeights(d, w)
|
||||||
|
| Error(err) => GenDistError(ArgumentError(err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
| Some(EvNumber(_))
|
||||||
|
| Some(EvDistribution(_)) =>
|
||||||
|
switch parseDistributionArray(args) {
|
||||||
|
| Ok(distributions) => mixtureWithDefaultWeights(distributions)
|
||||||
| Error(err) => GenDistError(ArgumentError(err))
|
| Error(err) => GenDistError(ArgumentError(err))
|
||||||
}
|
}
|
||||||
|
| _ => GenDistError(ArgumentError("Last argument of mx must be array or distribution"))
|
||||||
}
|
}
|
||||||
| Some(EvNumber(_))
|
|
||||||
| Some(EvDistribution(_)) =>
|
|
||||||
switch parseDistributionArray(args) {
|
|
||||||
| Ok(distributions) => mixtureWithDefaultWeights(distributions)
|
|
||||||
| Error(err) => GenDistError(ArgumentError(err))
|
|
||||||
}
|
|
||||||
| _ => GenDistError(ArgumentError("Last argument of mx must be array or distribution"))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user