Пример #1
0
        /// <summary>
        /// Calculates the defuzzification value with the CoG (Center of Gravity) technique.
        /// </summary>
        /// <returns>The defuzzification value.</returns>
        public double Defuzzify()
        {
            double numerator   = 0;
            double denominator = 0;

            // Reset values
            foreach (MembershipFunction membershipFunction in this.GetConsequent().MembershipFunctionCollection)
            {
                membershipFunction.Value = 0;
            }

            foreach (FuzzyRule fuzzyRule in this.fuzzyRuleCollection)
            {
                fuzzyRule.Value = Parse(fuzzyRule.Conditions());

                string[]           tokens             = fuzzyRule.Text.Split();
                MembershipFunction membershipFunction = this.GetConsequent().MembershipFunctionCollection.Find(tokens[tokens.Length - 1]);

                if (fuzzyRule.Value > membershipFunction.Value)
                {
                    membershipFunction.Value = fuzzyRule.Value;
                }
            }

            foreach (MembershipFunction membershipFunction in this.GetConsequent().MembershipFunctionCollection)
            {
                numerator   += membershipFunction.Centorid() * membershipFunction.Area();
                denominator += membershipFunction.Area();
            }

            return(numerator / denominator);
        }