Learn R Programming

set6 (version 0.2.4)

FuzzySet: Mathematical Fuzzy Set

Description

A general FuzzySet object for mathematical fuzzy sets, inheriting from Set.

Arguments

Super class

set6::Set -> FuzzySet

Methods

Public methods

Method new()

Create a new FuzzySet object.

Usage

FuzzySet$new(
  ...,
  elements = NULL,
  membership = rep(1, length(elements)),
  class = NULL
)

Arguments

...

Alternating elements and membership, see details.

elements

Elements in the set, see details.

membership

Corresponding membership of the elements, see details.

class

Optional string naming a class that if supplied gives the set the typed property.

Details

FuzzySets can be constructed in one of two ways, either by supplying the elements and their membership in alternate order, or by providing a list of elements to elements and a list of respective memberships to membership, see examples. If the class argument is non-NULL, then all elements will be coerced to the given class in construction, and if elements of a different class are added these will either be rejected or coerced.

Returns

A new FuzzySet object.

Method strprint()

Creates a printable representation of the object.

Usage

FuzzySet$strprint(n = 2)

Arguments

n

numeric. Number of elements to display on either side of ellipsis when printing.

Returns

A character string representing the object.

Method membership()

Returns the membership, i.e. value in [0, 1], of either the given element(s) or all elements in the fuzzy set.

Usage

FuzzySet$membership(element = NULL)

Arguments

element

element or list of element in the set, if NULL returns membership of all elements

Details

For FuzzySets this is straightforward and returns the membership of the given element(s), however in FuzzyTuples and FuzzyMultisets when an element may be duplicated, the function returns the membership of all instances of the element.

Returns

Value, or list of values, in [0, 1].

Examples

f = FuzzySet$new(1, 0.1, 2, 0.5, 3, 1)
f$membership()
f$membership(2)
f$membership(list(1, 2))

Method alphaCut()

The alpha-cut of a fuzzy set is defined as the set $$A_\alpha = \{x \epsilon F | m \ge \alpha\}$$ where \(x\) is an element in the fuzzy set, \(F\), and \(m\) is the corresponding membership.

Usage

FuzzySet$alphaCut(alpha, strong = FALSE, create = FALSE)

Arguments

alpha

numeric in [0, 1] to determine which elements to return

strong

logical, if FALSE (default) then includes elements greater than or equal to alpha, otherwise only strictly greater than

create

logical, if FALSE (default) returns the elements in the alpha cut, otherwise returns a crisp set of the elements

Returns

Elements in FuzzySet or a Set of the elements.

Examples

f = FuzzySet$new(1, 0.1, 2, 0.5, 3, 1)
# Alpha-cut
f$alphaCut(0.5)

# Strong alpha-cut f$alphaCut(0.5, strong = TRUE)

# Create a set from the alpha-cut f$alphaCut(0.5, create = TRUE)

Method support()

The support of a fuzzy set is defined as the set of elements whose membership is greater than zero, or the strong alpha-cut with \(\alpha = 0\), $$A_\alpha = \{x \epsilon F | m > 0\}$$ where \(x\) is an element in the fuzzy set, \(F\), and \(m\) is the corresponding membership.

Usage

FuzzySet$support(create = FALSE)

Arguments

create

logical, if FALSE (default) returns the support elements, otherwise returns a Set of the support elements

Returns

Support elements in fuzzy set or a Set of the support elements.

Examples

f = FuzzySet$new(0.1, 0, 1, 0.1, 2, 0.5, 3, 1)
f$support()
f$support(TRUE)

Method core()

The core of a fuzzy set is defined as the set of elements whose membership is equal to one, or the alpha-cut with \(\alpha = 1\), $$A_\alpha = \{x \epsilon F \ : \ m \ge 1\}$$ where \(x\) is an element in the fuzzy set, \(F\), and \(m\) is the corresponding membership.

Usage

FuzzySet$core(create = FALSE)

Arguments

create

logical, if FALSE (default) returns the core elements, otherwise returns a Set of the core elements

Returns

Core elements in FuzzySet or a Set of the core elements.

Examples

f = FuzzySet$new(0.1, 0, 1, 0.1, 2, 0.5, 3, 1)
f$core()
f$core(TRUE)

Method inclusion()

An element in a fuzzy set, with corresponding membership \(m\), is:

  • Included - If \(m = 1\)

  • Partially Included - If \(0 < m < 1\)

  • Not Included - If \(m = 0\)

Usage

FuzzySet$inclusion(element)

Arguments

element

element or list of elements in fuzzy set for which to get the inclusion level

Details

For FuzzySets this is straightforward and returns the inclusion level of the given element(s), however in FuzzyTuples and FuzzyMultisets when an element may be duplicated, the function returns the inclusion level of all instances of the element.

Returns

One of: "Included", "Partially Included", "Not Included"

Examples

f = FuzzySet$new(0.1, 0, 1, 0.1, 2, 0.5, 3, 1)
f$inclusion(0.1)
f$inclusion(1)
f$inclusion(3)

Method equals()

Tests if two sets are equal.

Usage

FuzzySet$equals(x, all = FALSE)

Arguments

x

Set or vector of Sets.

all

logical. If FALSE tests each x separately. Otherwise returns TRUE only if all x pass test.

Details

Two fuzzy sets are equal if they contain the same elements with the same memberships. Infix operators can be used for:

Equal ==
Not equal !=

Returns

If all is TRUE then returns TRUE if all x are equal to the Set, otherwise FALSE. If all is FALSE then returns a vector of logicals corresponding to each individual element of x.

Method isSubset()

Test if one set is a (proper) subset of another

Usage

FuzzySet$isSubset(x, proper = FALSE, all = FALSE)

Arguments

x

any. Object or vector of objects to test.

proper

logical. If TRUE tests for proper subsets.

all

logical. If FALSE tests each x separately. Otherwise returns TRUE only if all x pass test.

Details

If using the method directly, and not via one of the operators then the additional boolean argument proper can be used to specify testing of subsets or proper subsets. A Set is a proper subset of another if it is fully contained by the other Set (i.e. not equal to) whereas a Set is a (non-proper) subset if it is fully contained by, or equal to, the other Set.

Infix operators can be used for:

Subset <
Proper Subset <=
Superset >

Returns

If all is TRUE then returns TRUE if all x are subsets of the Set, otherwise FALSE. If all is FALSE then returns a vector of logicals corresponding to each individual element of x.

Method clone()

The objects of this class are cloneable with this method.

Usage

FuzzySet$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Details

Fuzzy sets generalise standard mathematical sets to allow for fuzzy relationships. Whereas a standard, or crisp, set assumes that an element is either in a set or not, a fuzzy set allows an element to be in a set to a particular degree, known as the membership function, which quantifies the inclusion of an element by a number in [0, 1]. Thus a (crisp) set is a fuzzy set where all elements have a membership equal to \(1\). Similarly to Sets, elements must be unique and the ordering does not matter, to establish order and non-unique elements, FuzzyTuples can be used.

See Also

Other sets: ConditionalSet, FuzzyMultiset, FuzzyTuple, Interval, Multiset, Set, Tuple

Examples

Run this code
# NOT RUN {
# Different constructors
FuzzySet$new(1, 0.5, 2, 1, 3, 0)
FuzzySet$new(elements = 1:3, membership = c(0.5, 1, 0))

# Crisp sets are a special case FuzzySet
# Note membership defaults to full membership
FuzzySet$new(elements = 1:5) == Set$new(1:5)

f <- FuzzySet$new(1, 0.2, 2, 1, 3, 0)
f$membership()
f$alphaCut(0.3)
f$core()
f$inclusion(0)
f$membership(0)
f$membership(1)

## ------------------------------------------------
## Method `FuzzySet$membership`
## ------------------------------------------------

f = FuzzySet$new(1, 0.1, 2, 0.5, 3, 1)
f$membership()
f$membership(2)
f$membership(list(1, 2))

## ------------------------------------------------
## Method `FuzzySet$alphaCut`
## ------------------------------------------------

f = FuzzySet$new(1, 0.1, 2, 0.5, 3, 1)
# Alpha-cut
f$alphaCut(0.5)

# Strong alpha-cut
f$alphaCut(0.5, strong = TRUE)

# Create a set from the alpha-cut
f$alphaCut(0.5, create = TRUE)

## ------------------------------------------------
## Method `FuzzySet$support`
## ------------------------------------------------

f = FuzzySet$new(0.1, 0, 1, 0.1, 2, 0.5, 3, 1)
f$support()
f$support(TRUE)

## ------------------------------------------------
## Method `FuzzySet$core`
## ------------------------------------------------

f = FuzzySet$new(0.1, 0, 1, 0.1, 2, 0.5, 3, 1)
f$core()
f$core(TRUE)

## ------------------------------------------------
## Method `FuzzySet$inclusion`
## ------------------------------------------------

f = FuzzySet$new(0.1, 0, 1, 0.1, 2, 0.5, 3, 1)
f$inclusion(0.1)
f$inclusion(1)
f$inclusion(3)
# }

Run the code above in your browser using DataLab