A general FuzzySet object for mathematical fuzzy sets, inheriting from Set
.
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.
Other sets:
ConditionalSet
,
FuzzyMultiset
,
FuzzyTuple
,
Interval
,
Multiset
,
Set
,
Tuple
set6::Set
-> FuzzySet
new()
Create a new FuzzySet
object.
...
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.
FuzzySet
s 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.
A new FuzzySet
object.
strprint()
Creates a printable representation of the object.
FuzzySet$strprint(n = 2)
n
numeric. Number of elements to display on either side of ellipsis when printing.
A character string representing the object.
membership()
Returns the membership, i.e. value in [0, 1], of either the given element(s) or all elements in the fuzzy set.
FuzzySet$membership(element = NULL)
element
element or list of element in the set
, if NULL
returns membership of all elements
For FuzzySet
s this is straightforward and returns the membership of the given element(s),
however in FuzzyTuple
s and FuzzyMultiset
s when an element may be duplicated, the function returns the membership of
all instances of the element.
Value, or list of values, in [0, 1].
f = FuzzySet$new(1, 0.1, 2, 0.5, 3, 1) f$membership() f$membership(2) f$membership(list(1, 2))
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.
FuzzySet$alphaCut(alpha, strong = FALSE, create = FALSE)
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
Elements in FuzzySet or a Set of the elements.
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)
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.
FuzzySet$support(create = FALSE)
create
logical, if FALSE
(default) returns the support elements, otherwise returns a Set of the support elements
Support elements in fuzzy set or a Set of the support elements.
f = FuzzySet$new(0.1, 0, 1, 0.1, 2, 0.5, 3, 1) f$support() f$support(TRUE)
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.
FuzzySet$core(create = FALSE)
create
logical, if FALSE
(default) returns the core elements, otherwise returns a Set of the core elements
Core elements in FuzzySet or a Set of the core elements.
f = FuzzySet$new(0.1, 0, 1, 0.1, 2, 0.5, 3, 1) f$core() f$core(TRUE)
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\)
FuzzySet$inclusion(element)
element
element or list of elements in fuzzy set for which to get the inclusion level
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.
One of: "Included", "Partially Included", "Not Included"
f = FuzzySet$new(0.1, 0, 1, 0.1, 2, 0.5, 3, 1) f$inclusion(0.1) f$inclusion(1) f$inclusion(3)
equals()
Tests if two sets are equal.
FuzzySet$equals(x, all = FALSE)
Two fuzzy sets are equal if they contain the same elements with the same memberships. Infix operators can be used for:
Equal | == |
Not equal | != |
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
.
isSubset()
Test if one set is a (proper) subset of another
FuzzySet$isSubset(x, proper = FALSE, all = FALSE)
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.
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 | > |
Proper Superset | >= |
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
.
clone()
The objects of this class are cloneable with this method.
FuzzySet$clone(deep = FALSE)
deep
Whether to make a deep clone.
# Different constructors FuzzySet$new(1, 0.5, 2, 1, 3, 0) #> {1(0.5), 2(1), 3(0)} FuzzySet$new(elements = 1:3, membership = c(0.5, 1, 0)) #> {1(0.5), 2(1), 3(0)} # Crisp sets are a special case FuzzySet # Note membership defaults to full membership FuzzySet$new(elements = 1:5) == Set$new(1:5) #> Called from: FUN(X[[i]], ...) #> debug: if (!testSet(y)) { #> return(FALSE) #> } #> debug: if (testFuzzy(y)) { #> if (!all(y$membership() == 1)) { #> return(FALSE) #> } #> } #> debug: if (testConditionalSet(y)) { #> return(FALSE) #> } else if (testInterval(y)) { #> if (testCountablyFinite(y)) { #> return(all(suppressWarnings(y$elements %in% self$elements & #> self$elements %in% y$elements))) #> } #> else { #> return(FALSE) #> } #> } else if (sum(testEmpty(self), testEmpty(y)) == 1) { #> return(FALSE) #> } else { #> comp <- suppressWarnings(y$.__enclos_env__$private$.str_elements %in% #> private$.str_elements & private$.str_elements %in% y$.__enclos_env__$private$.str_elements) #> return(all(comp)) #> } #> debug: if (testInterval(y)) { #> if (testCountablyFinite(y)) { #> return(all(suppressWarnings(y$elements %in% self$elements & #> self$elements %in% y$elements))) #> } #> else { #> return(FALSE) #> } #> } else if (sum(testEmpty(self), testEmpty(y)) == 1) { #> return(FALSE) #> } else { #> comp <- suppressWarnings(y$.__enclos_env__$private$.str_elements %in% #> private$.str_elements & private$.str_elements %in% y$.__enclos_env__$private$.str_elements) #> return(all(comp)) #> } #> debug: if (sum(testEmpty(self), testEmpty(y)) == 1) { #> return(FALSE) #> } else { #> comp <- suppressWarnings(y$.__enclos_env__$private$.str_elements %in% #> private$.str_elements & private$.str_elements %in% y$.__enclos_env__$private$.str_elements) #> return(all(comp)) #> } #> debug: comp <- suppressWarnings(y$.__enclos_env__$private$.str_elements %in% #> private$.str_elements & private$.str_elements %in% y$.__enclos_env__$private$.str_elements) #> debug: return(all(comp)) #> [1] TRUE f <- FuzzySet$new(1, 0.2, 2, 1, 3, 0) f$membership() #> $`1` #> [1] 0.2 #> #> $`2` #> [1] 1 #> #> $`3` #> [1] 0 #> f$alphaCut(0.3) #> [[1]] #> [1] 2 #> f$core() #> [[1]] #> [1] 2 #> f$inclusion(0) #> [1] "Not Included" f$membership(0) #> [1] 0 f$membership(1) #> [1] 0.2 ## ------------------------------------------------ ## Method `FuzzySet$membership` ## ------------------------------------------------ f = FuzzySet$new(1, 0.1, 2, 0.5, 3, 1) f$membership() #> $`1` #> [1] 0.1 #> #> $`2` #> [1] 0.5 #> #> $`3` #> [1] 1 #> f$membership(2) #> [1] 0.5 f$membership(list(1, 2)) #> $`1` #> [1] 0.1 #> #> $`2` #> [1] 0.5 #> ## ------------------------------------------------ ## Method `FuzzySet$alphaCut` ## ------------------------------------------------ f = FuzzySet$new(1, 0.1, 2, 0.5, 3, 1) # Alpha-cut f$alphaCut(0.5) #> [[1]] #> [1] 2 #> #> [[2]] #> [1] 3 #> # Strong alpha-cut f$alphaCut(0.5, strong = TRUE) #> [[1]] #> [1] 3 #> # Create a set from the alpha-cut f$alphaCut(0.5, create = TRUE) #> {2, 3} ## ------------------------------------------------ ## Method `FuzzySet$support` ## ------------------------------------------------ f = FuzzySet$new(0.1, 0, 1, 0.1, 2, 0.5, 3, 1) f$support() #> [[1]] #> [1] 1 #> #> [[2]] #> [1] 2 #> #> [[3]] #> [1] 3 #> f$support(TRUE) #> {1, 2, 3} ## ------------------------------------------------ ## Method `FuzzySet$core` ## ------------------------------------------------ f = FuzzySet$new(0.1, 0, 1, 0.1, 2, 0.5, 3, 1) f$core() #> [[1]] #> [1] 3 #> f$core(TRUE) #> {3} ## ------------------------------------------------ ## Method `FuzzySet$inclusion` ## ------------------------------------------------ f = FuzzySet$new(0.1, 0, 1, 0.1, 2, 0.5, 3, 1) f$inclusion(0.1) #> [1] "Not Included" f$inclusion(1) #> [1] "Partially Included" f$inclusion(3) #> [1] "Fully Included"