Membership Functions¶
anfis_toolbox.membership.GaussianMF ¶
Bases: MembershipFunction
Gaussian Membership Function.
Implements a Gaussian (bell-shaped) membership function using the formula: μ(x) = exp(-((x - mean)² / (2 * sigma²)))
This function is commonly used in fuzzy logic systems due to its smooth and differentiable properties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mean
|
float
|
Mean of the Gaussian (center). Defaults to 0.0. |
0.0
|
sigma
|
float
|
Standard deviation (width). Defaults to 1.0. |
1.0
|
Source code in anfis_toolbox/membership.py
backward ¶
Compute gradients w.r.t. parameters given upstream gradient.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dL_dy
|
ndarray
|
Gradient of the loss with respect to the output of this layer. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in anfis_toolbox/membership.py
forward ¶
Compute Gaussian membership values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Input array for which the membership values are computed. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Array of Gaussian membership values. |
Source code in anfis_toolbox/membership.py
anfis_toolbox.membership.Gaussian2MF ¶
Bases: MembershipFunction
Gaussian combination Membership Function (two-sided Gaussian).
This membership function uses Gaussian tails on both sides with an optional flat region in the middle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sigma1
|
float
|
Standard deviation of the left Gaussian tail (must be > 0). |
1.0
|
c1
|
float
|
Center of the left Gaussian tail. |
0.0
|
sigma2
|
float
|
Standard deviation of the right Gaussian tail (must be > 0). |
1.0
|
c2
|
float
|
Center of the right Gaussian tail. Must satisfy c1 <= c2. |
0.0
|
Definition (with c1 <= c2): - For x < c1: μ(x) = exp(-((x - c1)^2) / (2*sigma1^2)) - For c1 <= x <= c2: μ(x) = 1 - For x > c2: μ(x) = exp(-((x - c2)^2) / (2*sigma2^2))
Special case (c1 == c2): asymmetric Gaussian centered at c1 with sigma1 on the left side and sigma2 on the right side (no flat region).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sigma1
|
float
|
Standard deviation of the first Gaussian. Must be positive. Defaults to 1.0. |
1.0
|
c1
|
float
|
Center of the first Gaussian. Defaults to 0.0. |
0.0
|
sigma2
|
float
|
Standard deviation of the second Gaussian. Must be positive. Defaults to 1.0. |
1.0
|
c2
|
float
|
Center of the second Gaussian. Must satisfy c1 <= c2. Defaults to 0.0. |
0.0
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If sigma1 or sigma2 are not positive. |
ValueError
|
If c1 > c2. |
Attributes:
| Name | Type | Description |
|---|---|---|
parameters |
dict
|
Dictionary containing the parameters 'sigma1', 'c1', 'sigma2', 'c2'. |
gradients |
dict
|
Dictionary containing the gradients for each parameter, initialized to 0.0. |
Source code in anfis_toolbox/membership.py
backward ¶
Accumulate parameter gradients for the two-sided Gaussian.
The flat middle region contributes no gradients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dL_dy
|
ndarray
|
Upstream gradient of the loss w.r.t. the output. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in anfis_toolbox/membership.py
forward ¶
Compute two-sided Gaussian membership values.
The input space is divided by c1 and c2 into: - x < c1: left Gaussian tail with sigma1 centered at c1 - c1 <= x <= c2: flat region (1.0) - x > c2: right Gaussian tail with sigma2 centered at c2
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Input array of values. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Membership degrees for each input value. |
Source code in anfis_toolbox/membership.py
anfis_toolbox.membership.BellMF ¶
Bases: MembershipFunction
Bell-shaped (Generalized Bell) Membership Function.
Implements a bell-shaped membership function using the formula: μ(x) = 1 / (1 + |((x - c) / a)|^(2b))
This function is a generalization of the Gaussian function and provides more flexibility in controlling the shape through the 'b' parameter. It's particularly useful when you need asymmetric membership functions or want to fine-tune the slope characteristics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Width parameter (positive). Controls the width of the curve. |
1.0
|
b
|
float
|
Slope parameter (positive). Controls the steepness of the curve. |
2.0
|
c
|
float
|
Center parameter. Controls the center position of the curve. |
0.0
|
Note
Parameters 'a' and 'b' must be positive for a valid bell function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Width parameter (must be positive). Defaults to 1.0. |
1.0
|
b
|
float
|
Slope parameter (must be positive). Defaults to 2.0. |
2.0
|
c
|
float
|
Center parameter. Defaults to 0.0. |
0.0
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If 'a' or 'b' are not positive. |
Source code in anfis_toolbox/membership.py
backward ¶
Compute parameter gradients given upstream gradient.
Analytical gradients: - ∂μ/∂a: width - ∂μ/∂b: steepness - ∂μ/∂c: center
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dL_dy
|
ndarray
|
Gradient of the loss w.r.t. the output of this layer. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in anfis_toolbox/membership.py
692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 | |
forward ¶
Compute bell membership values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Input array for which the membership values are computed. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Array of bell membership values. |
Source code in anfis_toolbox/membership.py
anfis_toolbox.membership.SigmoidalMF ¶
Bases: MembershipFunction
Sigmoidal Membership Function.
Implements a sigmoidal (S-shaped) membership function using the formula: μ(x) = 1 / (1 + exp(-a(x - c)))
This function provides a smooth S-shaped curve that transitions from 0 to 1. It's particularly useful for modeling gradual transitions and is commonly used in neural networks and fuzzy systems.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Slope parameter. Controls the steepness of the sigmoid. - Positive values: standard sigmoid (0 → 1 as x increases) - Negative values: inverted sigmoid (1 → 0 as x increases) - Larger |a|: steeper transition |
1.0
|
c
|
float
|
Center parameter. Controls the inflection point where μ© = 0.5. |
0.0
|
Note
Parameter 'a' cannot be zero (would result in constant function).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Slope parameter (cannot be zero). Defaults to 1.0. |
1.0
|
c
|
float
|
Center parameter (inflection point). Defaults to 0.0. |
0.0
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If 'a' is zero. |
Source code in anfis_toolbox/membership.py
backward ¶
Compute parameter gradients given upstream gradient.
For μ(x) = 1/(1 + exp(-a(x-c))): - ∂μ/∂a = μ(x)(1-μ(x))(x-c) - ∂μ/∂c = -aμ(x)(1-μ(x))
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dL_dy
|
ndarray
|
Gradient of the loss w.r.t. the output of this layer. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in anfis_toolbox/membership.py
forward ¶
Compute sigmoidal membership values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Input array for which the membership values are computed. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Array of sigmoidal membership values. |
Source code in anfis_toolbox/membership.py
anfis_toolbox.membership.DiffSigmoidalMF ¶
Bases: MembershipFunction
Difference of two sigmoidal functions.
Implements y = s1(x) - s2(x), where each s is a logistic curve with its own slope and center parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a1
|
float
|
The first 'a' parameter for the membership function. |
required |
c1
|
float
|
The first 'c' parameter for the membership function. |
required |
a2
|
float
|
The second 'a' parameter for the membership function. |
required |
c2
|
float
|
The second 'c' parameter for the membership function. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
parameters |
dict
|
Dictionary containing the membership function parameters. |
gradients |
dict
|
Dictionary containing gradients for each parameter, initialized to 0.0. |
last_input |
dict
|
Stores the last input value (initially None). |
last_output |
dict
|
Stores the last output value (initially None). |
Source code in anfis_toolbox/membership.py
backward ¶
Compute gradients w.r.t. parameters and optionally input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dL_dy
|
ndarray
|
Gradient of the loss w.r.t. the output. |
required |
Returns:
| Type | Description |
|---|---|
None
|
np.ndarray | None: Gradient of the loss w.r.t. the input, if available. |
Source code in anfis_toolbox/membership.py
forward ¶
Compute y = s1(x) - s2(x).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Input array. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Membership values for the input. |
Source code in anfis_toolbox/membership.py
anfis_toolbox.membership.ProdSigmoidalMF ¶
Bases: MembershipFunction
Product of two sigmoidal functions.
Implements μ(x) = s1(x) * s2(x) with separate parameters for each sigmoid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a1
|
float
|
The first parameter for the membership function. |
required |
c1
|
float
|
The second parameter for the membership function. |
required |
a2
|
float
|
The third parameter for the membership function. |
required |
c2
|
float
|
The fourth parameter for the membership function. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
parameters |
dict
|
Dictionary containing the membership function parameters. |
gradients |
dict
|
Dictionary containing gradients for each parameter, initialized to 0.0. |
last_input |
dict
|
Stores the last input value (initialized to None). |
last_output |
dict
|
Stores the last output value (initialized to None). |
Source code in anfis_toolbox/membership.py
backward ¶
Compute parameter gradients and optionally return input gradient.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dL_dy
|
ndarray
|
Gradient of the loss w.r.t. the output. |
required |
Returns:
| Type | Description |
|---|---|
None
|
np.ndarray | None: Gradient of the loss w.r.t. the input, if available. |
Source code in anfis_toolbox/membership.py
forward ¶
Computes the membership value(s) for input x using the product of two sigmoidal functions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Input array to the membership function. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Output array after applying the membership function. |
Source code in anfis_toolbox/membership.py
anfis_toolbox.membership.SShapedMF ¶
Bases: MembershipFunction
S-shaped Membership Function.
Smoothly transitions from 0 to 1 between two parameters a and b using the smoothstep polynomial S(t) = 3t² - 2t³. Commonly used in fuzzy logic for gradual onset of membership.
Definition with a < b: - μ(x) = 0, for x ≤ a - μ(x) = 3t² - 2t³, t = (x-a)/(b-a), for a < x < b - μ(x) = 1, for x ≥ b
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Left foot (start of transition from 0). |
required |
b
|
float
|
Right shoulder (end of transition at 1). |
required |
Note
Requires a < b.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
The first parameter, must be less than 'b'. |
required |
b
|
float
|
The second parameter, must be greater than 'a'. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If 'a' is not less than 'b'. |
Attributes:
| Name | Type | Description |
|---|---|---|
parameters |
dict
|
Dictionary containing 'a' and 'b' as floats. |
gradients |
dict
|
Dictionary containing gradients for 'a' and 'b', initialized to 0.0. |
Source code in anfis_toolbox/membership.py
backward ¶
Accumulate gradients for a and b using analytical derivatives.
Uses S(t) = 3t² - 2t³, t = (x-a)/(b-a) on the transition region.
Source code in anfis_toolbox/membership.py
forward ¶
Compute S-shaped membership values.
Source code in anfis_toolbox/membership.py
anfis_toolbox.membership.LinSShapedMF ¶
Bases: MembershipFunction
Linear S-shaped saturation Membership Function.
Piecewise linear ramp from 0 to 1 between parameters a and b
- μ(x) = 0, for x ≤ a
- μ(x) = (x - a) / (b - a), for a < x < b
- μ(x) = 1, for x ≥ b
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Left foot (start of transition from 0). |
required |
b
|
float
|
Right shoulder (end of transition at 1). Requires a < b. |
required |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
The first parameter, must be less than 'b'. |
required |
b
|
float
|
The second parameter, must be greater than 'a'. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If 'a' is not less than 'b'. |
Attributes:
| Name | Type | Description |
|---|---|---|
parameters |
dict
|
Dictionary containing 'a' and 'b' as floats. |
gradients |
dict
|
Dictionary containing gradients for 'a' and 'b', initialized to 0.0. |
Source code in anfis_toolbox/membership.py
backward ¶
Accumulate gradients for 'a' and 'b' in the ramp region.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dL_dy
|
ndarray
|
Gradient of the loss w.r.t. the output. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in anfis_toolbox/membership.py
forward ¶
Compute linear S-shaped membership values for x.
The rules based on a and b: - x >= b: 1.0 (right saturated) - a < x < b: linear ramp from 0 to 1 - x <= a: 0.0 (left)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Input array of values. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Output array with membership values. |
Source code in anfis_toolbox/membership.py
anfis_toolbox.membership.ZShapedMF ¶
Bases: MembershipFunction
Z-shaped Membership Function.
Smoothly transitions from 1 to 0 between two parameters a and b using the smoothstep polynomial S(t) = 3t² - 2t³ (Z = 1 - S). Commonly used in fuzzy logic as the complement of the S-shaped function.
Definition with a < b: - μ(x) = 1, for x ≤ a - μ(x) = 1 - (3t² - 2t³), t = (x-a)/(b-a), for a < x < b - μ(x) = 0, for x ≥ b
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Left shoulder (start of transition). |
required |
b
|
float
|
Right foot (end of transition). |
required |
Note
Requires a < b. In the degenerate case a == b, the function becomes an instantaneous drop at x=a.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Lower bound parameter. |
required |
b
|
float
|
Upper bound parameter. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a is not less than b. |
Source code in anfis_toolbox/membership.py
backward ¶
Accumulate gradients for a and b using analytical derivatives.
Uses Z(t) = 1 - (3t² - 2t³), t = (x-a)/(b-a) on the transition region.
Source code in anfis_toolbox/membership.py
forward ¶
Compute Z-shaped membership values.
Source code in anfis_toolbox/membership.py
anfis_toolbox.membership.LinZShapedMF ¶
Bases: MembershipFunction
Linear Z-shaped saturation Membership Function.
Piecewise linear ramp from 1 to 0 between parameters a and b
- μ(x) = 1, for x ≤ a
- μ(x) = (b - x) / (b - a), for a < x < b
- μ(x) = 0, for x ≥ b
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Left shoulder (end of saturation at 1). |
required |
b
|
float
|
Right foot (end of transition to 0). Requires a < b. |
required |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
The first parameter of the membership function. Must be less than 'b'. |
required |
b
|
float
|
The second parameter of the membership function. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If 'a' is not less than 'b'. |
Attributes:
| Name | Type | Description |
|---|---|---|
parameters |
dict
|
Dictionary containing 'a' and 'b' as floats. |
gradients |
dict
|
Dictionary containing gradients for 'a' and 'b', initialized to 0.0. |
Source code in anfis_toolbox/membership.py
backward ¶
Accumulate gradients for 'a' and 'b'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dL_dy
|
ndarray
|
Gradient of the loss w.r.t. the output. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in anfis_toolbox/membership.py
forward ¶
Compute linear Z-shaped membership values for x.
Rules: - x <= a: 1.0 (left saturated) - a < x < b: linear ramp from 1 to 0 - x >= b: 0.0 (right)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Input array of values. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Output membership values for each input. |
Source code in anfis_toolbox/membership.py
anfis_toolbox.membership.PiMF ¶
Bases: MembershipFunction
Pi-shaped membership function.
The Pi-shaped membership function is characterized by a trapezoidal-like shape with smooth S-shaped transitions on both sides. It is defined by four parameters that control the shape and position:
Mathematical definition: μ(x) = S(x; a, b) for x ∈ [a, b] = 1 for x ∈ [b, c] = Z(x; c, d) for x ∈ [c, d] = 0 elsewhere
Where: - S(x; a, b) is an S-shaped function from 0 to 1 - Z(x; c, d) is a Z-shaped function from 1 to 0
The S and Z functions use smooth cubic splines for differentiability: S(x; a, b) = 2*((x-a)/(b-a))^3 for x ∈ [a, (a+b)/2] = 1 - 2*((b-x)/(b-a))^3 for x ∈ [(a+b)/2, b]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Left foot of the function (where function starts rising from 0) |
required |
b
|
float
|
Left shoulder of the function (where function reaches 1) |
required |
c
|
float
|
Right shoulder of the function (where function starts falling from 1) |
required |
d
|
float
|
Right foot of the function (where function reaches 0) |
required |
Note
Parameters must satisfy: a < b ≤ c < d
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Left foot parameter. |
required |
b
|
float
|
Left shoulder parameter. |
required |
c
|
float
|
Right shoulder parameter. |
required |
d
|
float
|
Right foot parameter. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If parameters don't satisfy a < b ≤ c < d. |
Source code in anfis_toolbox/membership.py
backward ¶
Compute gradients for backpropagation.
Analytical gradients are computed by region: - S-function: gradients w.r.t. a, b - Z-function: gradients w.r.t. c, d - Flat region: no gradients
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dL_dy
|
ndarray
|
Gradient of loss w.r.t. function output. |
required |
Source code in anfis_toolbox/membership.py
1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 | |
forward ¶
Compute the Pi-shaped membership function.
Combines S and Z functions for smooth transitions: - Rising edge: S-function from a to b - Flat top: constant 1 from b to c - Falling edge: Z-function from c to d - Outside: 0
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Input values. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Membership values μ(x) ∈ [0, 1]. |
Source code in anfis_toolbox/membership.py
1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 | |
anfis_toolbox.membership.TriangularMF ¶
Bases: MembershipFunction
Triangular Membership Function.
Implements a triangular membership function using piecewise linear segments: μ(x) = { 0, x ≤ a or x ≥ c { (x-a)/(b-a), a < x < b { (c-x)/(c-b), b ≤ x < c
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Left base point of the triangle. |
required |
b
|
float
|
Peak point of the triangle (μ(b) = 1). |
required |
c
|
float
|
Right base point of the triangle. |
required |
Note
Must satisfy: a ≤ b ≤ c
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Left base point (must satisfy a ≤ b). |
required |
b
|
float
|
Peak point (must satisfy a ≤ b ≤ c). |
required |
c
|
float
|
Right base point (must satisfy b ≤ c). |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If parameters do not satisfy a ≤ b ≤ c or if a == c (zero width). |
Source code in anfis_toolbox/membership.py
backward ¶
Accumulate gradients for a, b, c given upstream gradient.
Computes analytical derivatives for the rising (a, b) and falling (b, c) regions and sums them over the batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dL_dy
|
ndarray
|
Gradient of the loss w.r.t. μ(x); same shape or broadcastable to output. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in anfis_toolbox/membership.py
forward ¶
Compute triangular membership values μ(x).
Uses piecewise linear segments defined by (a, b, c): - 0 outside [a, c] - rising slope in (a, b) - peak 1 at x == b - falling slope in (b, c)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Input array. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Membership values in [0, 1] with the same shape as x. |
Source code in anfis_toolbox/membership.py
anfis_toolbox.membership.TrapezoidalMF ¶
Bases: MembershipFunction
Trapezoidal Membership Function.
Implements a trapezoidal membership function using piecewise linear segments: μ(x) = { 0, x ≤ a or x ≥ d { (x-a)/(b-a), a < x < b { 1, b ≤ x ≤ c { (d-x)/(d-c), c < x < d
This function is commonly used in fuzzy logic systems when you need a plateau region of full membership, providing robustness to noise and uncertainty.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Left base point of the trapezoid (lower support bound). |
required |
b
|
float
|
Left peak point (start of plateau where μ(x) = 1). |
required |
c
|
float
|
Right peak point (end of plateau where μ(x) = 1). |
required |
d
|
float
|
Right base point of the trapezoid (upper support bound). |
required |
Note
Parameters must satisfy: a ≤ b ≤ c ≤ d for a valid trapezoidal function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Left base point (μ(a) = 0). |
required |
b
|
float
|
Left peak point (μ(b) = 1, start of plateau). |
required |
c
|
float
|
Right peak point (μ© = 1, end of plateau). |
required |
d
|
float
|
Right base point (μ(d) = 0). |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If parameters don't satisfy a ≤ b ≤ c ≤ d. |
Source code in anfis_toolbox/membership.py
backward ¶
Compute gradients for parameters based on upstream loss gradient.
Analytical gradients for the piecewise linear function: - ∂μ/∂a: left slope - ∂μ/∂b: left slope and plateau transition - ∂μ/∂c: right slope and plateau transition - ∂μ/∂d: right slope
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dL_dy
|
ndarray
|
Gradient of the loss w.r.t. the output of this layer. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in anfis_toolbox/membership.py
forward ¶
Compute trapezoidal membership values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Input array. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Array containing the trapezoidal membership values. |