Ejemplo n.º 1
0
        double Defuzzify(IMembershipFunction mf, double min, double max)
        {
            if (_defuzzMethod == DefuzzificationMethod.Centroid)
            {
                int    k    = 50;
                double step = (max - min) / k;

                //
                // Calculate a center of gravity as integral
                //
                double ptLeft   = 0.0;
                double ptCenter = 0.0;
                double ptRight  = 0.0;

                double valLeft   = 0.0;
                double valCenter = 0.0;
                double valRight  = 0.0;

                double val2Left   = 0.0;
                double val2Center = 0.0;
                double val2Right  = 0.0;

                double numerator   = 0.0;
                double denominator = 0.0;
                for (int i = 0; i < k; i++)
                {
                    if (i == 0)
                    {
                        ptRight   = min;
                        valRight  = mf.GetValue(ptRight);
                        val2Right = ptRight * valRight;
                    }

                    ptLeft   = ptRight;
                    ptCenter = min + step * ((double)i + 0.5);
                    ptRight  = min + step * (i + 1);

                    valLeft   = valRight;
                    valCenter = mf.GetValue(ptCenter);
                    valRight  = mf.GetValue(ptRight);

                    val2Left   = val2Right;
                    val2Center = ptCenter * valCenter;
                    val2Right  = ptRight * valRight;

                    numerator   += step * (val2Left + 4 * val2Center + val2Right) / 3.0;
                    denominator += step * (valLeft + 4 * valCenter + valRight) / 3.0;
                }

                return(numerator / denominator);
            }
            else if (_defuzzMethod == DefuzzificationMethod.Bisector)
            {
                // TODO:
                throw new NotSupportedException();
            }
            else if (_defuzzMethod == DefuzzificationMethod.AverageMaximum)
            {
                // TODO:
                throw new NotSupportedException();
            }
            else
            {
                throw new Exception("Internal exception.");
            }
        }
Ejemplo n.º 2
0
        string DefuzzifyToClosestTerm(FuzzyVariable outputVariable, IMembershipFunction compositeMF, double min, double max)
        {
            int k = 50;
            double step = (max - min) / k;

            double maxArea = 0;
            string matchingTerm = outputVariable.Terms[0].Name;

            foreach (var term in outputVariable.Terms)
            {
                double coverageArea = 0;

                double leftX = min;
                double rightX = leftX + step;

                while (rightX <= max)
                {
                    coverageArea += step * (Math.Min(term.MembershipFunction.GetValue(leftX), compositeMF.GetValue(leftX)));
                    leftX += step;
                    rightX += step;
                }

                if (coverageArea > maxArea)
                {
                    maxArea = coverageArea;
                    matchingTerm = term.Name;
                }
            }

            return matchingTerm;
        }
Ejemplo n.º 3
0
        double Defuzzify(IMembershipFunction mf, double min, double max)
        {
            if (_defuzzMethod == DefuzzificationMethod.Centroid)
            {
                int    k    = 50;
                double step = (max - min) / k;

                //
                // Вычисление центра гравитации как интеграла
                //
                double ptLeft   = 0.0;
                double ptCenter = 0.0;
                double ptRight  = 0.0;

                double valLeft   = 0.0;
                double valCenter = 0.0;
                double valRight  = 0.0;

                double val2Left   = 0.0;
                double val2Center = 0.0;
                double val2Right  = 0.0;

                double numerator   = 0.0;
                double denominator = 0.0;
                for (int i = 0; i < k; i++)
                {
                    if (i == 0)
                    {
                        ptRight   = min;
                        valRight  = mf.GetValue(ptRight);
                        val2Right = ptRight * valRight;
                    }

                    ptLeft   = ptRight;
                    ptCenter = min + step * ((double)i + 0.5);
                    ptRight  = min + step * (i + 1);

                    valLeft   = valRight;
                    valCenter = mf.GetValue(ptCenter);
                    valRight  = mf.GetValue(ptRight);

                    val2Left   = val2Right;
                    val2Center = ptCenter * valCenter;
                    val2Right  = ptRight * valRight;

                    numerator   += step * (val2Left + 4 * val2Center + val2Right) / 3.0;
                    denominator += step * (valLeft + 4 * valCenter + valRight) / 3.0;
                }

                return(numerator / denominator);
            }
            else if (_defuzzMethod == DefuzzificationMethod.Bisector)
            {
                // TODO:
                throw new NotSupportedException();
            }
            else if (_defuzzMethod == DefuzzificationMethod.AverageMaximum)
            {
                // TODO:
                throw new NotSupportedException();
            }
            else
            {
                throw new Exception("Метод дефаззификации не найден.");
            }
        }
Ejemplo n.º 4
0
        double Defuzzify(IMembershipFunction mf, double min, double max)
        {
            if (_defuzzMethod == DefuzzificationMethod.Centroid)
            {
                int k = 50;
                double step = (max - min) / k;

                //
                // Calculate a center of gravity as integral
                //
                double ptLeft = 0.0;
                double ptCenter = 0.0;
                double ptRight = 0.0;

                double valLeft = 0.0;
                double valCenter = 0.0;
                double valRight = 0.0;

                double val2Left = 0.0;
                double val2Center = 0.0;
                double val2Right = 0.0;

                double numerator = 0.0;
                double denominator = 0.0;
                for (int i = 0; i < k; i++)
                {
                    if (i == 0)
                    {
                        ptRight = min;
                        valRight = mf.GetValue(ptRight);
                        val2Right = ptRight * valRight;
                    }

                    ptLeft = ptRight;
                    ptCenter = min + step * ((double)i + 0.5);
                    ptRight = min + step * (i + 1);

                    valLeft = valRight;
                    valCenter = mf.GetValue(ptCenter);
                    valRight = mf.GetValue(ptRight);

                    val2Left = val2Right;
                    val2Center = ptCenter * valCenter;
                    val2Right = ptRight * valRight;

                    numerator += step * (val2Left + 4 * val2Center + val2Right) / 3.0;
                    denominator += step * (valLeft + 4 * valCenter + valRight) / 3.0;
                }

                return numerator / denominator;
            }
            else if (_defuzzMethod == DefuzzificationMethod.Bisector)
            {
                // TODO:
                throw new NotSupportedException();
            }
            else if (_defuzzMethod == DefuzzificationMethod.AverageMaximum)
            {
                // TODO:
                throw new NotSupportedException();
            }
            else
            {
                throw new Exception("Internal exception.");
            }
        }