Пример #1
0
        private void btnTsukamotoInf_Click(object sender, EventArgs e)
        {
            double   a   = Convert.ToDouble(txtTsukamotoA.Text);
            double   c   = Convert.ToDouble(txtTsukamotoC.Text);
            FuzzySet sig = new SigmoidalFuzzySet(new Universe());

            sig.Parameters[0] = a;
            sig.Parameters[1] = c;
            double[] x           = new double[InputUniverses.Count]; //x值
            double[] w           = new double[RuleList.Count];       //weight
            double   totalWeight = 0.0;

            double[] z  = new double[RuleList.Count];
            double   wa = 0.0;
            double   ws = 0.0;

            for (int i = 0; i < InputUniverses.Count; i++)
            {
                x[i] = Convert.ToDouble(dataGridViewTsukamoto.Rows[0].Cells[i].Value); //讀進來
            }
            for (int r = 0; r < RuleList.Count; r++)                                   //計算w
            {
                w[r] = 1.0;
                for (int j = 0; j < InputUniverses.Count; j++)
                {
                    double temp = RuleList[r].inputFuzzySets[j].GetMembershipDegree(x[j]);
                    if (temp < w[r]) //取min
                    {
                        w[r] = temp;
                    }
                }
                totalWeight += w[r];
                z[r]         = sig.GetMembershipDegree(w[r]);
                ws          += z[r] * w[r];               //weighted sum
                wa          += z[r] * w[r] / totalWeight; //weighted average
            }
            txtTsukamotoWA.Text = wa.ToString();
            txtTsukamotoWS.Text = ws.ToString();
        }
Пример #2
0
        private void btnAddFuzzy_Click(object sender, EventArgs e)
        {
            FuzzySet fs = null; //local variable default

            if (ptgProperty.SelectedObject is FuzzySet)
            {
                MessageBox.Show("You must select a universe", "No Universe selected", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Universe uu = (Universe)ptgProperty.SelectedObject;

            switch (lsbOptions.SelectedIndex)
            {
            case 0:     //Triangular
                fs = new TriangularFuzzySet(uu);
                break;

            case 1:     //Gaussian
                fs = new GaussianFuzzySet(uu);
                break;

            case 2:    //Bell
                fs = new BellFuzzySet(uu);
                break;

            case 3:    //LeftRight
                fs = new LeftRightFuzzySet(uu);
                break;

            case 4:    //Sigmoodal
                fs = new SigmoidalFuzzySet(uu);
                break;

            case 5:    //Trapezoidal
                fs = new TrapezoidalFuzzySet(uu);
                break;

            case 6:    //Sshape
                fs = new SshapeFuzzySet(uu);
                break;

            case 7:
                fs = new ZshapeFuzzySet(uu);
                break;

            case 8:
                fs = new PishapeFuzzySet(uu);
                break;
            }
            if (SelectedNode.TreeView == treeViewInputUniverse)
            {
                //fuzzySetObjects.Add(fs);
                allInputFuzzySets[SelectedNode.Index].Add(fs);
                //加入comboBox
                comboBoxBinary1stFS.Items.Add(fs);
                comboBoxBinary2ndFS.Items.Add(fs);
                //add a node to represent the fuzzyset
                TreeNode tnn = new TreeNode(fs.title);
                treeViewInputUniverse.Nodes[SelectedNode.Index].Nodes.Add(tnn);
                tnn.ImageIndex         = 1;
                tnn.SelectedImageIndex = 1;
                inputCols1[SelectedNode.Index].Items.Add(fs);
                inputCols2[SelectedNode.Index].Items.Add(fs);
                treeViewInputUniverse.ExpandAll();
                chartInput.Series.Add(fs.line);
            }
            else //output universe
            {
                OutputFuzzySets.Add(fs);
                comboBoxBinary1stFS.Items.Add(fs);
                comboBoxBinary2ndFS.Items.Add(fs);
                //add a node to represent the fuzzyset
                TreeNode tnn = new TreeNode(fs.title);
                treeViewOutputU.Nodes[SelectedNode.Index].Nodes.Add(tnn);
                tnn.ImageIndex         = 1;
                tnn.SelectedImageIndex = 1;
                outputCol1.Items.Add(fs);
                outputCol2.Items.Add(fs);
                treeViewOutputU.ExpandAll();
                chartOutput.Series.Add(fs.line);
            }
        }