skfuzzy
¶scikit-fuzzy (a.k.a. skfuzzy): Fuzzy Logic Toolbox for Python.
This package implements many useful tools and functions for computation and projects involving fuzzy logic, also known as grey logic.
Most of the functionality is actually located in subpackages, but like numpy we bring most of the core functionality into the base namespace.
>>> import skfuzzy as fuzz
skfuzzy.addval (interval1, interval2) |
Add intervals interval1 and interval2. |
skfuzzy.arglcut (ms, lambdacut) |
Determines the subset of indices mi of the elements in an N-point resultant fuzzy membership sequence ms that have a grade of membership >= lambdacut. |
skfuzzy.cartadd (x, y) |
Cartesian addition of fuzzy membership vectors using the algebraic method. |
skfuzzy.cartprod (x, y) |
Cartesian product of two fuzzy membership vectors. |
skfuzzy.centroid (x, mfx) |
Defuzzification using centroid (center of gravity) method. |
skfuzzy.classic_relation (a, b) |
Determine the classic relation matrix, R , between two fuzzy sets. |
skfuzzy.cmeans (data, c, m, error, maxiter[, ...]) |
Fuzzy c-means clustering algorithm [1]. |
skfuzzy.cmeans_predict (test_data, ...[, ...]) |
Prediction of new data in given a trained fuzzy c-means framework [1]. |
skfuzzy.continuous_to_discrete (a, b, ...) |
Converts a continuous-time system to its equivalent discrete-time version. |
skfuzzy.contrast (arr[, amount, split, normalize]) |
General contrast booster or diffuser of normalized array-like data. |
skfuzzy.dcentroid (x, mfx, x0) |
Defuzzification using a differential centroidal method about x0. |
skfuzzy.defocus_local_means (im) |
Defocusing non-normalized image im using local arithmatic mean. |
skfuzzy.defuzz (x, mfx, mode) |
Defuzzification of a membership function, returning a defuzzified value of the function at x, using various defuzzification methods. |
skfuzzy.divval (interval1, interval2) |
Divide interval2 into interval1 , by inversion and multiplication. |
skfuzzy.dsigmf (x, b1, c1, b2, c2) |
Difference of two fuzzy sigmoid membership functions. |
skfuzzy.dsw_add (x, mfx, y, mfy, n) |
Add two fuzzy variables together using the restricted DSW method [1]. |
skfuzzy.dsw_div (x, mfx, y, mfy, n) |
Divide one fuzzy variable by another using the restricted DSW method [1]. |
skfuzzy.dsw_mult (x, mfx, y, mfy, n) |
Multiply two fuzzy variables using the restricted DSW method [1]. |
skfuzzy.dsw_sub (x, mfx, y, mfy, n) |
Subtract a fuzzy variable from another by the restricted DSW method [1]. |
skfuzzy.fire1d (x[, l1, l2]) |
1-D filtering using Fuzzy Inference Ruled by Else-action (FIRE) [1]. |
skfuzzy.fire2d (im[, l1, l2, fuzzyresolution]) |
2-D filtering using Fuzzy Inference Ruled by Else-action (FIRE) [1]. |
skfuzzy.fuzzy_add (x, a, y, b) |
Add fuzzy set a to fuzzy set b . |
skfuzzy.fuzzy_and (x, mfx, y, mfy) |
Fuzzy AND operator, a.k.a. |
skfuzzy.fuzzy_compare (q) |
Determine the comparison matrix, c , based on the fuzzy pairwise comparison matrix, q , using Shimura’s special relativity formula. |
skfuzzy.fuzzy_div (x, a, y, b) |
Divide fuzzy set b into fuzzy set a . |
skfuzzy.fuzzy_min (x, a, y, b) |
Find minimum between fuzzy set a fuzzy set b . |
skfuzzy.fuzzy_mult (x, a, y, b) |
Multiplies fuzzy set a and fuzzy set b . |
skfuzzy.fuzzy_not (mfx) |
Fuzzy NOT operator, a.k.a. |
skfuzzy.fuzzy_or (x, mfx, y, mfy) |
Fuzzy OR operator, a.k.a. |
skfuzzy.fuzzy_similarity (ai, b[, mode]) |
The fuzzy similarity between set ai and observation set b . |
skfuzzy.fuzzy_sub (x, a, y, b) |
Subtract fuzzy set b from fuzzy set a . |
skfuzzy.gauss2mf (x, mean1, sigma1, mean2, sigma2) |
Gaussian fuzzy membership function of two combined Gaussians. |
skfuzzy.gaussmf (x, mean, sigma) |
Gaussian fuzzy membership function. |
skfuzzy.gbellmf (x, a, b, c) |
Generalized Bell function fuzzy membership generator. |
skfuzzy.inner_product (a, b) |
Inner product (dot product) of two fuzzy sets. |
skfuzzy.interp10 (x) |
Utility function which conducts linear interpolation of any rank-1 array. |
skfuzzy.interp_membership (x, xmf, xx) |
Find the degree of membership u(xx) for a given value of x = xx . |
skfuzzy.interp_universe (x, xmf, y) |
Find interpolated universe value(s) for a given fuzzy membership value. |
skfuzzy.lambda_cut (ms, lcut) |
The crisp (binary) lambda-cut set of the membership sequence ms with membership >= lcut. |
skfuzzy.lambda_cut_boundaries (x, mfx, lambdacut) |
Find exact boundaries where mfx crosses lambdacut using interpolation. |
skfuzzy.lambda_cut_series (x, mfx, n) |
Determine a series of lambda-cuts in a sweep from 0+ to 1.0 in n steps. |
skfuzzy.maxmin_composition (s, r) |
The max-min composition t of two fuzzy relation matrices. |
skfuzzy.maxprod_composition (s, r) |
The max-product composition t of two fuzzy relation matrices. |
skfuzzy.modus_ponens (a, b, ap[, c]) |
Generalized modus ponens deduction to make approximate reasoning in a rules-base system. |
skfuzzy.multval (interval1, interval2) |
Multiply intervals interval1 and interval2. |
skfuzzy.nmse (known, degraded) |
Computes the percent normalized mean square error (NMSE %) between known and degraded arrays. |
skfuzzy.outer_product (a, b) |
Outer product of two fuzzy sets. |
skfuzzy.pad (array, pad_width[, mode]) |
Pads an array. |
skfuzzy.partial_dmf (x, mf_name, ...) |
Calculate the partial derivative of a specified membership function. |
skfuzzy.piecemf (x, abc) |
Piecewise linear membership function (particularly used in FIRE filters). |
skfuzzy.pimf (x, a, b, c, d) |
Pi-function fuzzy membership generator. |
skfuzzy.psigmf (x, b1, c1, b2, c2) |
Product of two sigmoid membership functions. |
skfuzzy.relation_min (a, b) |
Determine fuzzy relation matrix R using Mamdani implication for the fuzzy antecedent a and consequent b inputs. |
skfuzzy.relation_product (a, b) |
Determine the fuzzy relation matrix, R , using product implication for the fuzzy antecedent a and the fuzzy consequent b . |
skfuzzy.scaleval (q, interval) |
Multiply scalar q with interval interval . |
skfuzzy.sigmf (x, b, c) |
The basic sigmoid membership function generator. |
skfuzzy.sigmoid (x, power[, split]) |
Intensify grayscale values in an array using a sigmoid function. |
skfuzzy.smf (x, a, b) |
S-function fuzzy membership generator. |
skfuzzy.subval (interval1, interval2) |
Subtract interval interval2 from interval interval1. |
skfuzzy.test ([doctest, verbose]) |
Run all unit tests. |
skfuzzy.trapmf (x, abcd) |
Trapezoidal membership function generator. |
skfuzzy.trimf (x, abc) |
Triangular membership function generator. |
skfuzzy.view_as_blocks (arr_in, block_shape) |
Block view of the input n-dimensional array (using re-striding). |
skfuzzy.view_as_windows (arr_in, window_shape) |
Rolling window view of the input n-dimensional array. |
skfuzzy.zmf (x, a, b) |
Z-function fuzzy membership generator. |
skfuzzy.
addval
(interval1, interval2)[source]¶Add intervals interval1 and interval2.
Parameters: | interval1 : 2-element iterable
interval2 : 2-element iterable
|
---|---|
Returns: | Z : 2-element array
|
skfuzzy.
arglcut
(ms, lambdacut)[source]¶Determines the subset of indices mi of the elements in an N-point resultant fuzzy membership sequence ms that have a grade of membership >= lambdacut.
Parameters: | ms : 1d array
lambdacut : float
|
---|---|
Returns: | lidx : 1d array
|
Notes
This is a convenience function for np.nonzero(lambdacut <= ms) and only half of the indexing operation that can be more concisely accomplished via:
ms[lambdacut <= ms]
skfuzzy.
cartadd
(x, y)[source]¶Cartesian addition of fuzzy membership vectors using the algebraic method.
Parameters: | x : 1D array or iterable
y : 1D array or iterable
|
---|---|
Returns: | z : 2D array
|
skfuzzy.
cartprod
(x, y)[source]¶Cartesian product of two fuzzy membership vectors. Uses min()
.
Parameters: | x : 1D array or iterable
y : 1D array or iterable
|
---|---|
Returns: | z : 2D array
|
skfuzzy.
classic_relation
(a, b)[source]¶Determine the classic relation matrix, R
, between two fuzzy sets.
Parameters: | a : 1D array or iterable
b : 1D array or iterable
|
---|---|
Returns: | R : 2D array
|
Notes
The classic relation is defined as:
r = [a x b] U [(1 - a) x ones(1, N)],
where x
represents a cartesian product and N
is len(b
).
skfuzzy.
cmeans
(data, c, m, error, maxiter, init=None, seed=None)[source]¶Fuzzy c-means clustering algorithm [1].
Parameters: | data : 2d array, size (S, N)
c : int
m : float
error : float
maxiter : int
init : 2d array, size (S, N)
seed : int
|
---|---|
Returns: | cntr : 2d array, size (S, c)
u : 2d array, (S, N)
u0 : 2d array, (S, N)
d : 2d array, (S, N)
jm : 1d array, length P
p : int
fpc : float
|
Notes
The algorithm implemented is from Ross et al. [R11].
Fuzzy C-Means has a known problem with high dimensionality datasets, where the majority of cluster centers are pulled into the overall center of gravity. If you are clustering data with very high dimensionality and encounter this issue, another clustering method may be required. For more information and the theory behind this, see Winkler et al. [R12].
References
[R11] | (1, 2) Ross, Timothy J. Fuzzy Logic With Engineering Applications, 3rd ed. Wiley. 2010. ISBN 978-0-470-74376-8 pp 352-353, eq 10.28 - 10.35. |
[R12] | (1, 2) Winkler, R., Klawonn, F., & Kruse, R. Fuzzy c-means in high dimensional spaces. 2012. Contemporary Theory and Pragmatic Approaches in Fuzzy Computing Utilization, 1. |
skfuzzy.
cmeans_predict
(test_data, cntr_trained, m, error, maxiter, init=None, seed=None)[source]¶Prediction of new data in given a trained fuzzy c-means framework [1].
Parameters: | test_data : 2d array, size (S, N)
cntr_trained : 2d array, size (S, c)
m : float
error : float
maxiter : int
init : 2d array, size (S, N)
seed : int
|
---|---|
Returns: | u : 2d array, (S, N)
u0 : 2d array, (S, N)
d : 2d array, (S, N)
jm : 1d array, length P
p : int
fpc : float
|
Notes
Ross et al. [R13] did not include a prediction algorithm to go along with fuzzy c-means. This prediction algorithm works by repeating the clustering with fixed centers, then efficiently finds the fuzzy membership at all points.
References
[R13] | (1, 2) Ross, Timothy J. Fuzzy Logic With Engineering Applications, 3rd ed. Wiley. 2010. ISBN 978-0-470-74376-8 pp 352-353, eq 10.28 - 10.35. |
skfuzzy.
continuous_to_discrete
(a, b, sampling_rate)[source]¶Converts a continuous-time system to its equivalent discrete-time version.
Parameters: | a : (N, N) array of floats
b : (N,) or (N, 1) array of floats
sampling_rate : float
|
---|---|
Returns: | phi : (N, N) array of floats
gamma : (N,) or (N, 1) array of floats
|
skfuzzy.
contrast
(arr, amount=0.2, split=0.5, normalize=True)[source]¶General contrast booster or diffuser of normalized array-like data.
Parameters: | arr : ndarray
amount : float or length-2 iterable of floats
split : float
normalize : bool, default True
|
---|---|
Returns: | focused : ndarray
|
See also
Notes
The result of this algorithm is like applying a Curves adjustment in the GIMP or Photoshop.
Algorithm for curves adjustment at a given pixel, x, is given by:
| split * (x/split)^below, 0 <= x <= split
y(x) = |
| 1 - (1-split) * ((1-x) / (1-split))^above, split < x <= 1.0
skfuzzy.
dcentroid
(x, mfx, x0)[source]¶Defuzzification using a differential centroidal method about x0.
Parameters: | x : 1d array or iterable
mfx : 1d array or iterable
x0 : float
|
---|---|
Returns: | u : 1d array
|
skfuzzy.
defocus_local_means
(im)[source]¶Defocusing non-normalized image im
using local arithmatic mean.
Parameters: | im : ndarray
|
---|---|
Returns: | D : ndarray of floats, same shape as
|
Notes
Reduces ‘salt & pepper’ noise in a quantized image by taking the
arithmatic mean of the 4-connected neighborhood. So the new value at
X
, given the 4-connected neighborhood:
+---+
| c |
+---+---+---+
| a | X | b |
+---+---+---+
| d |
+---+
is defined by the relationship:
X = 0.25 * (a + b + c + d)
skfuzzy.
defuzz
(x, mfx, mode)[source]¶Defuzzification of a membership function, returning a defuzzified value of the function at x, using various defuzzification methods.
Parameters: | x : 1d array or iterable, length N
mfx : 1d array of iterable, length N
mode : string
|
---|---|
Returns: | u : float or int
|
skfuzzy.
dsigmf
(x, b1, c1, b2, c2)[source]¶Difference of two fuzzy sigmoid membership functions.
Parameters: | x : 1d array
b1 : float
c1 : float
b2 : float
c2 : float
|
---|---|
Returns: | y : 1d array
|
skfuzzy.
dsw_add
(x, mfx, y, mfy, n)[source]¶Add two fuzzy variables together using the restricted DSW method [1].
Parameters: | x : 1d array
mfx : 1d array
y : 1d array
mfy : 1d array
n : int
|
---|---|
Returns: | z : 1d array
mfz : 1d array
|
Notes
The Dong, Shah, and Wong (DSW) method requires convex fuzzy membership
functions. The dsw_*
functions return results similar to Matplotlib’s
fuzarith
function.
References
[R14] | W. Dong and H. Shah and F. Wong, Fuzzy computations in risk and decision analysis, Civ Eng Syst, 2, 1985, pp 201-208. |
skfuzzy.
dsw_div
(x, mfx, y, mfy, n)[source]¶Divide one fuzzy variable by another using the restricted DSW method [1].
Parameters: | x : 1d array
mfx : 1d array
y : 1d array
mfy : 1d array
n : int
|
---|---|
Returns: | z : 1d array
mfz : 1d array
|
Notes
The Dong, Shah, and Wong (DSW) method requires convex fuzzy membership
functions. The dsw_*
functions return results similar to Matplotlib’s
fuzarith
function.
References
[R15] | W. Dong and H. Shah and F. Wong, Fuzzy computations in risk and decision analysis, Civ Eng Syst, 2, 1985, pp 201-208. |
skfuzzy.
dsw_mult
(x, mfx, y, mfy, n)[source]¶Multiply two fuzzy variables using the restricted DSW method [1].
Parameters: | x : 1d array
mfx : 1d array
y : 1d array
mfy : 1d array
n : int
|
---|---|
Returns: | z : 1d array
mfz : 1d array
|
Notes
The Dong, Shah, and Wong (DSW) method requires convex fuzzy membership
functions. The dsw_*
functions return results similar to Matplotlib’s
fuzarith
function.
References
[R16] | W. Dong and H. Shah and F. Wong, Fuzzy computations in risk and decision analysis, Civ Eng Syst, 2, 1985, pp 201-208. |
skfuzzy.
dsw_sub
(x, mfx, y, mfy, n)[source]¶Subtract a fuzzy variable from another by the restricted DSW method [1].
Parameters: | x : 1d array
mfx : 1d array
y : 1d array
mfy : 1d array
n : int
|
---|---|
Returns: | z : 1d array
mfz : 1d array
|
Notes
The Dong, Shah, and Wong (DSW) method requires convex fuzzy membership
functions. The dsw_*
functions return results similar to Matplotlib’s
fuzarith
function.
References
[R17] | W. Dong and H. Shah and F. Wong, Fuzzy computations in risk and decision analysis, Civ Eng Syst, 2, 1985, pp 201-208. |
skfuzzy.
fire1d
(x, l1=0, l2=1)[source]¶1-D filtering using Fuzzy Inference Ruled by Else-action (FIRE) [1].
FIRE filtering is nonlinear, and is specifically designed to remove impulse (salt and pepper) noise.
Parameters: | x : 1d array or iterable
l1 : float
l2 : float
|
---|---|
Returns: | y : 1d array
|
Notes
Filtering occurs for l1 < |x| < l2
; for |x| < l1
there is no
effect.
References
[R18] | Fabrizio Russo, Fuzzy Filtering of Noisy Sensor Data, IEEE Instrumentation and Measurement Technology Conference, Brussels, Belgium, June 4 - 6, 1996, pp 1281 - 1285. |
skfuzzy.
fire2d
(im, l1=0, l2=255, fuzzyresolution=1)[source]¶2-D filtering using Fuzzy Inference Ruled by Else-action (FIRE) [1].
FIRE filtering is nonlinear, and is specifically designed to remove impulse (salt and pepper) noise.
Parameters: | I : 2d array
l1 : float
l2 : float
fuzzyresolution : float, default = 1
|
---|---|
Returns: | J : 2d array
|
Notes
Filtering occurs for l1 < |x| < l2
; outside this range the data is
unaffected.
References
[R19] | Fabrizio Russo, Fuzzy Filtering of Noisy Sensor Data, IEEE Instrumentation and Measurement Technology Conference, Brussels, Belgium, June 4 - 6, 1996, pp 1281 - 1285. |
skfuzzy.
fuzzy_add
(x, a, y, b)[source]¶Add fuzzy set a
to fuzzy set b
.
Parameters: | x : 1d array, length N
a : 1d array, length N
y : 1d array, length M
b : 1d array, length M
|
---|---|
Returns: | z : 1d array
mfz : 1d array
|
Notes
Uses Zadeh’s Extension Principle as described in Ross, Fuzzy Logic with Engineering Applications (2010), pp. 414, Eq. 12.17.
If these results are unexpected and your membership functions are convex,
consider trying the skfuzzy.dsw_*
functions for fuzzy mathematics
using interval arithmetic via the restricted Dong, Shah, and Wong method.
skfuzzy.
fuzzy_and
(x, mfx, y, mfy)[source]¶Fuzzy AND operator, a.k.a. the intersection of two fuzzy sets.
Parameters: | x : 1d array
mfx : 1d array
y : 1d array
mfy : 1d array
|
---|---|
Returns: | z : 1d array
mfz : 1d array
|
skfuzzy.
fuzzy_div
(x, a, y, b)[source]¶Divide fuzzy set b
into fuzzy set a
.
Parameters: | x : 1d array, length N
a : 1d array, length N
y : 1d array, length M
b : 1d array, length M
|
---|---|
Returns: | z : 1d array
mfz : 1d array
|
Notes
Uses Zadeh’s Extension Principle from Ross, Fuzzy Logic w/Engineering Applications, (2010), pp.414, Eq. 12.17.
If these results are unexpected and your membership functions are convex,
consider trying the skfuzzy.dsw_*
functions for fuzzy mathematics
using interval arithmetic via the restricted Dong, Shah, and Wong method.
skfuzzy.
fuzzy_min
(x, a, y, b)[source]¶Find minimum between fuzzy set a
fuzzy set b
.
Parameters: | x : 1d array, length N
a : 1d array, length N
y : 1d array, length M
b : 1d array, length M
|
---|---|
Returns: | z : 1d array
mfz : 1d array
|
Notes
Uses Zadeh’s Extension Principle from Ross, Fuzzy Logic w/Engineering Applications, (2010), pp.414, Eq. 12.17.
If these results are unexpected and your membership functions are convex,
consider trying the skfuzzy.dsw_*
functions for fuzzy mathematics
using interval arithmetic via the restricted Dong, Shah, and Wong method.
skfuzzy.
fuzzy_mult
(x, a, y, b)[source]¶Multiplies fuzzy set a
and fuzzy set b
.
Parameters: | x : 1d array, length N
A : 1d array, length N
y : 1d array, length M
b : 1d array, length M
|
---|---|
Returns: | z : 1d array
mfz : 1d array
|
Notes
Uses Zadeh’s Extension Principle from Ross, Fuzzy Logic w/Engineering Applications, (2010), pp.414, Eq. 12.17.
If these results are unexpected and your membership functions are convex,
consider trying the skfuzzy.dsw_*
functions for fuzzy mathematics
using interval arithmetic via the restricted Dong, Shah, and Wong method.
skfuzzy.
fuzzy_not
(mfx)[source]¶Fuzzy NOT operator, a.k.a. complement of a fuzzy set.
Parameters: | mfx : 1d array
|
---|---|
Returns: | mfz : 1d array
|
Notes
This operation does not require a universe variable, because the complement is defined for a single set. The output remains defined on the same universe.
skfuzzy.
fuzzy_or
(x, mfx, y, mfy)[source]¶Fuzzy OR operator, a.k.a. union of two fuzzy sets.
Parameters: | x : 1d array
mfx : 1d array
y : 1d array
mfy : 1d array
|
---|---|
Returns: | z : 1d array
mfz : 1d array
|
skfuzzy.
fuzzy_similarity
(ai, b, mode='min')[source]¶The fuzzy similarity between set ai
and observation set b
.
Parameters: | ai : 1d array
b : 1d array
mode : string
|
---|---|
Returns: | s : float
|
skfuzzy.
fuzzy_sub
(x, a, y, b)[source]¶Subtract fuzzy set b
from fuzzy set a
.
Parameters: | x : 1d array, length N
A : 1d array, length N
y : 1d array, length M
b : 1d array, length M
|
---|---|
Returns: | z : 1d array
mfz : 1d array
|
Notes
Uses Zadeh’s Extension Principle from Ross, Fuzzy Logic w/Engineering Applications, (2010), pp.414, Eq. 12.17.
If these results are unexpected and your membership functions are convex,
consider trying the skfuzzy.dsw_*
functions for fuzzy mathematics
using interval arithmetic via the restricted Dong, Shah, and Wong method.
skfuzzy.
gauss2mf
(x, mean1, sigma1, mean2, sigma2)[source]¶Gaussian fuzzy membership function of two combined Gaussians.
Parameters: | x : 1d array or iterable
mean1 : float
sigma1 : float
mean2 : float
sigma2 : float
|
---|---|
Returns: | y : 1d array
|
skfuzzy.
gaussmf
(x, mean, sigma)[source]¶Gaussian fuzzy membership function.
Parameters: | x : 1d array or iterable
mean : float
sigma : float
|
---|---|
Returns: | y : 1d array
|
skfuzzy.
gbellmf
(x, a, b, c)[source]¶Generalized Bell function fuzzy membership generator.
Parameters: | x : 1d array
a : float
b : float
c : float
|
---|---|
Returns: | y : 1d array
|
Notes
Definition of Generalized Bell function is:
y(x) = 1 / (1 + abs([x - c] / a) ** [2 * b])
skfuzzy.
interp_membership
(x, xmf, xx)[source]¶Find the degree of membership u(xx)
for a given value of x = xx
.
Parameters: | x : 1d array
xmf : 1d array
xx : float
|
---|---|
Returns: | xxmf : float
|
Notes
For use in Fuzzy Logic, where an interpolated discrete membership function
u(x) for discrete values of x on the universe of x
is given. Then,
consider a new value x = xx, which does not correspond to any discrete
values of x
. This function computes the membership value u(xx)
corresponding to the value xx
using linear interpolation.
skfuzzy.
interp_universe
(x, xmf, y)[source]¶Find interpolated universe value(s) for a given fuzzy membership value.
Parameters: | x : 1d array
xmf : 1d array
y : float
|
---|---|
Returns: | xx : list
|
Notes
For use in Fuzzy Logic, where a membership function level y
is given.
Consider there is some value (or set of values) xx
for which
u(xx) == y
is true, though xx
may not correspond to any discrete
values on x
. This function computes the value (or values) of xx
such that u(xx) == y
using linear interpolation.
skfuzzy.
lambda_cut
(ms, lcut)[source]¶The crisp (binary) lambda-cut set of the membership sequence ms with membership >= lcut.
Parameters: | ms : 1d array
lcut : float
|
---|---|
Returns: | mlambda : 1d array
|
skfuzzy.
lambda_cut_boundaries
(x, mfx, lambdacut)[source]¶Find exact boundaries where mfx crosses lambdacut using interpolation.
Parameters: | x : 1d array, length N
mfx : 1d array, length N
lambdacut : float
|
---|---|
Returns: | boundaries : 1d array
|
Notes
The values returned by this function can be thought of as intersections
between a hypothetical horizontal line at lambdacut
and the membership
function mfx
. This function assumes the end values of mfx
continue
on forever in positive and negative directions. This means there will NOT
be crossings found exactly at the bounds of x
unless the value of
mfx
at the boundary is exactly lambdacut
.
skfuzzy.
lambda_cut_series
(x, mfx, n)[source]¶Determine a series of lambda-cuts in a sweep from 0+ to 1.0 in n steps.
Parameters: | x : 1d array
mfx : 1d array
n : int
|
---|---|
Returns: | z : 2d array, (n, 3)
|
skfuzzy.
modus_ponens
(a, b, ap, c=None)[source]¶Generalized modus ponens deduction to make approximate reasoning in a rules-base system.
Parameters: | a : 1d array
b : 1d array
ap : 1d array
c : 1d array, OPTIONAL
|
---|---|
Returns: | R : 2d array
bp : 1d array
|
skfuzzy.
nmse
(known, degraded)[source]¶Computes the percent normalized mean square error (NMSE %) between known and degraded arrays.
Parameters: | known : ndarray
degraded : ndarray, same shape as known
|
---|---|
Returns: | nmse : float
|
Notes
Usually used to compare a true/original image to a degraded version. For this calculation, which image is provided as true and which degraded does not matter.
skfuzzy.
pad
(array, pad_width, mode=None, **kwargs)[source]¶Pads an array.
Parameters: | array : array_like of rank N
pad_width : {sequence, array_like, int}
mode : str or function
stat_length : sequence or int, optional
constant_values : sequence or int, optional
end_values : sequence or int, optional
reflect_type : {‘even’, ‘odd’}, optional
|
---|---|
Returns: | pad : ndarray
|
Notes
This function exists in NumPy >= 1.7.0, but is included in
scikit-fuzzy
for backwards compatibility with earlier versions.
For an array with rank greater than 1, some of the padding of later axes is calculated from padding of previous axes. This is easiest to think about with a rank 2 array where the corners of the padded array are calculated by using padded values from the first axis.
The padding function, if used, should return a rank 1 array equal in length to the vector argument with padded values replaced. It has the following signature:
padding_func(vector, iaxis_pad_width, iaxis, **kwargs)
where
- vector : ndarray
- A rank 1 array already padded with zeros. Padded values are vector[:pad_tuple[0]] and vector[-pad_tuple[1]:].
- iaxis_pad_width : tuple
- A 2-tuple of ints, iaxis_pad_width[0] represents the number of values padded at the beginning of vector where iaxis_pad_width[1] represents the number of values padded at the end of vector.
- iaxis : int
- The axis currently being calculated.
- kwargs : misc
- Any keyword arguments the function requires.
Examples
>>> a = [1, 2, 3, 4, 5]
>>> fuzz.pad(a, (2,3), 'constant', constant_values=(4, 6))
array([4, 4, 1, 2, 3, 4, 5, 6, 6, 6])
>>> fuzz.pad(a, (2, 3), 'edge')
array([1, 1, 1, 2, 3, 4, 5, 5, 5, 5])
>>> fuzz.pad(a, (2, 3), 'linear_ramp', end_values=(5, -4))
array([ 5, 3, 1, 2, 3, 4, 5, 2, -1, -4])
>>> fuzz.pad(a, (2,), 'maximum')
array([5, 5, 1, 2, 3, 4, 5, 5, 5])
>>> fuzz.pad(a, (2,), 'mean')
array([3, 3, 1, 2, 3, 4, 5, 3, 3])
>>> fuzz.pad(a, (2,), 'median')
array([3, 3, 1, 2, 3, 4, 5, 3, 3])
>>> a = [[1, 2], [3, 4]]
>>> fuzz.pad(a, ((3, 2), (2, 3)), 'minimum')
array([[1, 1, 1, 2, 1, 1, 1],
[1, 1, 1, 2, 1, 1, 1],
[1, 1, 1, 2, 1, 1, 1],
[1, 1, 1, 2, 1, 1, 1],
[3, 3, 3, 4, 3, 3, 3],
[1, 1, 1, 2, 1, 1, 1],
[1, 1, 1, 2, 1, 1, 1]])
>>> a = [1, 2, 3, 4, 5]
>>> fuzz.pad(a, (2, 3), 'reflect')
array([3, 2, 1, 2, 3, 4, 5, 4, 3, 2])
>>> fuzz.pad(a, (2, 3), 'reflect', reflect_type='odd')
array([-1, 0, 1, 2, 3, 4, 5, 6, 7, 8])
>>> fuzz.pad(a, (2, 3), 'symmetric')
array([2, 1, 1, 2, 3, 4, 5, 5, 4, 3])
>>> fuzz.pad(a, (2, 3), 'symmetric', reflect_type='odd')
array([0, 1, 1, 2, 3, 4, 5, 5, 6, 7])
>>> fuzz.pad(a, (2, 3), 'wrap')
array([4, 5, 1, 2, 3, 4, 5, 1, 2, 3])
>>> def padwithtens(vector, pad_width, iaxis, kwargs):
... vector[:pad_width[0]] = 10
... vector[-pad_width[1]:] = 10
... return vector
>>> a = np.arange(6)
>>> a = a.reshape((2, 3))
>>> fuzz.pad(a, 2, padwithtens)
array([[10, 10, 10, 10, 10, 10, 10],
[10, 10, 10, 10, 10, 10, 10],
[10, 10, 0, 1, 2, 10, 10],
[10, 10, 3, 4, 5, 10, 10],
[10, 10, 10, 10, 10, 10, 10],
[10, 10, 10, 10, 10, 10, 10]])
skfuzzy.
partial_dmf
(x, mf_name, mf_parameter_dict, partial_parameter)[source]¶Calculate the partial derivative of a specified membership function.
Parameters: | x : float
mf_name : string
mf_parameter_dict : dict
partial_parameter : string
|
---|---|
Returns: | d : float
|
Notes
Partial derivatives of fuzzy membership functions are only meaningful for continuous functions. Triangular, trapezoidal designs have no partial derivatives to calculate. The following
skfuzzy.
piecemf
(x, abc)[source]¶Piecewise linear membership function (particularly used in FIRE filters).
Parameters: | x : 1d array
abc : 1d array, length 3
|
---|---|
Returns: | y : 1d array
|
Notes
skfuzzy.
pimf
(x, a, b, c, d)[source]¶Pi-function fuzzy membership generator.
Parameters: | x : 1d array
a : float
b : float
c : float
d : float
|
---|---|
Returns: | y : 1d array
|
Notes
This is equivalently a product of smf and zmf.
skfuzzy.
psigmf
(x, b1, c1, b2, c2)[source]¶Product of two sigmoid membership functions.
Parameters: | x : 1d array
b1 : float
c1 : float
b2 : float
c2 : float
|
---|---|
Returns: | y : 1d array
|
Notes
For a smoothed rect-like function, c2 < 0 < c1. For its inverse (zero in middle, one at edges) c1 < 0 < c2.
skfuzzy.
relation_min
(a, b)[source]¶Determine fuzzy relation matrix R
using Mamdani implication for the
fuzzy antecedent a
and consequent b
inputs.
Parameters: | a : 1d array
b : 1d array
|
---|---|
Returns: | R : 2d array
|
skfuzzy.
relation_product
(a, b)[source]¶Determine the fuzzy relation matrix, R
, using product implication for
the fuzzy antecedent a
and the fuzzy consequent b
.
Parameters: | a : 1d array
b : 1d array
|
---|---|
Returns: | R : 2d array
|
skfuzzy.
sigmf
(x, b, c)[source]¶The basic sigmoid membership function generator.
Parameters: | x : 1d array
b : float
c : float
|
---|---|
Returns: | y : 1d array
|
Notes
These are the same values, provided separately and in the opposite order compared to the publicly available MathWorks’ Fuzzy Logic Toolbox documentation. Pay close attention to above docstring!
skfuzzy.
sigmoid
(x, power, split=0.5)[source]¶Intensify grayscale values in an array using a sigmoid function.
Parameters: | x : ndarray
p : float
split : float
|
---|---|
Returns: | y : ndarray, same size as x
|
See also
Notes
The sigmoid used herein is defined as:
y = 1 / (1 + exp(- exp(- power * (x-split))))
skfuzzy.
smf
(x, a, b)[source]¶S-function fuzzy membership generator.
Parameters: | x : 1d array
a : float
b : float
|
---|---|
Returns: | y : 1d array
|
Notes
Named such because of its S-like shape.
skfuzzy.
view_as_blocks
(arr_in, block_shape)[source]¶Block view of the input n-dimensional array (using re-striding).
Blocks are non-overlapping views of the input array.
Parameters: | arr_in: ndarray :
block_shape: tuple :
|
---|---|
Returns: | arr_out: ndarray :
|
Examples
>>> import numpy as np
>>> from skfuzzy import view_as_blocks
>>> A = np.arange(4*4).reshape(4,4)
>>> A
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11],
[12, 13, 14, 15]])
>>> B = view_as_blocks(A, block_shape=(2, 2))
>>> B[0, 0]
array([[0, 1],
[4, 5]])
>>> B[0, 1]
array([[2, 3],
[6, 7]])
>>> B[1, 0, 1, 1]
13
>>> A = np.arange(4*4*6).reshape(4,4,6)
>>> A
array([[[ 0, 1, 2, 3, 4, 5],
[ 6, 7, 8, 9, 10, 11],
[12, 13, 14, 15, 16, 17],
[18, 19, 20, 21, 22, 23]],
[[24, 25, 26, 27, 28, 29],
[30, 31, 32, 33, 34, 35],
[36, 37, 38, 39, 40, 41],
[42, 43, 44, 45, 46, 47]],
[[48, 49, 50, 51, 52, 53],
[54, 55, 56, 57, 58, 59],
[60, 61, 62, 63, 64, 65],
[66, 67, 68, 69, 70, 71]],
[[72, 73, 74, 75, 76, 77],
[78, 79, 80, 81, 82, 83],
[84, 85, 86, 87, 88, 89],
[90, 91, 92, 93, 94, 95]]])
>>> B = view_as_blocks(A, block_shape=(1, 2, 2))
>>> B.shape
(4, 2, 3, 1, 2, 2)
>>> B[2:, 0, 2]
array([[[[52, 53],
[58, 59]]],
[[[76, 77],
[82, 83]]]])
skfuzzy.
view_as_windows
(arr_in, window_shape)[source]¶Rolling window view of the input n-dimensional array.
Windows are overlapping views of the input array, with adjacent windows shifted by a single row or column (or an index of a higher dimension).
Parameters: | arr_in: ndarray :
window_shape: tuple :
|
---|---|
Returns: | arr_out: ndarray :
|
Notes
One should be very careful with rolling views when it comes to memory usage. Indeed, although a ‘view’ has the same memory footprint as its base array, the actual array that emerges when this ‘view’ is used in a computation is generally a (much) larger array than the original, especially for 2-dimensional arrays and above.
For example, let us consider a 3 dimensional array of size (100,
100, 100) of float64
. This array takes about 8*100**3 Bytes for
storage which is just 8 MB. If one decides to build a rolling view
on this array with a window of (3, 3, 3) the hypothetical size of
the rolling view (if one was to reshape the view for example) would
be 8*(100-3+1)**3*3**3 which is about 203 MB! The scaling becomes
even worse as the dimension of the input array becomes larger.
References
[R20] | (1, 2) http://en.wikipedia.org/wiki/Hyperrectangle |
Examples
>>> import numpy as np
>>> from skfuzzy import view_as_windows
>>> A = np.arange(4*4).reshape(4,4)
>>> A
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11],
[12, 13, 14, 15]])
>>> window_shape = (2, 2)
>>> B = view_as_windows(A, window_shape)
>>> B[0, 0]
array([[0, 1],
[4, 5]])
>>> B[0, 1]
array([[1, 2],
[5, 6]])
>>> A = np.arange(10)
>>> A
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> window_shape = (3,)
>>> B = view_as_windows(A, window_shape)
>>> B.shape
(8, 3)
>>> B
array([[0, 1, 2],
[1, 2, 3],
[2, 3, 4],
[3, 4, 5],
[4, 5, 6],
[5, 6, 7],
[6, 7, 8],
[7, 8, 9]])
>>> A = np.arange(5*4).reshape(5, 4)
>>> A
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11],
[12, 13, 14, 15],
[16, 17, 18, 19]])
>>> window_shape = (4, 3)
>>> B = view_as_windows(A, window_shape)
>>> B.shape
(2, 2, 4, 3)
>>> B
array([[[[ 0, 1, 2],
[ 4, 5, 6],
[ 8, 9, 10],
[12, 13, 14]],
[[ 1, 2, 3],
[ 5, 6, 7],
[ 9, 10, 11],
[13, 14, 15]]],
[[[ 4, 5, 6],
[ 8, 9, 10],
[12, 13, 14],
[16, 17, 18]],
[[ 5, 6, 7],
[ 9, 10, 11],
[13, 14, 15],
[17, 18, 19]]]])
skfuzzy.
zmf
(x, a, b)[source]¶Z-function fuzzy membership generator.
Parameters: | x : 1d array
a : float
b : float
|
---|---|
Returns: | y : 1d array
|
Notes
Named such because of its Z-like shape.