Welcome to phuzzy’s documentation!

phuzzy

https://img.shields.io/pypi/v/phuzzy.svg Documentation Status https://travis-ci.org/lepy/phuzzy.svg?branch=master https://coveralls.io/repos/github/lepy/phuzzy/badge.svg Updates https://api.codacy.com/project/badge/Grade/4814372e95c543a69c69004c853b17be https://img.shields.io/badge/Say%20Thanks-!-1EAEDB.svg https://zenodo.org/badge/DOI/10.5281/zenodo.1219616.svg

Fuzzy calculation in Python.

Features

  • TODO

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

Installation

https://img.shields.io/pypi/v/phuzzy.svg Documentation Status https://travis-ci.org/lepy/phuzzy.svg?branch=master https://coveralls.io/repos/github/lepy/phuzzy/badge.svg Updates https://api.codacy.com/project/badge/Grade/4814372e95c543a69c69004c853b17be

Stable release

To install phuzzy, run this command in your terminal:

$ pip install phuzzy

This is the preferred method to install phuzzy, as it will always install the most recent stable release.

If you don’t have pip installed, this Python installation guide can guide you through the process.

From sources

The sources for phuzzy can be downloaded from the Github repo.

You can either clone the public repository:

$ git clone git://github.com/lepy/phuzzy

Or download the tarball:

$ curl  -OL https://github.com/lepy/phuzzy/tarball/master

Once you have a copy of the source, you can install it with:

$ python setup.py install

Usage

To use phuzzy in a project:

import phuzzy
tn = phuzzy.TruncNorm(alpha0=[2, 3], alpha1=[], number_of_alpha_levels=15, name="t")
tri = phuzzy.Triangle(alpha0=[1, 4], alpha1=[2], number_of_alpha_levels=5)
f = tn + tri
print(f.df)

available shapes

Uniform

1
2
3
import phuzzy.mpl as phm
uni = phm.Uniform(alpha0=[1, 4], number_of_alpha_levels=5, name="x")
uni.plot(show=True, filepath="/tmp/uniform.png", title=True)
uniform fuzzy number

Uniform fuzzy number (this is just an interval)

Triangle

1
2
3
4
import phuzzy.mpl as phm

tri = phm.Triangle(alpha0=[1, 4], alpha1=[2], number_of_alpha_levels=5)
tri.plot(show=False, filepath="/tmp/triangle.png", title=True)
Triangle fuzzy number

Triangle fuzzy number

Trapezoid

1
2
3
import phuzzy.mpl as phm
trap = phm.Trapezoid(alpha0=[1, 5], alpha1=[2, 3], number_of_alpha_levels=5)
trap.plot(show=False, filepath="/tmp/trapezoid.png", title=True)
Trapezoid fuzzy number

Trapezoid fuzzy number

TruncNorm

1
2
3
import phuzzy.mpl as phm
tn = phm.TruncNorm(alpha0=[1, 3], number_of_alpha_levels=15, name="x")
tn.plot(show=False, filepath="/tmp/truncnorm.png", title=True)
TruncNorm fuzzy number

TruncNorm fuzzy number

TruncGenNorm

1
2
3
import phuzzy.mpl as phm
tgn = phm.TruncGenNorm(alpha0=[1, 4], alpha1=[2, 3], number_of_alpha_levels=15, beta=3.)
tgn.plot(show=False, filepath="/tmp/truncgennorm.png", title=True)
TruncGenNorm fuzzy number

TruncGenNorm fuzzy number

Superellipse

1
2
3
import phuzzy.mpl as phm
se = phm.Superellipse(alpha0=[-1, 2.], alpha1=None, m=1.0, n=.5, number_of_alpha_levels=17)
se.plot(show=True, filepath="/tmp/superellipse.png", title=True)
Superellipse fuzzy number

Superellipse fuzzy number

basic operations

Addition

z = x + y

1
2
3
4
x = phuzzy.Trapezoid(alpha0=[0, 4], alpha1=[2, 3], number_of_alpha_levels=5)
y = phuzzy.TruncNorm(alpha0=[1, 3], number_of_alpha_levels=15, name="y")
z = x + y
z.name = "x+y"
add

Addition of fuzzy numbers

z = 3 + x

1
2
3
x = phuzzy.Trapezoid(alpha0=[0, 4], alpha1=[2, 3], number_of_alpha_levels=5)
z = 3 + x
z = x + 3

Substraction

z = x - y

1
2
3
4
x = phuzzy.Trapezoid(alpha0=[0, 4], alpha1=[2, 3], number_of_alpha_levels=5)
y = phuzzy.TruncNorm(alpha0=[1, 3], number_of_alpha_levels=15, name="y")
z = x - y
z.name = "x-y"
add

Substraction of fuzzy numbers

y = 3 - x

z = x - 3

1
2
3
x = phuzzy.Trapezoid(alpha0=[0, 4], alpha1=[2, 3], number_of_alpha_levels=5)
y = 3 - x
z = x - 3

Multiplication

z = x  y

1
2
3
4
x = phuzzy.Trapezoid(alpha0=[0, 4], alpha1=[2, 3], number_of_alpha_levels=5)
y = phuzzy.TruncNorm(alpha0=[1, 3], number_of_alpha_levels=15, name="y")
z = x * y
z.name = "x*y"
add

Multiplication of fuzzy numbers

z = 3x

1
2
3
x = phuzzy.Trapezoid(alpha0=[0, 4], alpha1=[2, 3], number_of_alpha_levels=5)
z = 3 * x
z = x * 3

Division

z = \frac{x}{y}

1
2
3
4
x = phuzzy.Trapezoid(alpha0=[0, 4], alpha1=[2, 3], number_of_alpha_levels=5)
y = phuzzy.TruncNorm(alpha0=[1, 3], number_of_alpha_levels=15, name="y")
z = x / y
z.name = "x/y"
add

Division of fuzzy numbers

y = 3 / x

z = x / 3

1
2
3
x = phuzzy.Trapezoid(alpha0=[0, 4], alpha1=[2, 3], number_of_alpha_levels=5)
z = 3 / x
z = x / 3

Exponentiation

z = x^y

1
2
3
4
x = phuzzy.Trapezoid(alpha0=[0, 4], alpha1=[2, 3], number_of_alpha_levels=5)
y = phuzzy.TruncNorm(alpha0=[1, 3], number_of_alpha_levels=15, name="y")
z = x ** y
z.name = "x^y"
add

Power operation with fuzzy numbers

z = x^3

1
2
x = phuzzy.Trapezoid(alpha0=[0, 4], alpha1=[2, 3], number_of_alpha_levels=5)
z = x**3

Negation

z = -x

1
2
x = phuzzy.Trapezoid(alpha0=[0, 4], alpha1=[2, 3], number_of_alpha_levels=5)
z = -x

Absolute value

z = |x|

1
2
3
x = phuzzy.Trapezoid(alpha0=[-1, 4], alpha1=[2, 3], number_of_alpha_levels=5)
z = abs(x)
z = x.abs()

Shapes

Uniform

1
2
3
import phuzzy.mpl as phm
uni = phm.Uniform(alpha0=[1, 4], number_of_alpha_levels=5, name="x")
uni.plot(show=True, filepath="/tmp/uniform.png", title=True)
uniform fuzzy number

Uniform fuzzy number

uniform fuzzy number operations

Uniform fuzzy number operations

Triangle

1
2
3
4
import phuzzy.mpl as phm

tri = phm.Triangle(alpha0=[1, 4], alpha1=[2], number_of_alpha_levels=5)
tri.plot(show=False, filepath="/tmp/triangle.png", title=True)
Triangle fuzzy number

Triangle fuzzy number

Triangle fuzzy number operations

Triangle fuzzy number operations

Trapezoid

1
2
3
import phuzzy.mpl as phm
trap = phm.Trapezoid(alpha0=[1, 5], alpha1=[2, 3], number_of_alpha_levels=5)
trap.plot(show=False, filepath="/tmp/trapezoid.png", title=True)
Trapezoid fuzzy number

Trapezoid fuzzy number

Trapezoid fuzzy number operations

Trapezoid fuzzy number operations

TruncNorm

1
2
3
import phuzzy.mpl as phm
tn = phm.TruncNorm(alpha0=[1, 3], number_of_alpha_levels=15, name="x")
tn.plot(show=False, filepath="/tmp/truncnorm.png", title=True)
TruncNorm fuzzy number

TruncNorm fuzzy number

TruncNorm fuzzy number operations

TruncNorm fuzzy number operations

TruncGenNorm

1
2
3
import phuzzy.mpl as phm
tgn = phm.TruncGenNorm(alpha0=[1, 4], alpha1=[2, 3], number_of_alpha_levels=15, beta=3.)
tgn.plot(show=False, filepath="/tmp/truncgennorm.png", title=True)
TruncGenNorm fuzzy number

TruncGenNorm fuzzy number

TruncGenNorm fuzzy number operations

TruncGenNorm fuzzy number operations

Superellipse

1
2
3
import phuzzy.mpl as phm
se = phm.Superellipse(alpha0=[-1, 2.], alpha1=None, m=1.0, n=.5, number_of_alpha_levels=17)
se.plot(show=True, filepath="/tmp/superellipse.png", title=True)
Superellipse fuzzy number

Superellipse fuzzy number

Superellipse fuzzy number (variation m, n)

Superellipse fuzzy number (variation m, n)

Superellipse fuzzy number operations

Superellipse fuzzy number operations

Plots

import phuzzy
from phuzzy.mpl import mix_mpl
import phuzzy.mpl.plots
x = phuzzy.TruncNorm(alpha0=[1, 2], name="x")
y = phuzzy.Triangle(alpha0=[3, 6], alpha1=[4], name="y")
mix_mpl(x)
x.plot(filepath="FuzzyNumber_plot.png")
FuzzyNumber_plot.png

x.plot()

plot_xy.png

fig, ax = phuzzy.mpl.plots.plot_xy(x, y)

plot_xyz.png

fig, ax = phuzzy.mpl.plots.plot_xyz(x, y, x+y)

plot_3d.png

fig, ax = phuzzy.mpl.plots.plot_3d(x, y)

plot_xy_3d.png

fig, ax = phuzzy.mpl.plots.plot_xy_3d(x, y)

Examples

Three-point bending

Simply supported beam with central load

What is the maximum deflection of a simple supported beam with central load, if there is an uncertainty of only 1% for all input parameter? The input parameter are load P, beam length L, beam width W, beam height H and young’s modulus E.

P &= 5\, kN \pm 1\%

L &= 2\, m \pm 1\%

W &= 50\, mm \pm 1\%

H &= 100\, mm \pm 1\%

E &= 30000\, N/mm^2 \pm 1\%

three point bending test

Three point bending test [wikipedia.org]

w(x) &= {\begin{cases}-{\frac  {Px(4x^{2}-3L^{2})}{48EI}},&{\mbox{for }}0\leq x\leq {\tfrac  {L}{2}}\\{\frac  {P(x-L)(L^{2}-8Lx+4x^{2})}{48EI}},&{\mbox{for }}{\tfrac  {L}{2}}<x\leq L\end{cases}}

w &= w_{L/2} = \tfrac  {PL^{3}}{48EI}

A &= WH

I &= WH^3

Code

import phuzzy as ph
number_of_alpha_levels = 31

# load P
P0 = 5000.  # N
dP = 0.01 * P0  # N
P = ph.Triangle(alpha0=[P0 - dP, P0 + dP], alpha1=[P0], name="P", number_of_alpha_levels=number_of_alpha_levels)

# dimensions L, W, H
W0 = 50  # mm
H0 = 100  # mm
L0 = 2000  # mm

dW = 0.01 * W0  # mm
dH = 0.01 * H0  # mm
dL = 0.01 * L0  # mm

L = ph.Triangle(alpha0=[L0 - dL, L0 + dL], alpha1=[L0], name="L", number_of_alpha_levels=number_of_alpha_levels)
W = ph.Triangle(alpha0=[W0 - dW, W0 + dW], alpha1=[W0], name="W", number_of_alpha_levels=number_of_alpha_levels)
H = ph.Triangle(alpha0=[H0 - dH, H0 + dH], alpha1=[H0], name="H", number_of_alpha_levels=number_of_alpha_levels)

# material

E0 = 30000.  # N/mm2
dE = 0.1 * E0  # N/mm2
E = ph.TruncNorm(alpha0=[E0 - dE, E0 + dE], alpha1=[E0], name="E", number_of_alpha_levels=number_of_alpha_levels)

I0 = W0 * H0 ** 3 / 12.
w0 = P0 * L0 ** 3 / (48 * E0 * I0)

print("I0 = {:.4g} mm^4".format(I0))
# I0 = 4.167e+06 mm^4
print("w0 = {:.4g} mm".format(w0))
# w0 = 6.667 mm

I = W * H** 3 / 12.
I.name = "I"
w = P * L ** 3 / (48 * E * I)
w.name = r"P L^3 / (48 EI)"

print("I = {} mm^4".format(I))
# I = FuzzyNumber(W*H^3/12.0:[[4002483.375, 4335850.041666667], [4166666.6666666665, 4166666.6666666665]]) mm^4

print("w = {} mm".format(w))
# w = FuzzyNumber(P*L^3/E*48*W*H^3/12.0:[[5.594629603627992, 8.024370049019725], [6.666666666666667, 6.666666666666667]]) mm

w_mean = w.mean()
dw_l = w_mean - w.min()
dw_r = w.max() - w_mean
print("w = {:.4g} mm (- {:.4g}|+ {:.4g})".format(w_mean, dw_l, dw_r))
# w = 6.703 mm (- 1.109|+ 1.321)
print("w = {:.4g} mm [{:.4g},{:.4g}]".format(w_mean, w.min(), w.max()))
# w = 6.703 mm [5.595,8.024]

Parameter
ssb parameter

used Parameter

Results
three point bending test results

results area moment of inertia I and deflections w

phuzzy package

class phuzzy.Analysis(**kwargs)[source]

Bases: object

__dict__ = dict_proxy({'add_designvar': <function add_designvar>, '__module__': 'phuzzy', '__repr__': <function __str__>, '__dict__': <attribute '__dict__' of 'Analysis' objects>, '__weakref__': <attribute '__weakref__' of 'Analysis' objects>, 'designvars': <property object>, '__str__': <function __str__>, 'add_designvars': <function add_designvars>, '__init__': <function __init__>, '__doc__': None})
__init__(**kwargs)[source]

Analysis(kwargs)

__module__ = 'phuzzy'
__repr__()

x.__str__() <==> str(x)

__str__() <==> str(x)[source]
__weakref__

list of weak references to the object (if defined)

add_designvar(designvar)[source]

add design variable to doe

Parameters:designvar – design variable
Returns:None
add_designvars(designvars)[source]

add design variables to doe

Parameters:designvars – list of design variables
Returns:None
designvars

returns all design variables of doe

Returns:dict of designvars

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>, 'update': <function update>, '__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
update(alpha0=None, alpha1=None, alpha_levels=None)[source]
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

phuzzy.shapes.superellipse module

superelliptic fuzzy number

Superellipse(alpha0=[-1, 2], alpha1=None, m=1, n=.5, number_of_alpha_levels=15)
Superellipse fuzzy number

Superellipse fuzzy number

class phuzzy.shapes.superellipse.Superellipse(**kwargs)[source]

Bases: phuzzy.shapes.FuzzyNumber

superelliptic fuzzy number

__init__(**kwargs)[source]

superelliptic fuzzy number

Parameters:kwargs
Superellipse(alpha0=[1, 2], alpha1=None, m=2, n=None, number_of_alpha_levels=17)
__module__ = 'phuzzy.shapes.superellipse'
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_str(s)[source]

instantiate a fuzzy number from string

Parameters:s
Return type:phuzzy.FuzzyNumber
Returns:fuzzy number
shape(x)[source]

shape function

Parameters:x (array or float) – x values
Returns:y values
to_str()[source]

serialize fuzzy number to string

Return type:str
Returns:fuzzy string

phuzzy.shapes.truncnorm module

Normal distibuted membership function

TruncNorm(alpha0=[1, 3], alpha1=None, number_of_alpha_levels=15)
TruncNorm fuzzy number

TruncNorm fuzzy number

TruncGenNorm(alpha0=[1, 4], alpha1=None, number_of_alpha_levels=15, beta=5)
TruncGenNorm fuzzy number

TruncGenNorm fuzzy number

class phuzzy.shapes.truncnorm.TruncGenNorm(**kwargs)[source]

Bases: phuzzy.shapes.FuzzyNumber

Truncated generalized normal distibuted membership function

__init__(**kwargs)[source]

create a TruncNorm object

Parameters:kwargs
TruncGenNorm(alpha0=[1, 3], alpha1=None, number_of_alpha_levels=17, beta=3)
__module__ = 'phuzzy.shapes.truncnorm'
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

distr
loc
mean
scale
std
class phuzzy.shapes.truncnorm.TruncNorm(**kwargs)[source]

Bases: phuzzy.shapes.FuzzyNumber

Normal distibuted membership function

__init__(**kwargs)[source]

create a TruncNorm object

Parameters:kwargs
TruncNorm(alpha0=[1, 3], alpha1=None, number_of_alpha_levels=17)
__module__ = 'phuzzy.shapes.truncnorm'
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

distr

calculate truncated normal distribution

Returns:distribution object
loc

mean value

Return type:float
Returns:mean value aka location
mean

mean value

Return type:float
Returns:mean value aka location
scale

standard deviation

Return type:float
Returns:standard deviation
std

standard deviation

Return type:float
Returns:standard deviation

phuzzy.mpl module

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

Bases: phuzzy.shapes.FuzzyNumber, phuzzy.mpl.MPL_Mixin

Uniform fuzzy number with matplotlib mixin

__init__(**kwargs)[source]

base fuzzy number

Parameters:kwargs
__module__ = 'phuzzy.mpl'
class phuzzy.mpl.MPL_Mixin[source]
__module__ = 'phuzzy.mpl'
plot(ax=None, filepath=None, show=False, xlim=None, labels=True, title=False, ppf=None)[source]

plots fuzzy number with mpl

vplot(ax=None, filepath=None, show=False, xlim=None, labels=True, title=False, ppf=None)[source]

plots fuzzy number with mpl

class phuzzy.mpl.Superellipse(**kwargs)[source]

Bases: phuzzy.shapes.superellipse.Superellipse, phuzzy.mpl.MPL_Mixin

Superellipse fuzzy number with matplotlib mixin

__init__(**kwargs)[source]

superelliptic fuzzy number

Parameters:kwargs
Superellipse(alpha0=[1, 2], alpha1=None, m=2, n=None, number_of_alpha_levels=17)
__module__ = 'phuzzy.mpl'
class phuzzy.mpl.Trapezoid(**kwargs)[source]

Bases: phuzzy.shapes.Trapezoid, phuzzy.mpl.MPL_Mixin

Trapezoid fuzzy number with matplotlib mixin

__init__(**kwargs)[source]

base fuzzy number

Parameters:kwargs
__module__ = 'phuzzy.mpl'
class phuzzy.mpl.Triangle(**kwargs)[source]

Bases: phuzzy.shapes.Triangle, phuzzy.mpl.MPL_Mixin

Triangle fuzzy number with matplotlib mixin

__init__(**kwargs)[source]

base fuzzy number

Parameters:kwargs
__module__ = 'phuzzy.mpl'
class phuzzy.mpl.TruncGenNorm(**kwargs)[source]

Bases: phuzzy.shapes.truncnorm.TruncGenNorm, phuzzy.mpl.MPL_Mixin

Truncates general normal fuzzy number with matplotlib mixin

__init__(**kwargs)[source]

create a TruncNorm object

Parameters:kwargs
TruncGenNorm(alpha0=[1, 3], alpha1=None, number_of_alpha_levels=17, beta=3)
__module__ = 'phuzzy.mpl'
class phuzzy.mpl.TruncNorm(**kwargs)[source]

Bases: phuzzy.shapes.truncnorm.TruncNorm, phuzzy.mpl.MPL_Mixin

TruncNorm fuzzy number with matplotlib mixin

__init__(**kwargs)[source]

create a TruncNorm object

Parameters:kwargs
TruncNorm(alpha0=[1, 3], alpha1=None, number_of_alpha_levels=17)
__module__ = 'phuzzy.mpl'
class phuzzy.mpl.Uniform(**kwargs)[source]

Bases: phuzzy.shapes.Uniform, phuzzy.mpl.MPL_Mixin

Uniform fuzzy number with matplotlib mixin

__init__(**kwargs)[source]

base fuzzy number

Parameters:kwargs
__module__ = 'phuzzy.mpl'
phuzzy.mpl.extend_instance(obj, cls)[source]

Apply mixins to a class instance after creation

phuzzy.mpl.mix_mpl(obj)[source]

Contributing

Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.

You can contribute in many ways:

Types of Contributions

Report Bugs

Report bugs at https://github.com/lepy/phuzzy/issues.

If you are reporting a bug, please include:

  • Your operating system name and version.
  • Any details about your local setup that might be helpful in troubleshooting.
  • Detailed steps to reproduce the bug.

Fix Bugs

Look through the GitHub issues for bugs. Anything tagged with “bug” and “help wanted” is open to whoever wants to implement it.

Implement Features

Look through the GitHub issues for features. Anything tagged with “enhancement” and “help wanted” is open to whoever wants to implement it.

Write Documentation

phuzzy could always use more documentation, whether as part of the official phuzzy docs, in docstrings, or even on the web in blog posts, articles, and such.

Submit Feedback

The best way to send feedback is to file an issue at https://github.com/lepy/phuzzy/issues.

If you are proposing a feature:

  • Explain in detail how it would work.
  • Keep the scope as narrow as possible, to make it easier to implement.
  • Remember that this is a volunteer-driven project, and that contributions are welcome :)

Get Started!

Ready to contribute? Here’s how to set up phuzzy for local development.

  1. Fork the phuzzy repo on GitHub.

  2. Clone your fork locally:

    $ git clone git@github.com:your_name_here/phuzzy.git
    
  3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:

    $ mkvirtualenv phuzzy
    $ cd phuzzy/
    $ python setup.py develop
    
  4. Create a branch for local development:

    $ git checkout -b name-of-your-bugfix-or-feature
    

    Now you can make your changes locally.

  5. When you’re done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:

    $ flake8 phuzzy tests
    $ python setup.py test or py.test
    $ tox
    

    To get flake8 and tox, just pip install them into your virtualenv.

  6. Commit your changes and push your branch to GitHub:

    $ git add .
    $ git commit -m "Your detailed description of your changes."
    $ git push origin name-of-your-bugfix-or-feature
    
  7. Submit a pull request through the GitHub website.

Pull Request Guidelines

Before you submit a pull request, check that it meets these guidelines:

  1. The pull request should include tests.
  2. If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.
  3. The pull request should work for Python 2.7, 3.4, 3.5 and 3.6, and for PyPy. Check https://travis-ci.org/lepy/phuzzy/pull_requests and make sure that the tests pass for all supported Python versions.

Tips

To run a subset of tests:

$ py.test tests.test_phuzzy

Deploying

A reminder for the maintainers on how to deploy. Make sure all your changes are committed (including an entry in HISTORY.rst). Then run:

$ git push
$ git push --tags

Travis will then deploy to PyPI if tests pass.

Credits

Development Lead

Contributors

None yet. Why not be the first?

History

0.4.0 (2018-04-13)

  • First release on PyPI.

0.5.0 (2018-04-16)

  • rename FuzzyNumber.df.columns = [“alpha”, “l”, “r”]
  • add operators __add__
  • add operators __sub__
  • add operators __mul__
  • add operators __div__

0.6.0 (2018-04-19)

  • add operators __radd__, __rsub__, __rmul__, __rdiv__, __truediv__
  • add operators __neg__, __abs__, __min__, __max__, __mean__
  • add operators __lt__, __gt__, __eq__, __contain__

0.7.0 (2018-04-24)

  • add plots
  • add approximated function evaluation
lsdyna

Indices and tables