¿Qué es el conjunto borroso?
Borroso se refiere a algo que no está claro o es vago. Por lo tanto, Fuzzy Set es un conjunto en el que cada clave está asociada con un valor, que está entre 0 y 1 según la certeza. Este valor a menudo se denomina grado de pertenencia. El conjunto borroso se denota con un signo de tilde encima de la notación de conjunto normal.
Operaciones en conjunto borroso con código:
1. Unión:
Considere 2 conjuntos borrosos denotados por A y B, luego consideremos que Y es la unión de ellos, luego para cada miembro de A y B, Y será:
degree_of_membership(Y)= max(degree_of_membership(A), degree_of_membership(B))
EJEMPLO :
Python3
# Example to Demonstrate the # Union of Two Fuzzy Sets A = dict() B = dict() Y = dict() A = {"a": 0.2, "b": 0.3, "c": 0.6, "d": 0.6} B = {"a": 0.9, "b": 0.9, "c": 0.4, "d": 0.5} print('The First Fuzzy Set is :', A) print('The Second Fuzzy Set is :', B) for A_key, B_key in zip(A, B): A_value = A[A_key] B_value = B[B_key] if A_value > B_value: Y[A_key] = A_value else: Y[B_key] = B_value print('Fuzzy Set Union is :', Y)
The First Fuzzy Set is : {'a': 0.2, 'b': 0.3, 'c': 0.6, 'd': 0.6} The Second Fuzzy Set is : {'a': 0.9, 'b': 0.9, 'c': 0.4, 'd': 0.5} Fuzzy Set Union is : {'a': 0.9, 'b': 0.9, 'c': 0.6, 'd': 0.6}
2. Intersección:
Considere 2 conjuntos borrosos denotados por A y B, luego consideremos que Y es la intersección de ellos, luego para cada miembro de A y B, Y será:
degree_of_membership(Y)= min(degree_of_membership(A), degree_of_membership(B))
EJEMPLO :
Python3
# Example to Demonstrate # Intersection of Two Fuzzy Sets A = dict() B = dict() Y = dict() A = {"a": 0.2, "b": 0.3, "c": 0.6, "d": 0.6} B = {"a": 0.9, "b": 0.9, "c": 0.4, "d": 0.5} print('The First Fuzzy Set is :', A) print('The Second Fuzzy Set is :', B) for A_key, B_key in zip(A, B): A_value = A[A_key] B_value = B[B_key] if A_value < B_value: Y[A_key] = A_value else: Y[B_key] = B_value print('Fuzzy Set Intersection is :', Y)
The First Fuzzy Set is : {'a': 0.2, 'b': 0.3, 'c': 0.6, 'd': 0.6} The Second Fuzzy Set is : {'a': 0.9, 'b': 0.9, 'c': 0.4, 'd': 0.5} Fuzzy Set Intersection is : {'a': 0.2, 'b': 0.3, 'c': 0.4, 'd': 0.5}
3. Complemento:
Considere un conjunto borroso denotado por A, luego consideremos que Y es el complemento de este, luego para cada miembro de A, Y será:
degree_of_membership(Y)= 1 - degree_of_membership(A)
EJEMPLO :
Python3
# Example to Demonstrate the # Difference Between Two Fuzzy Sets A = dict() Y = dict() A = {"a": 0.2, "b": 0.3, "c": 0.6, "d": 0.6} print('The Fuzzy Set is :', A) for A_key in A: Y[A_key]= 1-A[A_key] print('Fuzzy Set Complement is :', Y)
The Fuzzy Set is : {'a': 0.2, 'b': 0.3, 'c': 0.6, 'd': 0.6} Fuzzy Set Complement is : {'a': 0.8, 'b': 0.7, 'c': 0.4, 'd': 0.4}
4. Diferencia:
Considere 2 conjuntos borrosos denotados por A y B, luego consideremos que Y es la intersección de ellos, luego para cada miembro de A y B, Y será:
degree_of_membership(Y)= min(degree_of_membership(A), 1- degree_of_membership(B))
EJEMPLO :
Python3
# Example to Demonstrate the # Difference Between Two Fuzzy Sets A = dict() B = dict() Y = dict() A = {"a": 0.2, "b": 0.3, "c": 0.6, "d": 0.6} B = {"a": 0.9, "b": 0.9, "c": 0.4, "d": 0.5} print('The First Fuzzy Set is :', A) print('The Second Fuzzy Set is :', B) for A_key, B_key in zip(A, B): A_value = A[A_key] B_value = B[B_key] B_value = 1 - B_value if A_value < B_value: Y[A_key] = A_value else: Y[B_key] = B_value print('Fuzzy Set Difference is :', Y)
Producción
The First Fuzzy Set is : {"a": 0.2, "b": 0.3, "c": 0.6, "d": 0.6} The Second Fuzzy Set is : {"a": 0.9, "b": 0.9, "c": 0.4, "d": 0.5} Fuzzy Set Difference is : {"a": 0.1, "b": 0.1, "c": 0.6, "d": 0.5}
Conjuntos difusos de clase
Python3
class FzSets: def __init__(self): self.A = dict() self.B = dict() self.complement_A = dict() self.complement_B = dict() self.union_AB = dict() self.intersection_AB = dict() self.differenceAB = dict() self.differenceBA = dict() self.change_union = False self.change_intersection = False self.change_complement = False def __init__(self,A,nA,B,nB): self.A = A self.B = B self.Aname = nA self.Bname = nB self.complement_A = dict() self.complement_B = dict() self.union_AB = dict() self.intersection_AB = dict() self.differenceAB = dict() self.differenceBA = dict() self.change_union = False self.change_intersection = False self.change_complement = False def unionOp(self): if self.change_union: print('Result of UNION operation :',self.union_AB) else: #unionSet = set(self.A.keys()).union(self.B.keys()) sa = set(self.A.keys()) sb = set(self.B.keys()) intersectionSet = set(self.A.keys()).intersection(self.B.keys()) for i in intersectionSet: self.union_AB[i] = max(self.A[i],self.B[i]) for i in sa-intersectionSet: self.union_AB[i] = self.A[i] for i in sb-intersectionSet: self.union_AB[i] = self.B[i] print('Result of UNION operation :',self.union_AB) def intersectionOp(self): if self.change_intersection: print('Result of INTERSECTION operation :\n\t\t',self.intersection_AB) else: #unionSet = set(self.A.keys()).union(self.B.keys()) sa = set(self.A.keys()) sb = set(self.B.keys()) intersectionSet = set(self.A.keys()).intersection(self.B.keys()) for i in intersectionSet: self.intersection_AB[i] = min(self.A[i],self.B[i]) for i in sa-intersectionSet: self.intersection_AB[i] = 0.0 for i in sb-intersectionSet: self.intersection_AB[i] = 0.0 print('Result of INTERSECTION operation :\n\t\t',self.intersection_AB) self.change_intersection = True def complementOp(self): if self.change_complement: print('Result of COMPLEMENT on ',self.Aname,' operation :',self.complement_A) print('Result of COMPLEMENT on ',self.Bname,' operation :',self.complement_B) else: for i in self.A: self.complement_A[i] = 1 - A[i] for i in self.B: self.complement_B[i] = 1 - B[i] print('Result of COMPLEMENT on ',self.Aname,' operation :',self.complement_A) print('Result of COMPLEMENT on ',self.Aname,' operation :',self.complement_B) self.change_complement = True def __oneMinustwo(self,L,R): minus_d = dict() Rcomp = dict() for i in R: Rcomp[i] = 1 - R[i] sa = set(L.keys()) sb = set(R.keys()) intersectionSet = sa.intersection(sb) # min( A , complement(B) ) # l - r OR a - b for i in intersectionSet: minus_d[i] = min(L[i],Rcomp[i]) for i in sa-intersectionSet: minus_d[i] = 0.0 for i in sb-intersectionSet: minus_d[i] = 0.0 return minus_d def AminusB(self): self.differenceAB = self.__oneMinustwo(self.A,self.B) print('Result of DIFFERENCE ',self.Aname,' | ',self.Bname,' operation :\n\t\t',self.differenceAB) def BminusA(self): self.differenceBA = self.__oneMinustwo(self.B,self.A) print('Result of DIFFERENCE ',self.Bname,' | ',self.Aname,' operation :\n\t\t',self.differenceBA) def change_Setz(self,A,B): self.A = A self.B = B print('\nSet ',self.Aname,' :',self.A) print('Set ',self.Bname,' :',self.B,end='') self.change_union = True self.change_intersection = True self.change_complement = True print('\t\t\t Cache Reset') def displaySets(self): print('\nSet ',self.Aname,' :',self.A) print('Set ',self.Bname,' :' ,self.B)