Example #1
0
  def Evaluate( self, membershipFunction, min, max, step ):
  
    membershipFunction.SetComposeFunction( BinaryFunction.GodelSNorm() )
  
    # Find the maximum value of the membership function
    flatMaxFunction = MembershipFunction.FlatMembershipFunction()
    flatMaxFunction.SetParameters( [ self.MaximumValue( membershipFunction, min, max, step ) ] )
  
    # This function is the max value when the original membership function achieves its max, and is zero otherwise
    maxFunction = MembershipFunction.MembershipFunction()
    maxFunction.AddBaseFunction( flatMaxFunction )
    maxFunction.AddBaseFunction( membershipFunction )
    maxFunction.SetComposeFunction( EqualBinaryFunction() )
  
    numeratorFunction = MembershipFunction.MembershipFunction()
    numeratorFunction.AddBaseFunction( maxFunction )
    numeratorFunction.AddBaseFunction( XMembershipFunction() )
    numeratorFunction.SetComposeFunction( BinaryFunction.GoguenTNorm() ) # Multiply x * func and integrate
  
    denominatorFunction = MembershipFunction.MembershipFunction()
    denominatorFunction.AddBaseFunction( maxFunction )
  
    num = self.Integrate( numeratorFunction, min, max, step )  
    denom = self.Integrate( denominatorFunction, min, max, step )

    if ( denom == 0 ):
      logging.warning( "DefuzzifierMOM::Evaluate: Membership function has zero maximum." )
      return 0

    return num / denom
Example #2
0
    def Evaluate(self, inputValues, transformOutputFunction):
        if (self.ComposeFunction == None
                or self.OutputMembershipFunction == None):
            emptyMembershipFunction = MembershipFunction.FlatMembershipFunction(
            )
            emptyMembershipFunction.SetParameters([0])
            return emptyMembershipFunction

        # Find the input membership values
        totalMembership = 1 - self.ComposeFunction.Evaluate(
            0, 1)  # This yields 1 for t-norm and 0 for s-norm
        ruleUsed = False

        for name in inputValues:
            if (name not in self.InputMembershipFunctions):
                continue

            currentMembership = self.InputMembershipFunctions[name].Evaluate(
                inputValues[name])
            totalMembership = self.ComposeFunction.Evaluate(
                totalMembership, currentMembership)
            ruleUsed = True

        # Assign the total memership to be zero if the rule is never used
        if (ruleUsed == False):
            totalMembership = 0

        # Compose the flat membership function
        flatMembershipFunction = MembershipFunction.FlatMembershipFunction()
        flatMembershipFunction.SetParameters([totalMembership])

        # Apply clipping or scaling to output membership function
        transformedOutputMembershipFunction = MembershipFunction.MembershipFunction(
        )
        transformedOutputMembershipFunction.AddBaseFunction(
            self.OutputMembershipFunction)
        transformedOutputMembershipFunction.AddBaseFunction(
            flatMembershipFunction)
        transformedOutputMembershipFunction.SetComposeFunction(
            transformOutputFunction)

        # Return the transformed output membership function
        return transformedOutputMembershipFunction