public void Execute(IExampleInterface app) { // build the bayesian network structure BayesianNetwork network = new BayesianNetwork(); BayesianEvent BlueTaxi = network.CreateEvent("blue_taxi"); BayesianEvent WitnessSawBlue = network.CreateEvent("saw_blue"); network.CreateDependency(BlueTaxi, WitnessSawBlue); network.FinalizeStructure(); // build the truth tales BlueTaxi.Table.AddLine(0.85, true); WitnessSawBlue.Table.AddLine(0.80, true, true); WitnessSawBlue.Table.AddLine(0.20, true, false); // validate the network network.Validate(); // display basic stats Console.WriteLine(network.ToString()); Console.WriteLine("Parameter count: " + network.CalculateParameterCount()); EnumerationQuery query = new EnumerationQuery(network); //SamplingQuery query = new SamplingQuery(network); query.DefineEventType(WitnessSawBlue, EventType.Evidence); query.DefineEventType(BlueTaxi, EventType.Outcome); query.SetEventValue(WitnessSawBlue, false); query.SetEventValue(BlueTaxi, false); query.Execute(); Console.WriteLine(query.ToString()); }
public void Execute(IExampleInterface app) { // Create a Bayesian network BayesianNetwork network = new BayesianNetwork(); // Create the Uber driver event BayesianEvent UberDriver = network.CreateEvent("uber_driver"); // create the witness event BayesianEvent WitnessSawUberDriver = network.CreateEvent("saw_uber_driver"); // Attach the two network.CreateDependency(UberDriver, WitnessSawUberDriver); network.FinalizeStructure(); // build the truth tables UberDriver?.Table?.AddLine(0.85, true); WitnessSawUberDriver?.Table?.AddLine(0.80, true, true); WitnessSawUberDriver?.Table?.AddLine(0.20, true, false); network.Validate(); Console.WriteLine(network.ToString()); Console.WriteLine($"Parameter count: {network.CalculateParameterCount()}"); EnumerationQuery query = new EnumerationQuery(network); // The evidence is that someone saw the Uber driver hit the car query.DefineEventType(WitnessSawUberDriver, EventType.Evidence); // The result was the Uber driver did it query.DefineEventType(UberDriver, EventType.Outcome); query.SetEventValue(WitnessSawUberDriver, false); query.SetEventValue(UberDriver, false); query.Execute(); Console.WriteLine(query.ToString()); }
public void TestCount() { BayesianNetwork network = new BayesianNetwork(); BayesianEvent a = network.CreateEvent("a"); BayesianEvent b = network.CreateEvent("b"); BayesianEvent c = network.CreateEvent("c"); BayesianEvent d = network.CreateEvent("d"); BayesianEvent e = network.CreateEvent("e"); network.CreateDependency(a, b, d, e); network.CreateDependency(c, d); network.CreateDependency(b, e); network.CreateDependency(d, e); network.FinalizeStructure(); Assert.AreEqual(16, network.CalculateParameterCount()); }
static void Main(string[] args) { /*Przykład 4.2.3 Teoria Bayesa - Zakłady Produkcyjne Etap Manualny * Lesson 1 - Machine Learning in C# for Amazon ML Group created by me :-) * PS. Kill me I use polish :-) */ BayesianNetwork network = new BayesianNetwork(); BayesianEvent WadliwyElement = network.CreateEvent("wadliwy_element"); BayesianEvent A1 = network.CreateEvent("wadliwy_element_zaklad_A1"); BayesianEvent A2 = network.CreateEvent("wadliwy_element_zaklad_A2"); BayesianEvent A3 = network.CreateEvent("wadliwy_element_zaklad_A3"); BayesianEvent A4 = network.CreateEvent("wadliwy_element_zaklad_A4"); network.CreateDependency(WadliwyElement, A1, A2, A3, A4); network.FinalizeStructure(); WadliwyElement?.Table?.AddLine(0.1083, true); A1?.Table.AddLine(0.069, true, true); A1?.Table.AddLine(1 - 0.069, true, false); A2?.Table.AddLine(0.277, true, true); A2?.Table.AddLine(1 - 0.277, true, false); A3?.Table.AddLine(0.007, true, true); A3?.Table.AddLine(1 - 0.007, true, false); A4?.Table.AddLine(0.646, true, true); A4?.Table.AddLine(1 - 0.646, true, false); network.Validate(); Console.WriteLine(network.ToString() + "\n"); Console.WriteLine($"Liczba parametrów: {network.CalculateParameterCount()}"); EnumerationQuery query = new EnumerationQuery(network); query.DefineEventType(WadliwyElement, EventType.Evidence); query.DefineEventType(A1, EventType.Outcome); query.DefineEventType(A2, EventType.Evidence); query.DefineEventType(A3, EventType.Evidence); query.DefineEventType(A4, EventType.Evidence); query.SetEventValue(WadliwyElement, false); query.SetEventValue(A1, false); query.SetEventValue(A2, false); query.SetEventValue(A3, false); query.SetEventValue(A4, false); query.Execute(); Console.WriteLine(query.ToString()); }
public void Execute(IExampleInterface app) { BayesianNetwork network = new BayesianNetwork(); BayesianEvent grass = network.CreateEvent("grass"); BayesianEvent sprinkler = network.CreateEvent("sprinkler"); BayesianEvent rain = network.CreateEvent("rain"); BayesianEvent DidRain = network.CreateEvent("did_rain"); BayesianEvent SprinklerOn = network.CreateEvent("sprinkler_on"); network.CreateDependency(rain, DidRain); network.CreateDependency(sprinkler, SprinklerOn); network.FinalizeStructure(); // build the truth tales rain.Table.AddLine(0.35, true); // 80% of the time they were right DidRain.Table.AddLine(0.80, false, true); // 20% of the time they were wrong DidRain.Table.AddLine(0.20, true, true); sprinkler.Table.AddLine(.65, true); // 60% of the time they were right SprinklerOn.Table.AddLine(.40, true, true); // 40% of the time they were wrong SprinklerOn.Table.AddLine(.60, false, true); // validate the network network.Validate(); // display basic stats Console.WriteLine(network.ToString()); Console.WriteLine("Parameter count: " + network.CalculateParameterCount()); EnumerationQuery query = new EnumerationQuery(network); //SamplingQuery query = new SamplingQuery(network); query.DefineEventType(SprinklerOn, EventType.Evidence); query.DefineEventType(sprinkler, EventType.Outcome); query.DefineEventType(DidRain, EventType.Evidence); query.DefineEventType(rain, EventType.Outcome); query.Execute(); Console.WriteLine(query.ToString()); }
public void Validate(BayesianNetwork network) { Assert.AreEqual(3, network.CalculateParameterCount()); }