Section for working with fuzzy numbers

class fuzzyops.fuzzy_numbers.fuzzify.fuzzy_number.Domain(fset: Tuple[float | int, float | int] | Tuple[float | int, float | int, float | int] | Tensor, name: str | None = None, method: str = 'minimax')[source]

Bases: object

A class for representing a set of possible values of fuzzy numbers

This class manages the domain of values (it adds a universal set on which fuzzy numbers are built), provides methods for creating fuzzy numbers, changing the calculation method and visualization

_x

A set of values in the domain

Type:

torch.Tensor

step

The step between the values in the domain

Type:

RealNum

name

The domain name

Type:

str

_method

The method used for fuzzy operations (for example, ‘minimax’ or ‘prob’)

Type:

str

_vars

Storage of fuzzy numbers in this domain

Type:

dict

bounds

The boundaries of the arguments used when creating fuzzy numbers

Type:

list

membership_type

Type of membership function for fuzzy numbers

Type:

str

Parameters:
  • fset (Union[Tuple[RealNum, RealNum], Tuple[RealNum, RealNum, RealNum], torch.Tensor]) – The beginning, the end, and the step (or tensor of values) to create the domain

  • name (str, optional) – The domain name (None by default)

  • method (str, optional) – Method for fuzzy operations (‘minimax’ or ‘prob’, default is ‘minimax’)

Properties:

method (str): Returns or sets the method used for fuzzy operations x (torch.Tensor): Returns a range of domain values

Raises:

AssertionError – If the passed parameters do not meet the expected requirements

copy() Domain[source]

Returns a range of domain values

Returns:

Fuzzy numbers domain

Return type:

Domain

create_number(membership: str | Callable, *args: float | int, name: str | None = None) FuzzyNumber[source]

Creates a new fuzzy number in the domain with the specified membership function

Parameters:
  • membership (Union[str, Callable]) – Name or function for calculating membership

  • *args (RealNum) – Arguments for the membership function

  • name (str, optional) – Name for the created fuzzy number (None by default)

Returns:

The created fuzzy number

Return type:

FuzzyNumber

Raises:

AssertionError – If membership is not a string or does not match the required number of arguments

get(name: str) FuzzyNumber[source]

Returns a fuzzy number with the specified name

Parameters:

name (str) – The name of the fuzzy number

Returns:

A fuzzy number with a given name

Return type:

FuzzyNumber

property method: str

Returns the method used for fuzzy operations

Returns:

method

Return type:

str

plot()[source]

Plots all the fuzzy numbers in the domain

Uses matplotlib to visualize the values of fuzzy numbers

to(device: str)[source]

Moves the domain to the specified device (‘cpu’ or ‘cuda’)

Parameters:

device (str) – The device to move (for example, ‘cpu’ or ‘cuda’)

property x: Tensor

Returns a range of domain values

Returns:

Range of values

Return type:

torch.Tensor

class fuzzyops.fuzzy_numbers.fuzzify.fuzzy_number.FuzzyNumber(domain: Domain, membership: Callable, method: str = 'minimax')[source]

Bases: object

A fuzzy number defined in a specific domain with a membership function

_domain Domain

The domain on which the number is based

_membership Callable

The membership function of a fuzzy number

_method str

Calculation method ‘minimax’ or ‘prob’. The default is ‘minimax’

Parameters:
  • Domain (domain) – The domain on which the number is based

  • Callable (membership) – The membership function of a fuzzy number (for example, a function that returns a tensor)

  • str (method) – Calculation method ‘minimax’ or ‘prob’. The default is ‘minimax’

Properties:
very:

A copy of a number with a membership function squared

negation:

A copy of a number with the opposite membership function

maybe:

A copy of a number with a membership function raised to the power of 0.5

method:

The method used for calculations

membership:

Fuzzy number membership function

domain:

The domain where the fuzzy number is located

values:

Fuzzy number values on a given domain

alpha_cut(alpha: float) Tensor[source]

Performs alpha cropping of a fuzzy number

Parameters:

alpha (float) – The alpha level for cutting

Returns:

Domain values for which the membership function is greater than or equal to alpha

Return type:

torch.Tensor

center_of_grav() float[source]

Center of gravity defuzzification

Returns:

The meaning of defazzification

Return type:

float

center_of_max(verbose: bool = False) float[source]

Defuzzification by the central maximum method

Parameters:

verbose (bool) – By default, False, If True, displays information about the maxima.

Returns:

The meaning of defuzzification

Return type:

float

clip_upper(upper: float | int) FuzzyNumber[source]

A method for slicing a fuzzy number along the boundary of the degree of confidence of a given clear value from a universal set

Parameters:

upper (RealNum) – Clear values for the slice

Returns:

Limited fuzzy number

Return type:

FuzzyNumber

copy() FuzzyNumber[source]

Creates and returns a copy of the fuzzy number

Returns:

The square of a fuzzy number

Return type:

FuzzyNumber

defuzz(by: str = 'default') float[source]

Defuzzification of a fuzzy number by a specific method

Parameters:

by (str) – Choosing a defazzification method

Returns:

The meaning of defuzzification

Return type:

float

property domain: Domain

Returns the domain where the fuzzy number is located

Returns:

Returns the domain

Return type:

Domain

entropy(norm: bool = True) float[source]

Calculates the entropy of a fuzzy number

Parameters:

norm (bool) – If True, the entropy is normalized by the number of elements in the domain

Returns:

The value of the entropy of a fuzzy number

Return type:

float

left_max() float[source]

Defuzzification by the left maximum method

Returns:

The meaning of defazzification

Return type:

float

property maybe: FuzzyNumber

A copy of a number with a membership function raised to the power of 0.5

Returns:

The square of a fuzzy number

Return type:

FuzzyNumber

property membership: Callable

Returns the membership function of a fuzzy number

Returns:

Returns the membership function of a fuzzy number

Return type:

Callable

property method: str

Returns the method used for calculations

Returns:

Returns the method

Return type:

str

moment_of_inertia(center: bool | None = None) float[source]

Defuzzification by the moment of inertia method

Parameters:

center (float) – The center relative to which the moment of inertia is calculated. If not specified, the center of gravity is used

Returns:

Значение дефаззификации.

Return type:

float

property negation: FuzzyNumber

A copy of a number with the opposite membership function

Returns:

The square of a fuzzy number

Return type:

FuzzyNumber

plot(ax=None)[source]

Plots a graph of a fuzzy number. Creates a new subgraph if not specified

Parameters:

ax (matplotlib.axes._subplots.AxesSubplot, optional) – An existing graph for adding data. If not specified, a new schedule will be created.

right_max() float[source]

Defuzzification by the right maximum method

Returns:

The meaning of defuzzification

Return type:

float

property values: Callable

Returns the values of a fuzzy number on the specified domain

Returns:

Returns the confidence level

Return type:

Callable

property very: FuzzyNumber

A copy of a number with a membership function squared

Returns:

The square of a fuzzy number

Return type:

FuzzyNumber