Beispiel #1
0
        /// <summary>
        /// Loads the network by instantiating the Net property of the DAGLoader
        /// </summary>
        /// <param name="path">relative path from BaseDirectory</param>
        public BNet LoadBNet(string path)
        {
            Debug.WriteLine($"Loading Bayesian Network from {path}...");
            _app.Visible = false;
            string   net_file_name = AppDomain.CurrentDomain.BaseDirectory + path;
            Streamer file          = _app.NewStream(net_file_name, null);
            BNet     net           = _app.ReadBNet(file);

            net.Compile();
            return(net);
        }
Beispiel #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();
        }