AD
AD
AD
Program:
% Enter the membership value of fuzzy set
u = input (‘Enter the membership value of First Fuzzy set’);
v = input (‘Enter the membership value of Second Fuzzy set’);
%performs Union, Intersection and Complement operations
w=max (u, v);
p=min (u, v);
q1=1-u;
q2=1-v;
%Display Output
disp(‘Union of Two Fuzzy sets’);
disp(w);
disp(‘Intersection of Two Fuzzy sets’);
disp(p);
disp(‘Complement of First Fuzzy set’);
disp(q1);
disp(‘Complement of Second Fuzzy set’);
disp(q2);
Sample Input and Output:
Discussion:
Thus, the MATLAB program to perform Union, Intersection and Complement operations
of two Fuzzy sets has been executed successfully and the output is verified.
0.3000. 0.5000
Intersection of two fuzzy sets
0.3000 0.4000.
Complement of first fuzzy set
0.7000 0.6000.
Complement of second fuzzy set
0.8000 0.5000.
De-Morgan’s Law: (i) (A ∪ B)' = A' ∩ B' and (ii) (A ∩ B)' = A'
∪ B'
Output: (0.3 0.5)’ = (0.7 0.6) ∩ (0.8 0.5) = (0.7 0.5)
Discussion:
Thus, the MATLAB program for implementation of De-Morgan’s has been executed
successfully and the output is verified.
A * B = (a * b)
g= c – 1
bp= max (0,g)
disp(‘The algebraic sum’)
disp(as)
disp(‘The algebraic difference’)
disp(ad)
disp(‘The algebraic product’)
disp(d)
disp(‘The bounded sum’)
disp(bs)
disp(‘The bounded difference’)
disp (bd)
disp(‘The bounded product’)
disp(bp)
Output:
Enter fuzzy set a [1 0.5]
Enter fuzzy set b [0.4 0.2]
The algebraic sum
[1.0000 0.6000 ]
The algebraic difference
[1 0.9000]
The algebraic product
[0.4000 0.1000]
The bounded sum
[1.0000 0.7000]
The bounded difference
[0.6000 0.3000]
The bounded product
[0.4000 0]
Discussion:
Thus, a program to perform simple fuzzy set operations has been executed and
successfully
verified.
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(X, Y, Z, cmap='coolwarm')
ax.scatter(*zip(*history), c='r', marker='o')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('f(x, y)')
plt.show()
Installation
From PyPi
pip install aco
Using Poetry
poetry add aco
Usage
AntColony(
nodes,
start=None,
ant_count=300,
alpha=0.5,
beta=1.2,
pheromone_evaporation_rate=0.40,
pheromone_constant=1000.0,
iterations=300,
)
Travelling Salesman Problem
import matplotlib.pyplot as plt
import random
from aco import AntColony
plt.style.use("dark_background")
COORDS = (
(20, 52),
(43, 50),
(20, 84),
(70, 65),
(29, 90),
(87, 83),
(73, 23),
)
def random_coord():
r = random.randint(0, len(COORDS))
return r
def plot_nodes(w=12, h=8):
for x, y in COORDS:
Step 2: Compute the dot products between the vector of inputs and weights
dot = I @ W
print(f'Dot product: {dot}')
Step 3: Define the threshold activation function
def linear_threshold_gate(dot: int, T: float) -> int:
'''Returns the binary threshold output'''
if dot >= T:
return 1
else:
return 0
Step 2: Compute the dot products between the matrix of inputs and weights
# dot product matrix of inputs and weights
dot_products = input_table @ weights
print(f'Dot products: {dot_products}')
Step 3: Define the threshold activation function
def linear_threshold_gate(dot: int, T: float) -> int:
'''Returns the binary threshold output'''
if dot >= T:
return 1
else:
return 0
Step 4: Compute the output based on the threshold
T = 2
for i in range(0,4):
activation = linear_threshold_gate(dot_products[i], T)
print(f'Activation: {activation}')
Step 2: Compute the dot products between the matrix of inputs and weights
# dot product matrix of inputs and weights
dot_products = input_table @ weights
print(f'Dot products: {dot_products}')
Step 3: Define the threshold activation function
def linear_threshold_gate(dot: int, T: float) -> int:
'''Returns the binary threshold output'''
if dot >= T:
return 1
else:
return 0
Discussion:
Thus, the MATLAB program for implementation of De-Morgan’s has been
executed successfully and the output is verified.