FuzzySystem package¶
FuzzySystem.config module¶
global configuration file
- FuzzySystem.config.default_points = 350¶
Default number of points to use in sampling and evaluating methods
FuzzySystem.defuzzifier module¶
- class FuzzySystem.defuzzifier.CenterOfSets(output, universe=None, samples=350, nout=0, multiple_instances=True)[source]¶
Bases:
FuzzySystem.defuzzifier.DefuzzifierA class for Center of Sets method defuzzification
- compute(fs)[source]¶
abstract method. Performs the defuzzification process
- Parameters
fs – [firing strength] firing strength values
- Returns
crisp values
- name = 'Center of Sets'¶
Default reference name
- class FuzzySystem.defuzzifier.Centroid(output, universe=None, samples=350, nout=0, multiple_instances=True)[source]¶
Bases:
FuzzySystem.defuzzifier.DefuzzifierA class for Centroid method defuzzification
- compute(fs)[source]¶
abstract method. Performs the defuzzification process
- Parameters
fs – [firing strength] firing strength values
- Returns
crisp values
- name = 'Centroid'¶
Defaulf reference name
- class FuzzySystem.defuzzifier.Defuzzifier(output, universe=None, samples=350, nout=0, multiple_instances=True)[source]¶
Bases:
objectAbstract class to design defuzzifiers
- Parameters
output – [Output] an output resulted of the implication process
universe – [list] range of the domain limits [min, max]
samples – [int] number of samples used to calculate the defuzzification
nout – [int] index of the output to defuzzify
multiple_instances – [bool] flag to define if the Output corresponds to multiple outputs
- compute(fs)[source]¶
abstract method. Performs the defuzzification process
- Parameters
fs – [firing strength] firing strength values
- Returns
crisp values
- name = 'Defuzzifier'¶
- class FuzzySystem.defuzzifier.FirstOfMaximum(output, universe=None, samples=350, nout=0, multiple_instances=True)[source]¶
Bases:
FuzzySystem.defuzzifier.DefuzzifierA class for First of Maximum method defuzzification
- compute(fs)[source]¶
abstract method. Performs the defuzzification process
- Parameters
fs – [firing strength] firing strength values
- Returns
crisp values
- name = 'First Of Maximum'¶
Default reference name
- class FuzzySystem.defuzzifier.Heights(output, universe=None, samples=350, nout=0, multiple_instances=True)[source]¶
Bases:
FuzzySystem.defuzzifier.DefuzzifierA class for Heights method defuzzification
- compute(fs)[source]¶
abstract method. Performs the defuzzification process
- Parameters
fs – [firing strength] firing strength values
- Returns
crisp values
- name = 'Heights'¶
Default reference name
- class FuzzySystem.defuzzifier.LastOfMaximum(output, universe=None, samples=350, nout=0, multiple_instances=True)[source]¶
Bases:
FuzzySystem.defuzzifier.DefuzzifierA class for Last of Maximum method defuzzification
- compute(fs)[source]¶
abstract method. Performs the defuzzification process
- Parameters
fs – [firing strength] firing strength values
- Returns
crisp values
- name = 'Least Of Maximum'¶
Default reference name
- class FuzzySystem.defuzzifier.MeanOfMaximum(output, universe=None, samples=350, nout=0, multiple_instances=True)[source]¶
Bases:
FuzzySystem.defuzzifier.DefuzzifierA class for Mean of Maximum method defuzzification
- compute(fs)[source]¶
abstract method. Performs the defuzzification process
- Parameters
fs – [firing strength] firing strength values
- Returns
crisp values
- name = 'Mean Of Maximum'¶
Default reference name
- class FuzzySystem.defuzzifier.ModifiedHeights(output, universe=None, samples=350, nout=0, multiple_instances=True)[source]¶
Bases:
FuzzySystem.defuzzifier.DefuzzifierA class for Modified Heights method defuzzification
- compute(fs)[source]¶
abstract method. Performs the defuzzification process
- Parameters
fs – [firing strength] firing strength values
- Returns
crisp values
- name = 'Modified Heights'¶
Default reference name
FuzzySystem.fis module¶
A python framework to build Fuzzy Inference Systems
Raul Navarro-Almanza<rnavarro@uabc.edu.mx>
- class FuzzySystem.fis.FuzzyInferenceSystem(rules, points=350, inputs=None, outputs=None, and_op='min', or_op='max', verbose=False)[source]¶
Bases:
objectClass to perform the inference process using fuzzy logic
- Parameters
rules – List of rules to conform the knowledge base
points – Number of points to perform the evaluation
inputs – dictionary of inputs
outputs – dictionary of outputs
and_op – Conjunction operator
or_op – Union operator
verbose – flag to print information
- add_rule(rule)[source]¶
Add a rule to the existing knowledge base
- Parameters
rule (FuzzyRule) – The rule to append to the system
- eval(inputs, verbose=None)[source]¶
Evaluates the fuzzy inference system
- Parameters
inputs (number, list, pandas data frame) – Inputs to evaluate.
verbose – flog to print information
- Returns
Output object that contains the fuzzy set of the evaluated consequent
- get_matrix_rules(negatives=True)[source]¶
Generates the matrix with the associations in the rules
- Parameters
negatives – If is True, the negated antecedents are multiplied by -1
- Returns
Matrix with the rule associations.
- get_structure()[source]¶
Create a json representation of the FIS structure
- Returns
Dictionary with all the elements in the FIS
- property inputs¶
Dictionary with the system’s inputs
- property matrix_rules¶
Matrix with the relationships between antecedents and consequent
- property outputs¶
Dictionary with the system’s outputs
FuzzySystem.fuzzy_operations module¶
- FuzzySystem.fuzzy_operations.algebraic_prod(x, y=None)[source]¶
Performs algebraic product between x and y, or x if y is None
- Parameters
x – [array] values
y – [array, optional] values
- Returns
array of values. x*y
- FuzzySystem.fuzzy_operations.algebraic_sum(x, y=None)[source]¶
Performs algebraic sum between x and y, or x if y is None
- Parameters
x – [array] values
y – [array, optional] values
- Returns
array of values. x + y - x*y
- FuzzySystem.fuzzy_operations.intersection(x, y, type='min')[source]¶
Performs intersection between x and y
- Parameters
x – [array] values
y – [array] values
type – [str] union operator. “min” or “prod”
- Returns
array of values
- FuzzySystem.fuzzy_operations.maximum(x, y=None)[source]¶
Performs the maximum between x and y, or x if y is None
- Parameters
x – [array] values
y – [array, optional] values
- Returns
array of values. max(x,y)
FuzzySystem.fuzzyrule module¶
- class FuzzySystem.fuzzyrule.Antecedent(proposition=None, conector=None)[source]¶
Bases:
objectA class to create conditional term of a IF-THEN fuzzy rule
- Parameters
proposition – [List of proposition] the operation FuzzyVariable[fuzzy_set_name] creates a proposition.
conector – [str] defines the type or logical relationship between propositions
- add(other)[source]¶
Adds some proposition to the actual antecedent
- Parameters
other – [Proposition] the proposition to add
- eval(x, and_op='min', or_op='max')[source]¶
Performs the evaluation of the antecedents
- Parameters
x – [dict, list, pandas Data Frame] input values
and_op – [str] type of disjunction operation. “min” or “prod”
or_op – [str] type of conjunction operation. “max” or “sum”
- Returns
[float] the antecedent firing strength
- property fuzzy_variables¶
Gets the fuzzy variable in the propositions in form of dict
- class FuzzySystem.fuzzyrule.Consequent(proposition=None)[source]¶
Bases:
objectA class to create consequent term of a IF-THEN fuzzy rule
- Parameters
proposition – [List of proposition] the operation FuzzyVariable[fuzzy_set_name] creates a proposition.
- add(other)[source]¶
Adds some proposition to the actual consequent
- Parameters
other – [Proposition] the proposition to add
- eval(x, and_op=None)[source]¶
Performs the evaluation of the consequent
- Parameters
x – [float] firing strength value
and_op – [str] type of disjunction operation for the implication. “min” or “prod”
- Returns
[FuzztSet] the resulted fuzzy set with a firing strength value
- property fuzzy_variables¶
Gets the fuzzy variable in the propositions in form of dict
- class FuzzySystem.fuzzyrule.FuzzyRule(antecedent=None, consequent=None, conector=None, and_op='min', or_op='max', weight=1)[source]¶
Bases:
objectA class for modeling fuzzy rules
- Parameters
antecedent – [Antecedent] an antecedent object that conforms the rule
consequent – [list of Consequent] a list of consequent objects that conforms the rule
and_op – [str] type of disjunction operation. “min” or “prod”
or_op – [str] type of conjunction operation. “max” or “sum”
weight – [float] weight value for the rule
- eval(x, and_op=None, or_op=None, verbose=False)[source]¶
Performs the implication process in the fuzzy rule
- Parameters
x – [float, array, dict, pandas Data Frame] input values
and_op – [str] type of disjunction operation. “min” or “prod”
or_op – [str] type of conjunction operation. “max” or “sum”
verbose – print process information
- Returns
[list of Output] outputs of the implication process
- property inputs¶
Gets the list of all fuzzy variables in the antecedent
- Returns
dictionary of the fuzzy variables
- property outputs¶
Gets the list of all fuzzy variables in the consequent
- Returns
dictionary of the fuzzy variables or functions
- class FuzzySystem.fuzzyrule.TSKConsequent(function, params=None, label=None)[source]¶
Bases:
objectA class to design consequent models type Sugeno
- Parameters
function – [str, callable] type of output function. “linear” or “constant”
params – [array] coefficients array
label – [str] given name to the consequent
- add(other)[source]¶
Adds some output consequent
- Parameters
other – [TSKConsequent] the new output to add
FuzzySystem.fuzzyset module¶
- class FuzzySystem.fuzzyset.FuzzySet(name, mf, fs_operator='min')[source]¶
Bases:
objectA class for modeling Fuzzy Sets
- Parameters
name (str) – label assigned to the fuzzy set
mf (MembershipFunction) – membership function to associate with the linguistic value
fs_operator (str) – firing strength operator. “min” or “prod”
- cut(firing_strength, and_op=None)[source]¶
Establishes a firing strength value
- Parameters
firing_strength (float) – value in [0,1]
and_op (str) – conjunction operation. “min” or “prod”
- Returns
self
- eval(x, fs_operator=None)[source]¶
Evaluate the fuzzy set given an input
- Parameters
x (list, numpy array, dictionary or pandas data frame) – inputs values
fs_operator (str) – firing strength operator. “min” or “prod”
- Returns
The membership function evaluation
- show(points=350, axes=None)[source]¶
Plots the fuzzy set’s membership function
- Parameters
points (int) – number of samples to evaluate the membership function
axes (plt.axes) – for outside plotting
- property universe¶
Universe range, [min, max]
FuzzySystem.fuzzyvariable module¶
- class FuzzySystem.fuzzyvariable.FuzzyVariable(name, fuzzysets, universe=None)[source]¶
Bases:
objectA class for modeling Fuzzy Variables
- Parameters
name (str) – Label to fuzzy variable domain
fuzzysets – List of fuzzy sets which the fuzzy variable can take as values
universe – Range that delimits the inferior and superior domain limits.
- discrete_universe(points=350, universe=None)[source]¶
Creates a list of numbers between the universe limits range
- Parameters
points – number of points to generate
universe – range of the universe limits
- Returns
Array of numbers in the universe
- eval(x)[source]¶
Evaluates the fuzzy variable given some input
- Parameters
x (number, list, dictionary, pandas data frame) – Input values
- Returns
Array of tuples with the name and evaluation of each fuzzy set [(name, eval),…]
FuzzySystem.matlab_importer module¶
FuzzySystem.membership_function module¶
- class FuzzySystem.membership_function.Cauchymf(params, universe=None, name=None, complement=False)[source]¶
Bases:
FuzzySystem.membership_function.MembershipFunctionClass to define a Caouchy Membership Function
- Parameters
params – List of design values of the membership function
universe – Range of domain limits
name – Name of the membership function
complement – If is True, the complement evaluation is performed
- compute(x)[source]¶
Perform the evaluation of the membership function
- Parameters
x (number, list, numpy array) – Input
- Returns
evaluation result
- name = 'Cauchy mf'¶
Default reference name
- set_params(params)[source]¶
Set the new parameters to design the membership function
- Parameters
params – list of membership function design parameters
- property spread¶
Calculates the spread of the membership function
- Returns
(float) spread
- class FuzzySystem.membership_function.GBellmf(params, universe=None, name=None, complement=False)[source]¶
Bases:
FuzzySystem.membership_function.MembershipFunctionClass to define a Generalized Gaussian Bell Membership Function
- Parameters
params – List of design values of the membership function
universe – Range of domain limits
name – Name of the membership function
complement – If is True, the complement evaluation is performed
- compute(x)[source]¶
Perform the evaluation of the membership function
- Parameters
x (number, list, numpy array) – Input
- Returns
evaluation result
- name = 'Generalized Bell mf'¶
Default reference name
- set_params(params)[source]¶
Set the new parameters to design the membership function
- Parameters
params – list of membership function design parameters
- property spread¶
Calculates the spread of the membership function
- Returns
(float) spread
- class FuzzySystem.membership_function.Gaussmf(params, universe=None, name=None, complement=False)[source]¶
Bases:
FuzzySystem.membership_function.MembershipFunctionClass to define a Gaussian Membership Function
- Parameters
params – List of design values of the membership function
universe – Range of domain limits
name – Name of the membership function
complement – If is True, the complement evaluation is performed
- compute(x)[source]¶
Perform the evaluation of the membership function
- Parameters
x (number, list, numpy array) – Input
- Returns
evaluation result
- name = 'Gaussian mf'¶
Default reference name
- set_params(params)[source]¶
Set the new parameters to design the membership function
- Parameters
params – list of membership function design parameters
- property spread¶
Calculates the spread of the membership function
- Returns
(float) spread
- class FuzzySystem.membership_function.Logmf(params, universe=None, name=None, complement=False)[source]¶
Bases:
FuzzySystem.membership_function.MembershipFunctionClass to define a Logistic Membership Function
- Parameters
params – List of design values of the membership function
universe – Range of domain limits
name – Name of the membership function
complement – If is True, the complement evaluation is performed
- compute(x)[source]¶
Perform the evaluation of the membership function
- Parameters
x (number, list, numpy array) – Input
- Returns
evaluation result
- name = 'Logistic mf'¶
Default reference name
- set_params(params)[source]¶
Set the new parameters to design the membership function
- Parameters
params – list of membership function design parameters
- property spread¶
Calculates the spread of the membership function
- Returns
(float) spread
- class FuzzySystem.membership_function.MembershipFunction(params, universe=None, name=None, complement=False)[source]¶
Bases:
objectAbstract class to define a Membership Function
- Parameters
params – List of design values of the membership function
universe – Range of domain limits
name – Name of the membership function
complement – If is True, the complement evaluation is performed
- property area¶
Calculates the area of the membership function
- Returns
(float) area
- property centroid¶
Calculates the centroid of the membership function
- Returns
(float) centroid
- compute(x)[source]¶
Perform the evaluation of the membership function
- Parameters
x (number, list, numpy array) – Input
- Returns
evaluation result
- eval(x)[source]¶
Evaluates the membership function given a input x
- Parameters
x (number, list.) – input
- Returns
resulted value(s) of the evaluation
- name = 'Membership Function'¶
Default reference name
- set_params(params)[source]¶
Set the new parameters to design the membership function
- Parameters
params – list of membership function design parameters
- show(points=350, axes=None, fmt='-', kwargs={})[source]¶
Plots the membership function
- Parameters
points – number of points to evaluate the membership function
axes (plt.axes) – for external plotting.
fmt – style format of the line
kwargs – additional values for plt
- property spread¶
Calculates the spread of the membership function
- Returns
(float) spread
- class FuzzySystem.membership_function.Sigmoidmf(params, universe=None, name=None, complement=False)[source]¶
Bases:
FuzzySystem.membership_function.MembershipFunctionClass to define a Sigmoid Membership Function
- Parameters
params – List of design values of the membership function
universe – Range of domain limits
name – Name of the membership function
complement – If is True, the complement evaluation is performed
- compute(x)[source]¶
Perform the evaluation of the membership function
- Parameters
x (number, list, numpy array) – Input
- Returns
evaluation result
- name = 'Sigmoid mf'¶
Default reference name
- set_params(params)[source]¶
Set the new parameters to design the membership function
- Parameters
params – list of membership function design parameters
- property spread¶
Calculates the spread of the membership function
- Returns
(float) spread
- class FuzzySystem.membership_function.Tanhmf(params, universe=None, name=None, complement=False)[source]¶
Bases:
FuzzySystem.membership_function.MembershipFunctionClass to define a Tanh Membership Function
- Parameters
params – List of design values of the membership function
universe – Range of domain limits
name – Name of the membership function
complement – If is True, the complement evaluation is performed
- compute(x)[source]¶
Perform the evaluation of the membership function
- Parameters
x (number, list, numpy array) – Input
- Returns
evaluation result
- name = 'Tanh mf'¶
Default reference name
- set_params(params)[source]¶
Set the new parameters to design the membership function
- Parameters
params – list of membership function design parameters
- property spread¶
Calculates the spread of the membership function
- Returns
(float) spread
- class FuzzySystem.membership_function.Trapmf(params, universe=None, name=None, complement=False)[source]¶
Bases:
FuzzySystem.membership_function.MembershipFunctionClass to define a Trapezoidal Membership Function
- Parameters
params – List of design values of the membership function
universe – Range of domain limits
name – Name of the membership function
complement – If is True, the complement evaluation is performed
- compute(x)[source]¶
Perform the evaluation of the membership function
- Parameters
x (number, list, numpy array) – Input
- Returns
evaluation result
- name = 'Trapezoidal mf'¶
Default reference name
- set_params(params)[source]¶
Set the new parameters to design the membership function
- Parameters
params – list of membership function design parameters
- property spread¶
Calculates the spread of the membership function
- Returns
(float) spread
- class FuzzySystem.membership_function.Trimf(params, universe=None, name=None, complement=False)[source]¶
Bases:
FuzzySystem.membership_function.MembershipFunctionClass to define a Triangular Membership Function
- Parameters
params – List of design values of the membership function
universe – Range of domain limits
name – Name of the membership function
complement – If is True, the complement evaluation is performed
- compute(x)[source]¶
Perform the evaluation of the membership function
- Parameters
x (number, list, numpy array) – Input
- Returns
evaluation result
- name = 'Triangular mf'¶
Default reference name
- set_params(params)[source]¶
Set the new parameters to design the membership function
- Parameters
params – list of membership function design parameters
- property spread¶
Calculates the spread of the membership function
- Returns
(float) spread
FuzzySystem.nonsingleton module¶
- class FuzzySystem.nonsingleton.NonSingleton(mf=None, values=None)[source]¶
Bases:
objectA Class for representing Non-singleton inputs to the system
- Parameters
mf (MembershipFunction) – Membership Function to map the input
values – Actual crisp numbers to evaluate the input
FuzzySystem.output module¶
- class FuzzySystem.output.Output(fuzzy_output, universe=None, type='Mamdani')[source]¶
Bases:
objectA class to represent the output of the FIS evaluation
- Parameters
fuzzy_output – the resulted list of consequent evaluations
universe – range of the domain limits
type (str) – fuzzy inference system type. “Mamdani” or “Sugeno”
- property fuzzysets¶
Gets the consequent fuzzy sets
- get_array(nout=0)[source]¶
Recalls an specific output
- Parameters
nout – index of the output to recall
- Returns
Output object
- get_outputs(nout=0)[source]¶
Gets the list of output’ names
- Parameters
nout – number of a specific output to get their name
- Returns
List of names
- static output_toDict(output)[source]¶
Converts the output list to a dictionary
- Parameters
output – a Output object to convert
- Returns
Dictionary of the output
- show(defuzzifier=None, points=350, axes=None, label=True, nout=0)[source]¶
Plots the output of a given evaluated FIS
- Parameters
defuzzifier (Defuzzifier) – (optional) shows the crisp value of the output given a defuzzifier
points – number of points to evaluate the output area
axes – for external plotting
label – label to show in the figure
nout – index of a specific output
FuzzySystem.utils module¶
- FuzzySystem.utils.format_inputs(x, inputs=None, data_columns=None, verbose=False)[source]¶
Adapts a given input to a dictionary of input values
- Parameters
x (number, list) – input values
inputs – list of features names
data_columns – list of features names from a Pandas Data Frame object
verbose – if True, prints status information
- Returns
Dictionary of inputs
- FuzzySystem.utils.fuzzy_similarity(A, B, points=100, method='sim1')[source]¶
Performs the fuzzy similarity measure between two fuzzy sets.
- Parameters
A – Fuzzy set A
B – Fuzzy set B
points – number of points to evaluate each fuzzy set
method – type of similitude to calculate. sim1 to sim12
- Returns
value that represent their similitude
- FuzzySystem.utils.get_fuzzy_operators(and_op='min', or_op='max')[source]¶
Return the functions to perform the disjunction and conjunction operation
- Parameters
and_op – type of operator. “min” or “prod”
or_op – type of operator. “max” or “sum”
- Returns
A list of functions to perform disjunction and conjunction, respectively