using BayesServer.Analysis;
using BayesServer.Inference;
using BayesServer.Inference.RelevanceTree;
using System;
using System.Collections.Generic;
using System.Text;
namespace BayesServer.HelpSamples
{
public static class SensitivityAnalysisExample
{
public static void Main()
{
var network = new Network();
network.Load(@"Asia.bayes");
var visitToAsia = network.Variables["Visit to Asia", true];
var hasLungCancer = network.Variables["Has Lung Cancer", true];
var tuberculosisOrCancer = network.Variables["Tuberculosis or Cancer", true];
var smoker = network.Variables["Smoker", true];
var hasTuberculosis = network.Variables["Has Tuberculosis", true];
var dyspnea = network.Variables["Dyspnea", true];
var xRayResult = network.Variables["XRay Result", true];
var hasBronchitis = network.Variables["Has Bronchitis", true];
var xRayResultAbnormal = xRayResult.States["Abnormal", true];
var smokerFalse = smoker.States["False", true];
var hasLungCancerFalse = hasLungCancer.States["False", true];
var evidence = new Evidence(network);
var sensitivity = new SensitivityToParameters(network, new RelevanceTreeInferenceFactory());
var parameter = new ParameterReference(hasLungCancer.Node, new State[] {smokerFalse, hasLungCancerFalse });
var oneWay = sensitivity.OneWay(
evidence,
xRayResultAbnormal,
parameter
);
Console.WriteLine($"Parameter value = {oneWay.ParameterValue}");
Console.WriteLine($"Sensitivity value = {oneWay.SensitivityValue}");
Console.WriteLine($"P(Abnormal | e) = {oneWay.ProbabilityHypothesisGivenEvidence}");
Console.WriteLine($"Alpha = {oneWay.Alpha}");
Console.WriteLine($"Beta = {oneWay.Beta}");
Console.WriteLine($"Delta = {oneWay.Delta}");
Console.WriteLine($"Gamma = {oneWay.Gamma}");
Console.WriteLine($"Eval(0.2) = {oneWay.Evaluate(0.2)}");
Console.WriteLine($"Eval'(0.2) = {oneWay.EvaluateDeriv(0.2)}");
}
}
}