ifis package

Submodules

ifis.interval_aggregations module

class ifis.interval_aggregations.IntervalFuzzyAggregator(verbose=False)[source]

Bases: FuzzyAggregator

Creates a new interval fuzzy aggregation object based on the FuzzyAggregator object from the Simpful library. Aggregations available: A_Prod, A_MeanPower, A_Mean.

param verbose:

toggles verbose mode, default to FALSE

type verbose:

bool

Methods

add_variables(*args)

Adds variables and their IVFS to perform fuzzy aggregation.

aggregate([variables, aggregation_fun, ...])

The method aggregates the terms of linguistic variables according to their affiliation and membership functions

set_variable(name, value)

Sets the interval value of a variable to be aggregated.

add_variables(*args)[source]
Adds variables and their IVFS to perform fuzzy aggregation.
param args:

‘’ifis.interval_fuzzy_sets.IntervalFuzzySet’’ objects, whose ‘term’ argument is the name of the variable.

type args:

IVFS objects

aggregate(variables=None, aggregation_fun='product', aggregation_param=None)[source]
The method aggregates the terms of linguistic variables according to their affiliation and membership functions
param aggregation_fun:

name of the aggregation we want to use (A_MeanPower, A_GMean, A_MeanMax, A_ProdMean, A_MinMax, A_Min, A_Max, A_W, A_1, A_2, A_3, A_4, A_Alpha, A_Mean are available)

type aggregation_fun:

str

param aggregation_param:

an optional parameter that is used in a specific aggregation that contains another aggregation inside

type aggregation_param:

str, int

return:

rtype:

list

set_variable(name, value)[source]
Sets the interval value of a variable to be aggregated.
param name:

name of the variables to be set

type name:

str

param value:

interval value to be set

type value:

list

ifis.interval_aggregations.aA1(memberships)[source]

Function to aggregate memberships of each linguistic variable terms by aggregation ‘A1’ This aggregation respect comparability relation: possible

param memberships:

list memberships of each linguistic variable terms

type memberships:

list

return:

list which contains lower and upper bound of interval after aggregation

rtype:

list

ifis.interval_aggregations.aA2(memberships)[source]

Function to aggregate memberships of each linguistic variable terms by aggregation ‘A2’ This aggregation respect comparability relation: possible

param memberships:

list memberships of each linguistic variable terms

type memberships:

list

return:

list which contains lower and upper bound of interval after aggregation

rtype:

list

ifis.interval_aggregations.aA3(memberships, inside_aggregation='g')[source]

Function to aggregate memberships of each linguistic variable terms by aggregation ‘A3’ This aggregation respect comparability relation: possible

param memberships:

list memberships of each linguistic variable terms

type memberships:

list

param inside_aggregation:

aggregation inside this aggregation function, able to use aggregations are geometric mean(g) and power mean(p), default to ‘g’(geometric mean)

type inside_aggregation:

str

return:

list which contains lower and upper bound of interval after aggregation

rtype:

list

ifis.interval_aggregations.aA4(memberships, inside_aggregation='g')[source]

Function to aggregate memberships of each linguistic variable terms by aggregation ‘A3’ This aggregation respect comparability relation: possible

param memberships:

list memberships of each linguistic variable terms

type memberships:

list

param inside_aggregation:

aggregation inside this aggregation function, able to use aggregations are geometric mean(g) and power mean(p), default to ‘g’(geometric mean)

type inside_aggregation:

str

return:

list which contains lower and upper bound of interval after aggregation

rtype:

list

ifis.interval_aggregations.aAlpha(memberships, alpha=0.5)[source]

Function to aggregate memberships of each linguistic variable terms by aggregation alpha If param alpha equals 0.5 we get Mean aggregation This aggregation respect orders: Lexicographical 1, Lexicographical 2 and Xu Yager

param memberships:

list memberships of each linguistic variable terms

type memberships:

list

param alpha:

parameter to builds aggregation, default to 0.5

type alpha:

float

return:

list which contains lower and upper bound of interval after aggregation

rtype:

list

ifis.interval_aggregations.aGMean(memberships)[source]

Function to aggregate memberships of each linguistic variable terms by aggregation ‘GeometricMean’ This aggregation respect orders: Lexicographical 1, Lexicographical 2 and Xu Yager and comparability relations: possible and necessary

param memberships:

list memberships of each linguistic variable terms

type memberships:

list

return:

list which contains lower and upper bound of interval after aggregation

rtype:

list

ifis.interval_aggregations.aMax(memberships)[source]

Function to aggregate memberships of each linguistic variable terms by aggregation ‘Max’ This aggregation respect orders: Lexicographical 1, Lexicographical 2 and Xu Yager and comparability relations: possible and necessary

param memberships:

list memberships of each linguistic variable terms

type memberships:

list

return:

list which contains lower and upper bound of interval after aggregation

rtype:

list

ifis.interval_aggregations.aMeanMax(memberships)[source]

Function to aggregate memberships of each linguistic variable terms by aggregation ‘MeanMax’ This aggregation respect orders: Lexicographical 1, Lexicographical 2 and Xu Yager

param memberships:

list memberships of each linguistic variable terms

type memberships:

list

return:

list which contains lower and upper bound of interval after aggregation

rtype:

list

ifis.interval_aggregations.aMeanPower(memberships)[source]

Function to aggregate memberships of each linguistic variable terms by aggregation ‘MeanPower’ This aggregation respect orders: Lexicographical 1, Lexicographical 2 and Xu Yager

param memberships:

list memberships of each linguistic variable terms

type memberships:

list

return:

lower and upper bound of interval after aggregation

rtype:

list

ifis.interval_aggregations.aMin(memberships)[source]

Function to aggregate memberships of each linguistic variable terms by aggregation ‘Min’ This aggregation respect orders: Lexicographical 1, Lexicographical 2 and Xu Yager and comparability relations: possible and necessary

param memberships:

list memberships of each linguistic variable terms

type memberships:

list

return:

list which contains lower and upper bound of interval after aggregation

rtype:

list

ifis.interval_aggregations.aMinMax(memberships)[source]

Function to aggregate memberships of each linguistic variable terms by aggregation ‘MinMax’ This aggregation respect orders: Lexicographical 1, Lexicographical 2 and Xu Yager

param memberships:

list memberships of each linguistic variable terms

type memberships:

list

return:

list which contains lower and upper bound of interval after aggregation

rtype:

list

ifis.interval_aggregations.aProdMean(memberships)[source]

Function to aggregate memberships of each linguistic variable terms by aggregation ‘ProdMean’ This aggregation respect orders: Lexicographical 1, Lexicographical 2 and Xu Yager

param memberships:

list memberships of each linguistic variable terms

type memberships:

list

return:

list which contains lower and upper bound of interval after aggregation

rtype:

list

ifis.interval_aggregations.aW(memberships)[source]
Function to aggregate memberships of each linguistic variable terms by aggregation ‘W’
param memberships:

list memberships of each linguistic variable terms

type memberships:

list

return:

list which contains lower and upper bound of interval after aggregation

rtype:

list

ifis.interval_fuzzy_sets module

class ifis.interval_fuzzy_sets.IntervalFuzzySet(function_start=None, function_end=None, points_start=None, points_end=None, term='')[source]

Bases: FuzzySet

Class representation Interval-Valued Fuzzy Set (IVFS).
param function_start:

start function to define a IVFS. Supports pre-implemented membership functions Trapezoidal_MF_2, Triangular_MF_2 or user-defined functions, defaults to None

type function_start:

MF_object_2

param function_end:

end function to define a IVFS. Supports pre-implemented membership functions Trapezoidal_MF_2, Triangular_MF_2 or user-defined functions, defaults to None

type function_end:

MF_object_2

param points_start:

list of start points to define a IVFS. Each point is defined as a list of two coordinates in the universe of discourse/membership degree space, defaults to None

type points_start:

MF_object_2

param points_end:

list of end points to define a IVFS. Each point is defined as a list of two coordinates in the universe of discourse/membership degree space, defaults to None

type points_end:

MF_object_2

param term:

string representing the linguistic term to be associated to the Interval Valued Fuzzy Set

type term:

str

Methods

get_term()

Return the linguistic term associated to this fuzzy set.

get_value(v)

Return the membership end value of v to this IVFS

get_value_cut(v, cut)

Function for return the membership value of v to this IVFS, capped to the cut value.

set_points(points)

Changes points of the point-based fuzzy set.

set_points_interval(points_start, points_end)

Changes points of the point-based IVFS.

get_type_end

get_type_start

get_value_cut_end

get_value_cut_start

get_value_end

get_value_fast

get_value_fast_end

get_value_fast_start

get_value_slow

get_value_slow_end

get_value_slow_start

get_value_start

integrate

set_params

get_type_end()[source]
get_type_start()[source]
get_value(v)[source]
Return the membership end value of v to this IVFS
param v:

element of the universe of discourse

return:

The membership end value of v to this IVFS

rtype:

tuple

get_value_cut(v, cut)[source]
Function for return the membership value of v to this IVFS, capped to the cut value.
param v:

element of the universe of discourse

param cut:

alpha cut of the IVFS

rtype:

float

get_value_cut_end(v, cut)[source]
get_value_cut_start(v, cut)[source]
get_value_end(v)[source]
get_value_fast_end(v)[source]
get_value_fast_start(v)[source]
get_value_slow_end(v)[source]
get_value_slow_start(v)[source]
get_value_start(v)[source]
set_params()[source]
set_points_interval(points_start, points_end)[source]
Changes points of the point-based IVFS.
param points_start:

a list of points to define lower bound of IVFS. Each point is defined as a list of two coordinates in the universe of discourse/membership degree space.

type points_start:

list

param points_end:

a list of points to define upper bound of IVFS. Each point is defined as a list of two coordinates in the universe of discourse/membership degree space.

type points_end:

list

class ifis.interval_fuzzy_sets.MF_object_2[source]

Bases: object

Class representing Interval-Valued Membership Function

Methods

__call__(x)

Overriding the __call__ method

class ifis.interval_fuzzy_sets.Trapezoidal_MF_2(a=0, b=0.25, c=0.75, d=1)[source]

Bases: MF_object_2

Class representing Interval-Valued Trapezoidal Membership Function
param a:

y coordinate for point on start Interval-Valued Trapezoidal Membership Function

type a:

float

param b:

y coordinate for point on first point of top edge Interval-Valued Trapezoidal Membership Function

type b:

float

param c:

y coordinate for point on second point of top edge Interval-Valued Trapezoidal Membership Function

type c:

float

param d:

y coordinate for point on end Interval-Valued Trapezoidal Membership Function

type d:

float

Methods

__call__(x)

Overriding the __call__ method

class ifis.interval_fuzzy_sets.Triangular_MF_2(a=0, b=0.5, c=1)[source]

Bases: MF_object_2

Class representing Interval-Valued Triangular Membership Function
param a:

y coordinate for point on start Interval-Valued Triangular Membership Function

type a:

float

param b:

y coordinate for point on top Interval-Valued Triangular Membership Function

type b:

float

param c:

y coordinate for point on end Interval-Valued Triangular Membership Function

type c:

float

Methods

__call__(x)

Overriding the __call__ method

ifis.interval_fuzzy_system module

class ifis.interval_fuzzy_system.IntervalFuzzySystem(type_system=1, show_banner=True, sanitize_input, verbose=False, operators=None)[source]

Bases: FuzzySystem

Class which creates a new interval valued fuzzy system (IVFS).

Parameters:
  • type_system – change type of system able to check 1 and 2 (2 is for special case of intervals when lower and upper bound of intervals is the same), default to 1

  • show_banner – toggles display of banner, default to True

  • sanitize_input – sanitize variables names to eliminate non-accepted characters (under development)

  • verbose – toggles verbose mode, default to False

  • operators – specifying interval fuzzy operators to be used instead of defaults.

Methods

set_variable(name, value, verbose)

Sets the interval value of a linguistic variable.

add_rules(rules, verbose)

Adds new interval valued fuzzy rules (IVFR) to the IVFS.

mediate_interval(outputs, antecedent, results, ignore_errors, ignore_warnings, verbose)

Function calculate Sugeno method of IVFS

mediate_interval_Mamdani(outputs, antecedent, results, ignore_errors, ignore_warnings, verbose, subdivisions)

Function calculate Mamdani method of IVFS

Sugeno_interval_inference(terms, ignore_errors, ignore_warnings, verbose)

Performs Sugeno interval fuzzy inference.

Mamdani_interval_inference(terms, subdivisions, ignore_errors, ignore_warnings, verbose)

Performs Mamdani interval fuzzy inference.

set_variable(name, value, verbose=False)[source]
Sets the interval value of a linguistic variable.
param name:

name of the linguistic variables to be set.

type name:

str

param value:

interval value to be set.

type value:

tuple

param verbose:

toggles verbose mode.

type verbose:

bool

add_rules(rules, verbose=False)[source]
Adds new interval valued fuzzy rules (IVFR) to the IVFS.
param rules:

name of the linguistic variables to be set.

type rules:

list of str

param verbose:

toggles verbose mode.

type verbose:

bool

mediate_interval(outputs, antecedent, results, ignore_errors=False, ignore_warnings=False, verbose=False)[source]
Function calculate Sugeno method of IVFS.
mediate_interval_Mamdani(outputs, antecedent,results, ignore_errors=False, ignore_warnings=False, verbose=False, subdivisions=1000)[source]
Function calculate Mamdani method of IVFS.
Sugeno_interval_inference(terms=None, ignore_errors=False, ignore_warnings=False, verbose=False)[source]
Performs Sugeno interval fuzzy inference.
param terms:

names of the variables on which inference must be performed If empty, all variables appearing in the consequent of a IVFR are inferred.

type terms:

list

param ignore_errors:

toggles the raising of errors during the inference.

type ignore_errors:

bool

param ignore_warnings:

toggles the raising of warnings during the inference.

type ignore_warnings:

bool

param verbose:

toggles verbose mode.

type verbose:

bool

param IntervalFuzzySystem:

the IntervalFuzzySystems object.

return:

a dictionary, containing as keys the variables names and as values their interval inferred values

Mamdani_interval_inference(terms=None, subdivisions=1000, ignore_errors=False, ignore_warnings=False, verbose=False)[source]
Performs Mamdani interval fuzzy inference.
param terms:

names of the variables on which inference must be performed If empty, all variables appearing in the consequent of a IVFR are inferred.

type terms:

list

param subdivisions:

nthe number of integration steps to be performed for calculating fuzzy set area, defaults to 1000.

type subdivisions:

int

param ignore_errors:

toggles the raising of errors during the inference.

type ignore_errors:

bool

param ignore_warnings:

toggles the raising of warnings during the inference.

type ignore_warnings:

bool

param verbose:

toggles verbose mode.

type verbose:

bool

param IntervalFuzzySystem:

the IntervalFuzzySystems object.

return:

a dictionary, containing as keys the variables names and as values their interval inferred values

ifis.interval_linguistic_variable module

class ifis.interval_linguistic_variable.IntervalLinguisticVariable(FS_list=[], concept=None, universe_of_discourse=None)[source]

Bases: LinguisticVariable

Class which represent new interval linguistic variable

Parameters:
  • FS_list – a list of IVFS instances

  • concept – a string providing a brief description of the concept represented by the linguistic variable, (optional)

  • universe_of_discourse – a list of two elements, specifying min and max of the universe of discourse. Optional, but it must be specified to exploit plotting facilities.

Methods

draw(ax[, TGT, highlight])

This method returns a matplotlib ax, representing all IVFS contained in the liguistic variable.

get_universe_of_discourse()

This method provides the leftmost and rightmost values of the universe of discourse of the linguistic variable.

plot([outputfile, TGT, highlight])

Shows a plot representing all IVFS contained in the liguistic variable.

get_index

get_values

draw(ax, TGT=None, highlight=None)[source]
This method returns a matplotlib ax, representing all IVFS contained in the liguistic variable.
param ax:

the matplotlib axis to plot to.

param TGT:

show the memberships of a specific element of discourse TGT in the figure.

param highlight:

string, indicating the linguistic term/fuzzy set to highlight in the plot.

return:

A matplotlib axis, representing all IVFS contained in the liguistic variable.

get_universe_of_discourse()[source]
This method provides the leftmost and rightmost values of the universe of discourse of the linguistic variable.
return:

the two boundary values of the universe of discourse.

rtype:

tuple

get_values(v)[source]
plot(outputfile='', TGT=None, highlight=None)[source]
Shows a plot representing all IVFS contained in the liguistic variable.
param outputfile:

path and filename where the plot must be saved

type outputfile:

str

param TGT:

show the memberships of a specific element of discourse TGT in the figure

param highlight:

string, indicating the linguistic term/fuzzy set to highlight in the plot.

ifis.interval_rule_parsing module

class ifis.interval_rule_parsing.IntervalClause[source]

Bases: Clause

Class representing Interval Clause

Methods

evaluate_interval(IntervalFuzzySystem,  verbose,  operators)

This method returns a answer for IntervalFuzzySystem object.

evaluate_interval(IntervalFuzzySystem, verbose=False, operators=None)[source]
This method returns a answer for IntervalFuzzySystem object.
param IntervalFuzzySystem:

the IntervalFuzzySystems object.

param verbose:

toggles verbose mode, default to FALSE.

return:

answer for Interval Fuzzy System

class ifis.interval_rule_parsing.IntervalFunctional[source]

Bases: Functional

Class representing Interval Functional

Methods

evaluate_interval(IntervalFuzzySystem)

This method returns a answer for IntervalFuzzySystem object.

evaluate_interval(IntervalFuzzySystem, verbose=None, operators=None)[source]
This method returns a answer for IntervalFuzzySystem object.
param IntervalFuzzySystem:

the IntervalFuzzySystems object.

return:

answer for Interval Fuzzy System

ifis.interval_rule_parsing.OR(x, y)[source]

Definition of basic OR aggregator in rules

param x:

first aggregated value

type x:

tuple, float

param y:

second aggregated value

type y:

tuple, float

return:

aggregated value

rtype:

tuple, float

ifis.interval_rule_parsing.AND(x, y)[source]

Definition of basic AND aggregator in rules as Mean aggregation in case intervals and min function when input data are floats

param x:

first aggregated value

type x:

tuple, float

param y:

second aggregated value

type y:

tuple, float

return:

aggregated value

rtype:

tuple, float

ifis.interval_rule_parsing.AND_p(x, y)[source]

Definition of basic AND aggregator in rules as Product aggregation in case intervals and product function when input data are floats

param x:

first aggregated value

type x:

tuple, float

param y:

second aggregated value

type y:

tuple, float

return:

aggregated value

rtype:

tuple, float

ifis.interval_rule_parsing.NOT(x)[source]

Negation operator in rules

param x:

value to negation

type x:

tuple, float

return:

value after negation

rtype:

tuple, float

ifis.interval_rule_parsing.interval_preparse(STRINGA)[source]

Function extract the antecedent

param STRINGA:

text of rule

type STRINGA:

str

return:

antecedent part from rule

rtype:

str

ifis.interval_rule_parsing.interval_postparse(STRINGA, verbose)[source]

Function extract the successor

param STRINGA:

text of rule

type STRINGA:

str

param verbose:

toggles verbose mode, default to False

type verbose:

bool

return:

successor part from rule

rtype:

str

ifis.interval_rule_parsing.interval_find_index_operator(string, verbose)[source]

Function finding indexes of operators in string

param string:

rule / part of rule

type string:

str

param verbose:

toggles verbose mode, default to False

type verbose:

bool

return:

start and end indexes of the found operator

rtype:

tuple

ifis.interval_rule_parsing.interval_recursive_parse(text, verbose, operators, allow_empty)[source]

Function for parse rules using recursive and extract each of the clauses from rule

param text:

rule / part of rule

type text:

str

param verbose:

toggles verbose mode, default to False

type verbose:

bool

param operators:

recognized in previous calling of function aggregation operator, default to None

type operators:

str

param allow_empty:

toggles allow empty clause, default to True

type allow_empty:

bool

return:

recognized part of function with aggregators

rtype:

IntervalFunctional