Group A

QA5: Write a Python program to simulate Bidirectional Associative Memory (BAM).

Bidirectional Associative Memory

Solution and implementation for QA5 from Artificial Neural Network (ann).

A5_bam_bidirectional_memory.py Download
import numpy as np

def sign(v):
    if v >= 0:
        return 1
    else:
        return -1

input = np.array([[1, -1, 1], [-1, 1, -1]])
output = np.array([[1, 1], [-1, -1]])

weight = np.zeros((3, 2))

for i in range(len(input)):
    weight = weight + np.outer(input[i], output[i])

print("W:\n", weight)

print("\nFwd:")
for i in range(len(input)):
    res = np.dot(input[i], weight)
    pred = [sign(v) for v in res]
    print(input[i], "->", pred)

print("\nBwd:")
for i in range(len(output)):
    res = np.dot(output[i], weight.T)
    pred = [sign(v) for v in res]
    print(output[i], "->", pred)

Other Questions in Artificial Neural Network

See All Available Questions
Download