本文整理汇总了Python中skfuzzy.defuzz函数的典型用法代码示例。如果您正苦于以下问题:Python defuzz函数的具体用法?Python defuzz怎么用?Python defuzz使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了defuzz函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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')
示例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
示例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()
示例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')
示例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
'''
示例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
示例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')
示例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
示例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)
示例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'))
示例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
示例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
示例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
示例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
示例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