Logical Systems

Logical system extends boolean logic operator into fuzzy domain. And operator is mapped by t-norm while Or operation is substituted by t-conorm. Negation operator is fuzzy domain is commonly referred as complement and most of the time is defined as \(1 - \mu(x)\)

Fuzzy Negation

(Source code, png, hires.png, pdf)

_images/complementary_mf.png

Defined as \(1 - \mu(x)\) or not complement operation should always negate membership, i.e each full member of fuzzy set should be casted outside of that set and each non-member should become full member. Partial memberships should be resolved analogously.

Fuzzy And and Or

(Source code, png, hires.png, pdf)

_images/zadeh.png

Each logical system have to define at least they own t-norm (t-conorm may be skipped, because it can be easily deduced using relation with t-norm). T-Norm should behave semantically similar to and/intersection operator. T-Conorm analogously have to be defined as implementation of or/union operator (if you decide to define it on your own).

Parametrized logical systems

There are logical systems that allow parametrisation of they’r t-norm and t-conorm behaviour (complement operator is most of the time untouched). Most of the time parametrised systems are depended on single parameter p. Popular pater is such systems is to use other system when value of p reach some edge case (like 0, inf, -inf)

For example, we can take Dombi system with parameter can vary in range [0,inf]. Each figure represents t-norm and t-conorm combining 3 membership functions with different value of p.

For p values close to zero we are getting results similar to Drastic system:

(Source code, png, hires.png, pdf)

_images/dombi_with_p_0_dot_1.png

(Source code, png, hires.png, pdf)

_images/drastic.png

While increasing p values leads to result similar with Zadeh ones:

(Source code, png, hires.png, pdf)

_images/dombi_with_p_1.png

(Source code, png, hires.png, pdf)

_images/dombi_with_p_4.png

In fact Dombi system is explicitly defined to be Drastic at \(p=0\) and Zadeh at \(p=\infty\). Intermediate values works analogously, i.e. values closer to zero works similar to Drastic while values closer to infinity works more similarly to Zadeh.

Custom logical systems

Each logical system should inherit from LogicalSystem class. Only method you have to override is t_norm as t_conorm is implemented in LogicalSystem using general relationship between t_norm and t_conorm. complement function will persist same for most of the systems, you don’t have to worry about it.

As an example Zadeh logic can be implemented as:

from yvain.logical_systems import LogicalSystem
from yvain.membership_functions import MembershipFunction


class MyZadeh(LogicalSystem):
    def t_norm(self, membership_a: MembershipFunction, membership_b: MembershipFunction) \
            -> MembershipFunction:
        return lambda x: min(membership_a(x), membership_b(x))

T-Norm same as t-conorm have to be implemented as higher order function with transforms two input membership functions into new one.

In fact this library does override t_conorm but this is not required. Resulting system will work same no matter if t-conorm was overridden or not:

(Source code, png, hires.png, pdf)

_images/custom_zadeh.png

Predefined logical systems

class yvain.logical_systems.Dombi(p: float)
_inherit_logic() → Optional[yvain.logical_systems.LogicalSystem]

Choose if given parametrized logic should inherit some of parametrised logic norms.

Returns

LogicalSystem with norms should be used by this logical system. None if embedded norms should be used.

_t_norm(membership_a: Callable[[float], float], membership_b: Callable[[float], float]) → Callable[[float], float]
Parameters
  • membership_a\(\mu_1\)

  • membership_b\(\mu_2\)

Returns

\(\mu\prime(x)=\frac{1}{1 + (((\frac{1 - \mu_1(x)}{\mu_1(x)})^p + (\frac{1 - \mu_2(x)}{\mu_2(x)})^p)^p)^{1/p}}\)

class yvain.logical_systems.Drastic
t_conorm(membership_a: Callable[[float], float], membership_b: Callable[[float], float]) → Callable[[float], float]
Parameters
  • membership_a\(\mu_1\)

  • membership_b\(\mu_2\)

Returns

\(\mu\prime(x)\) = If \(\mu_1(x) = 0\) or \(\mu_2(x) = 0\) then return 0 else 1

t_norm(membership_a: Callable[[float], float], membership_b: Callable[[float], float]) → Callable[[float], float]
Parameters
  • membership_a\(\mu_1\)

  • membership_b\(\mu_2\)

Returns

\(\mu\prime(x)\) = If \(\mu_1(x) = 1\) or \(\mu_2(x) = 1\) then return 1 else 0

class yvain.logical_systems.Fodor
t_conorm(membership_a: Callable[[float], float], membership_b: Callable[[float], float]) → Callable[[float], float]
Parameters
  • membership_a\(\mu_1(x)\)

  • membership_b\(\mu_2(x)\)

Returns

\(\mu\prime(x)\) = If \(\mu_1(x) + \mu_2(x) < 1\) then return \(max(\mu_1(x), \mu_2(x))\) else 1

t_norm(membership_a: Callable[[float], float], membership_b: Callable[[float], float]) → Callable[[float], float]
Parameters
  • membership_a\(\mu_1(x)\)

  • membership_b\(\mu_2(x)\)

Returns

\(\mu\prime(x)\) = If \(\mu_1(x) + \mu_2(x) > 1\) then return \(min(\mu_1(x), \mu_2(x))\) else 0

class yvain.logical_systems.Frank(p: float)
_inherit_logic() → Optional[yvain.logical_systems.LogicalSystem]

Choose if given parametrized logic should inherit some of parametrised logic norms.

Returns

LogicalSystem with norms should be used by this logical system. None if embedded norms should be used.

_t_norm(membership_a: Callable[[float], float], membership_b: Callable[[float], float]) → Callable[[float], float]
Parameters
  • membership_a\(\mu_1\)

  • membership_b\(\mu_2\)

Returns

\(\mu\prime(x)=\log_p(1 + \frac{(p^{\mu_1(x)} - 1) * (p^{\mu_2(x)} - 1)}{p - 1})\)

class yvain.logical_systems.LogicalSystem

Logical system describes T-Norm, T-Conorm and negation used in fuzzy set operations. Instead of whole sets LogicalSystem operates on membership functions.

complement(membership: Callable[[float], float]) → Callable[[float], float]

Strong negation. Fuzzy set resulting from this operation will have all memberships reversed - i.e. element with full membership will not belong to fuzzy set anymore and elements that was previously not in fuzzy set will gain full membership. Intermediate memberships will change proportionally.

Parameters

membership\(\mu\)

Returns

\(\mu\prime(x)=1 - \mu(x)\)

t_conorm(membership_a: Callable[[float], float], membership_b: Callable[[float], float]) → Callable[[float], float]

By default t-conorm is defined by they’r correlation with t-norm. For performance and precision reasons it should be overridden in subclass (if possible)

Parameters
  • membership_a\(\mu_1\)

  • membership_b\(\mu_2\)

Returns

\(\mu\prime(x) = \neg(\mu_1(x) and \mu_2(x))\)

class yvain.logical_systems.Lukasiewicz
t_conorm(membership_a: Callable[[float], float], membership_b: Callable[[float], float]) → Callable[[float], float]
Parameters
  • membership_a\(\mu_1\)

  • membership_b\(\mu_2\)

Returns

\(\mu\prime(x) = min(\mu_1(x)) + \mu_2(x), 1)\)

t_norm(membership_a: Callable[[float], float], membership_b: Callable[[float], float]) → Callable[[float], float]
Parameters
  • membership_a\(\mu_1\)

  • membership_b\(\mu_2\)

Returns

\(\mu\prime(x) = max(0, \mu_1(x)) + \mu_2(x) - 1)\)

class yvain.logical_systems.ParametrizedLogicalSystem(p: float)
_inherit_logic() → Optional[yvain.logical_systems.LogicalSystem]

Choose if given parametrized logic should inherit some of parametrised logic norms.

Returns

LogicalSystem with norms should be used by this logical system. None if embedded norms should be used.

_t_conorm(membership_a: Callable[[float], float], membership_b: Callable[[float], float]) → Callable[[float], float]

Implementation of t-conorm covering cases when t-conorm is not inherited from non-parametrised logic. It defaults to general equation derived from t-norm/conorm relation

Parameters
  • membership_a\(\mu_1\)

  • membership_b\(\mu_2\)

Returns

\(\mu\prime(x) = \neg(\mu_1(x) and \mu_2(x))\)

_t_norm(membership_a: Callable[[float], float], membership_b: Callable[[float], float]) → Callable[[float], float]

Implementation of t-norm covering cases when t-norm is not inherited from non-parametrised logic.

Parameters
  • membership_a\(\mu_1(x)\)

  • membership_b\(\mu_2(x)\)

Returns

\(\mu\prime(x)\)

t_conorm(membership_a: Callable[[float], float], membership_b: Callable[[float], float]) → Callable[[float], float]

Most of the time parametrized logical systems equations would not work for edge values of p (like 0, 1, inf, -inf). Such systems are inheriting non-parametrised system behaviours in such cases.

Parameters
  • membership_a\(\mu_1(x)\)

  • membership_b\(\mu_2(x)\)

Returns

\(\mu\prime(x)\)

t_norm(membership_a: Callable[[float], float], membership_b: Callable[[float], float]) → Callable[[float], float]

Most of the time parametrized logical systems equations would not work for edge values of p (like 0, 1, inf, -inf). Such systems are inheriting non-parametrised system behaviours in such cases.

Parameters
  • membership_a\(\mu_1(x)\)

  • membership_b\(\mu_2(x)\)

Returns

\(\mu\prime(x)\)

class yvain.logical_systems.Product
t_conorm(membership_a: Callable[[float], float], membership_b: Callable[[float], float]) → Callable[[float], float]
Parameters
  • membership_a\(\mu_1\)

  • membership_b\(\mu_2\)

Returns

\(\mu\prime(x) = \mu_1(x) + \mu_2(x) - \mu_1(x) * \mu_2(x)\)

t_norm(membership_a: Callable[[float], float], membership_b: Callable[[float], float]) → Callable[[float], float]
Parameters
  • membership_a\(\mu_1\)

  • membership_b\(\mu_2\)

Returns

\(\mu\prime(x) = \mu_1(x) * \mu_2(x)\)

class yvain.logical_systems.ShweizerSklar(p: float)
_inherit_logic() → Optional[yvain.logical_systems.LogicalSystem]

Choose if given parametrized logic should inherit some of parametrised logic norms.

Returns

LogicalSystem with norms should be used by this logical system. None if embedded norms should be used.

_t_norm(membership_a: Callable[[float], float], membership_b: Callable[[float], float]) → Callable[[float], float]
Parameters
  • membership_a\(\mu_1\)

  • membership_b\(\mu_2\)

Returns

\(\mu\prime(x)=max(0, \mu_1(x)^p + \mu_2(x)^p - 1)^{1/p}\)

class yvain.logical_systems.Yager(p: float)
_inherit_logic() → Optional[yvain.logical_systems.LogicalSystem]

Choose if given parametrized logic should inherit some of parametrised logic norms.

Returns

LogicalSystem with norms should be used by this logical system. None if embedded norms should be used.

_t_norm(membership_a: Callable[[float], float], membership_b: Callable[[float], float]) → Callable[[float], float]
Parameters
  • membership_a\(\mu_1\)

  • membership_b\(\mu_2\)

Returns

\(\mu\prime(x)=max(0, 1 - ((1 - \mu_1(x))^p + (1 - \mu_2(x))^p))^{1/p}\)

class yvain.logical_systems.Zadeh
t_conorm(membership_a: Callable[[float], float], membership_b: Callable[[float], float]) → Callable[[float], float]
Parameters
  • membership_a\(\mu_1\)

  • membership_b\(\mu_2\)

Returns

\(\mu\prime(x)=max(\mu_1(x), \mu2(x))\)

t_norm(membership_a: Callable[[float], float], membership_b: Callable[[float], float]) → Callable[[float], float]
Parameters
  • membership_a\(\mu_1\)

  • membership_b\(\mu_2\)

Returns

\(\mu\prime(x)=min(\mu_1(x), \mu2(x))\)