public static void H(diseases d, symptoms s) { foreach (var item in s) { item.entropy = H(d, item); } }
public void fillic() { Queue <Node> Q = new Queue <Node>(); Q.Enqueue(root); Node h; while (Q.Count > 0) { h = Q.Dequeue(); if (h.NodeDef == 0) { if (h.yes != null) { Q.Enqueue(h.yes); } if (h.no != null) { Q.Enqueue(h.no); } } if (h != null && h.NodeDef == 2) { ic hold = h.d.ic; diseases pasdis = new diseases(AllDiseases, hold.diseases); List <symptom> passym = new List <symptom>(); //Console.WriteLine(pasdis.Count); h.ic = insert(h, pasdis, passym); } } }
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); }
public diseases(diseases d, List <int> d2) { foreach (var item in d2) { foreach (var item2 in d) { if (item2.Num == item) { sl.Add(item2); } } } }
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 SearchForDisease(List <int> d) { diseases retvalue = new diseases(); foreach (var item in this) { foreach (var item2 in d) { if (item.Num == item2) { retvalue.Add(item); } } } return(retvalue); }
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 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)); }
public diseases Rest(List <int> d) { diseases retvalue = new diseases(); bool flag; foreach (var item in this) { flag = true; foreach (var item2 in d) { if (item.Num == item2) { flag = false; break; } } if (flag) { retvalue.Add(item); } } return(retvalue); }
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); }