/** * Sets the distribution of a normal variable in the AMIDST model from the ith-normal distribution in the list * of multinomial parent assignments for this variable in the Hugin model. * @param huginVar the Hugin variable with the distribution to be converted. * @param normal the <code>Normal</code> distribution to be modified. * @param i the position in which an assignment of the multinomial parents is indexed in Hugin. This is needed to * obtain the mean and variance of the normal distribution associated to the assignment. * Note that <code>i</code> is equal to 0 when the variable has no multinomial parents. * @throws ExceptionHugin */ private void setNormal(Node huginVar, Normal normal, int i) throws ExceptionHugin { double huginMean = ((ContinuousChanceNode)huginVar).getAlpha(i); double huginVariance = ((ContinuousChanceNode)huginVar).getGamma(i); normal.setMean(huginMean); normal.setVariance(huginVariance); }
normalMultiDist.getNormal(0).setVariance(1.0); normalMultiDist.getNormal(1).setVariance(1.0);
/** * {@inheritDoc} */ @Override public <E extends UnivariateDistribution> E getPosterior(Variable var) { try { Node huginNode = huginBN.getNodeByName(var.getName()); if (var.isMultinomial()) { Multinomial dist = new Multinomial(var); for(int i=0;i<var.getNumberOfStates();i++){ dist.setProbabilityOfState(i, ((DiscreteNode) huginNode).getBelief(i)); } return (E)dist; } else if (var.isNormal()) { Normal dist = new Normal(var); dist.setMean(((ContinuousChanceNode)huginNode).getMean()); dist.setVariance(((ContinuousChanceNode) huginNode).getVariance()); return (E)dist; } else { throw new IllegalArgumentException("Variable type not allowed."); } } catch (ExceptionHugin exceptionHugin) { exceptionHugin.printStackTrace(); } return null; }
public static void main(String[] args) throws Exception { //Load the learnt model BayesianNetwork fireDetector = BayesianNetworkLoader.loadFromFile("./models/LearntFireDetectorModel.bn"); //Access the variable of interest. Variable fire = fireDetector.getVariables().getVariableByName("Fire"); Variable temperature = fireDetector.getVariables().getVariableByName("Temperature"); Variable smoke = fireDetector.getVariables().getVariableByName("Smoke"); //Modify the parameters of the model according to our prior knowledge. Multinomial fireprob = fireDetector.getConditionalDistribution(fire); fireprob.setProbabilities(new double[]{0.999, 0.001}); Normal_MultinomialParents tempprob = fireDetector.getConditionalDistribution(temperature); tempprob.getNormal(1).setMean(tempprob.getNormal(0).getMean()+10); tempprob.getNormal(1).setVariance(tempprob.getNormal(0).getVariance()); Multinomial_MultinomialParents smokeProb = fireDetector.getConditionalDistribution(smoke); smokeProb.getMultinomial(1).setProbabilities(new double[]{0.001, 0.999}); //Print the model System.out.println(fireDetector); //Save to disk the new model BayesianNetworkWriter.save(fireDetector,"./models/FireDetectorModel.bn"); } }
tempprob.getNormal(0).setVariance(3); sensorSmokeProb.getNormal(0).setVariance(0.1); sensorSmokeProb.getNormal(1).setMean(5); sensorSmokeProb.getNormal(1).setVariance(3);
tempprob.getNormal(0).setVariance(3); sensorSmokeProb.getNormal(0).setVariance(0.1); sensorSmokeProb.getNormal(1).setMean(5); sensorSmokeProb.getNormal(1).setVariance(3);
tempprobBuilding.setVariance(3); sensorSmokeProb.getNormal(0).setVariance(0.1); sensorSmokeProb.getNormal(1).setMean(5); sensorSmokeProb.getNormal(1).setVariance(3);
tempprob.getNormal(0).setVariance(3); sensorSmokeProb.getNormal(0).setVariance(0.1); sensorSmokeProb.getNormal(1).setMean(5); sensorSmokeProb.getNormal(1).setVariance(3); sensorSmokeProbTimeT.getNormal(0).setVariance(0.1); sensorSmokeProbTimeT.getNormal(1).setMean(5); sensorSmokeProbTimeT.getNormal(1).setVariance(3);
tempprob.getNormal(1).setVariance(tempprob.getNormal(0).getVariance());