using BayesServer.Analysis;
using BayesServer.Inference;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using System.Text;
namespace BayesServer.HelpSamples
{
public static class ImpactAnalysisExample
{
public static void Main()
{
var network = new Network();
network.Load(@"Waste.bayes");
var burningRegimen = network.Variables["Burning Regimen", true];
var wasteType = network.Variables["Waste type", true];
var filterState = network.Variables["Filter state", true];
var filterEfficiency = network.Variables["Filter efficiency", true];
var dustEmission = network.Variables["Dust emission", true];
var metalsInWaste = network.Variables["Metals in waste", true];
var co2Concentration = network.Variables["CO2 concentration", true];
var lightPenetrability = network.Variables["Light penetrability", true];
var metalsEmission = network.Variables["Metals emission", true];
var filterStateIntact = filterState.States["Intact", true];
var wasteTypeIndustrial = wasteType.States["Industrial", true];
var evidence = new Evidence(network);
evidence.Set(lightPenetrability, 0.2);
evidence.Set(co2Concentration, -1.0);
evidence.SetState(wasteTypeIndustrial);
var options = new ImpactOptions();
options.SubsetMethod = ImpactSubsetMethod.Exclude;
options.MaxEvidenceSubsetSize = 1;
var evidenceToAnalyse = new Variable[] { lightPenetrability, co2Concentration, wasteType };
var output = Impact.Calculate(
network,
filterState,
filterStateIntact,
evidence,
evidenceToAnalyse,
options
);
Console.WriteLine($"P(Intact) (all evdience) = {output.Hypothesis.StateProbabilityAll}");
Console.WriteLine($"P(Intact) (no evdience) = {output.Hypothesis.StateProbabilityNone}");
Console.WriteLine();
foreach (var item in output.Items)
{
Console.WriteLine(string.Join(',', item.EvidenceFlags));
Console.WriteLine("\tP(Intact)\t" + item.StateProbability);
}
}
}
}