Section for working with the fuzzy linear regression algorithm

class fuzzyops.prediction.linear.TriFNum(domain: Domain, a: Tensor, b: Tensor, c: Tensor)[source]

Bases: object

Represents a triangular fuzzy number (TriFNum) for the fuzzy linear regression method

domain

The area of definition of a fuzzy number

Type:

Domain

a

The left end of the triangle

Type:

torch.Tensor

b

The peak of the triangle

Type:

torch.Tensor

c

The right end of the triangle

Type:

torch.Tensor

integrate() Tensor[source]

Calculates the integral (total area) under the curve of a triangular fuzzy number

Returns:

The value of the integral

Return type:

torch.Tensor

integrate_left() Tensor[source]

Calculates the integral for the left side of a triangular fuzzy number

Returns:

The value of the integral

Return type:

torch.Tensor

integrate_right() Tensor[source]

Calculates the integral for the right side of a triangular fuzzy number

Returns:

The value of the integral

Return type:

torch.Tensor

to_fuzzy_number() FuzzyNumber[source]

Converts a triangular fuzzy number into its fuzzy representation

Returns:

A fuzzy number created from a triangular fuzzy number

Return type:

FuzzyNumber

values() Tensor[source]

Calculates the values of a fuzzy number on a given definition area

Returns:

The values of the fuzzy number in the definition area

Return type:

torch.Tensor

fuzzyops.prediction.linear.convert_fuzzy_number_for_lreg(n: FuzzyNumber) TriFNum[source]

Converts a fuzzy number of the FuzzyNumber class to a triangular fuzzy number TriNum

Parameters:

n (FuzzyNumber) – A fuzzy number for conversion

Returns:

A transformed triangular fuzzy number

Return type:

TriFNum

fuzzyops.prediction.linear.fit_fuzzy_linear_regression(X: List[TriFNum], Y: List[TriFNum]) Tuple[float, float][source]

Implements fuzzy linear regression using triangular fuzzy numbers

This function finds coefficients a and b for linear regression that minimize the distance between the predicted fuzzy values and the actual fuzzy values Implemented on the basis of materials https://ej.hse.ru/data/2014/09/03/1316474700/%D0%A8%D0%B2%D0%B5%D0%B4%D0%BE%D0%B2.pdf

Parameters:
  • X (List[TriFNum]) – A list of triangular fuzzy numbers representing independent variables (features)

  • (List[TriFNum] (Y) – A list of triangular fuzzy numbers representing the dependent variable (target variable)

Returns:

Coefficients a and b of linear regression,

where a is the angular coefficient and b is the free term

Return type:

Tuple[float, float]

Raises:

ValueError – If the lengths of the X and Y lists do not match

Notes

Integration and calculation of various moments based on fuzzy numbers are used to perform calculations

fuzzyops.prediction.linear.fuzzy_distance(fn0: TriFNum, fn1: TriFNum) float[source]

Calculates the distance between two triangular fuzzy numbers

Parameters:
  • fn0 (TriFNum) – The first triangular fuzzy number

  • fn1 (TriFNum) – The second triangular fuzzy number

Returns:

The distance between two fuzzy numbers

Return type:

float

fuzzyops.prediction.linear.integral_of_product(a_0: Tensor, b_0: Tensor, a_1: Tensor, b_1: Tensor) Tensor[source]

Calculates the integral of the product of two intervals

Parameters:
  • a_0 (torch.Tensor) – The beginning of the first interval

  • b_0 (torch.Tensor) – The end of the first interval

  • a_1 (torch.Tensor) – The beginning of the second interval

  • b_1 (torch.Tensor) – The end of the second interval

Returns:

The result of the integral of the product

Return type:

torch.Tensor

fuzzyops.prediction.linear.integrate_sum_squares(a_0: Tensor, b_0: Tensor, a_1: Tensor, b_1: Tensor) Tensor[source]

Calculates the integral of the sum of the squares of two intervals

Parameters:
  • a_0 (torch.Tensor) – The beginning of the first interval

  • b_0 (torch.Tensor) – The end of the first interval

  • a_1 (torch.Tensor) – The beginning of the second interval

  • b_1 (torch.Tensor) – The end of the second interval

Returns:

The result of the integral of the sum of squares

Return type:

torch.Tensor