Example #1
0
        public CrossOver(List <Individu> individu, double crossrate, int popSize)
        {
            double offspring = crossrate * (double)popSize;

            offspring = Math.Floor(offspring);

            SqliteDatabase db = new SqliteDatabase();

            DataTable dt = db.query("SELECT * FROM gejala");

            rule = new List <Gejala>();

            foreach (DataRow row in dt.Rows)
            {
                Gejala   g = new Gejala();
                double[] p = new double[3];
                g.SetKodeGejala(Convert.ToString(row["kode_gejala"]));
                g.SetNamaGejala(Convert.ToString(row["nama_gejala"]));
                p[0] = Convert.ToDouble(row["pneumonia"]);
                p[1] = Convert.ToDouble(row["bronkitis"]);
                p[2] = Convert.ToDouble(row["urti"]);
                g.SetPenyakit(p);
                rule.Add(g);
            }

            Density de = new Density(rule);

            de.setMinMax(-0.25, 0.25);
            Individu alpha = new Individu(de.GetDensity());

            crossover = new List <Individu>();

            int[] randomIndividu = generateNumber(individu.Count);
            int   offset         = 0;

            while (crossover.Count < offspring)
            {
                List <Gejala> c = new List <Gejala>();
                c = Cross(individu[offset], individu[offset + 1], alpha);
                Individu v = new Individu(c);
                crossover.Add(v);

                if (crossover.Count < offspring)
                {
                    c = Cross(individu[offset + 1], individu[offset], alpha);
                    Individu v2 = new Individu(c);
                    crossover.Add(v2);
                    offset = offset + 2;
                }
            }
        }
Example #2
0
        public CrossOver(List<Individu> individu, double crossrate, int popSize)
        {
            double offspring = crossrate * (double) popSize;
            offspring = Math.Floor(offspring);

            SqliteDatabase db = new SqliteDatabase();

            DataTable dt = db.query("SELECT * FROM gejala");

            rule = new List<Gejala>();

            foreach (DataRow row in dt.Rows)
            {
                Gejala g = new Gejala();
                double[] p = new double[3];
                g.SetKodeGejala(Convert.ToString(row["kode_gejala"]));
                g.SetNamaGejala(Convert.ToString(row["nama_gejala"]));
                p[0] = Convert.ToDouble(row["pneumonia"]);
                p[1] = Convert.ToDouble(row["bronkitis"]);
                p[2] = Convert.ToDouble(row["urti"]);
                g.SetPenyakit(p);
                rule.Add(g);
            }

            Density de = new Density(rule);
            de.setMinMax(-0.25, 0.25);
            Individu alpha = new Individu(de.GetDensity());

            crossover = new List<Individu>();

            int[] randomIndividu = generateNumber(individu.Count);
            int offset = 0;
            while (crossover.Count < offspring)
            {
                List<Gejala> c = new List<Gejala>();
                c = Cross(individu[offset], individu[offset + 1], alpha);
                Individu v = new Individu(c);
                crossover.Add(v);

                if (crossover.Count < offspring)
                {
                    c = Cross(individu[offset + 1], individu[offset], alpha);
                    Individu v2 = new Individu(c);
                    crossover.Add(v2);
                    offset = offset + 2;
                }    
            }
            
        }
Example #3
0
        public Form1()
        {
            InitializeComponent();
            db = new SqliteDatabase();
            DataTable dt = new DataTable();
            dt = db.query("SELECT * FROM gejala");

            List<Gejala> rule = new List<Gejala>();

            double[,] cek = {
                {0.534, 0.875, 0.530},
                {0.238, 0.374, 0.573},
                {0.468,	0,	0},
                {0.375,	0.583, 0.384},
                {0,	0.347, 0.474},
                {0.472,	0.582, 0},
                {0,	0.285, 0.372},
                {0,	0.514, 0.572},
                {0.372,	0.512, 0},
                {0.582,	0, 0},
                {0,	0.352, 0},
                {0,	0,	0.235},
                {0.682,	0.235, 0},
                {0,	0.523, 0},
                {0.5325, 0,	0},
                {0.5244, 0.483,	0},
                {0,	0.602, 0.662}
            };

            List<double[]> c*k = new List<double[]>();
            for (int z = 0; z < cek.GetLength(0); z++)
            {
                double[] fak = new double[3];
                fak[0] = cek[z, 0];
                fak[1] = cek[z, 1];
                fak[2] = cek[z, 2];
                c*k.Add(fak);
            }


                foreach (DataRow row in dt.Rows)
                {
                    Gejala g = new Gejala();
                    double[] p = new double[3];
                    g.SetKodeGejala(Convert.ToString(row["kode_gejala"]));
                    g.SetNamaGejala(Convert.ToString(row["nama_gejala"]));
                    p[0] = Convert.ToDouble(row["pneumonia"]);
                    p[1] = Convert.ToDouble(row["bronkitis"]);
                    p[2] = Convert.ToDouble(row["urti"]);
                    g.SetPenyakit(p);
                    rule.Add(g);
                }

            List<Gejala> pesatu = new List<Gejala>();

            for (int i = 0; i < rule.Count; i++)
            {
                Gejala h = new Gejala();
                h.SetKodeGejala(rule[i].GetKodeGejala());
                h.SetPenyakit(c*k[i]);
                pesatu.Add(h);
            }

            de = new Density(rule);
            p1 = new Individu(pesatu);
            p2 = new Individu(de.GetDensity());
        }
Example #4
0
        public Form1()
        {
            InitializeComponent();
            db = new SqliteDatabase();
            DataTable dt = new DataTable();

            dt = db.query("SELECT * FROM gejala");

            List <Gejala> rule = new List <Gejala>();

            double[,] cek =
            {
                {  0.534, 0.875, 0.530 },
                {  0.238, 0.374, 0.573 },
                {  0.468,     0,     0 },
                {  0.375, 0.583, 0.384 },
                {      0, 0.347, 0.474 },
                {  0.472, 0.582,     0 },
                {      0, 0.285, 0.372 },
                {      0, 0.514, 0.572 },
                {  0.372, 0.512,     0 },
                {  0.582,     0,     0 },
                {      0, 0.352,     0 },
                {      0,     0, 0.235 },
                {  0.682, 0.235,     0 },
                {      0, 0.523,     0 },
                { 0.5325,     0,     0 },
                { 0.5244, 0.483,     0 },
                {      0, 0.602, 0.662 }
            };

            List <double[]> c*k = new List <double[]>();

            for (int z = 0; z < cek.GetLength(0); z++)
            {
                double[] fak = new double[3];
                fak[0] = cek[z, 0];
                fak[1] = cek[z, 1];
                fak[2] = cek[z, 2];
                c*k.Add(fak);
            }


            foreach (DataRow row in dt.Rows)
            {
                Gejala   g = new Gejala();
                double[] p = new double[3];
                g.SetKodeGejala(Convert.ToString(row["kode_gejala"]));
                g.SetNamaGejala(Convert.ToString(row["nama_gejala"]));
                p[0] = Convert.ToDouble(row["pneumonia"]);
                p[1] = Convert.ToDouble(row["bronkitis"]);
                p[2] = Convert.ToDouble(row["urti"]);
                g.SetPenyakit(p);
                rule.Add(g);
            }

            List <Gejala> pesatu = new List <Gejala>();

            for (int i = 0; i < rule.Count; i++)
            {
                Gejala h = new Gejala();
                h.SetKodeGejala(rule[i].GetKodeGejala());
                h.SetPenyakit(c*k[i]);
                pesatu.Add(h);
            }

            de = new Density(rule);
            p1 = new Individu(pesatu);
            p2 = new Individu(de.GetDensity());
        }
Example #5
0
        private void prosesBtn_Click(object sender, EventArgs e)
        {
            beliefDgv.Rows.Clear();
            individuDgv.Rows.Clear();
            int popSize = Convert.ToInt32(popSizeBox.Text);
            int iterasi = Convert.ToInt32(iterationBox.Text);
            double cr = Convert.ToDouble(crBox.Text);
            double mr = Convert.ToDouble(mrBox.Text);

            DataTable dt = db.query("SELECT * FROM gejala");

            rule = new List<Gejala>();

            foreach (DataRow row in dt.Rows)
            {
                Gejala g = new Gejala();
                double[] p = new double[3];
                g.SetKodeGejala(Convert.ToString(row["kode_gejala"]));
                g.SetNamaGejala(Convert.ToString(row["nama_gejala"]));
                p[0] = Convert.ToDouble(row["pneumonia"]);
                p[1] = Convert.ToDouble(row["bronkitis"]);
                p[2] = Convert.ToDouble(row["urti"]);
                g.SetPenyakit(p);
                rule.Add(g);
            }

            DataTable ks = db.query("SELECT * FROM kasus");

            List<Kasus> listKasus = new List<Kasus>();
            foreach (DataRow r in ks.Rows)
            {
                string s = Convert.ToString(r["gejala"]);
                string[] gejala = Array.ConvertAll(s.Split(','), ge => ge.Trim());
                string d = Convert.ToString(r["diagnosa"]);
                string[] diagnosa = Array.ConvertAll(d.Split(','), di => di.Trim());
                Kasus k = new Kasus();
                k.SetGejala(gejala);
                k.SetDiagnosa(diagnosa);
                listKasus.Add(k);
            }
            
            de = new Density(rule);
            iBaru = new List<Individu>();
            List<int> index = new List<int>();
            for (int iter = 0; iter < iterasi; iter++)
            {
                // Init
                List<Individu> P;
                Console.WriteLine("Iterasi ke - " + (iter + 1) + " ---------------------------------");
                if (iter == 0)
                {
                    P = new List<Individu>();
                    Console.WriteLine("-- Dempster Shafer Individu --");
                    for (int i = 0; i < popSize; i++)
                    {
                        Console.WriteLine(">> Individu ke - " + (i + 1));
                        Individu inv = new Individu(de.GetDensity());
                        DempsterShafer ds = new DempsterShafer(inv, listKasus);
                        inv.SetFitness(ds.GetFitness());
                        P.Add(inv);
                    }
                }
                else
                {
                    P = iBaru;
                }
                
                List<Individu> C = new List<Individu>();
                CrossOver co = new CrossOver(P, cr, popSize);
                C = co.GetCrossover();

                Console.WriteLine("-- Dempster Shafer Crossover --");
                for (int j = 0; j < C.Count; j++)
                {
                    Console.WriteLine(">> Crossover ke - " + (j + 1));
                    DempsterShafer ds = new DempsterShafer(C[j], listKasus);
                    C[j].SetFitness(ds.GetFitness());
                }

                double minimum = C[0].GetFitness();
                double maximum = 0;
                for (int k = 0; k < C.Count; k++)
                {
                    if (minimum > C[k].GetFitness()) minimum = C[k].GetFitness();
                    if (maximum < C[k].GetFitness()) maximum = C[k].GetFitness();
                }

                double maxmin = maximum - minimum;

                Console.WriteLine("-- Mutasi, Dempster Shafer Mutasi --");
                Mutasi mts = new Mutasi(P, mr, popSize, maxmin, rule);
                C.Add(mts.GetMutasi());
                DempsterShafer dss = new DempsterShafer(C[C.Count - 1], listKasus);
                C[C.Count - 1].SetFitness(dss.GetFitness());

                Console.WriteLine("-- Nilai Fitness Akhir --");
                Selection slct = new Selection(P, C, popSize);
                iBaru = slct.GetITerbaik();
                index = slct.GetIndex();
            }
            PopulateDgv(rule, iBaru[0]);
            double akurasi = iBaru[0].GetFitness() * 100; 
            labelAkurasi.Text = akurasi.ToString() + " %";

            for (int i = 0; i < iBaru.Count; i++)
            {
                int idIndividu = index[i]+1;
                string kode;
                if ( idIndividu > popSize)
                {
                    idIndividu -= popSize;
                    kode = "C" + idIndividu;
                }
                else
                {
                    kode = "P" + idIndividu;
                }
                this.individuDgv.Rows.Add(kode, iBaru[i].GetFitness());
            }

            MessageBox.Show("Proses Perhitungan Selesai");
        }
Example #6
0
        private void prosesBtn_Click(object sender, EventArgs e)
        {
            beliefDgv.Rows.Clear();
            individuDgv.Rows.Clear();
            int    popSize = Convert.ToInt32(popSizeBox.Text);
            int    iterasi = Convert.ToInt32(iterationBox.Text);
            double cr      = Convert.ToDouble(crBox.Text);
            double mr      = Convert.ToDouble(mrBox.Text);

            DataTable dt = db.query("SELECT * FROM gejala");

            rule = new List <Gejala>();

            foreach (DataRow row in dt.Rows)
            {
                Gejala   g = new Gejala();
                double[] p = new double[3];
                g.SetKodeGejala(Convert.ToString(row["kode_gejala"]));
                g.SetNamaGejala(Convert.ToString(row["nama_gejala"]));
                p[0] = Convert.ToDouble(row["pneumonia"]);
                p[1] = Convert.ToDouble(row["bronkitis"]);
                p[2] = Convert.ToDouble(row["urti"]);
                g.SetPenyakit(p);
                rule.Add(g);
            }

            DataTable ks = db.query("SELECT * FROM kasus");

            List <Kasus> listKasus = new List <Kasus>();

            foreach (DataRow r in ks.Rows)
            {
                string   s        = Convert.ToString(r["gejala"]);
                string[] gejala   = Array.ConvertAll(s.Split(','), ge => ge.Trim());
                string   d        = Convert.ToString(r["diagnosa"]);
                string[] diagnosa = Array.ConvertAll(d.Split(','), di => di.Trim());
                Kasus    k        = new Kasus();
                k.SetGejala(gejala);
                k.SetDiagnosa(diagnosa);
                listKasus.Add(k);
            }

            de    = new Density(rule);
            iBaru = new List <Individu>();
            List <int> index = new List <int>();

            for (int iter = 0; iter < iterasi; iter++)
            {
                // Init
                List <Individu> P;
                Console.WriteLine("Iterasi ke - " + (iter + 1) + " ---------------------------------");
                if (iter == 0)
                {
                    P = new List <Individu>();
                    Console.WriteLine("-- Dempster Shafer Individu --");
                    for (int i = 0; i < popSize; i++)
                    {
                        Console.WriteLine(">> Individu ke - " + (i + 1));
                        Individu       inv = new Individu(de.GetDensity());
                        DempsterShafer ds  = new DempsterShafer(inv, listKasus);
                        inv.SetFitness(ds.GetFitness());
                        P.Add(inv);
                    }
                }
                else
                {
                    P = iBaru;
                }

                List <Individu> C  = new List <Individu>();
                CrossOver       co = new CrossOver(P, cr, popSize);
                C = co.GetCrossover();

                Console.WriteLine("-- Dempster Shafer Crossover --");
                for (int j = 0; j < C.Count; j++)
                {
                    Console.WriteLine(">> Crossover ke - " + (j + 1));
                    DempsterShafer ds = new DempsterShafer(C[j], listKasus);
                    C[j].SetFitness(ds.GetFitness());
                }

                double minimum = C[0].GetFitness();
                double maximum = 0;
                for (int k = 0; k < C.Count; k++)
                {
                    if (minimum > C[k].GetFitness())
                    {
                        minimum = C[k].GetFitness();
                    }
                    if (maximum < C[k].GetFitness())
                    {
                        maximum = C[k].GetFitness();
                    }
                }

                double maxmin = maximum - minimum;

                Console.WriteLine("-- Mutasi, Dempster Shafer Mutasi --");
                Mutasi mts = new Mutasi(P, mr, popSize, maxmin, rule);
                C.Add(mts.GetMutasi());
                DempsterShafer dss = new DempsterShafer(C[C.Count - 1], listKasus);
                C[C.Count - 1].SetFitness(dss.GetFitness());

                Console.WriteLine("-- Nilai Fitness Akhir --");
                Selection slct = new Selection(P, C, popSize);
                iBaru = slct.GetITerbaik();
                index = slct.GetIndex();
            }
            PopulateDgv(rule, iBaru[0]);
            double akurasi = iBaru[0].GetFitness() * 100;

            labelAkurasi.Text = akurasi.ToString() + " %";

            for (int i = 0; i < iBaru.Count; i++)
            {
                int    idIndividu = index[i] + 1;
                string kode;
                if (idIndividu > popSize)
                {
                    idIndividu -= popSize;
                    kode        = "C" + idIndividu;
                }
                else
                {
                    kode = "P" + idIndividu;
                }
                this.individuDgv.Rows.Add(kode, iBaru[i].GetFitness());
            }

            MessageBox.Show("Proses Perhitungan Selesai");
        }