phuzzy.shapes package

class phuzzy.shapes.FuzzyNumber(**kwargs)[source]

Bases: object

convex fuzzy number

__abs__()[source]

apply abs operator to a fuzzy number

Parameters:other – phuzzy.FuzzyNumber
Returns:fuzzy number
__add__(other)[source]

adds a fuzzy number

Parameters:other – phuzzy.FuzzyNumber
Returns:fuzzy number
__contains__(other)[source]

operator in

Return type:bool
Returns:True or False
__dict__ = dict_proxy({'cdf': <function cdf>, 'ppf': <function ppf>, 'get_shape': <function get_shape>, '__str__': <function __str__>, 'export_csv': <function export_csv>, '__rsub__': <function __rsub__>, '__rdiv__': <function __rdiv__>, '__rmul__': <function __rmul__>, '__lt__': <function __lt__>, '__weakref__': <attribute '__weakref__' of 'FuzzyNumber' objects>, 'make_convex': <function make_convex>, '__rpow__': <function __rpow__>, 'convert_df': <function convert_df>, 'get_01': <property object>, '_get_df': <function _get_df>, '__abs__': <function __abs__>, 'defuzzification_centroid2': <function defuzzification_centroid2>, 'from_data': <classmethod object>, '__doc__': 'convex fuzzy number', '__sub__': <function __sub__>, 'df': <property object>, '_set_df': <function _set_df>, 'defuzzification': <function defuzzification>, 'defuzzification_centroid': <function defuzzification_centroid>, 'from_results': <classmethod object>, '__pow__': <function __pow__>, '__gt__': <function __gt__>, 'copy': <function copy>, '__eq__': <function __eq__>, 'from_str': <classmethod object>, 'has_zero': <function has_zero>, 'defuzzification_alpha_one': <function defuzzification_alpha_one>, '__hash__': None, '_get_cls': <staticmethod object>, 'mean': <function mean>, 'discretize': <function discretize>, '__module__': 'phuzzy.shapes', '__radd__': <function __radd__>, 'rvs': <function rvs>, '__dict__': <attribute '__dict__' of 'FuzzyNumber' objects>, '__truediv__': <function __truediv__>, 'defuzzification_mean': <function defuzzification_mean>, '_get_number_of_alpha_levels': <function _get_number_of_alpha_levels>, '__init__': <function __init__>, 'alpha0': <property object>, 'alpha1': <property object>, '__contains__': <function __contains__>, '_disretize_range': <function _disretize_range>, 'defuzzification_p50': <function defuzzification_p50>, 'abs': <function abs>, '__neg__': <function __neg__>, '__ne__': <function __ne__>, 'get_alpha_from_value': <function get_alpha_from_value>, 'import_csv': <function import_csv>, 'max': <function max>, '_unify': <function _unify>, '__add__': <function __add__>, 'pdf': <function pdf>, 'alpha': <function alpha>, 'min': <function min>, 'number_of_alpha_levels': <property object>, 'to_str': <function to_str>, '__div__': <function __truediv__>, '__mul__': <function __mul__>, 'get_01_str': <property object>, '__repr__': <function __repr__>, '_set_number_of_alpha_levels': <function _set_number_of_alpha_levels>})
__div__(other)

divide by a fuzzy number

Parameters:other – phuzzy.FuzzyNumber
Returns:fuzzy number
__eq__(other)[source]

operation ==

Return type:bool
Returns:True or False
__gt__(other)[source]

operation >

Return type:bool
Returns:True or False
__hash__ = None
__init__(**kwargs)[source]

base fuzzy number

Parameters:kwargs
__lt__(other)[source]

operation <

Returns:True or False
__module__ = 'phuzzy.shapes'
__mul__(other)[source]

multiply with a fuzzy number

Parameters:other – phuzzy.FuzzyNumber
Returns:fuzzy number
__ne__(other)[source]

operation !=

Return type:bool
Returns:True or False
__neg__()[source]

apply unary neg operator to a fuzzy number

Parameters:other – phuzzy.FuzzyNumber
Returns:fuzzy number
__pow__(other)[source]

apply power of a fuzzy number

Parameters:other – phuzzy.FuzzyNumber
Returns:fuzzy number
__radd__(other)[source]
__rdiv__(other)[source]
__repr__() <==> repr(x)[source]
__rmul__(other)[source]
__rpow__(other)[source]

apply exponent of a fuzzy number

Parameters:other – phuzzy.FuzzyNumber
Returns:fuzzy number
__rsub__(other)[source]
__str__() <==> str(x)[source]
__sub__(other)[source]

substract a fuzzy number

Parameters:other – phuzzy.FuzzyNumber
Returns:fuzzy number
__truediv__(other)[source]

divide by a fuzzy number

Parameters:other – phuzzy.FuzzyNumber
Returns:fuzzy number
__weakref__

list of weak references to the object (if defined)

abs()[source]

calculate absolute value

Returns:FuzzyNumber
alpha(x)[source]

get alpha from x

alpha0

row for alpha=0

alpha1

row for alpha=1

cdf(x, **kwargs)[source]

Cumulative distribution function

Parameters:
  • x – x values
  • n – number of integration points
Returns:

y

convert_df(alpha_levels=None, zero=0)[source]
copy()[source]

return a copy

Returns:copy of fuzzy number
defuzzification(method='centroid')[source]
defuzzification_alpha_one()[source]

defuzzification

(alpha1_r + alpha1_l) / 2

defuzzification_centroid()[source]

defuzzification center of gravity

defuzzification_centroid2()[source]

defuzzification center of gravity

defuzzification_mean()[source]

defuzzification mean with discrete values

defuzzification_p50()[source]

defuzzification mean my means of ppf(0.5)

df

number of alpha levels

discretize(alpha0, alpha1, alpha_levels)[source]

discretize shape function

Parameters:
  • alpha0 – range at alpha=0
  • alpha1 – range at alpha=1
  • alpha_levels – number of alpha levels
Returns:

None

export_csv(filepath=None)[source]

export alpha levels to csv

Parameters:filepath – csv file path
Returns:
classmethod from_data(**kwargs)[source]

instantiate fuzzy number from attributes

Parameters:kwargs
Return type:phuzzy.FuzzyNumber or derived object
Returns:fuzzy number
classmethod from_results(df_res, name=None, number_of_alpha_levels=11)[source]

create FuzzyNumber from DataFrame(“alpha”, “res”)

Parameters:df – DataFrame with columns=[“alpha”, “res”]
Returns:FuzzyNumber
classmethod from_str(s)[source]

deserialize fuzzy number to string

Returns:fuzzy number string
get_01

get alpha=0 and alpha=1 values

Returns:[[a0_l, a0_r], [a1_l, a1_r]]
get_01_str

get alpha=0 and alpha=1 values

Returns:[[a0_l, a0_r], [a1_l, a1_r]]
get_alpha_from_value(x)[source]

get alpha values from given x values

Parameters:x – x values
Returns:alpha values
get_shape()[source]

get shape dataframe

Returns:pandas.DataFrame(columns=[“alpha”, “x”])
has_zero()[source]

is zero in range

Return type:bool
Returns:True od False
import_csv(fh)[source]

load alpha levels from csv

Parameters:fh – csv file path or file handle
Returns:alpha level dataframe
make_convex()[source]

make fuzzy number convex

Returns:None
max()[source]

maximal

Return type:float
Returns:max value of df
mean()[source]

mean value

Return type:float
Returns:mean value
min()[source]

minimum

Return type:float
Returns:min value of df
number_of_alpha_levels

number of alpha levels

pdf(x)[source]

Probability density function

Parameters:x – x values
Returns:
ppf(x, **kwargs)[source]

Percent point function (inverse of cdf-percentiles).

Parameters:
  • x – x values
  • n – number of integration points
Returns:

y

rvs(size, seed=None)[source]

Sample points according membership function

Parameters:size – number of sample points
Returns:sample points
to_str()[source]

serialize fuzzy number to string

Returns:fuzzy number string
class phuzzy.shapes.Trapezoid(**kwargs)[source]

Bases: phuzzy.shapes.FuzzyNumber

triange fuzzy number

__init__(**kwargs)[source]

base fuzzy number

Parameters:kwargs
__module__ = 'phuzzy.shapes'
cdf(x, **kwargs)[source]

Cumulative distribution function

Parameters:
  • x – x values
  • n – number of integration points
Returns:

y

discretize(alpha0, alpha1, alpha_levels)[source]

discretize shape function

Parameters:
  • alpha0 – range at alpha=0
  • alpha1 – range at alpha=1
  • alpha_levels – number of alpha levels
Returns:

None

pdf(x)[source]
Parameters:x
Returns:
to_str()[source]

serialize fuzzy number to string

Returns:fuzzy number string
class phuzzy.shapes.Triangle(**kwargs)[source]

Bases: phuzzy.shapes.FuzzyNumber

triange fuzzy number

__init__(**kwargs)[source]

base fuzzy number

Parameters:kwargs
__module__ = 'phuzzy.shapes'
cdf(x, **kwargs)[source]

Cumulative distribution function

Parameters:
  • x – x values
  • n – number of integration points
Returns:

y

discretize(alpha0, alpha1, alpha_levels)[source]

discretize shape function

Parameters:
  • alpha0 – range at alpha=0
  • alpha1 – range at alpha=1
  • alpha_levels – number of alpha levels
Returns:

None

classmethod from_data(**kwargs)[source]

instantiate fuzzy number from attributes

Parameters:kwargs
Return type:phuzzy.FuzzyNumber or derived object
Returns:fuzzy number
pdf(x)[source]

https://en.wikipedia.org/wiki/Triangular_distribution

to_str()[source]

serialize fuzzy number to string

Returns:fuzzy number string
class phuzzy.shapes.Uniform(**kwargs)[source]

Bases: phuzzy.shapes.FuzzyNumber

triange fuzzy number

__init__(**kwargs)[source]

base fuzzy number

Parameters:kwargs
__module__ = 'phuzzy.shapes'
cdf(x, **kwargs)[source]

Cumulative distribution function

Parameters:
  • x – x values
  • n – number of integration points
Returns:

y

discretize(alpha0, alpha1, alpha_levels)[source]

discretize shape function

Parameters:
  • alpha0 – range at alpha=0
  • alpha1 – range at alpha=1
  • alpha_levels – number of alpha levels
Returns:

None

pdf(x)[source]

https://en.wikipedia.org/wiki/Uniform_distribution_(continuous)

to_str()[source]

serialize fuzzy number to string

Returns:fuzzy number string