Skip to content

Commit be38f4f

Browse files
committed
Rename adjective to term
1 parent 385de5e commit be38f4f

File tree

4 files changed

+84
-84
lines changed

4 files changed

+84
-84
lines changed

skfuzzy/control/antecedent_consequent.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@ def set_patch(self, label, cut):
8686
Floating-point value from 0 to 1 calculated from current inputs
8787
via a fuzzy rule.
8888
"""
89-
if self.adjectives[label].membership_value is None:
90-
self.adjectives[label].membership_value = cut
91-
elif self.adjectives[label].membership_value < cut:
89+
if self.terms[label].membership_value is None:
90+
self.terms[label].membership_value = cut
91+
elif self.terms[label].membership_value < cut:
9292
# Update existing cut using an accumulation method
9393
# (this is assuming ACCU = max)
9494
# TODO: Multiple accumulation methods
95-
self.adjectives[label].membership_value = cut
95+
self.terms[label].membership_value = cut
9696

9797

9898
class Intermediary(FuzzyVariable):
@@ -103,17 +103,17 @@ def __init__(self, universe, label):
103103

104104
def set_patch(self, label, cut):
105105
### Consequent mocking
106-
if self.adjectives[label].membership_value is None:
107-
self.adjectives[label].membership_value = cut
108-
elif self.adjectives[label].membership_value < cut:
106+
if self.terms[label].membership_value is None:
107+
self.terms[label].membership_value = cut
108+
elif self.terms[label].membership_value < cut:
109109
# Update existing cut using an accumulation method
110110
# (this is assuming ACCU = max)
111111
# TODO: Multiple accumulation methods
112-
self.adjectives[label].membership_value = cut
112+
self.terms[label].membership_value = cut
113113

114114
# Update my crisp value given this new patch
115115
output_mf, cut_mfs = self._find_crisp_value()
116116
assert len(cut_mfs) > 0
117-
crisp = defuzz(self.universe, output_mf, self.defuzzy_method)
117+
crisp = defuzz(self.universe, output_mf, self.defuzzify_method)
118118
self.crisp_value = crisp
119119
print "%s is now %s" % (self, crisp)

skfuzzy/control/controlsystem.py

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import networkx as nx
77
import matplotlib.pylab as plt
88
from .antecedent_consequent import Antecedent, Consequent, Intermediary
9-
from .fuzzyvariable import FuzzyVariable, FuzzyVariableAdjective
9+
from .fuzzyvariable import FuzzyVariable, FuzzyVariableTerm
1010
from .visualization import ControlSystemVisualizer
1111

1212
try:
@@ -51,9 +51,6 @@ def __init__(self, antecedents=None, consequents=None, kind='or',
5151
self.collected_firing = {}
5252
self.final_firing = None
5353

54-
if self.label is None:
55-
self.label = "Rule %d" % self._id
56-
5754
if antecedents is None or consequents is None:
5855
self.connections = None
5956
else:
@@ -63,6 +60,8 @@ def __repr__(self):
6360
"""
6461
Print a concise, readable summary of the fuzzy rule.
6562
"""
63+
if self.label is not None:
64+
return self.label
6665
# All this for a pretty printed representation of the rule...
6766
antlen = len(self.antecedents)
6867
conlen = len(self.consequents)
@@ -93,23 +92,23 @@ def _chk_obj(self, var, obj):
9392
Argument checking to ensure every adjective's parent is type ``obj``.
9493
"""
9594
temp = self._iter(var)
96-
for adj in temp:
97-
parent = adj.parent_variable
98-
if not isinstance(adj, FuzzyVariableAdjective):
99-
raise ValueError("All elements must be adjectives")
95+
for term in temp:
96+
parent = term.parent_variable
97+
if not isinstance(term, FuzzyVariableTerm):
98+
raise ValueError("All elements must be terms")
10099
if parent is None:
101-
raise ValueError("All adjectives must have a parent")
100+
raise ValueError("All terms must have a parent")
102101
if not isinstance(parent, obj) and \
103102
not isinstance(parent, Intermediary):
104-
raise ValueError("All adjective's variables must be of type "
103+
raise ValueError("All term's variables must be of type "
105104
"{0}".format(obj))
106105
return temp
107106

108107
def _iter(self, var):
109108
"""
110109
Ensure a variable is iterable; wrap in a list if necessary.
111110
"""
112-
if issubclass(var.__class__, FuzzyVariableAdjective):
111+
if issubclass(var.__class__, FuzzyVariableTerm):
113112
return [var, ]
114113
else:
115114
return var
@@ -124,30 +123,30 @@ def _chk_kind(self, string):
124123
else:
125124
raise ValueError("Incorrect kind. Options are 'or' or 'and'.")
126125

127-
def add_antecedent(self, antecedent_adj):
126+
def add_antecedent(self, antecedent_term):
128127
"""
129128
Populate the graph with a new antecedent, connecting it to this rule.
130129
"""
131-
assert isinstance(antecedent_adj, FuzzyVariableAdjective)
132-
antecedent = antecedent_adj.parent_variable
130+
assert isinstance(antecedent_term, FuzzyVariableTerm)
131+
antecedent = antecedent_term.parent_variable
133132
assert isinstance(antecedent, Antecedent) or isinstance(antecedent, Intermediary)
134133

135-
# Antecedent -> Antecedent_Adj -> Rule
136-
self.graph.add_path([antecedent, antecedent_adj])
137-
self.graph.add_path([antecedent_adj, self])
134+
# Antecedent -> Antecedent_Term -> Rule
135+
self.graph.add_path([antecedent, antecedent_term])
136+
self.graph.add_path([antecedent_term, self])
138137

139138

140-
def add_consequent(self, consequent_adj):
139+
def add_consequent(self, consequent_term):
141140
"""
142141
Populate the graph with a new consequent, connecting it to this rule.
143142
"""
144-
assert isinstance(consequent_adj, FuzzyVariableAdjective)
145-
consequent = consequent_adj.parent_variable
143+
assert isinstance(consequent_term, FuzzyVariableTerm)
144+
consequent = consequent_term.parent_variable
146145
assert isinstance(consequent, Consequent) or isinstance(consequent, Intermediary)
147146

148-
# Rule -> Consequent_Adjective -> Consequent
149-
self.graph.add_path([self, consequent_adj])
150-
self.graph.add_path([consequent_adj, consequent])
147+
# Rule -> Consequent_Term -> Consequent
148+
self.graph.add_path([self, consequent_term])
149+
self.graph.add_path([consequent_term, consequent])
151150

152151

153152

@@ -168,12 +167,12 @@ def compute(self):
168167

169168
# Collect the firing of all input membership functions
170169
self.collected_firing = {}
171-
for antecedent_adj in self.graph.predecessors(self):
172-
mv = antecedent_adj.membership_value
170+
for antecedent_term in self.graph.predecessors(self):
171+
mv = antecedent_term.membership_value
173172
if mv is None:
174173
raise Exception("Membership value missing for " +
175-
antecedent_adj.full_label)
176-
self.collected_firing[antecedent_adj.full_label] = mv
174+
antecedent_term.full_label)
175+
self.collected_firing[antecedent_term.full_label] = mv
177176

178177
# Combine membership function firing as appropriate for this rule
179178
if self.kind == 'or':
@@ -184,9 +183,9 @@ def compute(self):
184183
raise NotImplementedError("Unexpected kind: " + self.kind)
185184

186185
# Cap output membership function(s) in consequents
187-
for consequent_adj in self.graph.successors(self):
188-
consequent_adj.parent_variable.set_patch(
189-
consequent_adj.label, self.final_firing)
186+
for consequent_term in self.graph.successors(self):
187+
consequent_term.parent_variable.set_patch(
188+
consequent_term.label, self.final_firing)
190189

191190
def view(self):
192191
ControlSystemVisualizer(self).view().show()
@@ -336,8 +335,8 @@ def print_state(self):
336335
print "==========="
337336
for v in self.fuzzy_variables:
338337
print "{0:<25} = {1}".format(v, v.crisp_value)
339-
for adj in v.adjectives.values():
340-
print " - {0:<22}: {1}".format(adj.label, adj.membership_value)
338+
for term in v.terms.values():
339+
print " - {0:<22}: {1}".format(term.label, term.membership_value)
341340
print ""
342341
print "======="
343342
print " Rules "

skfuzzy/control/fuzzyvariable.py

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
from .ordereddict import OrderedDict
1515

1616

17-
class FuzzyVariableAdjective(object):
17+
class FuzzyVariableTerm(object):
1818
"""
19-
An adjective and associated member function for a fuzzy varaible.
19+
An term and associated member function for a fuzzy varaible.
2020
For example, if one were creating a FuzzyVariable with a simple three-point
21-
liker scale, three `FuzzyVariableAdjective` would be created: poor, average,
21+
liker scale, three `FuzzyVariableTerm` would be created: poor, average,
2222
and good.
2323
"""
2424

@@ -31,9 +31,9 @@ def __init__(self, label, membership_function):
3131

3232
@property
3333
def full_label(self):
34-
"""Adjective with parent. Ex: velocity['fast']"""
34+
"""Term with parent. Ex: velocity['fast']"""
3535
if self.parent_variable is None:
36-
raise ValueError("This adjective must be bound to a parent first")
36+
raise ValueError("This term must be bound to a parent first")
3737
return self.parent_variable.label + "[" + self.label + "]"
3838

3939
def __repr__(self):
@@ -69,7 +69,7 @@ class FuzzyVariable(object):
6969
This class is designed as the base class underlying the Antecedent and
7070
Consequent classes, not for individual use.
7171
"""
72-
def __init__(self, universe, label, defuzzy_method='centroid'):
72+
def __init__(self, universe, label, defuzzify_method='centroid'):
7373
"""
7474
Initialization of fuzzy variable
7575
@@ -83,8 +83,8 @@ def __init__(self, universe, label, defuzzy_method='centroid'):
8383
"""
8484
self.universe = np.asarray(universe)
8585
self.label = label
86-
self.defuzzy_method = defuzzy_method
87-
self.adjectives = OrderedDict()
86+
self.defuzzify_method = defuzzify_method
87+
self.terms = OrderedDict()
8888

8989
self._id = id(self)
9090
self._crisp_value_accessed = False
@@ -94,17 +94,17 @@ def __init__(self, var):
9494
self.var = var
9595

9696
def __getitem__(self, key):
97-
# Get the positive version of the adjective
97+
# Get the positive version of the term
9898
lbl = "NOT-" + key
99-
if lbl in self.var.adjectives.keys():
99+
if lbl in self.var.terms.keys():
100100
return self.var[lbl]
101101

102-
posadj = self.var[key]
103-
negadj = FuzzyVariableAdjective(lbl, 1. - posadj.mf)
104-
if posadj.membership_value is not None:
105-
negadj.membership_value = 1. - posadj.membership_value
106-
self.var[lbl] = negadj
107-
return negadj
102+
posterm = self.var[key]
103+
negterm = FuzzyVariableTerm(lbl, 1. - posterm.mf)
104+
if posterm.membership_value is not None:
105+
negterm.membership_value = 1. - posterm.membership_value
106+
self.var[lbl] = negterm
107+
return negterm
108108
self.not_ = _NotGenerator(self)
109109

110110
def __repr__(self):
@@ -115,17 +115,17 @@ def __len__(self):
115115

116116
def __getitem__(self, key):
117117
"""
118-
Calling variable['label'] will activate 'label' membership function.
118+
Calling variable['label'] will return the 'label' term
119119
"""
120-
if key in self.adjectives.keys():
121-
return self.adjectives[key]
120+
if key in self.terms.keys():
121+
return self.terms[key]
122122
else:
123123
# Build a pretty list of available mf labels and raise an
124124
# informative error message
125125
options = ''
126-
i0 = len(self.adjectives) - 1
127-
i1 = len(self.adjectives) - 2
128-
for i, available_key in enumerate(self.adjectives.keys()):
126+
i0 = len(self.terms) - 1
127+
i1 = len(self.terms) - 2
128+
for i, available_key in enumerate(self.terms.keys()):
129129
if i == i1:
130130
options += "'" + str(available_key) + "', or "
131131
elif i == i0:
@@ -139,19 +139,20 @@ def __getitem__(self, key):
139139

140140
def __setitem__(self, key, item):
141141
"""
142-
Enables new membership functions or adjectives to be added with the
142+
Enables new membership functions or term to be added with the
143143
syntax::
144144
145145
variable['new_label'] = new_mf
146146
"""
147-
if isinstance(item, FuzzyVariableAdjective):
147+
if isinstance(item, FuzzyVariableTerm):
148148
if item.label != key:
149-
raise ValueError("Adjective's label must match new key")
149+
raise ValueError("Term's label must match new key")
150150
if item.parent_variable is not None:
151-
raise ValueError("Adjective must not already have a parent")
151+
raise ValueError("Term must not already have a parent")
152152
else:
153-
# Try to create an adjective
154-
item = FuzzyVariableAdjective(key, np.asarray(item))
153+
# Try to create a term from item, assuming it is a membership
154+
# function
155+
item = FuzzyVariableTerm(key, np.asarray(item))
155156

156157
if self._crisp_value_accessed:
157158
# TODO: Overcome this limitation
@@ -172,45 +173,45 @@ def __setitem__(self, key, item):
172173

173174
# If above pass, add the new membership function
174175
item.parent_variable = self
175-
self.adjectives[key] = item
176+
self.terms[key] = item
176177

177178
@property
178179
def crisp_value(self):
179180
"""Derive crisp value based on membership of adjectives"""
180181
output_mf, cut_mfs = self._find_crisp_value()
181182
if len(cut_mfs) == 0:
182-
raise ValueError("No adjectives have memberships. Make sure you "
183+
raise ValueError("No terms have memberships. Make sure you "
183184
"have at least one rule connected to this "
184185
"variable and have run the rules calculation.")
185186
self._crisp_value_accessed = True
186-
return defuzz(self.universe, output_mf, self.defuzzy_method)
187+
return defuzz(self.universe, output_mf, self.defuzzify_method)
187188

188189
@crisp_value.setter
189190
def crisp_value(self, value):
190191
"""Propagate crisp value down to adjectives by calculating membership"""
191-
if len(self.adjectives) == 0:
192-
raise ValueError("Set Adjective membership function(s) first")
192+
if len(self.terms) == 0:
193+
raise ValueError("Set Term membership function(s) first")
193194

194-
for label, adj in self.adjectives.items():
195+
for label, adj in self.terms.items():
195196
adj.membership_value = \
196197
interp_membership(self.universe, adj.mf, value)
197198
self._crisp_value_accessed = True
198199

199200
def _find_crisp_value(self):
200201
# Check we have some adjectives
201-
if len(self.adjectives.keys()) == 0:
202-
raise ValueError("Set Adjective membership function(s) first")
202+
if len(self.terms.keys()) == 0:
203+
raise ValueError("Set term membership function(s) first")
203204

204205
# Initilize membership
205206
output_mf = np.zeros_like(self.universe, dtype=np.float64)
206207

207208
# Build output membership function
208209
cut_mfs = {}
209-
for label, adj in self.adjectives.items():
210-
cut = adj.membership_value
210+
for label, term in self.terms.items():
211+
cut = term.membership_value
211212
if cut is None:
212213
continue # No membership defined for this adjective
213-
cut_mfs[label] = np.minimum(cut, adj.mf)
214+
cut_mfs[label] = np.minimum(cut, term.mf)
214215
np.maximum(output_mf, cut_mfs[label], output_mf)
215216

216217
return output_mf, cut_mfs
@@ -316,7 +317,7 @@ def automf(self, number=5, variable_type='quality', names=None,
316317
abcs = [[c - w / 2, c, c + w / 2] for c, w in zip(centers, widths)]
317318

318319
# Clear existing adjectives, if any
319-
self.adjectives = OrderedDict()
320+
self.terms = OrderedDict()
320321

321322
# Repopulate
322323
for name, abc in zip(names, abcs):

skfuzzy/control/visualization.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def view(self, *args, **kwargs):
5151
# Plot defuzzified output if available
5252
if len(cut_mfs) > 0:
5353
crip_value = defuzz(self.fuzzy_var.universe, output_mf,
54-
self.fuzzy_var.defuzzy_method)
54+
self.fuzzy_var.defuzzify_method)
5555
if crip_value is not None:
5656
y = interp_membership(self.fuzzy_var.universe,
5757
output_mf, crip_value)
@@ -67,9 +67,9 @@ def _init_plot(self):
6767
self.fuzzy_var.universe.max()])
6868

6969
# Make the plots
70-
for key, adj in self.fuzzy_var.adjectives.items():
70+
for key, term in self.fuzzy_var.terms.items():
7171
self.plots[key] = self.ax.plot(self.fuzzy_var.universe,
72-
adj.mf,
72+
term.mf,
7373
label=key,
7474
lw=1)
7575

0 commit comments

Comments
 (0)