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 *
network_path = 'networks/Asia.bayes'
network = Network()
network.load(network_path)
variables = network.getVariables()
visit_to_asia = variables.get('Visit to Asia', True)
has_lung_cancer = variables.get('Has Lung Cancer', True)
tuberculosis_or_cancer = variables.get('Tuberculosis or Cancer', True)
smoker = variables.get('Smoker', True)
has_tuberculosis = variables.get('Has Tuberculosis', True)
dyspnea = variables.get('Dyspnea', True)
xray_result = variables.get('XRay Result', True)
has_bronchitis = variables.get('Has Bronchitis', True)
xRayResultAbnormal = xray_result.getStates().get('Abnormal', True)
smokerFalse = smoker.getStates().get('False', True)
hasLungCancerFalse = has_lung_cancer.getStates().get('False', True)
evidence = DefaultEvidence(network)
sensitivity = SensitivityToParameters(network, RelevanceTreeInferenceFactory())
parameter = ParameterReference(has_lung_cancer.getNode(), [smokerFalse, hasLungCancerFalse])
oneWay = sensitivity.oneWay(
evidence,
xRayResultAbnormal,
parameter
)
print('Parameter value = {}'.format(oneWay.getParameterValue()))
print('Sensitivity value = {}'.format(oneWay.getSensitivityValue()))
print('P(Abnormal | e) = {}'.format(oneWay.getProbabilityHypothesisGivenEvidence()))
print('Alpha = {}'.format(oneWay.getAlpha()))
print('Beta = {}'.format(oneWay.getBeta()))
print('Delta = {}'.format(oneWay.getDelta()))
print('Gamma = {}'.format(oneWay.getGamma()))
print('Eval(0.2) = {}'.format(oneWay.evaluate(0.2)))
print('Eval\'(0.2) = {}'.format(oneWay.evaluateDeriv(0.2)))