• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python skfuzzy.defuzz函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中skfuzzy.defuzz函数的典型用法代码示例。如果您正苦于以下问题:Python defuzz函数的具体用法?Python defuzz怎么用?Python defuzz使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了defuzz函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_defuzz

def test_defuzz():
    x = np.arange(21) - 10
    gmf = fuzz.gaussmf(x, 0, 2)

    assert_allclose(0, fuzz.defuzz(x, gmf, 'centroid'), atol=1e-9)
    assert_allclose(0, fuzz.defuzz(x, gmf, 'bisector'), atol=1e-9)
    assert_allclose(0, fuzz.defuzz(x, gmf, 'mom'))
    assert_allclose(0, fuzz.defuzz(x, gmf, 'som'))
    assert_allclose(0, fuzz.defuzz(x, gmf, 'lom'))

    # Fuzzy plateau to differentiate mom, som, lom
    trapmf = fuzz.trapmf(x, [-1, 3, 7, 8])

    assert_allclose(3, fuzz.defuzz(x, trapmf, 'som'))
    assert_allclose(5, fuzz.defuzz(x, trapmf, 'mom'))
    assert_allclose(7, fuzz.defuzz(x, trapmf, 'lom'))


    # Make sure som/lom work for all-negative universes:
    x_neg = x-20
    assert_allclose(-17, fuzz.defuzz(x_neg, trapmf, 'som'))
    assert_allclose(-13, fuzz.defuzz(x_neg, trapmf, 'lom'))
    
    # Bad string argument
    assert_raises(ValueError, fuzz.defuzz, x, trapmf, 'bad string')
开发者ID:JDWarner,项目名称:scikit-fuzzy,代码行数:25,代码来源:test_defuzz.py


示例2: defuzz

    def defuzz(self):
        """Derive crisp value based on membership of adjective(s)."""
        if not self.sim._array_inputs:
            ups_universe, output_mf, cut_mfs = self.find_memberships()

            if len(cut_mfs) == 0:
                raise ValueError("No terms have memberships.  Make sure you "
                                 "have at least one rule connected to this "
                                 "variable and have run the rules calculation.")

            try:
                return defuzz(ups_universe, output_mf,
                              self.var.defuzzify_method)
            except AssertionError:
                raise ValueError("Crisp output cannot be calculated, likely "
                                 "because the system is too sparse. Check to "
                                 "make sure this set of input values will "
                                 "activate at least one connected Term in each "
                                 "Antecedent via the current set of Rules.")
        else:
            # Calculate using array-aware version, one cut at a time.
            output = np.zeros(self.sim._array_shape, dtype=np.float64)

            it = np.nditer(output, ['multi_index'], [['writeonly', 'allocate']])

            for out in it:
                universe, mf = self.find_memberships_nd(it.multi_index)
                out[...] = defuzz(universe, mf, self.var.defuzzify_method)

            return output
开发者ID:JDWarner,项目名称:scikit-fuzzy,代码行数:30,代码来源:controlsystem.py


示例3: run

    def run(self):

            """ inputs[0] =  ERROR AXIS          ., so stores all possible error values
                inputs[1] =  DEL_ERROR AXIS      .,     ,,
                inputs[2] =  CONTROL_OUTPUT AXIS .,     ,,
                    
                ERROR                  DEL_ERROR               CONTROL_OUTPUT         m_value for crisp e and delta_e values

                b[0][0] -ve Medium  || b[1][0] -ve Medium  ||  b[2][0] -ve Medium   ..        f[0] |  f_d[0] 
                b[0][1] -ve small   || b[1][1] -ve small   ||  b[2][1] -ve small    ..        f[1] |  f_d[1]
                b[0][2] zero        || b[1][2] zero        ||  b[2][2] zero         ..        f[2] |  f_d[2]
                b[0][3] +ve small   || b[1][3] +ve small   ||  b[2][3] +ve small    ..        f[3] |  f_d[3]
                b[0][4] +ve Medium  || b[1][4] +ve Medium  ||  b[2][4] +_ve Medium  ..        f[4] |  f_d[4] 
                
                f_mat is fuzzy fuzzy_matrix
            """
            inputs = [ np.arange(var[0], var[1]+1, 1) for var in self.var_ranges] #step size  = 1, third dimension of b matrix. As of now, an assumption.
            b  = []
            output = [0,0,0,0,0]
            out_final = []
            for i in range(3) :
                    b.append( [membership_f(self.mu[i], inputs[i], a) for a in self.d_mu[i] ])
            # To visualize the membership func. call .. [ visualize_mf(b,inputs)  ]
            
            f ,f_d = error_fuzzify(inputs, b, self.error, self.delta_e)            
            f_mat = fuzzy_matrix(f,f_d)
            output = rule_base(b, f_mat, output)
            print 'output : ', output
            aggregated = np.fmax(output[0], np.fmax(output[1],np.fmax(output[2], np.fmax(output[3], output[4]))))
            out_final = fuzz.defuzz(inputs[2], aggregated, 'centroid')
            out_activation = fuzz.interp_membership(inputs[2], aggregated, out_final)  # for plot
            visualize.visualize_mf(b,inputs,output, out_final, out_activation, aggregated)
            visualize.visualize_output(b, inputs, out_final, out_activation, aggregated)
            plt.show()
开发者ID:icyflame,项目名称:fuzzy-control,代码行数:34,代码来源:fuzzy.py


示例4: compute_pi3k

def compute_pi3k(egfr_value, erk_value, time_value, initial_values, mfs):
	"""Rules ---
	if egfr is high and erk is low and time is high then pi3k is high
	if egfr is low or erk is high or time is low then pi3k is low"""

	a1_1 = mfs[0][1][initial_values[0] == egfr_value] #egfr_high[egfr == egfr_value]
	a1_2 = mfs[1][0][ initial_values[1] == erk_value] #erk_low[erk == erk_value]
	a1_3 = mfs[3][1][ initial_values[3] == time_value]

	if( a1_1.size == 0):
		a1_1 = mfs[0][1][ find_closest(initial_values[0], egfr_value)]
	if( a1_2.size == 0):
		a1_2 = mfs[1][0][ find_closest(initial_values[1], erk_value)]
	if( a1_3.size == 0):
		a1_3 = mfs[3][1][ find_closest(initial_values[3], time_value)]

	a1 = min(a1_1 , a1_2, a1_3)
	c1 = np.fmin( np.linspace(a1, a1, 100), mfs[2][1])

	a2_1 = mfs[0][0][ initial_values[0] == egfr_value] #egfr_low[egfr == egfr_value]
	a2_2 = mfs[1][1][ initial_values[1] == erk_value] #erk_high[erk == erk_value]
	a2_3 = mfs[3][0][ initial_values[3] == time_value]

	if( a2_1.size == 0):
		a2_1 = mfs[0][0][ find_closest(initial_values[0], egfr_value)]
	if( a2_2.size == 0):
		a2_2 = mfs[1][1][ find_closest(initial_values[1], erk_value)]
	if( a2_3.size == 0):
		a2_3 = mfs[3][0][ find_closest(initial_values[3], time_value)]

	a2 = max(a2_1 , a2_2, a2_3)
	c2 = np.fmin( np.linspace(a2, a2, 100), mfs[2][0] )

	c_com = np.fmax(c1, c2)
	return fuzz.defuzz(initial_values[2], c_com, 'centroid')
开发者ID:NPSDC,项目名称:Modeling,代码行数:35,代码来源:r.py


示例5: getFuzzyAcceleration

 def getFuzzyAcceleration(self,currentBatAngle,predictedBatAngle):
     
     dif = abs(currentBatAngle - predictedBatAngle)
     if(dif > 180):
         self.InputDistanceAngle = 360- dif
     else:
         self.InputDistanceAngle = dif
     '''    
     self.thetaOne = abs(currentBatAngle-predictedBatAngle)
     self.thetaTwo = currentBatAngle + (360-predictedBatAngle)
     
     if(self.thetaOne < self.thetaTwo):
         self.InputDistanceAngle = self.thetaOne
     else:
         self.InputDistanceAngle = self.thetaTwo
     '''
            
     self.InputDistanceAngle = int(self.InputDistanceAngle)
      
     #print "final angle to cover----",int(self.InputDistanceAngle)
     #print "buggy parth=============",self.R_combined[self.distance == self.InputDistanceAngle]
         
     self.OutputAcceleration = fuzz.defuzz(self.acceleration,self.R_combined[self.distance == self.InputDistanceAngle], 'centroid')
     
     #print "correspoinding acceleration",self.OutputAcceleration
     
     return self.OutputAcceleration
 
     #test code starts here
     '''
开发者ID:ansrivas,项目名称:gameailab,代码行数:30,代码来源:fuzzyControl.py


示例6: get_output

    def get_output(self, current_temp, target_temp, rate_of_change_per_minute):
        temp_err_in = self.temp_error_category(current_temp, target_temp, rate_of_change_per_minute)
        print "Temp Error", temp_err_in

        #What is the temperature doing?
        mf_temp_too_cold = temp_err_in['too_cold']
        mf_temp_cold     = temp_err_in['cold']
        mf_temp_optimal  = temp_err_in['optimal']
        mf_temp_hot      = temp_err_in['hot']
        mf_temp_too_hot  = temp_err_in['too_hot']

        mf_cooling_quickly = temp_err_in['cooling_quickly']

        #Then:
        when_too_cold = np.fmin(mf_temp_too_cold, self.ho_high)
        when_cold     = np.fmin(mf_temp_cold, self.ho_low)
        when_optimal  = np.fmin(mf_temp_optimal, self.co_off)
        when_hot      = np.fmin(mf_temp_hot, self.co_low)
        when_too_hot  = np.fmin(mf_temp_too_hot, self.co_high)

        #If the temperate is temp_hot AND cooling_quickly SET chiller off
        when_hot_and_cooling_quickly = np.fmin(np.fmin(mf_temp_hot, mf_cooling_quickly), self.co_off)

        aggregate_membership = np.fmax(when_hot_and_cooling_quickly, np.fmax(when_too_cold, np.fmax(when_cold, np.fmax(when_optimal, np.fmax(when_hot, when_too_hot)))))
        result = fuzz.defuzz(self.chill_out, aggregate_membership, 'centroid')

        return result
开发者ID:chrisdpa,项目名称:brumulus,代码行数:27,代码来源:ControlTemperature.py


示例7: compute_akt

def compute_akt(pi3k_value, time_value, initial_values, mfs):
	"""Rules-
		If pi3k is high and time is high akt is high
		If pi3k is low or time is low then akt is low"""
	a1_1 = mfs[0][1][initial_values[0] == pi3k_value]
	a1_2 = mfs[2][1][initial_values[2] == time_value]

	if( a1_1.size == 0):
		a1_1 = mfs[0][1][ find_closest(initial_values[0], pi3k_value)]
	if( a1_2.size == 0):
		a1_2 = mfs[2][1][ find_closest(initial_values[2], time_value)]

	a1 = min(a1_1, a1_2)
	c1 = np.fmin( np.linspace(a1, a1, 100), mfs[1][1])

	a2_1 = mfs[0][0][initial_values[0] == pi3k_value]
	a2_2 = mfs[2][0][initial_values[2] == time_value]

	if( a2_1.size == 0):
		a2_1 = mfs[0][0][ find_closest(initial_values[0], pi3k_value)]
	if( a2_2.size == 0):
		a2_2 = mfs[2][0][ find_closest(initial_values[2], time_value)]

	a2 = max(a2_1, a2_2)
	c2 = np.fmin( np.linspace(a2, a2, 100), mfs[1][0])

	c_com = np.fmax(c1,c2)
	return fuzz.defuzz( initial_values[1], c_com, 'centroid')
开发者ID:NPSDC,项目名称:Modeling,代码行数:28,代码来源:r.py


示例8: compute_erk_change

def compute_erk_change(raf_value, time_value, initial_values, mfs):
	"""Rules-
		If raf is high and time is high then positive_change_erk is high
		If raf is high1 and time is low then positive_change_erk is low
		If raf is low then positive_change_erk is low
		If raf is low and time is high then negative_change_erk is high
		If raf is low and time is low then negative_change_erk is low"""

	
	#Antecedent 1
	f = interp1d(initial_values[0][0], mfs[0][1])
	a1_1 = f(raf_value) #raf_high[raf == raf_value]
	f = interp1d(initial_values[2], mfs[2][1])
	a1_2 = f(time_value) #time_high[time == time_value]

	a1 = min(a1_1, a1_2)
	c1 = np.fmin( a1, mfs[1][3]) #mfs[1][3] is positive_change_erk_high

	#Antecedent 2
	f = interp1d(initial_values[0][0], mfs[0][6])
	a2_1 = f(raf_value)
	f = interp1d(initial_values[2], mfs[2][0]) #time_low[time == time_value]
	a2_2 = f(time_value)

	a2 = min(a2_1, a2_2)
	c2 = np.fmin( a2, mfs[1][2]) #mfs[1][2] is positive_change_raf_low

	c_com_positive = np.fmax(c1,c2)

	f = interp1d(initial_values[0][0], mfs[0][0])
	a3 = f(raf_value)
	c3 = np.fmin(a3, mfs[1][2])

	c_com_positive = np.fmax(c_com_positive, c3)
	pos_change = fuzz.defuzz( initial_values[1][1], c_com_positive, 'centroid') #initial_values[1][1] is positive_change_erk

	###Negative Change

	#Antecedent 3
	'''f = interp1d(initial_values[0][0], mfs[0][0])
	a3_1 = f(raf_value) #raf_low[raf == raf_value]
	a3_2 = a1_2 #time_high[time == time_value]

	a3 = min(a3_1,a3_2)
	c3 = np.fmin(a3, mfs[1][5]) #mfs[1][3] is negative_change_erk_high

	#Antecedent 4
	a4_1 = a3_1 #raf_low[raf == raf_value]
	a4_2 = a2_2 #time_low[time == time_value]

	a4 = min(a4_1, a4_2)
	c4 = np.fmin(a4, mfs[1][4]) #mfs[1][4] is negative_change_erk_low

	c_com_negative = np.fmax(c3, c4)
	neg_change = fuzz.defuzz(initial_values[1][2], c_com_negative, 'centroid') #initial_values[1][2] is negative_change_erk'''
	
	#print pos_change, neg_change
	#print pos_change
	return pos_change 
开发者ID:NPSDC,项目名称:Modeling,代码行数:59,代码来源:binary_fuzzy_egfr.py


示例9: defuzz

 def defuzz(self):
     """Derive crisp value based on membership of adjective(s)."""
     output_mf, cut_mfs = self.find_memberships()
     if len(cut_mfs) == 0:
         raise ValueError("No terms have memberships.  Make sure you "
                          "have at least one rule connected to this "
                          "variable and have run the rules calculation.")
     return defuzz(self.var.universe, output_mf, self.var.defuzzify_method)
开发者ID:castelao,项目名称:scikit-fuzzy,代码行数:8,代码来源:controlsystem.py


示例10: test_bisector

def test_bisector():
    x = np.arange(6)
    mfx = fuzz.trimf(x, [0, 5, 5])
    expected = 3.53553390593274

    # Test both triangle code paths
    assert_allclose(expected, fuzz.defuzz(x, mfx, 'bisector'))
    assert_allclose(5 - expected, fuzz.defuzz(x, 1 - mfx, 'bisector'))

    # Test singleton input
    y = np.r_[2]
    mfy = np.r_[0.33]
    assert_allclose(y, fuzz.defuzz(y, mfy, 'bisector'))

    # Test rectangle code path
    mfx = fuzz.trapmf(x, [2, 2, 4, 4])
    assert_allclose(3., fuzz.defuzz(x, mfx, 'bisector'))
开发者ID:duongtrung,项目名称:scikit-fuzzy,代码行数:17,代码来源:test_defuzz.py


示例11: compute_akt_change

def compute_akt_change(pi3k_value, time_value, initial_values, mfs):
	"""Rules-
		If pi3k is high and time is high then positive_change_akt is high
		If pi3k is high1 and time is low then positive_change_akt is low
		If pi3k is low then positive_change_pi3k is low
		If pi3k is low and time is high then negative_change_akt is high
		If pi3k is low and time is low then negative_change_akt is low"""

	###Positive Change
	#Antecedent 1
	f = interp1d(initial_values[0][0], mfs[0][1])	
	a1_1 = f(pi3k_value) #pi3k_high[pi3k == pi3k_value]
	f = interp1d(initial_values[2], mfs[2][1])
	a1_2 = f(time_value) #time_high[time == time_value]

	a1 = min(a1_1, a1_2)
	c1 = np.fmin(a1, mfs[1][3]) #positive_change_akt is high

	#Antecedent 2
	f = interp1d(initial_values[0][0], mfs[0][6])
	a2_1 = f(pi3k_value) #pi3k_high[pi3k == pi3k_value]
	f = interp1d(initial_values[2], mfs[2][0])
	a2_2 = f(time_value) #time_low[time == time_value]

	a2 = min(a2_1, a2_2)
	c2 = np.fmin( a2, mfs[1][2]) #positive_change_akt is low

	c_com_positive = np.fmax(c1,c2)

	f = interp1d(initial_values[0][0], mfs[0][0])
	a3 = f(pi3k_value)
	c3 = np.fmin(a3, mfs[1][2])
	c_com_positive = np.fmax(c_com_positive, c3)
	pos_change = fuzz.defuzz( initial_values[1][1], c_com_positive, 'centroid') #initial_values[1][1] is positive_change_akt

	###Negative Change

	#Antecedent 3
	'''f = interp1d(initial_values[0][0], mfs[0][0])
	a3_1 = f(pi3k_value) #pi3k_low[pi3k == pi3k_value]
	a3_2 = a1_2 #time_high[time == time_value]

	a3 = min(a3_1, a3_2)
	c3 = np.fmin(a3, mfs[1][5]) #mfs[1][5] is negative_change_akt_high

	#Antecedent 4
	a4_1 = a3_1 #pi3k_low[pi3k == pi3k_value]
	a4_2 = a2_2 #time_low[time == time_value]

	a4 = min(a4_1, a4_2)
	c4 = np.fmin(a4, mfs[1][4]) #mfs[1][4] is negative_change_akt_low

	c_com_negative = np.fmax(c3, c4)
	neg_change = fuzz.defuzz(initial_values[1][2], c_com_negative, 'centroid') #initial_values[1][2] is negative_change_akt'''

	return pos_change 
开发者ID:NPSDC,项目名称:Modeling,代码行数:56,代码来源:binary_fuzzy_egfr.py


示例12: next_action

def next_action(t, b, s):
    """
    ¦  t: target angle
    ¦  b: ball angle
    ¦  s: spin
    """
    output = fuzz.defuzz(angle_dmn, output_function(t, b, s), 'centroid')
    outputrad = math.radians(output)
    cos_output = math.cos(outputrad)
    sin_output = math.sin(outputrad)
    return cos_output, sin_output
开发者ID:hoarf,项目名称:robotsoccer,代码行数:11,代码来源:fuzzy_ia.py


示例13: run_system

    def run_system(self, input_list, output_key, TESTMODE=False):
        """
        Runs the fuzzy system for a single output
        ------INPUTS------
        input_list : dict
            dict of inputs {'input1':value, 'input2':value, ...} 
        output_key : string
            string key of output to calculate
        TESTMODE : int
            testmode flag (1 = On)
        ------OUTPUTS------ 
        """
        self.TESTMODE = TESTMODE
        outs = []
        for rule in self.rulebase:   #iterate over rulebase
            if TESTMODE: 
                print '------------------------------------------------------------------------'
                print 'TRANSLATING RULE: ', rule.rule_id
                  
            #break apart antecedent and consequent
            if_i = rule.rule_list.index('IF')   
            then_i = rule.rule_list.index('THEN')
            rule_ant = copy.deepcopy(rule.rule_list[if_i+1:then_i])                         #get the rule antecedent
            rule_con = copy.deepcopy(rule.rule_list[then_i+1:len(rule.rule_list)+1])[0]     #get the rule consequent
            
            if rule_con[0] == output_key:               #only follow rule if it applies to given output 

                fs = self.rule_recurse(rule_ant, input_list, TESTMODE)[0]   #get firing strength

                if TESTMODE: print 'FIRING STREGTH, RULE', rule.rule_id, ':', fs
            
                output = copy.deepcopy(self.outputs[rule_con[0]].MFs[rule_con[2]]) #get output
                output[1] = self.implicate(fs, output)#use implication to get fuzzy consequent
                
                if TESTMODE: self.implicatedOutputs[rule.rule_id][self.outputs[rule_con[0]].name] = copy.deepcopy(output)
                    
                outs.append(output)
        
        #aggregate outputs
        if len(outs) > 0: 
            output_result = self.aggregate(outs)    #aggregate outputs if there are outputs
            
            if self.defuzz <> None: #defuzzify outputs
                output_result = fuzz.defuzz(output_result[0], output_result[1], self.defuzz)
        else:
            m1 = self.outputs[output_key].data_range[0]         #get output min
            m2 = self.outputs[output_key].data_range[1]         #get output max
            x1 = np.arange(m1,m2,0.01)                          #get x range
            output_result = [x1, np.asarray([0 for i in range(len(x1))])]   #return mf function of zeros
            
            if self.defuzz <> None: #defuzzify outputs
                output_result = [0,0]
            
        return output_result
开发者ID:pattersoniv,项目名称:FFAS,代码行数:54,代码来源:fuzzy_systems.py


示例14: calaculate_akt

def calaculate_akt(pi3k_mfs, akt_mfs, akt, pi3k_index):
	a1 = pi3k_mfs[0][pi3k_index]
	c1 = np.fmin(a1, akt_mfs[0])
	a2 = pi3k_mfs[1][pi3k_index]
	c2 = np.fmin(a2, akt_mfs[1])
	c_com = np.fmax(c1, c2)
	try:
		akt_val = fuzz.defuzz(akt, c_com, 'centroid')
	except AssertionError as e:
		akt_val = 0
	return akt_val
开发者ID:NPSDC,项目名称:Modeling,代码行数:11,代码来源:egfr.py


示例15: calculate_egfr

def calculate_egfr(time_mfs, egfr_mfs, egfr, time_index):
	a1 = time_mfs[0][time_index]
	c1 = np.fmin(a1, egfr_mfs[0])
	a2 = time_mfs[1][time_index]
	c2 = np.fmin(a2, egfr_mfs[1])
	c_com = np.fmax(c1, c2)
	try:
		egfr_val = fuzz.defuzz(egfr, c_com, 'centroid')
	except AssertionError as e:
		egfr_val = 0
	return egfr_val
开发者ID:NPSDC,项目名称:Modeling,代码行数:11,代码来源:egfr.py


示例16: calculate_erk

def calculate_erk(raf_mfs, erk_mfs, erk, raf_index):
	a1 = raf_mfs[0][raf_index]
	c1 = np.fmin(a1, erk_mfs[0])
	a2 = raf_mfs[1][raf_index]
	c2 = np.fmin(a2, erk_mfs[1])
	c_com = np.fmax(c1, c2)
	try:
		erk_val = fuzz.defuzz(erk, c_com, 'centroid')
	except AssertionError as e:
		erk_val = 0
	return erk_val
开发者ID:NPSDC,项目名称:Modeling,代码行数:11,代码来源:egfr.py


示例17: run

    def run(self):

        """ 
        Finds appropriate value of pid gains

        NO arguments : 

        inputs : List to contain discrete values of io variables in their range (step size = 1) for plotting. i.e, x axis
            inputs[0] =  ERROR AXIS          ., so stores all possible error values
            inputs[1] =  DEL_ERROR AXIS      .,     ,,
            inputs[2] =  CONTROL_OUTPUT AXIS .,     ,,
                
        b : 3d list, each layer (i.e, 2d list) contains 1d lists of y-values (in x of step size 1) of a particular fuzzy 
            subset of a particular i/o variable 
        
        muval_de, muval_e: Stores membership value of error and delta_error for each fuzzy subsets

            ERROR                  DEL_ERROR               CONTROL_OUTPUT         m_value for crisp e and delta_e values

            b[0][0] -ve Medium  || b[1][0] -ve Medium  ||  b[2][0] -ve Medium   ..        muval[0] |  muval_d[0] 
            b[0][1] -ve small   || b[1][1] -ve small   ||  b[2][1] -ve small    ..        muval[1] |  muval_d[1]
            b[0][2] zero        || b[1][2] zero        ||  b[2][2] zero         ..        muval[2] |  muval_d[2]
            b[0][3] +ve small   || b[1][3] +ve small   ||  b[2][3] +ve small    ..        muval[3] |  muval_d[3]
            b[0][4] +ve Medium  || b[1][4] +ve Medium  ||  b[2][4] +_ve Medium  ..        muval[4] |  muval_d[4] 
            
        f_mat is a 2d matrix containing rule strengths
        """
        inputs = [ np.arange(var[0], var[1]+1, 1) for var in self.io_ranges]
        b  = []
        for i in range(3) :
                b.append( [membership_f(self.mf_types[i], inputs[i], a) for a in self.f_ssets[i] ])

        # visualize.visualize_mf(b,inputs)
        # fuzzify Error and delta error to obtain their membership values for corr. fuzzy subsets
        muval_e  = fuzzify(inputs[0], b[0], self.error)
        muval_de = fuzzify(inputs[1], b[1], self.delta_e) 

        # print 'muval_e:', muval_e
        # print 'muval_de:', muval_de
        # Obtain the rule strength matrix
        f_mat = fuzzy_matrix(muval_e, muval_de)
        #  obtian the y value clipped by output activation for output fuzzy subsets
        output = rule_base(b, f_mat)
        aggregated = np.fmax(output[0], np.fmax(output[1],np.fmax(output[2], np.fmax(output[3], output[4]))))
        out_final  = fuzz.defuzz(inputs[2], aggregated, 'centroid')
        print "output:",out_final
        # plotting final output
        visualize.visualize_output(b, inputs, output, out_final, aggregated)
        plt.show()
开发者ID:nevinvalsaraj,项目名称:fuzzy-control,代码行数:49,代码来源:fuzzy.py


示例18: game_type

def game_type(player, comp):
    """ A fuzzy algorithm to define the offensiveness and/or 
    defensiveness of the game. Determines how aggressive the fuzzy 
    player is"""

    score_diff = float(player-comp)
    ### Inputs ###
    # Input Variable Domain
    score = np.arange(-21, 21, 1)
    
    # Input membership functions
    score_ahead = fuzz.gaussmf(score, -21, 8.823)
    score_tied = fuzz.gaussmf(score, 0, 9.012)
    score_behind = fuzz.gaussmf(score, 21, 8.823)

    # Fuzzifying the current input
    def score_category(sc):
        score_cat_ahead = fuzz.interp_membership(score, score_ahead, sc)
        score_cat_tied = fuzz.interp_membership(score, score_tied, sc)
        score_cat_behind = fuzz.interp_membership(score, score_behind, sc)
        return dict(ahead = score_cat_ahead, tied = score_cat_tied, behind = score_cat_behind)

    ### Outputs ###
    # Output Variable Domain
    game = np.arange(0, 1, 1)

    # Output membership functions
    game_defensive = fuzz.gaussmf(game, 0, 0.162899)
    game_offensive = fuzz.gauss2mf(game, 0.30291, 0.090976, 1.31, 0.416)

    ### Rules ###
    current_score = score_category(score_diff)

    # Going to make this a hard opponent, so if the score is tied or 
    # if the human is winning, it will play offensively
    rule1 = current_score['ahead']
    rule2 = np.fmax(current_score['tied'], current_score['behind'])

    # Apply implication operator (Mamdami)
    imp1 = np.fmin(rule1, game_defensive)
    imp2 = np.fmin(rule2, game_offensive)

    # Aggregate outputs using max
    aggregate_membership = np.fmax(imp1, imp2)

    # Defuzzify using centroid and return the result
    result_game = fuzz.defuzz(game, aggregate_membership, 'centroid')
    return result_game
开发者ID:SophiaMitchell,项目名称:Python_PONG,代码行数:48,代码来源:fuzzpaddle.py


示例19: rule_actividad

def rule_actividad(value, graficar=False):

    # recibe los datos para poder seguir el proceso difuso para encontrar la pertenencia
    # retorna el valor al que pertenece en la clase segun la hora
    mf_actividad = generar_actividad(False)
    mf_calorico = generar_calorico(False)

    # se usa para encontrar los grados de pertenencia del valor, borrificacion
    actividad_nivel_rest = fuzz.interp_membership(mf_actividad['intensity'], mf_actividad['rest'], value)
    actividad_nivel_std = fuzz.interp_membership(mf_actividad['intensity'], mf_actividad['active'], value)
    actividad_nivel_work = fuzz.interp_membership(mf_actividad['intensity'], mf_actividad['workout'], value)

    # regla: si rest -> low
    rest_activation = np.fmin(actividad_nivel_rest, mf_calorico['low'])
    # regla: si active -> std
    active_activation = np.fmin(actividad_nivel_std, mf_calorico['standard'])
    # regla: si workout -> high
    workout_activation = np.fmin(actividad_nivel_work, mf_calorico['high'])

    # deborrificacion
    agregado = np.fmax(rest_activation, np.fmax(active_activation, workout_activation))
    caloric = fuzz.defuzz(mf_calorico['caloric'], agregado, 'centroid')


    # # graficar
    # if graficar:
    #     select_caloric = fuzz.interp_membership(mf_calorico['caloric'], agregado, caloric)
    #     caloric0 = np.zeros_like(mf_calorico['caloric'])
    #     fig, ax0 = plt.subplots(figsize=(8, 3))
    #
    #     ax0.plot(mf_calorico['caloric'], mf_calorico['low'], 'b', linewidth=0.5, linestyle='--', label='Low')
    #     ax0.plot(mf_calorico['caloric'], mf_calorico['standard'], 'g', linewidth=0.5, linestyle='--', label='Standard')
    #     ax0.plot(mf_calorico['caloric'], mf_calorico['high'], 'r', linewidth=0.5, linestyle='--', label='High')
    #     ax0.fill_between(mf_calorico['caloric'], caloric0, agregado, facecolor='Orange', alpha=0.7)
    #     ax0.plot([caloric, caloric], [0, select_caloric], 'k', linewidth=1.5, alpha=0.9)
    #     ax0.set_title('Dish Classification and Result (line)')
    #     ax0.legend()
    #     # Turn off top/right axes
    #     for ax in (ax0,):
    #         ax.spines['top'].set_visible(False)
    #         ax.spines['right'].set_visible(False)
    #         ax.get_xaxis().tick_bottom()
    #         ax.get_yaxis().tick_left()
    #
    #     plt.tight_layout()
    #     #fig.savefig('graphs/result_calorico.png', bbox_inches='tight')
    # 
    return caloric, "caloric"
开发者ID:Zelev,项目名称:IA_SE-DataJoy,代码行数:48,代码来源:generar_fm.py


示例20: defuzz

 def defuzz(self):
     """Derive crisp value based on membership of adjective(s)."""
     ups_universe, output_mf, cut_mfs = self.find_memberships()
     if len(cut_mfs) == 0:
         raise ValueError("No terms have memberships.  Make sure you "
                          "have at least one rule connected to this "
                          "variable and have run the rules calculation.")
     try:
         return defuzz(ups_universe, output_mf,
                       self.var.defuzzify_method)
     except AssertionError:
         raise ValueError("Crisp output cannot be calculated, likely "
                          "because the system is too sparse. Check to "
                          "make sure this set of input values will "
                          "activate at least one connected Term in each "
                          "Antecedent via the current set of Rules.")
开发者ID:boton-rojo-ml,项目名称:scikit-fuzzy,代码行数:16,代码来源:controlsystem.py



注:本文中的skfuzzy.defuzz函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python skfuzzy.trimf函数代码示例发布时间:2022-05-27
下一篇:
Python skew.scan函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap