0% found this document useful (0 votes)
21 views1 page

Practical 7.Write a Python Program for Bidirectional Associative Memory With Two Pairs of Vectors

The document presents a Python program for Bidirectional Associative Memory using two pairs of input and output vectors. It computes a weight matrix using the outer product rule and defines a recall function for bidirectional retrieval. The program tests the recall functionality by retrieving output vectors from input vectors and vice versa.

Uploaded by

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

Practical 7.Write a Python Program for Bidirectional Associative Memory With Two Pairs of Vectors

The document presents a Python program for Bidirectional Associative Memory using two pairs of input and output vectors. It computes a weight matrix using the outer product rule and defines a recall function for bidirectional retrieval. The program tests the recall functionality by retrieving output vectors from input vectors and vice versa.

Uploaded by

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

Write a python Program for Bidirectional Associative Memory

with two pairs of vectors


import numpy as np

# Define the training pairs


X = np.array([[1, -1, 1], [-1, 1, -1]]) # Input Vectors
Y = np.array([[1, 1, -1], [-1, -1, 1]]) # Output Vectors

# Compute the weight matrix using the outer product rule


W = np.dot(X.T, Y) # W = X^T * Y

# Function for recall (bidirectional retrieval)


def recall(input_vector, weight_matrix, is_forward=True):
output = np.sign(np.dot(input_vector, weight_matrix))
output[output == 0] = 1 # To handle zero activations
return output

# Test the recall in forward and backward direction


test_X = np.array([[1, -1, 1]]) # Given an input X, find Y
recalled_Y = recall(test_X, W, is_forward=True)
print("Recalled Y for given X:", recalled_Y)

test_Y = np.array([[1, 1, -1]]) # Given an output Y, find X


recalled_X = recall(test_Y, W.T, is_forward=False)
print("Recalled X for given Y:", recalled_X)

You might also like