Classes
T1FS
- class pyit2fls.T1FS(domain, mf=<function zero_mf>, params=[])
Type 1 Fuzzy Set (T1FS).
Parameters
Parameters of the constructor function:
domain : numpy (n,) shaped array
Indicates the universe of discourse dedicated to the T1FS.
mf : Membership function
params : List of parameters of the membership function
Functions
Functions defined in T1FS class:
copy : Returns a copy of the T1FS.
plot : Plots the T1FS.
defuzzify : Defuzzifies the set.
negation operator - : Returns the negated T1FS.
Examples
>>> mySet = T1FS(linspace(0., 1., 100), trapezoid_mf, [0, 0.4, 0.6, 1., 1.]) >>> mySet.plot()
- pyit2fls.T1FS.__repr__(self, /)
Return repr(self).
- pyit2fls.T1FS.copy(self)
Copies the T1FS.
Returns
output : T1FS
Returns a copy of the T1FS.
- pyit2fls.T1FS.__call__(self, x)
Call self as a function.
- pyit2fls.T1FS.__neg__(self)
- pyit2fls.T1FS._CoG(self)
- pyit2fls.T1FS.defuzzify(self, method='CoG')
Defuzzifies the type 1 fuzzy set.
Parameters
method : str
Must be one of the methods listed below:
CoG: Center of gravity
Returns
output : float
Defuzzified crisp output.
- pyit2fls.T1FS.plot(self, title=None, legends=None, filename=None, ext='pdf', grid=True, xlabel='Domain', ylabel='Membership degree', legendloc='best', bbox_to_anchor=None, alpha=0.5)
Plots the T1FS.
Parameters
title : str
If set, it indicates the title which will be represented in the plot. If not set, the plot will not have a title.
legend_text : str
If set, it indicates the legend text which will be represented in the plot. If not set, the plot will not contain a legend.
filename : str
If set, the plot will be saved as a filename.ext file.
ext : str
Extension of the output file with ‘pdf’ as the default value.
grid : bool
Determines whether the grid is displayed in the plot.
xlabel : str
Label of the x axis.
ylabel : str
Label of the y axis.
Examples
>>> mySet = T1FS(linspace(0., 1., 100), trapezoid_mf, [0, 0.4, 0.6, 1., 1.]) >>> mySet.plot(filename="mySet")
T1TSK
- class pyit2fls.T1TSK(default=0.0)
Type 1 TSK Fuzzy Logic System.
Parameters
Parameters of the constructor function:
The constructor function of the T1TSK class has no parameters.
Members
inputs : list of str
List of the inputs names as str.
outputs : list of str
List of the outputs names as str.
rules : list of tuples (antacedent, consequent)
List of rules, which each rule is defined as a tuple (antecedent, consequent)
Functions
add_input_variable:
Adds an input variable to the inputs list of the T1 TSK FLS.
add_output_variable:
Adds an output variable to the outputs list of the T1 TSK FLS.
add_rule:
Adds a rule to the rules list of the T1 TSK FLS.
copy:
Returns a copy of the T1 TSK FLS.
evaluate:
Evaluates the T1 TSK FLS based on the crisp inputs given by the user.
- pyit2fls.T1TSK.__repr__(self)
Return repr(self).
- pyit2fls.T1TSK.copy(self)
Returns a copy of the IT2FLS.
- pyit2fls.T1TSK.add_input_variable(self, name)
Adds new input variable name.
Parameters
name : str
Name of the new input variable as a str.
- pyit2fls.T1TSK.add_output_variable(self, name)
Adds new output variable name.
Parameters
name : str
Name of the new output variable as a str.
- pyit2fls.T1TSK.add_rule(self, antecedent, consequent)
Adds new rule to the rule base of the T1 TSK FLS.
Parameters
antecedent : list of tuples
Antecedent is a list of tuples in which each tuple indicates assignement of a variable to a T1FS. The first element of the tuple must be the input variable name as a string, and the second element of the tuple must be a T1FS.
consequent : list of tuples
Consequent is a list of tuples in which each tuple indicates assignement of a variable to an output state. The first element of the tuple must be the output vriable name as a string, and the second element of the tuple must be a callable object.
- pyit2fls.T1TSK.evaluate(self, inputs, params)
Evaluates the T1 TSK FLS based on the crisp inputs given by the user.
Parameters
inputs : dictionary
Inputs is a dictionary, where the keys are input variable names as strings and the corresponded values are the crisp values of the inputs to be evaluated.
params : tuple
This tuple contains the parameters of the functions assigned to the consequents of the system rules.
Returns
Output : dict
The output is a dictionary, where the keys are output variable names as strings and the corresponded values are the crisp outputs of the system.
T1Mamdani
- class pyit2fls.T1Mamdani(engine='Product', defuzzification='CoG')
Type 1 Mamdani Fuzzy Logic System.
Parameters
Parameters of the constructor function:
engine=”Product”: str
Inference engine of the type 1 Mamdani fuzzy logic system. This parameters is a string an can be one of the following items: Product, Minimum, Lukasiewicz, Zadeh, and Dienes-Rescher.
defuzzification=”CoG”: str
Defuzzification method of the system. When Lukasiewicz, Zadeh, and Dienes-Rescher inference engines are selected, the defuzzification method is center of the gravity by default. But for Product and Minimum inference engines, defuzzification can be selected among the methods CoG and CoA.
Members
inputs : list of str
List of the inputs names as strings.
outputs : list of str
List of the outputs names as strings.
rules : list of tuples (antacedent, consequent)
List of rules, which each rule is defined as a tuple (antecedent, consequent). Both antacedent and consequent are lists of tuples. Each tuple of this list represents the assignement of a variable to a T1FS. The first element of the tuple must be the variable name (input or output) as a string, and the second element must be a T1FS.
engine : str
Indicates the engine selected by the user.
defuzzification : str
Indicates the defuzzification method selected by the user.
Functions
add_input_variable:
Adds an input variable to the inputs list of the T1FLS.
add_output_variable:
Adds an output variable to the outputs list of the T1FLS.
add_rule:
Adds a rule to the rules list of the T1FLS.
copy:
Returns a copy of the type 1 Mamdani fuzzy logic system.
evaluate:
Evaluates the T1 Mamdani FLS’s output for the specified crisp input. The only input of the evaluate function is a dictionary in which the keys are input variable names as strings and the values are the crisp value of inputs to be evaluated. The output of the evaluate function depends on the method selected while constructing the class. For more information, please refer to the examples.
- pyit2fls.T1Mamdani.__repr__(self)
Return repr(self).
- pyit2fls.T1Mamdani.copy(self)
- pyit2fls.T1Mamdani.add_input_variable(self, name)
Adds a new input variable by name.
Parameters
name : str
Name of the new input variable as a string.
- pyit2fls.T1Mamdani.add_output_variable(self, name)
Adds a new output variable by name.
Parameters
name : str
Name of the new output variable as a string.
- pyit2fls.T1Mamdani.add_rule(self, antecedent, consequent)
Adds a new rule to the rule base of the T1 Mamdani FLS.
Parameters
antecedent : list of tuples
Antecedent is a list of tuples in which each tuple indicates assignment of a variable to a T1FS. The first element of the tuple must be the input variable name as a string, and the second element of the tuple must be a T1FS.
consequent : list of tuples
Consequent is a list of tuples in which each tuple indicates assignment of a variable to a T1FS. The first element of the tuple must be the output variable name as a string, and the second element of the tuple must be a T1FS.
- pyit2fls.T1Mamdani._CoG(self, B)
- pyit2fls.T1Mamdani._CoA(self, B)
- pyit2fls.T1Mamdani._product_evaluate(self, inputs)
- pyit2fls.T1Mamdani._minimum_evaluate(self, inputs)
- pyit2fls.T1Mamdani._lukasiewicz_evaluate(self, inputs)
- pyit2fls.T1Mamdani._zadeh_evaluate(self, inputs)
- pyit2fls.T1Mamdani._dienes_rescher_evaluate(self, inputs)
IT2FS
- class pyit2fls.IT2FS(domain, umf=<function zero_mf>, umf_params=[], lmf=<function zero_mf>, lmf_params=[], check_set=False)
Interval Type 2 Fuzzy Set (IT2FS).
Parameters
Parameters of the constructor function:
domain : numpy (n,) shaped array
Indicates the universe of discourse dedicated to the IT2FS.
umf : Upper membership function
umf_params : list
Parameters of the upper membership function
lmf : Lower membership function
lmf_params : list
Parameters of lower membership function
check_set : bool
If True, then a function named check_set in IT2FS will verify the condition LMF(x) < UMF(x) for any x in the domain. If the user is sure that they have selected the parameters of the membership functions correctly, then calling this time-consuming function is not needed. By default the parameter check_set is False.
Functions
Functions defined in IT2FS class:
copy:
Returns a copy of the IT2FS.
plot:
Plots the IT2FS.
negation operator -:
Returns the negated IT2FS.
Examples
>>> mySet = IT2FS(linspace(0., 1., 100), trapezoid_mf, [0, 0.4, 0.6, 1., 1.], tri_mf, [0.25, 0.5, 0.75, 0.6]) >>> mySet.plot(filename="mySet")
- pyit2fls.IT2FS.__repr__(self)
Return repr(self).
- property IT2FS.upper
- property IT2FS.lower
- pyit2fls.IT2FS.check_set(self)
Verifies the condition LMF(x) < UMF(x) for any x in the domain.
- pyit2fls.IT2FS.copy(self)
Copies the IT2FS.
Returns
output : IT2FS
Returns a copy of the IT2FS.
- pyit2fls.IT2FS.plot(self, title=None, legends=None, filename=None, ext='pdf', grid=True, xlabel='Domain', ylabel='Membership degree', legendloc='best', bbox_to_anchor=None, alpha=0.5)
Plots the IT2FS.
Parameters
title : str
If set, it indicates the title to be represented in the plot. If not set, the plot will not have a title.
legend_text : str
If set, it indicates the legend text to be represented in the plot. If not set, the plot will not contain a legend.
filename : str
If set, the plot will be saved as a filename.ext file.
ext : str
Extension of the output file, with ‘pdf’ as the default value.
grid : bool
Determines whether the grid is displayed in the plot.
xlabel : str
Label of the x-axis.
ylabel : str
Label of the y-axis.
Examples
>>> mySet = IT2FS(linspace(0., 1., 100), trapezoid_mf, [0, 0.4, 0.6, 1., 1.], tri_mf, [0.25, 0.5, 0.75, 0.6]) >>> mySet.plot(filename="mySet")
- pyit2fls.IT2FS.__neg__(self)
Negates the IT2FS.
Returns
output : IT2FS
Returns a negated copy of the IT2FS.
IT2FLS
- class pyit2fls.IT2FLS
Interval type 2 fuzzy logic system.
No construction parameter is needed.
Members
inputs : List of str
List of names of inputs as str
output : List of str
List of names ot outputs as str
rules : List of tuples (antecedent, consequent)
List of rules which each rule is defined as a tuple (antecedent, consequent)
Both antacedent and consequent are lists of tuples. Each tuple of this list shows assignement of a variable to an IT2FS. First element of the tuple must be variable name (input or output) as a str and the second element must be an IT2FS.
Functions
add_input_variable:
Adds an input variable to the inputs list of the IT2FLS.
add_output_variable:
Adds an output variable to the outputs list of the IT2FLS.
add_rule:
Adds a rule to the rules list of the IT2FLS.
copy:
Returns a copy of the IT2FLS.
evaluate:
Evaluates the IT2FLS’s output for a specified crisp input.
Examples
Assume that we are going to simulate an IT2FLS with two inputs and two outputs. Each input is defined by three IT2FSs, Small, Medium, and Large. These IT2FSs are from Gaussian type with uncertain standard deviation value. The universe of discourse of the fuzzy system is defined as the interval [0, 1]. Also, the rule base of the system is defined as below:
IF x1 is Small and x2 is Small THEN y1 is Small and y2 is Large
IF x1 is Medium and x2 is Medium THEN y1 is Medium and y2 is Small
IF x1 is Large and x2 is Large THEN y1 is Large and y2 is Small
The codes to simulate the aforementioned system using the PyIT2FLS would be as below:
>>> domain = linspace(0., 1., 100) >>> >>> Small = IT2FS_Gaussian_UncertStd(domain, [0, 0.15, 0.1, 1.]) >>> Medium = IT2FS_Gaussian_UncertStd(domain, [0.5, 0.15, 0.1, 1.]) >>> Large = IT2FS_Gaussian_UncertStd(domain, [1., 0.15, 0.1, 1.]) >>> IT2FS_plot(Small, Medium, Large, legends=["Small", "Medium", "large"]) >>> >>> myIT2FLS = IT2FLS() >>> myIT2FLS.add_input_variable("x1") >>> myIT2FLS.add_input_variable("x2") >>> myIT2FLS.add_output_variable("y1") >>> myIT2FLS.add_output_variable("y2") >>> >>> myIT2FLS.add_rule([("x1", Small), ("x2", Small)], [("y1", Small), ("y2", Large)]) >>> myIT2FLS.add_rule([("x1", Medium), ("x2", Medium)], [("y1", Medium), ("y2", Small)]) >>> myIT2FLS.add_rule([("x1", Large), ("x2", Large)], [("y1", Large), ("y2", Small)]) >>> >>> it2out, tr = myIT2FLS.evaluate({"x1":0.9, "x2":0.9}, min_t_norm, max_s_norm, domain) >>> it2out["y1"].plot() >>> TR_plot(domain, tr["y1"]) >>> print(crisp(tr["y1"])) >>> >>> it2out["y2"].plot() >>> TR_plot(domain, tr["y2"]) >>> print(crisp(tr["y2"])) >>>
Notes
While using the PyIT2FLS the user must take care of the items listed below:
The UMF defined for an IT2FS must be greater than or equal with the LMF at all points of the discrete universe of discourse.
The inputs and outputs defined must be compatible while adding the rules and evluating the IT2FLS.
- pyit2fls.IT2FLS.__repr__(self)
Return repr(self).
- pyit2fls.IT2FLS.add_input_variable(self, name)
Adds new input variable name.
Parameters
name : str
Name of the new input variable as a str.
- pyit2fls.IT2FLS.add_output_variable(self, name)
Adds new output variable name.
Parameters
name : str
Name of the new output variable as a str.
- pyit2fls.IT2FLS.add_rule(self, antecedent, consequent)
Adds new rule to the rule base of the IT2FLS.
Parameters
antecedent : List of tuples
Antecedent is a list of tuples in which each tuple indicates assignement of a variable to an IT2FS. First element of the tuple must be input variable name as str, and the second element of the tuple must be an IT2FS.
consequent : List of tuples
Consequent is a list of tuples in which each tuple indicates assignement of a variable to an IT2FS. First element of the tuple must be output variable name as str, and the second element of the tuple must be an IT2FS.
- pyit2fls.IT2FLS.copy(self)
Returns a copy of the IT2FLS.
- pyit2fls.IT2FLS.evaluate_list(self, inputs, t_norm, s_norm, domain, method='Centroid', method_params=[], algorithm='EIASC', algorithm_params=[])
Evaluates the IT2FLS based on list of crisp inputs given by user.
Parameters
inputs : dictionary
Inputs is a dictionary in which the keys are input variable names as str and the values are the list of crisp values corresponded with the inputs to be evaluated.
t_norm : function
Indicates the t-norm operator to be used, and should be chosen between min_t_norm, product_t_norm, or other user defined t-norms.
s_norm : function
Indicates the s-norm operator to be used, and should be chosen between max_s_norm or other user defined s-norms.
domain : numpy (n,) shaped array
Indicates the universe of discourse dedicated to the IT2FS.
method=”Centroid” : str
Indicates the type reduction method name and should be one of the methods listed below:
Centroid, CoSet, CoSum, Height, and ModiHe.
method_params=[] : List
Parameters of the type reduction method, if needed.
algorithm=”EIASC” : str
Indicates the type reduction algorithm name and should be one of the algorithms listed below:
KM, EKM, WEKM, TWEKM, EIASC, WM, BMM, LBMM, and NT.
algorithm_params=[] : List
Parameters of the type reduction algorithm, if needed.
Returns
output : tuple or list
It depends on which method and algorithm for type reduction is chosen. If Centroid type reduction method is chosen the output is a tuple with two elements. First element is the overall IT2FS outputs of the system as a list of dictionaries with output names as keys and sets as values. The second output is outputs of the selected type reduction algorithm as a list of dictionaries with output names as keys and type reduction algorithm function output as value. For other type reduction methods the only output is a list of dictionaries of the type reduction algorithm function outputs for each output variable name as a key.
Notes
While using the evaluate function some cares must be taken by the user himself which are listed as below:
The inputs must be lay in the defined universe of discourse.
The type reduction method and the type reduction algorithm must be selected from the lists provided in docstrings.
- pyit2fls.IT2FLS.evaluate(self, inputs, t_norm, s_norm, domain, method='Centroid', method_params=[], algorithm='EIASC', algorithm_params=[])
Evaluates the IT2FLS based on crisp inputs given by user.
Parameters
inputs : dictionary
Inputs is a dictionary in which the keys are input variable names as str and the values are the crisp value of inputs to be evaluated.
t_norm : function
Indicates the t-norm operator to be used, and should be chosen between min_t_norm, product_t_norm, or other user defined t-norms.
s_norm : function
Indicates the s-norm operator to be used, and should be chosen between max_s_norm or other user defined s-norms.
domain : numpy (n,) shaped array
Indicates the universe of discourse dedicated to the IT2FS.
method=”Centroid” : str
Indicates the type reduction method name and should be one of the methods listed below:
Centroid, CoSet, CoSum, Height, and ModiHe.
method_params=[] : List
Parameters of the type reduction method, if needed.
algorithm=”EIASC” : str
Indicates the type reduction algorithm name and should be one of the algorithms listed below:
KM, EKM, WEKM, TWEKM, EIASC, WM, BMM, LBMM, and NT.
algorithm_params=[] : List
Parameters of the type reduction algorithm, if needed.
Returns
output : tuple or dict
It depends on which method and algorithm for type reduction is chosen. If Centroid type reduction method is chosen the output is a tuple with two elements. First element is the overall IT2FS outputs of the system as a dictionary with output names as keys and sets as values. The second output is outputs of the selected type reduction algorithm as a dictionary with output names as keys and type reduction algorithm function output as value. For other type reduction methods the only output is the dictionary of the type reduction algorithm function outputs for each output variable name as a key.
Notes
While using the evaluate function some cares must be taken by the user himself which are listed as below:
The inputs must be lay in the defined universe of discourse.
The type reduction method and the type reduction algorithm must be selected from the lists provided in docstrings.
IT2TSK
- class pyit2fls.IT2TSK(t_norm, s_norm)
Interval type 2 TSK fuzzy logic system.
Parameters
Parameters of the constructor function:
t_norm : function
T-norm operator which would be used by FLS.
s_norm : function
S-norm operator which would be used bu FLS.
Members
inputs : List of str
List of the inputs name as str.
output : List of str
List of the outputs name as str.
rules : List of tuples (antecedent, consequent)
List of rules which each rule is defined as a tuple (antecedent, consequent)
Both antacedent and consequent are lists of tuples. Each tuple of the antacedent list shows assignement of a variable to an IT2FS. First element of the tuple must be the input variable name as a str, and the second element must be an IT2FS.
Each tuple of the consequent indicates assignement of a variable to an output state. First element of the tuple must be output vriable name as str, and the second element of the tuple must be a dictionary. This dictionary shows the output polynomial in the case of the rule. For example let an output polynomial be as 2 x1 + 4 x2 + 5. Then the dictionary for this case would be {“const”:5., “x1”:2., “x2”:4.}. Note that this is written for an IT2 TSK FLS with two inputs, named x1 and x2.
Functions
add_input_variable:
Adds an input variable to the inputs list of the IT2 TSK FLS.
add_output_variable:
Adds an output variable to the outputs list of the IT2 TSK FLS.
add_rule:
Adds a rule to the rules list of the IT2 TSK FLS.
copy:
Returns a copy of the interval type 2 tsk fuzzy logic system.
evaluate:
Evaluates the IT2 TSK FLS based on the crisp inputs given by the user.
Notes
While using the IT2TSK class the user must take care of the items listed below:
The UMF defined for an IT2FS must be greater than or equal with the LMF at all points of the discrete universe of discourse.
The inputs and outputs defined must be compatible while adding the rules and evluating the IT2FLS.
- pyit2fls.IT2TSK.__repr__(self)
Return repr(self).
- pyit2fls.IT2TSK.add_input_variable(self, name)
Adds new input variable name.
Parameters
name : str
Name of the new input variable as a str.
- pyit2fls.IT2TSK.add_output_variable(self, name)
Adds new output variable name.
Parameters
name : str
Name of the new output variable as a str.
- pyit2fls.IT2TSK.add_rule(self, antecedent, consequent)
Adds new rule to the rule base of the IT2FLS.
Parameters
antecedent : List of tuples
Antecedent is a list of tuples in which each tuple indicates assignement of a variable to an IT2FS. First element of the tuple must be the input variable name as str, and the second element of the tuple must be an IT2FS.
consequent : List of tuples
Consequent is a list of tuples in which each tuple indicates assignement of a variable to an output state. First element of the tuple must be output vriable name as str, and the second element of the tuple must be a dictionary. This dictionary shows the output polynomial in the case of the rule. For example let an output polynomial be as 2 x1 + 4 x2 + 5. Then the dictionary for this case would be {“const”:5., “x1”:2., “x2”:4.}. Note that this is written for an IT2 TSK FLS with two inputs, named x1 and x2.
Example
Assume that we are going to simulate an IT2 TSK FLS with two inputs named x1 and x2. Our rule base is defined as below:
IF x1 is Small and x2 is Small THEN y1 = x1 + x2 + 1 and y2 = 2 x1 - x2 + 1
IF x1 is Small and x2 is Big THEN y1 = 1.5 x1 + 0.5 x2 + 0.5 and y2 = 1.5 x1 - 0.5 x2 + 0.5
IF x1 is Big and x2 is Small THEN y1 = 2. x1 + 0.1 x2 - 0.2 and y2 = 0.5 x1 + 0.1 x2
IF x1 is Big and x2 is Big THEN y1 = 4. x1 -0.5 x2 - 1 and y2 = -0.5 x1 + x2 - 0.5
Then these rules can be added to the system using the codes below:
>>> myIT2FLS.add_rule([("x1", Small), ("x2", Small)], [("y1", {"const":1., "x1":1., "x2":1.}), ("y2", {"const":1., "x1":2., "x2":-1.})]) >>> myIT2FLS.add_rule([("x1", Small), ("x2", Big)], [("y1", {"const":0.5, "x1":1.5, "x2":0.5}), ("y2", {"const":0.5, "x1":1.5, "x2":-0.5})]) >>> myIT2FLS.add_rule([("x1", Big), ("x2", Small)], [("y1", {"const":-0.2, "x1":2., "x2":0.1}), ("y2", {"const":0., "x1":0.5, "x2":0.1})]) >>> myIT2FLS.add_rule([("x1", Big), ("x2", Big)], [("y1", {"const":-1., "x1":4., "x2":-0.5}), ("y2", {"const":-0.5, "x1":-0.5, "x2":1.})])
- pyit2fls.IT2TSK.copy(self)
Returns a copy of the IT2FLS.
- pyit2fls.IT2TSK.evaluate(self, inputs)
Evaluates the IT2 TSK FLS based on the crisp inputs given by the user.
Parameters
inputs : dictionary
Inputs is a dictionary, which the keys are input variable names as str and the values are the crisp value of the inputs to be evaluated.
Returns
output : dictionary
The output is a dictionary, which the keys are output variable names as str and the values are the crisp output of the system.
IT2Mamdani
- class pyit2fls.IT2Mamdani(t_norm, s_norm, method='Centroid', method_params=[], algorithm='EIASC', algorithm_params=[])
Interval Type 2 Mamadani Fuzzy Logic System.
Parameters
Parameters of the constructor function:
t_norm : function
T-norm operator which would be used by FLS.
s_norm : function
S-norm operator which would be used by FLS.
method=”Centroid” : str
Indicates the type reduction method name and should be one of the methods listed below: Centroid, CoSet, CoSum, Height, and ModiHe.
method_params=[] : List
Parameters of the type reduction method, if needed.
algorithm=”EIASC” : str
Indicates the type reduction algorithm name and should be one of the algorithms listed below: KM, EKM, WEKM, TWEKM, EIASC, WM, BMM, LBMM, and NT.
algorithm_params=[] : List
Parameters of the type reduction algorithm, if needed.
Members
inputs : List of str
List of the inputs name as str.
output : List of str
List of the outputs name as str.
rules : List of tuples (antecedent, consequent)
List of rules which each rule is defined as a tuple (antecedent, consequent)
Both antacedent and consequent are lists of tuples. Each tuple of these lists shows assignement of a variable to an IT2FS. First element of the tuple must be variable name (input or output) as a str, and the second element must be an IT2FS.
Functions
add_input_variable:
Adds an input variable to the inputs list of the IT2 Mamdani FLS.
add_output_variable:
Adds an output variable to the outputs list of the IT2 Mamdani FLS.
add_rule:
Adds a rule to the rules list of the IT2 Mamdani FLS.
copy:
Returns a copy of the interval type 2 mamdani fuzzy logic system.
evaluate:
Evaluates the IT2FLS’s output for a specified crisp input. This function is selected based on the constructor function parameter, method, among 5 private functions below: __Mamdani_Centroid, __Mamdani_CoSet, __Mamdani_CoSum, __Mamdani_Height, and __Mamdani_ModiHe. The only input of the evaluate function is a dictionary named inputs in which the keys are input variable names as str and the values are the crisp value of inputs to be evaluated. The output of the evaluate function is depended on the method selected while constructing the class. For more information, please refer to the examples.
Notes
While using the IT2Mamdani class the user must take care of the items listed below:
The UMF defined for an IT2FS must be greater than or equal with the LMF at all points of the discrete universe of discourse.
The inputs and outputs defined must be compatible while adding the rules and evluating the IT2FLS.
- pyit2fls.IT2Mamdani.add_input_variable(self, name)
Adds new input variable name.
Parameters
name : str
Name of the new input variable as a str.
- pyit2fls.IT2Mamdani.add_output_variable(self, name)
Adds new output variable name.
Parameters
name : str
Name of the new output variable as a str.
- pyit2fls.IT2Mamdani.add_rule(self, antecedent, consequent)
Adds new rule to the rule base of the IT2FLS.
Parameters
antecedent : List of tuples
Antecedent is a list of tuples in which each tuple indicates assignement of a variable to an IT2FS. First element of the tuple must be input variable name as str, and the second element of the tuple must be an IT2FS.
consequent : List of tuples
Consequent is a list of tuples in which each tuple indicates assignement of a variable to an IT2FS. First element of the tuple must be output variable name as str, and the second element of the tuple must be an IT2FS.
- pyit2fls.IT2Mamdani.copy(self)
Returns a copy of the IT2FLS.
- pyit2fls.IT2Mamdani.__repr__(self)
Return repr(self).
- pyit2fls.IT2Mamdani.__meet(self, domain, it2fs1, l, u, t_norm)
- pyit2fls.IT2Mamdani.__join(self, domain, it2fs1, l, u, s_norm)
- pyit2fls.IT2Mamdani.__Mamdani_Centroid(self, inputs)
- pyit2fls.IT2Mamdani.__Mamdani_CoSet(self, inputs)
- pyit2fls.IT2Mamdani.__Mamdani_CoSum(self, inputs)
- pyit2fls.IT2Mamdani.__Mamdani_Height(self, inputs)
- pyit2fls.IT2Mamdani.__Mamdani_ModiHe(self, inputs)
T1Fuzzy_ML
- class pyit2fls.T1Fuzzy_ML(N, M, Bounds=None, algorithm='DE', algorithm_params=[])
A general type fuzzy model for learning from data. T1Mamdani_ML and T1TSK_ML classes are build up based on this class and they only help to provide a linguistic interpretation of the results by the T1Fuzzy_ML class.
Parameters
Parameters of the constructor function:
N : int
The inputs number of the model.
M : int
The rules number of the model.
Bounds : tuple of float
The upper and lower bounds of the parameters of the model.
algorithm : str
Indicates the algorithm to be used for determining the model parameters. It should be one of the strings “DE”, “Nelder-Mead”, “Powell”, “CG”, “PSO”, and “GA”. More optimization techniques will be gradually added. The first four algorithms, which are based on scipy, are not computationally efficient. So, we have provided embedded GA and PSO algorithms for calculating model parameters by optimizing an error function.
algorithm_params : list of numbers
The parameters of the selected algorithm. Only GA and PSO algorithms need algorithm_params to be set. For the GA, this list must contain five numbers: population size, number of iterations, number of mutations in each iteration, number of combinations in each iteration, and top percent of the population which mutation is only applyed on them; a floating point number in range (0, 1). For the PSO algorithm, the list must also contain five numbers: population size, number of iterations, \(\omega\), \(\phi\), and \(\phi_{g}\).
Functions
Functions defined in T1Fuzzy_ML class:
error : The error function utilized for parameter optimization of the model.
fit : Fits the model based on the given input output data.
score : Evaluates the model for desired input data.
- pyit2fls.T1Fuzzy_ML.error(self, P, X, y)
The error function for optimizing the model parameters.
Parameters
P : list of float or numpy (n,) shaped array
P provides the list of parameters which the model error would be evaluated based on it.
X : list of 1D numpy array or 2D numpy array
X is the set of data which the model error would be evaluated for them.
y : list of float or numpy (n,) shaped array
y is the set of desired outputs which the model error would be evaluated based on them.
- pyit2fls.T1Fuzzy_ML.fit(self, X, y)
Function for finding the best set of parameters fitting the pair of input and output data.
Parameters
X :
X is the set of data which the model error would be evaluated for them.
y :
y is the set of desired outputs which the model error would be evaluated based on them.
- pyit2fls.T1Fuzzy_ML.score(self, X)
Function for evaluating the model output for desired set of inputs.
Parameters
X :
X is the set of data which the model would be evaluated for them.
T1Mamdani_ML
- class pyit2fls.T1Mamdani_ML(N, M, Bounds=None, algorithm='DE', algorithm_params=[])
- pyit2fls.T1Mamdani_ML.get_T1Mamdani(self, std=1.0)
T1TSK_ML
- class pyit2fls.T1TSK_ML(N, M, Bounds=None, algorithm='DE', algorithm_params=[])
- pyit2fls.T1TSK_ML.get_T1TSK(self, std=1.0)
Linear_System
- class pyit2fls.Linear_System(A, B, C, D)
A class for representing linear systems.
- pyit2fls.Linear_System.__call__(self, t, X, U)
Call self as a function.
Parameters
Parameters of the function:
t : float
The time variable.
X : numpy (n,) shaped array
The system states at time t.
U : function of t and X
A function for calculating the system input(s) at time t and state X.
- pyit2fls.Linear_System.Y(self, t, X, U)
A function for calculating the system output based on the current time, systemstates, and system input(s).
Parameters
Parameters of the function:
t : float
The time variable.
X : numpy (n,) shaped array
The system states at time t.
U : function of t and X
A function for calculating the system input(s) at time t and state X.
- pyit2fls.Linear_System.__repr__(self)
Return repr(self).
- pyit2fls.Linear_System.__str__(self)
Return str(self).
- pyit2fls.Linear_System.__add__(self, other)
Simple element-wise addition for all system matrices to form a new linear system.
Parameters
other : Linear_System
The other linear system to be added.
- pyit2fls.Linear_System.__sub__(self, other)
Simple element-wise subtraction for all system matrices to form a new linear system.
Parameters
other : Linear_System
The other linear system to be subtracted.
- pyit2fls.Linear_System.__neg__(self)
Simple element-wise negation for all system matrices to form a new linear system.
- pyit2fls.Linear_System.__mul__(self, other)
Simple element-wise multiplication for all system matrices to form a new linear system.
Parameters
other : int or float
The number to be multiplicated.
- pyit2fls.Linear_System.__truediv__(self, other)
Simple element-wise true division for all system matrices to form a new linear system.
Parameters
other : int or float
The number to be used in division.
- pyit2fls.Linear_System.__isub__(self, other)
Simple element-wise subtraction for all system matrices to form a new linear system.
Parameters
other : Linear_System
The other linear system to be subtracted.
- pyit2fls.Linear_System.__iadd__(self, other)
Simple element-wise addition for all system matrices to form a new linear system.
Parameters
other : Linear_System
The other linear system to be added.
- pyit2fls.Linear_System.__imul__(self, other)
Simple element-wise multiplication for all system matrices to form a new linear system.
Parameters
other : int or float
The number to be multiplicated.
- pyit2fls.Linear_System.__idiv__(self, other)
Simple element-wise division for all system matrices to form a new linear system.
Parameters
other : int or float
The number to be used in division.
T1_TS_Model
- class pyit2fls.T1_TS_Model(mfList, mfParamsList, systemList, R, N, M, P)
A class for creating type 1 Takagi-Sugeno models. Unlike the T1TSK class, which is a general purpose implementation, T1_TS_Model have been developed to be faster but less general. It needs more low-level configurations while dealing with it directly.
Parameters
Parameters of the constructor function:
mfList : list of list of membership functions
Membership functions describing each input of the TS system in each rule of the rule base.
mfParamsList : list of list of list of floats
List of parameters corresponded with mmbership functions describing each input of the TS system in each rule of the rule base.
systemList : list of Linear_System
List of antecedent of each rule as a linear system.
R : int
Number of the rules in the rule base of the system.
N : int
Number of the state variables of the systtem.
M : int
Number of the inputs of the system.
P : int
Number of the outputs of the system.
Functions
d0 :
.
__call__ :
.
Y :
.
- pyit2fls.T1_TS_Model.d0(self, d0x)
- pyit2fls.T1_TS_Model.__call__(self, t, X, U)
Call self as a function.
- pyit2fls.T1_TS_Model.Y(self, t, X, U)
IT2TSK_ML_Model
- class pyit2fls.IT2TSK_ML_Model(P, N, M, it2fs, c=1.0)
- pyit2fls.IT2TSK_ML_Model.__call__(self, X)
Call self as a function.
IT2TSK_ML
- class pyit2fls.IT2TSK_ML(N, M, it2fs, Bounds=None, algorithm='DE', algorithm_params=[], c=1.0)
- pyit2fls.IT2TSK_ML.error(self, P, X, y)
- pyit2fls.IT2TSK_ML.fit(self, X, y)
- pyit2fls.IT2TSK_ML.score(self, X)
IT2Mamdani_ML_Model
- class pyit2fls.IT2Mamdani_ML_Model(P, N, M, it2fs, c=1.0)
- pyit2fls.IT2Mamdani_ML_Model.__call__(self, X)
Call self as a function.
IT2Mamdani_ML
- class pyit2fls.IT2Mamdani_ML(N, M, it2fs, Bounds=None, algorithm='DE', algorithm_params=[], c=1.0)
- pyit2fls.IT2Mamdani_ML.error(self, P, X, y)
- pyit2fls.IT2Mamdani_ML.fit(self, X, y)
- pyit2fls.IT2Mamdani_ML.score(self, X)
IT2_TS_Model
- class pyit2fls.IT2_TS_Model(lmfList, lmfParamsList, umfList, umfParamsList, systemList, R, N, M, P)
- pyit2fls.IT2_TS_Model.d0(self, d0x)
- pyit2fls.IT2_TS_Model.__call__(self, t, X, U)
Call self as a function.
- pyit2fls.IT2_TS_Model.Y(self, t, X, U)