Esempio n. 1
0
 /// <summary>
 /// Set evidence for a particular node. This is a wrapper for EnterFindings so we can use values instead of indices.
 /// </summary>
 /// <param name="node">target RV</param>
 /// <param name="state">The value of the evindence.</param>
 public void Observe(BNode node, int state)
 {
     try
     {
         int index = UndefinedState;
         for (int i = 0; i < node.NumberStates; i++)
         {
             if (node.StateLabel[i].Equals(state.ToString()))
             {
                 index = i;                                              //iterating over StateLabels. Names are not set and hence we can't use node.GetStateIndex(str statename)
             }
         }
         node.EnterFinding(index);
     }
     catch (COMException e)
     {
         throw new COMException($"No state {state} could be found for node {node.Name}", e);
     }
 }
Esempio n. 2
0
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("Welcome to Netica API for C# !");
                Netica.Application app = new Netica.Application();
                app.Visible = true;
                string net_file_name = AppDomain.CurrentDomain.BaseDirectory + "..\\..\\..\\ChestClinic.dne";

                Streamer file = app.NewStream(net_file_name, null);
                BNet     net  = app.ReadBNet(file, "");
                net.Compile();
                BNode  TB  = net.Node("Tuberculosis");
                double bel = TB.GetBelief("present");
                Console.WriteLine("The probability of tuberculosis is " + bel.ToString("G4"));

                BNode XRay = net.Node("XRay");
                XRay.EnterFinding("abnormal");
                bel = TB.GetBelief("present");
                Console.WriteLine("Given an abnormal X-Ray, the probability of tuberculosis is " + bel.ToString("G4"));

                net.Node("VisitAsia").EnterFinding("visit");
                bel = TB.GetBelief("present");
                Console.WriteLine("Given abnormal X-Ray and visit to Asia, the probability of TB is " + bel.ToString("G4"));

                net.Node("Cancer").EnterFinding("present");
                bel = TB.GetBelief("present");
                Console.WriteLine("Given abnormal X-Ray, Asia visit, and lung cancer, the probability of TB is " + bel.ToString("G4"));

                net.Delete();
                if (!app.UserControl)
                {
                    app.Quit();
                }
            }
            catch (System.Runtime.InteropServices.COMException e)
            {
                Console.WriteLine("Netica Demo: Error " + (e.ErrorCode & 0x7FFF) + ": " + e.Message);
            }
            Console.WriteLine("Press <enter> to quit.");
            Console.ReadLine();
        }