Commit 747f20c1 authored by Guillaume Chérel's avatar Guillaume Chérel
Browse files

ABC: Added descriptive error message when covariance matrix is singular.

parent 5e354b57
......@@ -130,7 +130,11 @@ object APMC {
Array.fill(n - nAlpha) {
Iterator.continually {
val resampledTheta = thetasM.getRow(weightedDistributionTheta.sample)
new MultivariateNormalDistribution(apacheRandom(rng), resampledTheta, sigmaSquared.getData).sample
try {
new MultivariateNormalDistribution(apacheRandom(rng), resampledTheta, sigmaSquared.getData).sample
} catch {
case e: SingularMatrixException => throw new SingularCovarianceException
}
}.dropWhile { priorDensity(_) == 0 }.next
}
......@@ -245,8 +249,7 @@ object APMC {
val inverseSigmaSquared = try {
new LUDecomposition(sigmaSquared).getSolver().getInverse()
} catch {
case e: SingularMatrixException =>
throw new SingularCovarianceException(s, "The weighted covariance matrix of the particles thetas is singular. Possible cause: the model is deterministic.")
case e: SingularMatrixException => throw new SingularCovarianceException
}
val weightsSelected =
(0 until thetasSelected.size).map { i =>
......@@ -267,5 +270,6 @@ object APMC {
weightsSelected
}
case class SingularCovarianceException(s: State, msg: String) extends RuntimeException(msg)
case class SingularCovarianceException()
extends RuntimeException("The weighted covariance matrix of the particles thetas is singular. Possible cause: the model is deterministic for all of some parameter values. For example, if your model is based on the stochastic dynamics of a population of agents and one of the parameter controls the population size, your model is likely to become deterministic when this parameter is set to 0. Be careful to exclude those values from the research space (by setting the prior to 0 for those values).")
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment