Пример #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
Пример #2
0
 def Copy(self, other):
     if (other.OutputMembershipFunction != None):
         copyOutputMembershipFunction = MembershipFunction.MembershipFunction(
         )
         copyOutputMembershipFunction.Copy(other.OutputMembershipFunction)
         self.OutputMembershipFunction = copyOutputMembershipFunction
     for name in other.InputMembershipFunctions:
         copyInputMembershipFunction = MembershipFunction.MembershipFunction(
         )
         copyInputMembershipFunction.Copy(
             other.InputMembershipFunctions[name])
         self.InputMembershipFunctions[name] = copyInputMembershipFunction
     if (other.ComposeFunction != None):
         copyComposeFunction = MembershipFunction.MembershipFunction()
         copyComposeFunction.Copy(other.ComposeFunction)
         self.ComposeFunction = copyComposeFunction
Пример #3
0
    def AddInputMembershipFunction(self, newInputMembershipFunction,
                                   inputName):
        if (inputName not in self.InputMembershipFunctions):
            self.InputMembershipFunctions[
                inputName] = MembershipFunction.MembershipFunction()
            self.InputMembershipFunctions[inputName].SetComposeFunction(
                self.ComposeFunction)

        self.InputMembershipFunctions[inputName].AddBaseFunction(
            newInputMembershipFunction)
Пример #4
0
  def Evaluate( self, membershipFunction, min, max, step ):
  
    membershipFunction.SetComposeFunction( BinaryFunction.GodelSNorm() )
  
    numeratorFunction = MembershipFunction.MembershipFunction()
    numeratorFunction.AddBaseFunction( membershipFunction )
    numeratorFunction.AddBaseFunction( XMembershipFunction() )
    numeratorFunction.SetComposeFunction( BinaryFunction.GoguenTNorm() ) # Multiply x * func and integrate
  
    denominatorFunction = MembershipFunction.MembershipFunction()
    denominatorFunction.AddBaseFunction( membershipFunction )
  
    num = self.Integrate( numeratorFunction, min, max, step )  
    denom = self.Integrate( denominatorFunction, min, max, step )

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

    return num / denom
Пример #5
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
    def __init__(self, min_thrust, max_thrust):
        self.min_thrust = min_thrust
        self.max_thrust = max_thrust
        self.recommended_left = 0.0
        self.recommended_right = 0.0
        self.lastErr = 0.0

        # prepare membership functions for input parameters
        self.angle_err = {}
        self.angle_err[2] = MembershipFunction.MembershipFunction(
            False, True, 1.0 / 45.0, 90.0)
        self.angle_err[1] = MembershipFunction.MembershipFunction(
            False, False, 1.0 / 45.0, 45.0)
        self.angle_err[0] = MembershipFunction.MembershipFunction(
            False, False, 1.0 / 45.0, 0.0)
        self.angle_err[-1] = MembershipFunction.MembershipFunction(
            False, False, 1.0 / 45.0, -45.0)
        self.angle_err[-2] = MembershipFunction.MembershipFunction(
            True, False, 1.0 / 45.0, -90.0)

        self.ang_vel = {}
        self.ang_vel[2] = MembershipFunction.MembershipFunction(
            False, True, 1.0 / 20.0, 40.0)
        self.ang_vel[1] = MembershipFunction.MembershipFunction(
            False, False, 1.0 / 20.0, 20.0)
        self.ang_vel[0] = MembershipFunction.MembershipFunction(
            False, False, 1.0 / 20.0, 0.0)
        self.ang_vel[-1] = MembershipFunction.MembershipFunction(
            False, False, 1.0 / 20.0, -20.0)
        self.ang_vel[-2] = MembershipFunction.MembershipFunction(
            True, False, 1.0 / 20.0, -40.0)

        # prepare membership functions for outpur thrust recommendations
        self.thr_reco = {}
        self.thr_reco[3] = MembershipFunction.MembershipFunction(
            False, False, 1.0 / 5.0, 60.0)
        self.thr_reco[2] = MembershipFunction.MembershipFunction(
            False, False, 1.0 / 5.0, 40.0)
        self.thr_reco[1] = MembershipFunction.MembershipFunction(
            False, False, 1.0 / 5.0, 20.0)
        self.thr_reco[0] = MembershipFunction.MembershipFunction(
            False, False, 1.0 / 5.0, 0.0)  #!!!

        # prepare rulebase
        self.rules = []

        self.rules.append(Rule(-2, -2, 3))
        self.rules.append(Rule(-2, -1, 3))
        self.rules.append(Rule(-2, 0, 2))
        self.rules.append(Rule(-2, 1, 1))
        self.rules.append(Rule(-2, 2, 0))

        self.rules.append(Rule(-1, -2, 3))
        self.rules.append(Rule(-1, -1, 2))
        self.rules.append(Rule(-1, -0, 1))
        self.rules.append(Rule(-1, 1, 0))
        self.rules.append(Rule(-1, 2, -1))

        self.rules.append(Rule(0, -2, 2))
        self.rules.append(Rule(0, -1, 1))
        self.rules.append(Rule(0, 0, 0))
        self.rules.append(Rule(0, 1, -1))
        self.rules.append(Rule(0, 2, -2))

        self.rules.append(Rule(1, -2, 1))
        self.rules.append(Rule(1, -1, 0))
        self.rules.append(Rule(1, 0, -1))
        self.rules.append(Rule(1, 1, -2))
        self.rules.append(Rule(1, 2, -3))

        self.rules.append(Rule(2, -2, 0))
        self.rules.append(Rule(2, -1, -1))
        self.rules.append(Rule(2, 0, -2))
        self.rules.append(Rule(2, 1, -3))
        self.rules.append(Rule(2, 2, -3))
Пример #7
0
    def __init__(self, min_thrust, max_thrust, reactions):
        self.min_thrust = min_thrust
        self.max_thrust = max_thrust
        self.recommended_left = 0.0
        self.recommended_right = 0.0
        self.lastErr = 0.0
        
        # prepare membership functions for input parameters
        self.angle_err = {}
        self.angle_err[4] = MembershipFunction.MembershipFunction(False, True, 1.0/20.0, 60.0)
        self.angle_err[3] = MembershipFunction.MembershipFunction(False, False, 1.0/15.0, 40.0)
        self.angle_err[2] = MembershipFunction.MembershipFunction(False, False, 1.0/15.0, 20.0)
        self.angle_err[1] = MembershipFunction.MembershipFunction(False, False, 1.0/10.0, 10.0)
        self.angle_err[0] = MembershipFunction.MembershipFunction(False, False, 1.0/3.0, 0.0)
        self.angle_err[-1] = MembershipFunction.MembershipFunction(False, False, 1.0/10.0, -10.0)
        self.angle_err[-2] = MembershipFunction.MembershipFunction(False, False, 1.0/15.0, -20.0)
        self.angle_err[-3] = MembershipFunction.MembershipFunction(False, False, 1.0/15.0, -40.0)
        self.angle_err[-4] = MembershipFunction.MembershipFunction(True, False, 1.0/20.0, -60.0)
        
        self.ang_vel = {}
        self.ang_vel[4] = MembershipFunction.MembershipFunction(False, True, 1.0/7.5, 30.0)
        self.ang_vel[3] = MembershipFunction.MembershipFunction(False, False, 1.0/7.5, 22.5)
        self.ang_vel[2] = MembershipFunction.MembershipFunction(False, False, 1.0/7.5, 12.5)
        self.ang_vel[1] = MembershipFunction.MembershipFunction(False, False, 1.0/5.0, 5.0)
        self.ang_vel[0] = MembershipFunction.MembershipFunction(False, False, 1.0/5.0, 0.0)
        self.ang_vel[-1] = MembershipFunction.MembershipFunction(False, False, 1.0/5.0, -5.0)
        self.ang_vel[-2] = MembershipFunction.MembershipFunction(False, False, 1.0/7.5, -12.5)
        self.ang_vel[-3] = MembershipFunction.MembershipFunction(False, False, 1.0/7.5, -22.5)
        self.ang_vel[-4] = MembershipFunction.MembershipFunction(True, False, 1.0/7.5, -30.0)
                  
        # prepare membership functions for output thrust recommendations
        span = max_thrust - min_thrust
        factor = span / 8.0
        self.thr_reco = {}
        self.thr_reco[8] = MembershipFunction.MembershipFunction(False, False, factor, max_thrust)
        self.thr_reco[7] = MembershipFunction.MembershipFunction(False, False, factor, min_thrust + span/8.0 * 7)
        self.thr_reco[6] = MembershipFunction.MembershipFunction(False, False, factor, min_thrust + span/8.0 * 6)
        self.thr_reco[5] = MembershipFunction.MembershipFunction(False, False, factor, min_thrust + span/8.0 * 5)
        self.thr_reco[4] = MembershipFunction.MembershipFunction(False, False, factor, min_thrust + span/8.0 * 4)
        self.thr_reco[3] = MembershipFunction.MembershipFunction(False, False, factor, min_thrust + span/8.0 * 3)
        self.thr_reco[2] = MembershipFunction.MembershipFunction(False, False, factor, min_thrust + span/8.0 * 2)
        self.thr_reco[1] = MembershipFunction.MembershipFunction(False, False, factor, min_thrust + span/8.0 * 1)
        self.thr_reco[0] = MembershipFunction.MembershipFunction(False, False, factor, min_thrust)
        
        # prepare rulebase
        self.rules = []

        z = 0

        for verse in range(9):
            for column in range(9):
                self.rules.append(Rule(verse - 4, column - 4, reactions[z]))
                z += 1
        print(str(z) + " rules loaded")