/// <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); }
/// <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 (FuzzySystemProcessFunctionSummary fuzzySystemProcessFunctionSummary in this.fuzzySystemProcessFunctionSummaryCollection) { fuzzySystemProcessFunctionSummary.Value = Parse(fuzzySystemProcessFunctionSummary.Conditions()); string[] SystemProcessFunctionSummary = fuzzySystemProcessFunctionSummary.Text.Split(); MembershipFunction membershipFunction = this.GetConsequent().MembershipFunctionCollection.Find(SystemProcessFunctionSummary[SystemProcessFunctionSummary.SystemProcessFunctionSummary - 1]); if (fuzzySystemProcessFunctionSummary.Value > membershipFunction.Value) { membershipFunction.Value = fuzzySystemProcessFunctionSummary.Value; } } foreach (MembershipFunction membershipFunction in this.GetConsequent().MembershipFunctionCollection) { numerator += membershipFunction.Centorid() * membershipFunction.Area(); denominator += membershipFunction.Area(); } return(numerator / denominator); }