import jpype
import jpype.imports
from jpype.types import *
classpath = "lib/bayesserver-10.8.jar"
jpype.startJVM(classpath=[classpath])
from com.bayesserver import *
from com.bayesserver.inference import *
from com.bayesserver.analysis import *
from jpype import java
network_path = 'networks/Waste.bayes'
network = Network()
network.load(network_path)
variables = network.getVariables()
burning_regimen = variables.get('Burning Regimen', True)
waste_type = variables.get('Waste type', True)
filter_state = variables.get('Filter state', True)
filter_efficiency = variables.get('Filter efficiency', True)
dust_emission = variables.get('Dust emission', True)
metals_in_waste = variables.get('Metals in waste', True)
co2_concentration = variables.get('CO2 concentration', True)
light_penetrability = variables.get('Light penetrability', True)
metals_emission = variables.get('Metals emission', True)
evidence = DefaultEvidence(network)
evidence.setState(burning_regimen.getStates().get("Unstable", True))
evidence.setState(filter_state.getStates().get("Defect", True))
evidence.set(filter_efficiency, -0.45)
evidence.set(light_penetrability, 2.0)
evidence.set(metals_emission, 6.3)
evidence_to_analyse = JArray(Variable)([None] * evidence.size())
evidence.getVariables(evidence_to_analyse)
evidence_to_analyse_list = java.util.Arrays.asList(evidence_to_analyse)
options = LogLikelihoodAnalysisOptions()
options.setSubsetMethod(LogLikelihoodAnalysisSubsetMethod.EXCLUDE)
options.setMaxEvidenceSubsetSize(1)
output = LogLikelihoodAnalysis.calculate(
network,
evidence,
evidence_to_analyse_list,
options)
print(f'None={output.getBaseline().getLogLikelihoodNone()}\tAll={output.getBaseline().getLogLikelihoodAll()}')
print()
print('\t'.join(map(lambda v: str(v.getName()), evidence_to_analyse)))
for item in sorted(output.getItems(), key=lambda i: i.getLogLikelihood(), reverse=True):
flags = '\t'.join(map(lambda f: 'T' if f else 'F', item.getEvidenceFlags()))
print(f'{item.getLogLikelihood()}\t{flags}')