BeginPackage["FuzzySetFunctions`"] (* FuzzySetFunctions contains functions that provide operations and tests on lists that are in the form of finite fuzzy sets i.e. are lists of pairs in which the first slot contains the value of the membership function and the second slot contains the element. *) FuzzyQ::usage = "FuzzyQ[a] returns True if a is a finite fuzzy set" CrispQ::usage = "CrispQ[a] returns True if a is a finite crisp set" mu::usage = "mu[a] returns a list which represents the membership function of a" Elements::usage = "Elements[a] returns a list of the elements of a" (* a == Transpose[List[mu[a], Elements[a]]] *) Support::usage= "Support[a] returns a list of the elements of a for which the value of the membership function is non- zero" LevelSet::usage = "LevelSet[a,alpha] returns a list of elements of a for which the value of the membership function is greater than or equal to alpha" Height::usage = "Height[a] returns the supremum of the membership function taken over the fuzzy set a" NormalQ::usage = "NormalQ[a] returns True if the height of a is unity" FuzzySubsetQ::usage = "FuzzySubsetQ[a,b] returns True if a is a fuzzy subset of b" FuzzyIntersection::usage = "FuzzyIntersection[a,b] returns the fuzzy intersection of the fuzzy sets a and b" FuzzyUnion::usage = "FuzzyUnion[a,b] returns the fuzzy union of the fuzzy sets a and b" FuzzyProduct::usage = "FuzzyProduct[a,b] returns the fuzzy product of the fuzzy sets a and b" FuzzyPower::usage = "FuzzyPower[a,alpha] modifies the membership func- tion of a via slotwise application of alpha as an exponent and returns the result" Concentration::usage = "Concentration[a] returns the fuzzy power of the fuzzy set a with alpha set equal to 2.0" Dilation::usage = "Dilation[a] returns the fuzzy power of the fuzzy set a with alpha set equal to 0.5" FuzzyScalarProduct::usage = "FuzzyScalarProduct[a,alpha] scales the membership function of a via slotwise multiplication by alpha and returns the result" FuzzyBoundedSum::usage = "FuzzyBoundedSum[a,b] returns the fuzzy sum of the the fuzzy sets a and b with unity as an upper bound of the membership function" FuzzyBoundedDifference::usage = "FuzzyBoundedDifference[a,b] returns the fuzzy difference of the fuzzy sets a and b with zero as the lower bound of the membership function" FuzzyComplement::usage = "FuzzyComplement[a] returns the fuzzy comple- ment of the fuzzy set a" Begin["`private`"] FuzzyQ[a_List] := OrderedQ[a, OrderedQ[List[#1[[2]],#2[[2]]]]&] && Apply[And, Map[(SameQ[2,Length[#]])&, a]] && Apply[ And, Map[(If[0 <= #[[1]] <= 1, True, False])&, a]] CrispQ[a_List?FuzzyQ] := Apply[And, Map[(SameQ[#[[1]],N[Sign[#[[1]]]]])&, a]] mu[a_List?FuzzyQ] := Map[First, a] Elements[a_List?FuzzyQ] := Map[Last, a] Support[a_List?FuzzyQ] := Elements[Select[a, (#[[1]] > 0)&]] LevelSet[a_List?FuzzyQ, alpha_?((0 <= # <= 1)&)] := Elements[Select[a, (#[[1]] >= alpha)&]] Height[a_List?FuzzyQ] := Apply[Max, mu[a]] NormalQ[a_List?FuzzyQ] := SameQ[1.0,Height[a]] FuzzySubsetQ[a_List?FuzzyQ, b_List?FuzzyQ] := Apply[And, Map[(If[#[[1]] <= #[[2]], True, False])&, Transpose[ List[mu[a],mu[b]]]]] /; SameQ[Elements[a],Elements[b]] FuzzyIntersection[a_List?FuzzyQ, b_List?FuzzyQ] := Transpose[List[Map[(Apply[Min, #])&, Transpose[ List[mu[a],mu[b]]]], Elements[a]]] /; SameQ[Elements[a],Elements[b]] FuzzyUnion[a_List?FuzzyQ, b_List?FuzzyQ] := Transpose[List[Map[(Apply[Max, #])&, Transpose[ List[mu[a],mu[b]]]], Elements[a]]] /; SameQ[Elements[a],Elements[b]] FuzzyProduct[a_List?FuzzyQ, b_List?FuzzyQ] := Transpose[List[Map[(Apply[Times, #])&, Transpose[ List[mu[a],mu[b]]]], Elements[a]]] /; SameQ[Elements[a],Elements[b]] FuzzyPower[a_List?FuzzyQ, alpha_?((# > 0)&)] := Map[(List[#[[1]]^alpha,#[[2]]])&, a] Concentration[a_List?FuzzyQ] := FuzzyPower[a, 2.0] Dilation[a_List?FuzzyQ] := FuzzyPower[a, 0.5] FuzzyScalarProduct[a_List?FuzzyQ, alpha_?((# >= 0)&)] := Map[(List[#[[1]] alpha,#[[2]]])&, a] /; alpha Height[a] <= 1.0 FuzzyBoundedSum[a_List?FuzzyQ, b_List?FuzzyQ] := Transpose[List[Map[(Min[1.0, #])&, Map[(#[[1]] + #[[2]])&, Transpose[ List[mu[a],mu[b]]]]], Elements[a]]] /; SameQ[Elements[a],Elements[b]] FuzzyBoundedDifference[a_List?FuzzyQ, b_List?FuzzyQ] := Transpose[List[Map[(Max[0.0, #])&, Map[(#[[1]] - #[[2]])&, Transpose[ List[mu[a],mu[b]]]]], Elements[a]]] /; SameQ[Elements[a],Elements[b]] FuzzyComplement[a_List?FuzzyQ] := Map[(List[1 - #[[1]],#[[2]]])&, a] End[ ] Protect[FuzzyQ, CrispQ, NormalQ, FuzzySubsetQ, mu, FuzzyIntersection, FuzzyUnion, FuzzyProduct, FuzzyPower, FuzzyComplement, Height, FuzzyScalarProduct, Elements, Support, LevelSet, Dilation, Concentration, FuzzyBoundedSum, FuzzyBoundedDifference] EndPackage[ ] (* 27-01-94 *) (* functions -- Marmion Hays *)