public symptoms SearchForSymptoms(diseases d, List <symptom> sin)
        {
            //Console.WriteLine("sfs");
            symptoms ret = new symptoms();
            bool     flag;

            foreach (var item in this)
            {
                flag = true;
                foreach (var item2 in sin)
                {
                    if (item.Number == item2.Number)
                    {
                        flag = false;
                        break;
                    }
                }
                foreach (var item2 in d)
                {
                    if (item2.symptoms.Contains(item.Number) && !ret.Contains(item) && flag)
                    {
                        ret.Add(item);
                    }
                }
            }

            //Console.WriteLine("sfsd");
            return(ret);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            //decisionTree d = new decisionTree(@"C:\Users\h\Desktop\uni\AIP\tab.xml", @"C:\Users\h\Desktop\uni\AIP\tab2.xml");
            //d.fill();
            //d.print();
            //Console.WriteLine("done");
            //Console.WriteLine(d.findlvl());
            //////////////////////////////////////////////////////////////////////
            //ices ic = new ices();
            //ic.loadexcel(@"C:\Users\h\Desktop\uni\AIP\table_final.xlsx");
            //ic.loadxml(@"C:\Users\h\Desktop\uni\AIP\tab2.xml");
            //Console.WriteLine(ic);
            //////////////////////////////////////////////////////////////////////
            symptoms s = new symptoms();

            s.loadexcel(@"C:\Users\h\Desktop\bakhtar-semi\b.xlsx");
            ////s.save(@"C:\Users\h\Desktop\uni\AIP\tab.xml");
            //diseases d = new diseases(s);
            //statics.H(d, s);
            //Node a = new Node(null, 1, d[0]);
            //Console.WriteLine(a);
            //Node b = new Node(null, 0, s[0]);
            //Console.WriteLine(b);
            //a = b;
            //Console.WriteLine(a);
            //s.sort();
            //Console.WriteLine(s);
            ///////////////////////////////////////////////////////////////////////
            //Console.ReadKey();
        }
 public static void H(diseases d, symptoms s)
 {
     foreach (var item in s)
     {
         item.entropy = H(d, item);
     }
 }
Exemple #4
0
 public decisionTree(string path1, string path2)
 {
     root        = null;
     AllSymptoms = new symptoms();
     AllSymptoms.loadxml(path1);
     allnotchanged = new symptoms();
     allnotchanged.loadxml(path1);
     AllDiseases = new diseases(AllSymptoms);
     AllIces     = new ices();
     AllIces.loadxml(path2);
     statics.H(AllDiseases, AllSymptoms);
     statics.H(AllDiseases, allnotchanged);
     AllSymptoms.sort();
 }
        public diseases(symptoms s)
        {
            int  x    = 0;
            bool isis = true;;

            for (int i = 0; i < 9; i++)
            {
                if (i > 3)
                {
                    isis = false;
                }
                sl.Add(new disease(x++, statics.map[i], !isis, s));
            }
        }
        public void set(symptoms s)
        {
            sl.Clear();
            int  x    = 0;
            bool isis = true;;

            for (int i = 0; i < statics.map.Count; i++)
            {
                if (i > 3)
                {
                    isis = false;
                }
                sl.Add(new disease(x++, statics.map[i], !isis, s));
            }
        }
        public static int next(symptoms s, int p)
        {
            symptom s1;
            Random  rnd = new Random();
            int     i   = p;

            for (i = p; i < s.Count; i++)
            {
                s1 = s[i - 1];
                if (s1.entropy != s[i].entropy)
                {
                    break;
                }
            }
            return(i + 1);
        }
Exemple #8
0
 public disease(int x, string name, bool isic, symptoms s)
 {
     Num      = x;
     symptoms = new List <int>();
     Name     = name;
     Isic     = isic;
     for (int i = 0; i < s.Count; i++)
     {
         if (s[i].Disease.Contains(statics.map2[name]))
         {
             symptoms.Add(i);
         }
     }
     py = ((double)symptoms.Count / s.Count);
     pn = 1 - py;
 }
Exemple #9
0
 private Node insert(Node par, diseases d, List <symptom> used)
 {
     //Console.WriteLine(d);
     if (d.Count == 1)
     {
         //Console.WriteLine("here"+d);
         //Console.WriteLine("disease\r\n"+d);
         if (!d[0].Isic)
         {
             return(new Node(par, 1, d[0]));
         }
         else
         {
             return(new Node(par, 2, AllIces.CastToIc(d[0])));
         }
     }
     else
     {
         List <symptom> passused = new List <symptom>();
         passused.AddRange(used);
         diseases passdisyes;
         diseases passdisno;
         symptoms PossibleSymptoms = AllSymptoms.SearchForSymptoms(d, passused);
         statics.H(d, PossibleSymptoms);
         PossibleSymptoms.sort();
         //Console.WriteLine(PossibleSymptoms.Count+"  "+d.Count);
         symptom ThisSymptom = PossibleSymptoms[statics.Ran(PossibleSymptoms)];
         while (ThisSymptom.Disease.Count >= d.Count)
         {
             int rand = statics.Ran(PossibleSymptoms);
             //Console.WriteLine(rand);
             ThisSymptom = PossibleSymptoms[rand + 2];
         }
         //symptom ThisSymptom = PossibleSymptoms[0];
         //Console.WriteLine("passs");
         passused.Add(ThisSymptom);
         //Console.WriteLine("symptoms" + d+"_________\r\n"+ThisSymptom);
         //Console.WriteLine("alld"+d.Count);
         passdisyes = d.SearchForDisease(ThisSymptom.Disease);
         passdisno  = d.Rest(ThisSymptom.Disease);
         //Console.WriteLine("yesd"+passdisyes.Count+"   nod"+passdisno.Count);
         Node hold = new Node(par, 0, ThisSymptom);
         hold.yes = insert(hold, passdisyes, passused);
         hold.no  = insert(hold, passdisno, passused);
         return(hold);
     }
 }
        public static int Ran(symptoms s)
        {
            if (s.Count == 1)
            {
                return(0);
            }
            symptom s1;
            Random  rnd = new Random();
            int     i   = 1;

            for (i = 1; i < s.Count; i++)
            {
                s1 = s[i - 1];
                if (s1.entropy != s[i].entropy)
                {
                    break;
                }
            }
            return(rnd.Next(0, i - 1));
        }
        public static symptoms clear(symptoms s, int x)
        {
            symptoms p = new symptoms();

            p.Clear();
            diseases ds = new diseases(s);

            foreach (symptom item in s)
            {
                if (item.Disease.Count < x)
                {
                    //foreach (disease d in ds)
                    //{
                    //    if (d.symptoms.Count < 2 && d.symptoms.Contains(item.Number)) p.Add(item);
                    //}
                    p.Add(item);
                }
                //else
                //{
                //    p.Add(item);
                //}
            }
            return(p);
        }