public FuzzyValue Build() { var result = new FuzzyValue(); result.Name = name; result.Category = category; result.Index = index; result.Center = center; result.UpperWidth = upperWidth; result.LowerWidth = lowerWidth; result.LeftModifier = leftModifier; result.RightModifier = rightModifier; result.GetMembership = membershipFunction; if (autoIncrement) { index++; } return(result); }
private double Linear(FuzzyValue value, double CrispValue) { var distance = Math.Abs(value.Center - CrispValue); // CrispValue is the same as the value's center if (distance == 0) { return(1); } // if either side of the center is immediately raised to 0 or 100 if (value.LeftModifier != 0 || value.RightModifier != 0) { var modifier = (value.Center > CrispValue ? value.LeftModifier : value.RightModifier); if (modifier != DEFAULT) { return(modifier == CEIL ? 1 : 0); } } var upperDistance = value.UpperWidth / 2; var lowerDistance = value.LowerWidth / 2; // distance is within upper part of the trapezoid if (distance <= upperDistance) { return(1); } // distance is on the slope trapezoid else if (distance < lowerDistance) { var medianDistance = lowerDistance - upperDistance; return(Math.Abs((lowerDistance - distance) / medianDistance)); } // distance is outside the trapezoid else { return(0); } }