cc.kave.repackaged.jayes.inference.AbstractInferer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cc.kave.repackaged.jayes Show documentation
Show all versions of cc.kave.repackaged.jayes Show documentation
Repackaging of Jayes (Eclipse Code Recommenders) to make it available in Maven.
The newest version!
/**
* Copyright (c) 2011 Michael Kutschke.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Michael Kutschke - initial API and implementation.
*/
package cc.kave.repackaged.jayes.inference;
import java.util.HashMap;
import java.util.Map;
import cc.kave.repackaged.jayes.BayesNet;
import cc.kave.repackaged.jayes.BayesNode;
import cc.kave.repackaged.jayes.factor.FactorFactory;
public abstract class AbstractInferer implements IBayesInferer {
protected Map evidence = new HashMap();
protected double[][] beliefs;
protected boolean beliefsValid;
protected FactorFactory factory = FactorFactory.defaultFactory();
public void setFactorFactory(FactorFactory factory) {
this.factory = factory;
}
public FactorFactory getFactory() {
return factory;
}
@Override
public void addEvidence(final BayesNode node, final String outcome) {
evidence.put(node, outcome);
beliefsValid = false;
}
@Override
public double[] getBeliefs(final BayesNode node) {
if (!beliefsValid) {
beliefsValid = true;
updateBeliefs();
}
return beliefs[node.getId()];
}
@Override
public void setNetwork(final BayesNet bayesNet) {
beliefs = new double[bayesNet.getNodes().size()][];
for (final BayesNode n : bayesNet.getNodes()) {
beliefs[n.getId()] = new double[n.getOutcomeCount()];
}
this.factory.setReferenceNetwork(bayesNet);
}
@Override
public void setEvidence(final Map evidence) {
this.evidence = evidence;
beliefsValid = false;
}
@Override
public Map getEvidence() {
return evidence;
}
protected abstract void updateBeliefs();
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy