0% found this document useful (0 votes)
1K views

Implement Union, Intersection, Complement and Difference Operations of Fuzzy Set Using Python

This document demonstrates how to implement union, intersection, complement, and difference operations on fuzzy sets using Python. It defines two fuzzy sets A and B with membership functions, then performs the fuzzy set operations - union uses the maximum membership value, intersection the minimum, complement calculates 1 minus the original membership, and difference takes the maximum of the first set's membership minus the second. The results are plotted on a graph for visualization.

Uploaded by

Soniya Datti
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views

Implement Union, Intersection, Complement and Difference Operations of Fuzzy Set Using Python

This document demonstrates how to implement union, intersection, complement, and difference operations on fuzzy sets using Python. It defines two fuzzy sets A and B with membership functions, then performs the fuzzy set operations - union uses the maximum membership value, intersection the minimum, complement calculates 1 minus the original membership, and difference takes the maximum of the first set's membership minus the second. The results are plotted on a graph for visualization.

Uploaded by

Soniya Datti
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Implement union, intersection , complement and difference

operations of fuzzy set using python

import numpy as np

# Define the fuzzy sets


setA = np.array([0.1, 0.4, 0.7, 0.9])
setB = np.array([0.2, 0.5, 0.8])

# Define the universe of discourse


x = np.linspace(0, 1, 100)

# Define the membership functions


mA = np.interp(x, [0, 0.5, 1], [0, 1, 0])
mB = np.interp(x, [0, 0.5, 1], [0, 1, 0.5])

# Perform union
union = np.fmax(mA, mB)

# Perform intersection
intersection = np.fmin(mA, mB)

# Perform complement
complementA = 1 - mA

# Perform difference
difference = np.fmax(mA - mB, np.zeros_like(x))

# Plot the fuzzy sets and the operations


import matplotlib.pyplot as plt

plt.figure(figsize=(10, 8))

plt.plot(x, mA, label="A")


plt.plot(x, mB, label="B")
plt.plot(x, union, label="A union B")
plt.plot(x, intersection, label="A intersection B")
plt.plot(x, complementA, label="A complement")
plt.plot(x, difference, label="A difference B")

plt.legend(loc="upper right")
plt.show()

Output:

You might also like