Alpha Cuts

Fuzzy sets can be represented as a crisp set for a given value of membership α.

This module provides functions to convert between fuzzy sets and alpha cut representations.

For this module, an Alpha Cut is represented as a python set and refers to the crisp set that is is true for a specific alpha value.

The term Alpha Range is used to refer to a dataclass that represents a crisp set that is true for a range of alpha values (between its min and max).

class fuzzy_sets.alpha.AlphaRange(alpha_min: float, alpha_max: float, crisp_set: set[Any])

Bases: object

A crisp set that is true between a min and a max alpha value.

alpha_min[float]

The minimum alpha value for which the crisp set is true. Between 0 and 1.

alpha_max[float]

The maximum alpha value for which the crisp set is true. Between 0 and 1.

crisp_set[set, Any]

The set of values.

alpha_max: float
alpha_min: float
crisp_set: set[Any]
fuzzy_sets.alpha.alpha_cut(fuzzy_set: FuzzySet, alpha: float) {typing.Any}

Return the crisp set for a given alpha value.

Parameters:
  • fuzzy_set – The fuzzy set.

  • alpha[float] – The alpha value (between 0 and 1)

Returns:

The crisp set.

Return type:

set[Any]

Raises:

ValueError – If alpha is not between 0 and 1.

Examples

>>> fuzzy_set = FuzzySet(
                    {FuzzySetMember(1, 0.2),
                    FuzzySetMember(2, 0.4),
                    FuzzySetMember(3, 0.6),
                    FuzzySetMember(4, 0.8)}
                )
>>> alpha_cut(fuzzy_set, 0.5)
{3, 4}
fuzzy_sets.alpha.alpha_ranges(fuzzy_set: FuzzySet) list[AlphaRange]

Produce an alpha cut representation of a fuzzy set.

Parameters:

fuzzy_set (FuzzySet) – The fuzzy set to represent/convert.

Returns:

A list of alpha ranges that represent the fuzzy set.

Return type:

list[AlphaRange]

Examples

>>> froodiness = FuzzySet(
                    {
                        FuzzySetMember("Ford Prefect", 1.0),
                        FuzzySetMember("Zaphod Beeblebrox", 1.0),
                        FuzzySetMember("Trillian", 0.7),
                        FuzzySetMember("Fenchurch", 0.7),
                        FuzzySetMember("Slartibartfast", 0.6),
                        FuzzySetMember("Arthur Dent", 0.5),
                        FuzzySetMember("Deep Thought", 0.4),
                        FuzzySetMember("Agrajag", 0.3),
                        FuzzySetMember("The poor whale", 0.2),
                        FuzzySetMember("Marvin", 0.1),
                        FuzzySetMember("Vogon", 0.1),
                    }
                )
>>> print("Froodiness:", froodiness)
Froodiness: Vogon/0.1 + Marvin/0.1 + The poor whale/0.2 + Agrajag/0.3 + Deep Thought/0.4 + Arthur Dent/0.5 + Slartibartfast/0.6 + Trillian/0.7 + Fenchurch/0.7 + Ford Prefect/1.0 + Zaphod Beeblebrox/1.0
>>> ranges = alpha_ranges(froodiness)
>>> print("\n".join([str(range) for range in ranges]))
{Agrajag, Arthur Dent, Deep Thought, Fenchurch, Ford Prefect, Marvin, Slartibartfast, The poor whale, Trillian, Vogon, Zaphod Beeblebrox}: α ∈ (0.0, 0.1]
{Agrajag, Arthur Dent, Deep Thought, Fenchurch, Ford Prefect, Slartibartfast, The poor whale, Trillian, Zaphod Beeblebrox}: α ∈ (0.1, 0.2]
{Agrajag, Arthur Dent, Deep Thought, Fenchurch, Ford Prefect, Slartibartfast, Trillian, Zaphod Beeblebrox}: α ∈ (0.2, 0.3]
{Arthur Dent, Deep Thought, Fenchurch, Ford Prefect, Slartibartfast, Trillian, Zaphod Beeblebrox}: α ∈ (0.3, 0.4]
{Arthur Dent, Fenchurch, Ford Prefect, Slartibartfast, Trillian, Zaphod Beeblebrox}: α ∈ (0.4, 0.5]
{Fenchurch, Ford Prefect, Slartibartfast, Trillian, Zaphod Beeblebrox}: α ∈ (0.5, 0.6]
{Fenchurch, Ford Prefect, Trillian, Zaphod Beeblebrox}: α ∈ (0.6, 0.7]
{Ford Prefect, Zaphod Beeblebrox}: α ∈ (0.7, 1.0]
fuzzy_sets.alpha.fuzzy_set_from_alpha_ranges(alpha_ranges: list[AlphaRange]) FuzzySet

Convert an alpha cut representation into a fuzzy set.

Parameters:

alpha_ranges (list[AlphaRange]) – A list of alpha ranges representing the alpha cuts.

Returns:

The fuzzy set representation

Return type:

FuzzySet

Examples

>>> fun_alpha_ranges = [
        AlphaRange(0, 0.5, {"video games", "uncertainty modelling coursework"}),
        AlphaRange(0.5, 1, {"uncertainty modelling coursework"}),
    ]
>>> print("\n".join([str(range) for range in fun_alpha_ranges]))
{uncertainty modelling coursework, video games}: α ∈ (0, 0.5]
{uncertainty modelling coursework}: α ∈ (0.5, 1]
>>> print(fuzzy_sets.alpha.fuzzy_set_from_alpha_ranges(fun_alpha_ranges))
video games/0.5 + uncertainty modelling coursework/1