Error message on deterministic bayes net
@@ -30,13 +30,10 @@ public class MetropolisHastings {
final List<? extends Vertex<?>> fromVertices,
final int sampleCount,
final Random random) {
- if (bayesNet.isInImpossibleState()) {
- throw new RuntimeException("Cannot start optimizer on zero probability network");
- }
-
+ checkBayesNetInHealthyState(bayesNet);
Map<String, List<?>> samplesByVertex = new HashMap<>();
List<? extends Vertex<?>> latentVertices = bayesNet.getLatentVertices();
- assert (latentVertices.size() > 0) : "Error: Cannot sample from a completely deterministic graph.";
+
Map<Vertex<?>, Set<Vertex<?>>> affectedVerticesCache = getVerticesAffectedByLatents(latentVertices);
Map<String, Map<String, Long>> setAndCascadeCache = new HashMap<>();
@@ -116,4 +113,12 @@ public class MetropolisHastings {
samplesForVertex.add(vertex.getValue());
}
+ private static void checkBayesNetInHealthyState(BayesNet bayesNet) {
+ if (bayesNet.getVerticesThatContributeToMasterP().size() == 0) {
+ throw new IllegalArgumentException("Cannot sample from a completely deterministic BayesNet");
+ } else if (bayesNet.isInImpossibleState()) {
+ throw new RuntimeException("Cannot start optimizer on zero probability network");
+ }
+ }
+
}
