Value of Information with a Bayesian network in Matlab
bayesVersion = '7.24';
networkPath = ['C:\ProgramData\Bayes Server ', bayesVersion, '\Sample Networks\Waste.bayes'];
jarPath = ['C:\Program Files\Bayes Server\Bayes Server ', bayesVersion, '\API\Java\BayesServer-', bayesVersion, '.jar'];
javaaddpath(jarPath);
import com.bayesserver.*;
import com.bayesserver.inference.*;
import com.bayesserver.analysis.*;
network = Network();
network.load(networkPath);
disp(['Network has ', num2str(network.getNodes.size), ' nodes']);
filterState = network.getVariables().get('Filter state', true);
filterStateIntact = filterState.getStates().get('Intact', true);
dustEmission = network.getVariables().get('Dust emission', true);
wasteType = network.getVariables().get('Waste type', true);
wasteTypeIndustrial = wasteType.getStates().get('Industrial', true);
wasteTypeHousehold = wasteType.getStates().get('Household', true);
evidence = DefaultEvidence(network);
options = ValueOfInformationOptions();
output = ValueOfInformation.calculate(wasteType, network.getVariables(), evidence, RelevanceTreeInferenceFactory(), options);
disp(['Hypothesis statistic = ', num2str(output.getHypothesisStatistic())]);
testOutputs = output.getTestOutputs();
for i=0:testOutputs.size()-1
testOutput = testOutputs.get(i);
variableName = testOutput.getVariable().getVariable().getName();
hypothesisStat = testOutput.getHypothesisStatistic().doubleValue();
disp([char(variableName), ', MI = ', num2str(hypothesisStat)])
end