Beispiel #1
0
        private void showRules(FuzzyRules rls)
        {
            string[] values = rls.getValues();
            string[][] args = rls.getKeys();
            for (int i=nDiv; i<nDiv*nIn; i++)
            {
                dataGridView2.Columns.Add(keys[i], keys[i]);
            }
            dataGridView2.Rows.Add(nDiv);
            dataGridView2.RowHeadersWidth = 110;
            dataGridView2.Height = dataGridView2.Rows[0].Height * (dataGridView2.Rows.Count+2);

            for (int i=0; i<nDiv; i++)
            {
                dataGridView2.Rows[i].HeaderCell.Value = keys[i];
            }

            for (int i=0; i<values.Length; i++)
            {
                int index = 0;
                int ct = 0;
                for (int j=0; j< dataGridView2.Rows.Count-1; j++)
                {
                    if (dataGridView2.Rows[j].HeaderCell.Value.ToString() == args[i][0])
                    {
                        index = j;
                        break;
                    }
                }
                dataGridView2.Rows[index].Cells[args[i][1]].Value = values[i].ToString();
            }
        }
Beispiel #2
0
        private void initData()
        {
            membershipIn = new List<double[,]>();
            membershipOut = new List<double[,]>();

            m = new double[size, nIn];
            mY = new double[size];
            rT = new double[size];

            categoryXL = new string[size, nIn];
            categoryYL = new string[size];
            categoryYT1 = new string[size];
            categoryYT2 = new string[size];

            LearningX = new List<double[]>();
            LearningY = new List<double[]>();
            TestX = new List<double[]>();
            TestY = new List<double[]>();

            genData = new List<double[]>();
            decisions = new List<string[]>();
            inputDef = new List<DeFuzzySet>();

            data = new List<double[]>();
            rules = new FuzzyRules();
            fuzzy = new FuzzySet();
            rFuzzy = new FuzzySet();
            func = new Membership();

            keys = new string[nDiv * nIn];
            classes = new string[nDiv];
            double d = 0;
            for (int i = 0; i < nDiv * nIn; i++)
            {
                if (i < nDiv)
                {
                    keys[i] = i + "A" + i;
                    classes[i] = i + "B" + i;
                }
                else
                {
                    keys[i] = (i - nDiv) + "A." + (i - nDiv);
                }
            }
            if (fu == "tr")
            {
                int ln = nDiv + 1;
                d = (minGen + maxGen) / ln;
            }
            else if (fu == "trap")
            {
                if (nDiv==3)
                    d= (minGen + maxGen) / 7;
                else d = (minGen + maxGen) / 11;
            }
            else if (fu == "gauss")
            {
                int ln = nDiv + 1;
                d = (minGen + maxGen) / ln;
            }

            if (nDiv == 3)
            {
                if (fu == "tr")
                {
                    data.Add(new double[] { minGen, minGen + d, minGen + 2 * d });
                    data.Add(new double[] { minGen + d, minGen + 2 * d, minGen + 3 * d });
                    data.Add(new double[] { minGen + 2 * d, minGen + 3 * d, maxGen });

                    data.Add(new double[] { minGen, minGen + d, minGen + 2 * d });
                    data.Add(new double[] { minGen + d, minGen + 2 * d, minGen + 3 * d });
                    data.Add(new double[] { minGen + 2 * d, minGen + 3 * d, maxGen });

                    data.Add(new double[] { minGen, minGen + d, minGen + 2 * d });
                    data.Add(new double[] { minGen + d, minGen + 2 * d, minGen + 3 * d });
                    data.Add(new double[] { minGen + 2 * d, minGen + 3 * d, maxGen });
                }
                else if (fu == "trap")
                {
                    data.Add(new double[] { minGen, minGen + d, minGen + 2 * d, minGen + 3 * d });
                    data.Add(new double[] { minGen + 2 * d, minGen + 3 * d, minGen + 4 * d, minGen + 5 * d });
                    data.Add(new double[] { minGen + 4 * d, minGen + 5 * d, minGen + 6 * d, maxGen });

                    data.Add(new double[] { minGen, minGen + d, minGen + 2 * d, minGen + 3 * d });
                    data.Add(new double[] { minGen + 2 * d, minGen + 3 * d, minGen + 4 * d, minGen + 5 * d });
                    data.Add(new double[] { minGen + 4 * d, minGen + 5 * d, minGen + 6 * d, maxGen });

                    data.Add(new double[] { minGen, minGen + d, minGen + 2 * d, minGen + 3 * d });
                    data.Add(new double[] { minGen + 2 * d, minGen + 3 * d, minGen + 4 * d, minGen + 5 * d });
                    data.Add(new double[] { minGen + 4 * d, minGen + 5 * d, minGen + 6 * d, maxGen });
                }
                else if (fu == "gauss")
                {
                    data.Add(new double[] { minGen + d, d/3 });
                    data.Add(new double[] { minGen + 2 * d, d / 3 });
                    data.Add(new double[] { minGen + 3 * d, d / 3 });

                    data.Add(new double[] { minGen + d, d / 3 });
                    data.Add(new double[] { minGen + 2 * d, d / 3 });
                    data.Add(new double[] { minGen + 3 * d, d / 3 });

                    data.Add(new double[] { minGen + d, d / 3 });
                    data.Add(new double[] { minGen + 2 * d, d / 3 });
                    data.Add(new double[] { minGen + 3 * d, d / 3 });
                }
            }
            else
            {
                if (fu == "tr")
                {
                    data.Add(new double[] { minGen, minGen + d, minGen + 2 * d });
                    data.Add(new double[] { minGen + d, minGen + 2 * d, minGen + 3 * d });
                    data.Add(new double[] { minGen + 2 * d, minGen + 3 * d, minGen + 4 * d });
                    data.Add(new double[] { minGen + 3 * d, minGen + 4 * d, minGen + 5 * d });
                    data.Add(new double[] { minGen + 4 * d, minGen + 5 * d, maxGen });

                    data.Add(new double[] { minGen, minGen + d, minGen + 2 * d });
                    data.Add(new double[] { minGen + d, minGen + 2 * d, minGen + 3 * d });
                    data.Add(new double[] { minGen + 2 * d, minGen + 3 * d, minGen + 4 * d });
                    data.Add(new double[] { minGen + 3 * d, minGen + 4 * d, minGen + 5 * d });
                    data.Add(new double[] { minGen + 4 * d, minGen + 5 * d, maxGen });

                    data.Add(new double[] { minGen, minGen + d, minGen + 2 * d });
                    data.Add(new double[] { minGen + d, minGen + 2 * d, minGen + 3 * d });
                    data.Add(new double[] { minGen + 2 * d, minGen + 3 * d, minGen + 4 * d });
                    data.Add(new double[] { minGen + 3 * d, minGen + 4 * d, minGen + 5 * d });
                    data.Add(new double[] { minGen + 4 * d, minGen + 5 * d, maxGen });
                }
                else if (fu == "trap")
                {
                    data.Add(new double[] { minGen, minGen + d, minGen + 2 * d, minGen + 3 * d });
                    data.Add(new double[] { minGen + 2 * d, minGen + 3 * d, minGen + 4 * d, minGen + 5 * d });
                    data.Add(new double[] { minGen + 4 * d, minGen + 5 * d, minGen + 6 * d, minGen + 7 * d });
                    data.Add(new double[] { minGen + 6 * d, minGen + 7 * d, minGen + 8 * d, minGen + 9 * d });
                    data.Add(new double[] { minGen + 8 * d, minGen + 9 * d, minGen + 10 * d, maxGen });

                    data.Add(new double[] { minGen, minGen + d, minGen + 2 * d, minGen + 3 * d });
                    data.Add(new double[] { minGen + 2 * d, minGen + 3 * d, minGen + 4 * d, minGen + 5 * d });
                    data.Add(new double[] { minGen + 4 * d, minGen + 5 * d, minGen + 6 * d, minGen + 7 * d });
                    data.Add(new double[] { minGen + 6 * d, minGen + 7 * d, minGen + 8 * d, minGen + 9 * d });
                    data.Add(new double[] { minGen + 8 * d, minGen + 9 * d, minGen + 10 * d, maxGen });

                    data.Add(new double[] { minGen, minGen + d, minGen + 2 * d, minGen + 3 * d });
                    data.Add(new double[] { minGen + 2 * d, minGen + 3 * d, minGen + 4 * d, minGen + 5 * d });
                    data.Add(new double[] { minGen + 4 * d, minGen + 5 * d, minGen + 6 * d, minGen + 7 * d });
                    data.Add(new double[] { minGen + 6 * d, minGen + 7 * d, minGen + 8 * d, minGen + 9 * d });
                    data.Add(new double[] { minGen + 8 * d, minGen + 9 * d, minGen + 10 * d, maxGen });
                }
                else if (fu == "gauss")
                {
                    data.Add(new double[] { minGen + d, d / 3 });
                    data.Add(new double[] { minGen + 2 * d, d / 3 });
                    data.Add(new double[] { minGen + 3 * d, d / 3 });
                    data.Add(new double[] { minGen + 4 * d, d / 3 });
                    data.Add(new double[] { minGen + 5 * d, d / 3 });

                    data.Add(new double[] { minGen + d, d / 3 });
                    data.Add(new double[] { minGen + 2 * d, d / 3 });
                    data.Add(new double[] { minGen + 3 * d, d / 3 });
                    data.Add(new double[] { minGen + 4 * d, d / 3 });
                    data.Add(new double[] { minGen + 5 * d, d / 3 });

                    data.Add(new double[] { minGen + d, d / 3 });
                    data.Add(new double[] { minGen + 2 * d, d / 3 });
                    data.Add(new double[] { minGen + 3 * d, d / 3 });
                    data.Add(new double[] { minGen + 4 * d, d / 3 });
                    data.Add(new double[] { minGen + 5 * d, d / 3 });
                }
            }

            int ct = 0;
            foreach (string obj in keys)
            {
                fuzzy.Set.Add(obj, data[ct]);
                ct++;
            }
            ct = 0;
            foreach (string obj in classes)
            {
                rFuzzy.Set.Add(obj, data[ct]);
                ct++;
            }
            for (int i = 0; i < nIn; i++)
            {
                LearningX.Add(new double[size + 1]);
                TestX.Add(new double[size + 1]);

                genData.Add(new double[size]);
            }
            LearningY.Add(new double[size]);
            TestY.Add(new double[size]);

            rL = new double[size + 1];
        }