0% found this document useful (0 votes)
118 views

2 - WAP in Python To Perform Various Operations in Fuzzy

This document discusses fuzzy sets and operations that can be performed on them using Python code examples. It defines fuzzy sets as sets where elements have membership values between 0 and 1 instead of binary values. It then shows code to perform union, intersection, complement, and difference operations on fuzzy sets by manipulating the membership values of elements in each set according to specific mathematical rules.

Uploaded by

vinayak mishra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
118 views

2 - WAP in Python To Perform Various Operations in Fuzzy

This document discusses fuzzy sets and operations that can be performed on them using Python code examples. It defines fuzzy sets as sets where elements have membership values between 0 and 1 instead of binary values. It then shows code to perform union, intersection, complement, and difference operations on fuzzy sets by manipulating the membership values of elements in each set according to specific mathematical rules.

Uploaded by

vinayak mishra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

WAP in python to perform various operations in fuzzy

What is Fuzzy Set ?


Fuzzy refers to something that is unclear or vague. Hence, Fuzzy Set is a Set where every key
is associated with value, which is between 0 to 1 based on the certainty. This value is often
called as degree of membership. Fuzzy Set is denoted with a Tilde Sign on top of the normal
Set notation.

In command prompt
pip install fuzzywuzzy

Operations on Fuzzy Set to perform union


Consider 2 Fuzzy Sets denoted by A and B, then let’s consider Y be the Union of them, then
for every member of A and B, Y will be:
degree_of_membership(Y)= max(degree_of_membership(A), degree_of_membership(B))
program
# 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)


output:
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}
Operations on Fuzzy Set to perform intersection
Consider 2 Fuzzy Sets denoted by A and B, then let’s consider Y be the Intersection of them,
then for every member of A and B, Y will be:
degree_of_membership(Y)= min(degree_of_membership(A), degree_of_membership(B))
program
# 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)
OUTPUT:
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}

Complement :

Consider a Fuzzy Sets denoted by A , then let’s consider Y be the Complement of it, then
for every member of A , Y will be:
degree_of_membership(Y)= 1 - degree_of_membership(A)
Program
# 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)
OUTPUT:
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. Difference :
Consider 2 Fuzzy Sets denoted by A and B, then let’s consider Y be the Intersection of them,
then for every member of A and B, Y will be:
degree_of_membership(Y)= min(degree_of_membership(A), 1- degree_of_membership(B))
Program
# 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)

OUTPUT:
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.09999999999999998, 'b': 0.09999999999999998, 'c': 0.6, 'd':
0.5}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy