API Documentation

Version:1.0.0
Status:developing version

Fuzzy class

class fuzzy.fism(type='mamdani', Ninputs=0, Noutputs=0)

Class object storing settings and configuration parameters (data attributes) for Fuzzy Mamdani or Tagaki-Sugeno type Fuzzy system.

By default initialization mamdani type fuzzy is set with settings:

ANDmethod: Tnorm ‘min’

ORmethod: Snorm ‘max’

Implication method: Tnorm ‘min’

Aggregation method: ‘max’

Deffuzyfication method: ‘centroid’

Note

fism in ver.1.0.0 is only fuzzy structure container. Fuzzy Inference Process is implemented by evaluate(fis,x) from fuzzy_sets.py.

Atributes format Description
type string =’mamdani’ or ‘tsk’ : type of fuzzy system
Ninputs Int Number of inputs
Noutputs Int Number of outputs
varName string list, store of variable names
varRange [float,float] store of variable physical range
ORmethod string default:’max’ other: ‘prod’ ‘eprod
ANDmethod string default ‘min’ , other: ,’prod’ , eprod’
Implmethod string Implication method, default: ‘min’ . other:’tnorm’, ‘eprod’
Aggmethod string Aggregation Method, default: ‘max’
Defuzzymethod string Defuzzyfication Method, defalult: ‘centroid’
RuleList 2D int array store rules (Array Nrules x(Ninputs+Noutputs+1
RuleWeights 1D float array list of Rule’s weights
mfnames_in string list list, names of input’s mf
mfnames_out string list, names of output’s mf
mfpari 2D float array array list of inputs mf types and parameters
mfparo 2D float array array list of outrputs mf types and parameters
Nin_mf Int list list, Numbenr of inputs mf [N_mf in1, N_mf in2…]
Nout_mf Int list list, Numbenr of inputs mf [N_mf out1, N_mf out2…]
Npts Int No of points resolution for defuzzyfication process
outOfRange Int = 1 when any of input is out of Range
NoRuleFired int = 1 when no rule fired

Example initialization

from fuzzy  import *
from fuzzy_sets import *

fis1 = fism()               # empty mamdani fuzzy structure
fis2 = fism('mamdani',2,1)  # 2 input, 1 output mamdani fuzzy structure
addmf(var_type, var_index, namemf, typemf, parammf)

Add membership function (mf) to fuzzy structure

Parameters:
  • var_type (string) – “in” or “out” type variable
  • var_index (int) – Number of added mf
  • namemf (string) – name of membership function
  • typemf (string) – type of mf: ‘trimf’,’trapmf’,’gaussmf’,’gauss2mf’,’gbellmf’,’sigmf’,’singleton’
  • parammf (string) – [param 1, param2, param 3, param 4]
addrule(rule, weight)

Add rule to fuzzy structure.

Parameters:
  • rule (list of Int) – rule
  • weight (double) – weighting parameter
addvar(type, name, range)

Add variable (input or output) to the fuzzy system

Parameters:
  • type (string) – ‘in’ or ‘out’
  • name (string) – name of variable
  • range – [min,max] range value of variable

Example

fis1.addvar('in','x1',[0.,3.0])
fis1.addvar('in','x2',[0.,3.0])
fis1.addvar('out','y1',[0.,3.0])
delmf(var_type, var_index, mf_index)

Delete membership function from fuzzy system

Parameters:
  • var_type – variable type: input(“in”) or output(“out”)
  • var_index (Int) – No. of variable
  • mf_index (Int) – No. of mf
delrule(ruleNo)

Delete rule from fuzzy structure

Parameters:ruleNo (Int) – Rule’s number
delvar(var_type, idx)

Delete variable from fism structure

Parameters:
  • var_type (string) – “in” or “out” type variable
  • idx (Int) – No of variable
getmf(var_type, var_index)

Return list of membership function of input or output

Parameters:
  • var_type (string) – variable type: ‘in’ or ‘out’
  • var_index (Int) – index of variable 1…
Returns:

mf list ie mf_list[i]=[name_i,type, params], i=0..Nmf-1

setmf(var_type, var_index, mf_index, typemf, parammf)

Set new parameters for members ship function (mf) for input/output

Parameters:
  • var_type (string) – variable type: input(“in”) or output(“out”)
  • var_index (Int) – index of variable
  • mf_idx (Int) – No of mf function
  • typemf (string) – type of mf
  • parammf (list of doubles) – list [1x4] of mf parameters

Memebership Functions

mfs.eval_mf(xn, params)

Return value of mf function for input xn. type, and parameters of mf stored in params vector where: params=[mf code, mf params] : mf code: 0=’trimf’,1=’trapmf’,3=’gaussmf’,4=’gauss2mf’,5=’gbellmf’,6=’sigmf’,7=’singleton’]

Parameters:
  • xn (float) – input value
  • params (vector) – [mf code, mf params]
Returns:

value of mf an xn

mfs.gauss2mf(xn, param)

Compute nonsymmetric gaussian function membership return value of nonsymmetric Gaussian function depends of param=[sigma_1, c1, sigma_2, c2]

Parameters:
  • xn (float) – input sample
  • param (float) – [sigma1, const.1,sigma 2, const.2]
Returns:

value of nonsymmetric Gaussian function

Return type:

float

mfs.gaussmf(xn, param)

Compute gaussian function membership return value of symmetric Gaussian function \(gaussmf(x,[\sigma,c])= e^{\frac{-(x-c)^2}{2\sigma^2}}\)

Parameters:
  • xn (float) – input sample
  • param (float) – [1x2] vector = [sigma value, expected value]
Returns:

return value of symmetric Gaussian function

Return type:

float

mfs.gbellmf(xn, param)

Generalized bell-shaped membership function retur value of Generalized bell-shaped function: :math: ‘f(x,a,b,c) = gbellmf[x,[a,b,c]] = 1/(1+(abs((x−c)/a))^2b)’ :param xn: input value, :param param: [a,b,c], :type xn: float, :type param: float, :return: value of Generalized bell-shaped, :rtype: float,

mfs.sigmf(xn, param)

Sigmoidal membership function

Math:

‘f(x,[a,c]) = sigmf[x,[a,c]] = 1/(1+exp(-a(x−c)))’

Parameters:
  • xn (float) – input value
  • param (float) – =[a,c]
Returns:

value of sigmoidal function

Return type:

float

mfs.singletonmf(xn, param)

singleton function

Parameters:
  • xn – input value
  • param – [x0]
Returns:

mfs.trapmf(xn, param)

Trapezoidal membership function compute value of trapezoidal shape function. trapezoid is described by parameters: \(a<=b <=c <= d\)

Parameters:
  • xn (float) – input value
  • param (float) – ([1x4] vector) Trapezoid parameters: param=[a,b,c,d]
Returns:

value of Trapezoid mf

Return type:

float

mfs.trimf(xn, param)

Compute value of triangular membership function \(f(x_n,a,b,c)=max(min((x-a)/(b-a),(c-x)/(c-b)),0)\).

Parameters:
  • xn (float) – input value
  • param (float) – [1x3] vector: param[0]=a,param[1]=b,param[2]=c
Returns:

value of triangular mf

Return type:

float

Fuzzy sets

fuzzy_sets.complement(x, type)

Compute complement of x according to “type” method: “one” - classic complement, “sugeno” - sugeno complement

Parameters:
  • x (float) – iput value
  • type – “one” or “sugeno” type complement
Returns:

complement of input x

Return type:

float

fuzzy_sets.defuzzy(y, method)

Defuzzify membership function with defined method. ‘centroid’ -CENTROID ‘mom’ MEAN OF MAXIMUM (MOM) ‘som’ SHORTEST OF MAXIMUM (SOM) ‘lom’ LARGEST OF MAXIMUM (LOM) ‘bisector’ BISECTOR

Parameters:
  • y (folat[]) –
  • method (String) – defuzzy method: ‘centroid’,’mom’,’som’,’lom’,’bisector
Returns:

None

fuzzy_sets.evaluate(fis, x)

Compute fuzzy output of fis system for inputs x=[x1,x2…]

Parameters:
  • fis (fism object) – fuzzy structure (fism class) of fuzzy system
  • x (float[]) – input vector data
Returns:

fuzzy out

Return type:

float

fuzzy_sets.getsurf(fis, Npts, in1=1, in2=2, out=1)

Generate fuzzy system surface

Parameters:
  • fis – fis structure
  • Npts – No of points
  • in1 – No of input 1
  • in2 – No of input 2
  • out – No of outpt
Returns:

X,Y,Z - x,y cooordinates and z: data surface value

fuzzy_sets.snorm(x, y, norm_type)

Compute “type” s-norm for input data x,y. the s-norm types:”max” - maximum: MAX(x,y), “prod” - algebraic sum: x + y - xy “eprod” - einstein sum: (x + y)/ (1 + xy)

Parameters:
  • x – input data 1
  • y – input data 2
  • norm_type – “max”, “prod” or “eprod” type snorm
Returns:

S-Norm of x,y

fuzzy_sets.tnorm(x, y, norm_type)

Return “type” tnorm of input x and y. Types of tnorm: “min” : Minimum sum t-norm “prod” : Algebic product t-norm “eprod”: Einstein product tnorm

Parameters:
  • x – value 1
  • y – value 2
  • norm_type – “min”, “prod”, eprod
Returns:

“type” tnorm of (x,y)