Beispiel #1
0
        //public static double entropy(double inp)
        //{

        //    return (-(inp * Math.Log(inp, 2)) - ((1 - inp) * Math.Log((1 - inp), 2)));
        //}
        //public static double entropy(disease d,symptom s)
        //{
        //    return (d.py) * (d.symptoms.Contains(s.Number)?(entropy((double)1/d.symptoms.Count)):0) + (d.pn) * (d.symptoms.Contains(s.Number) ? entropy(((double)(65-d.symptoms.Count) / (65))) : 0);
        //}
        //public static double InformationGain(symptom s,disease d)
        //{
        //    return entropy(s.py) - entropy(d,s);
        //}
        public static double pck(disease d, symptom s, bool b)
        {
            if (b)
            {
                if (s.Disease.Contains(d.Num))
                {
                    return((double)1 / s.Disease.Count);
                }
                else
                {
                    return(0);
                }
            }
            else
            {
                if (s.Disease.Contains(d.Num))
                {
                    return(0);
                }
                else
                {
                    return((double)1 / (9 - s.Disease.Count));
                }
            }
        }
Beispiel #2
0
 public data(int i, object obj)
 {
     if (i == 0)
     {
         ic = null;
         d  = null;
         s  = (symptom)obj;
     }
     else if (i == 1)
     {
         ic = null;
         s  = null;
         d  = (disease)obj;
     }
     else if (i == 2)
     {
         ic = (ic)obj;
         s  = null;
         d  = null;
     }
     else
     {
         ic = null;
         s  = null;
         d  = null;
     }
 }
Beispiel #3
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);
     }
 }
Beispiel #4
0
        public static double H(diseases d, symptom s)
        {
            double a = 0, b = 0;

            foreach (var item in d)
            {
                if (pck(item, s, true) != 0)
                {
                    a += (pck(item, s, true) * Math.Log(pck(item, s, true), 2));
                }
                if (pck(item, s, false) != 0)
                {
                    b += (pck(item, s, false) * Math.Log(pck(item, s, false), 2));
                }
                //Console.WriteLine(a + "       " + b);
            }

            return((s.py * -a) + (s.pn * -b));
        }