Package fuzzy :: Package set :: Module operations
[hide private]
[frames] | no frames]

Module operations

source code


Helper functions for calculation with fuzzy sets.

Examples can be found here U{http://pyfuzzy.sourceforge.net/demo/merge/}

* Intersection of set1 and set2 can be done by
  
  C{set = merge(T_NORM,set1,set2)}
  
  where T_NORM is a t-norm eg. Min.
  (or a function which accepts two parameters as min().)

* Union of set1 and set2 can be done by
  
  C{set = merge(S_NORM,set1,set2)}
  
  where S_NORM is a s-norm eg. Max.
  (or a function which accepts two parameters as max().)

* Complement of set1 can be done by
  
  C{set = norm(lambda a,b:1.0-a ,set1,0.0)}
  
  using a user defined function for it.
  (The second parameter is ignored or better said
  it doesn't influence the value, it only influences
  maybe where the points of the resulting polygon are
  set.)

* Activation function can be done by
  
  C{set = norm(act_norm,set,act_value)}
  
  where act_norm is any L{fuzzy.norm} or two params function (eg. min)
  and act_value is the result of a rule calculation.

Functions [hide private]
float
_find_root(f, x1, x2, f1=None, f2=None, epsilon=None)
Find root of function f between x1,x2 by using the regula falsi method with the pegasus modification.
source code
float
_find_root_linear(x1, x2, f1, f2)
Find root x1,x2 by using interpolation.
source code
float
_find_intersection(x1, x2, fa1, fa2, fb1, fb2)
Find intersection of two linear functions fa/fb between x1,x2 with values there fa1/fb1 and fa2/fb2.
source code
 
check(x, y1, y2) source code
fuzzy.set.Polygon.Polygon
_merge_generator1(set1, set2)
Returns a new fuzzy set which is the merger of set1 and set2, where the membership of the result set is equal to NORM(set1(x),set2(x)).
source code
fuzzy.set.Polygon.Polygon
_merge_generator(NORM, set1, set2)
Returns a new fuzzy set which is the merger of set1 and set2, where the membership of the result set is equal to NORM(set1(x),set2(x)).
source code
fuzzy.set.Polygon.Polygon
merge(NORM, set1, set2, segment_size=None)
Returns a new fuzzy set which is the merger of set1 and set2, where the membership of the result set is equal to NORM(set1(x),set2(x)).
source code
 
_norm_generator(NORM, set, value)
Returns a new fuzzy set which is this set normed with value.
source code
fuzzy.set.Polygon.Polygon
norm(NORM, set, value, segment_size=None)
Returns a new fuzzy set which ist this set normed with value.
source code
fuzzy.set.Polygon.Polygon
_complement_generator(COMPLEMENT, set)
Returns a new fuzzy set which is this complement of the given set.
source code
fuzzy.set.Polygon.Polygon
complement(COMPLEMENT, set, segment_size=None)
Returns a new fuzzy set which is this complement of the given set.
source code
Variables [hide private]
  __revision__ = '$Id: operations.py,v 1.13 2013-01-09 20:10:19 ...
  __package__ = 'fuzzy.set'
Function Details [hide private]

_find_root(f, x1, x2, f1=None, f2=None, epsilon=None)

source code 

Find root of function f between x1,x2 by using the regula falsi method with the pegasus modification. See also http://de.wikipedia.org/wiki/Regula_Falsi. (The english version lacks the description of pegasus modification.) The algorithm stops if the error estimation is smaller than epsilon or there is an ZeroDivisionError, which means both values f1 and f2 are identical (should be 0 then).

Parameters:
  • f (f(x)) - function for which to find f(x)=0
  • x1 (float) - left border of range
  • x2 (float) - right border of range
  • f1 (float) - value for x1, if available
  • f2 (float) - value for x2, if available
  • epsilon (float/None) - break condition for algorithm (value < epsilon)
Returns: float
x where f(x)=0

_find_root_linear(x1, x2, f1, f2)

source code 

Find root x1,x2 by using interpolation.

Parameters:
  • x1 (float) - left border of range
  • x2 (float) - right border of range
  • f1 (float) - value for x1
  • f2 (float) - value for x2
Returns: float
x where f(x)=0

_find_intersection(x1, x2, fa1, fa2, fb1, fb2)

source code 

Find intersection of two linear functions fa/fb between x1,x2 with values there fa1/fb1 and fa2/fb2.

Parameters:
  • x1 (float) - left border of range
  • x2 (float) - right border of range
  • fa1 (float) - value for x1
  • fa2 (float) - value for x2
  • fb1 (float) - value for x1
  • fb2 (float) - value for x2
Returns: float
x where fa(x)-fb(x)=0

_merge_generator1(set1, set2)

source code 

Returns a new fuzzy set which is the merger of set1 and set2, where the membership of the result set is equal to NORM(set1(x),set2(x)).

Parameters:
Returns: fuzzy.set.Polygon.Polygon
resulting fuzzy set

_merge_generator(NORM, set1, set2)

source code 

Returns a new fuzzy set which is the merger of set1 and set2, where the membership of the result set is equal to NORM(set1(x),set2(x)).

Parameters:
  • NORM (fuzzy.norm.Norm.Norm) - fuzzy norm to calculate both sets values. For example Min(), Max(), ... Also possible as two params function, eg. lambda a,b: (a+b)/2..
  • set1 (fuzzy.set.Set) - fuzzy set
  • set2 (fuzzy.set.Set) - fuzzy set
Returns: fuzzy.set.Polygon.Polygon
resulting fuzzy set

merge(NORM, set1, set2, segment_size=None)

source code 

Returns a new fuzzy set which is the merger of set1 and set2, where the membership of the result set is equal to NORM(set1(x),set2(x)).

For nonlinear operations you might want set the segment size to a value which controls how large a linear segment of the result can be. See also the following examples:

Parameters:
  • NORM (fuzzy.norm.Norm.Norm) - fuzzy norm to calculate both sets values. For example Min(), Max(), ... Also possible as two params function, eg. lambda a,b: (a+b)/2..
  • set1 (fuzzy.set.Set) - fuzzy set
  • set2 (fuzzy.set.Set) - fuzzy set
  • segment_size (float/None) - maximum size of a segment
Returns: fuzzy.set.Polygon.Polygon
resulting fuzzy set

_norm_generator(NORM, set, value)

source code 

Returns a new fuzzy set which is this set normed with value. where the membership of the result set is equal to NORM(set(x),value).

Parameters:
  • NORM (fuzzy.norm.Norm.Norm) - fuzzy norm to calculate set's values with value. For example Min(), Max(), ... Also possible as two params function, eg. lambda a,b: (a+b)/2..
  • set (fuzzy.set.Set) - fuzzy set
  • value (float) - value

norm(NORM, set, value, segment_size=None)

source code 

Returns a new fuzzy set which ist this set normed with value. where the membership of the result set is equal to NORM(set(x),value).

For meaning of segment_size see also fuzzy.set.operations.merge.

Parameters:
  • NORM (fuzzy.norm.Norm.Norm) - fuzzy norm to calculate set's values with value. For example Min(), Max(), ... Also possible as two params function, eg. lambda a,b: (a+b)/2..
  • set (fuzzy.set.Set) - fuzzy set
  • value (float) - value
  • segment_size (float/None) - maximum size of a segment
Returns: fuzzy.set.Polygon.Polygon
resulting fuzzy set

_complement_generator(COMPLEMENT, set)

source code 

Returns a new fuzzy set which is this complement of the given set. (Where the membership of the result set is equal to COMPLEMENT(set(x)).

Parameters:
Returns: fuzzy.set.Polygon.Polygon
resulting fuzzy set

complement(COMPLEMENT, set, segment_size=None)

source code 

Returns a new fuzzy set which is this complement of the given set. (Where the membership of the result set is equal to COMPLEMENT(set(x)).

For meaning of segment_size see also fuzzy.set.operations.merge.

Parameters:
  • COMPLEMENT (fuzzy.complement.Base.Base) - fuzzy complement to use. For example Zadeh(), ... Also possible as one param function, eg. lambda x: 1.-x.
  • set (fuzzy.set.Set) - fuzzy set
  • segment_size (float/None) - maximum size of a segment
Returns: fuzzy.set.Polygon.Polygon
resulting fuzzy set

Variables Details [hide private]

__revision__

Value:
'$Id: operations.py,v 1.13 2013-01-09 20:10:19 rliebscher Exp $'