Open In App

ANN – Bidirectional Associative Memory (BAM) Learning Algorithm

Improve
Improve
Like Article
Like
Save
Share
Report
Prerequisite: ANN | Bidirectional Associative Memory (BAM) There are three main steps to construct the BAM model.
  1. Learning
  2. Testing
  3. Retrieval
Each step has been described with mathematical formulation in the article ANN | Bidirectional Associative Memory (BAM). Here, this learning algorithm is explained iteratively with an example. Assume, Set A: Input Patterns

    \[$\operatorname{Set} \boldsymbol{A}: X_{1}=\left[\begin{array}{c}1 \\ 1 \\ 1 \\ 1 \\ 1 \\ 1\end{array}\right] \quad X_{2}=\left[\begin{array}{c}-1 \\ -1 \\ -1 \\ -1 \\ -1 \\ -1\end{array}\right] \quad X_{3}=\left[\begin{array}{r}1 \\ 1 \\ -1 \\ -1 \\ 1 \\ 1\end{array}\right] \quad X_{4}=\left[\begin{array}{r}-1 \\ -1 \\ 1 \\ 1 \\ -1 \\ -1\end{array}\right]$\]

Set B: Corresponding Target Patterns

    \[$\operatorname{Set} \mathbf{B}: Y_{1}=\left[\begin{array}{l}1 \\ 1 \\ 1\end{array}\right] \quad Y_{2}=\left[\begin{array}{r}-1 \\ -1 \\ -1\end{array}\right] \quad Y_{3}=\left[\begin{array}{r}1 \\ -1 \\ 1\end{array}\right] \quad Y_{4}=\left[\begin{array}{r}-1 \\ 1 \\ -1\end{array}\right]$\]

Step 1: Here, the value of M (no of pairs of patterns) is 4. Step 2: Assign the neurons in the input and output layer. Here, neurons in the input layer are 6 and the output layer are 3 Step 3: Now, compute the Weight Matrix (W):

    \[$\begin{aligned} W=\left[\begin{array}{l}1 \\ 1 \\ 1 \\ 1 \\ 1 \\ 1\end{array}\right]\left[\begin{array}{lll}1 & 1 & 1\end{array}\right]+\left[\begin{array}{lll}-1 \\ -1 \\ -1 \\ -1 \\ -1 \\ -1\end{array}\right]\left[\begin{array}{lll}-1 & -1 & -1\end{array}\right]+\left[\begin{array}{r}1 \\ 1 \\ -1 \\ -1 \\ 1 \\ 1\end{array}\right]\left[\begin{array}{llll}1 & -1 & 1\end{array}\right]+\left[\begin{array}{r}-1 \\ -1 \\ 1 \\ 1 \\ -1 \\ -1\end{array}\right]\left[\begin{array}{lll}-1 & 1 & -1\end{array}\right]\] \[=\left[\begin{array}{lll}4 & 0 & 4 \\ 4 & 0 & 4 \\ 0 & 4 & 0 \\ 0 & 4 & 0 \\ 4 & 0 & 4 \\ 4 & 0 & 4\end{array}\right] \end{aligned}$\]

Step 4: Test the BAM model learning algorithm- for the input patterns BAM will return the corresponding target patterns as output. And for each of the target patterns, BAM will return the corresponding input patterns.
  • Test on input patterns (Set A) using-
  •     \[Y_{m}=\operatorname{sign}\left(W^{T} X_{m}\right), \quad m=1.2, \ldots, M\]

         \[$\boldsymbol{Y}_{1}=\operatorname{sign}\left(\boldsymbol{W}^{T} \boldsymbol{X}_{1}\right)=\operatorname{sign}\left\{\left[\begin{array}{cccccc}\mathbf{4} & \mathbf{4} & \mathbf{0} & \mathbf{0} & \mathbf{4} & \mathbf{4} \\ \mathbf{0} & \mathbf{0} & \mathbf{4} & \mathbf{4} & \mathbf{0} & \mathbf{0} \\ \mathbf{4} & \mathbf{4} & \mathbf{0} & \mathbf{0} & \mathbf{4} & \mathbf{4}\end{array}\right]\left[\begin{array}{c}\mathbf{1} \\ \mathbf{1} \\ \mathbf{1} \\ \mathbf{1} \\ \mathbf{1} \\ \mathbf{1}\end{array}\right]\right\}=\left[\begin{array}{c}\mathbf{1} \\ \mathbf{1} \\ \mathbf{1}\end{array}\right]$\] \[$\boldsymbol{Y}_{2}=\operatorname{sign}\left(\boldsymbol{W}^{T} \boldsymbol{X}_{2}\right)=\operatorname{sign}\left\{\left[\begin{array}{cccccc}\mathbf{4} & \mathbf{4} & \mathbf{0} & \mathbf{0} & \mathbf{4} & \mathbf{4} \\ \mathbf{0} & \mathbf{0} & \mathbf{4} & \mathbf{4} & \mathbf{0} & \mathbf{0} \\ \mathbf{4} & \mathbf{4} & \mathbf{0} & \mathbf{0} & \mathbf{4} & \mathbf{4}\end{array}\right]\left[\begin{array}{c}\mathbf{-1} \\ \mathbf{-1} \\ \mathbf{-1} \\ \mathbf{-1} \\ \mathbf{-1} \\ \mathbf{-1}\end{array}\right]\right\}=\left[\begin{array}{c}\mathbf{-1} \\ \mathbf{-1} \\ \mathbf{-1}\end{array}\right]$\] \[$\boldsymbol{Y}_{3}=\operatorname{sign}\left(\boldsymbol{W}^{T} \boldsymbol{X}_{3}\right)=\operatorname{sign}\left\{\left[\begin{array}{cccccc}\mathbf{4} & \mathbf{4} & \mathbf{0} & \mathbf{0} & \mathbf{4} & \mathbf{4} \\ \mathbf{0} & \mathbf{0} & \mathbf{4} & \mathbf{4} & \mathbf{0} & \mathbf{0} \\ \mathbf{4} & \mathbf{4} & \mathbf{0} & \mathbf{0} & \mathbf{4} & \mathbf{4}\end{array}\right]\left[\begin{array}{c}\mathbf{1} \\ \mathbf{1} \\ \mathbf{-1} \\ \mathbf{-1} \\ \mathbf{1} \\ \mathbf{1}\end{array}\right]\right\}=\left[\begin{array}{c}\mathbf{1} \\ \mathbf{-1} \\ \mathbf{1}\end{array}\right]$\] \[$\boldsymbol{Y}_{4}=\operatorname{sign}\left(\boldsymbol{W}^{T} \boldsymbol{X}_{4}\right)=\operatorname{sign}\left\{\left[\begin{array}{cccccc}\mathbf{4} & \mathbf{4} & \mathbf{0} & \mathbf{0} & \mathbf{4} & \mathbf{4} \\ \mathbf{0} & \mathbf{0} & \mathbf{4} & \mathbf{4} & \mathbf{0} & \mathbf{0} \\ \mathbf{4} & \mathbf{4} & \mathbf{0} & \mathbf{0} & \mathbf{4} & \mathbf{4}\end{array}\right]\left[\begin{array}{c}\mathbf{-1} \\ \mathbf{-1} \\ \mathbf{1} \\ \mathbf{1} \\ \mathbf{-1} \\ \mathbf{-1}\end{array}\right]\right\}=\left[\begin{array}{c}\mathbf{-1} \\ \mathbf{1} \\ \mathbf{-1}\end{array}\right]$\]

  • Test on target patterns (Set B) using-
  •     \[X_{m}=\operatorname{sign}\left(W Y_{m}\right), \quad m=1.2, \ldots, M\]

         \[$\boldsymbol{X}_{1}=\operatorname{sign}\left(\boldsymbol{W} \boldsymbol{Y}_{1}\right)=\operatorname{sign}\left\{\left[\begin{array}{ccc}\mathbf{4} & \mathbf{0} & \mathbf{4} \\ \mathbf{4} & \mathbf{0} & \mathbf{4} \\ \mathbf{0} & \mathbf{4} & \mathbf{0} \\ \mathbf{0} & \mathbf{4} & \mathbf{0} \\ \mathbf{4} & \mathbf{0} & \mathbf{4} \\ \mathbf{0} & \mathbf{4} & \mathbf{0}\end{array}\right]\left[\begin{array}{c}\mathbf{1} \\ \mathbf{1} \\ \mathbf{1}\end{array}\right]\right\}=\left[\begin{array}{c}\mathbf{1} \\ \mathbf{1} \\ \mathbf{1} \\ \mathbf{1} \\ \mathbf{1} \\ \mathbf{1}\end{array}\right]$\] \[$\boldsymbol{X}_{2}=\operatorname{sign}\left(\boldsymbol{W} \boldsymbol{Y}_{2}\right)=\operatorname{sign}\left\{\left[\begin{array}{ccc}\mathbf{4} & \mathbf{0} & \mathbf{4} \\ \mathbf{4} & \mathbf{0} & \mathbf{4} \\ \mathbf{0} & \mathbf{4} & \mathbf{0} \\ \mathbf{0} & \mathbf{4} & \mathbf{0} \\ \mathbf{4} & \mathbf{0} & \mathbf{4} \\ \mathbf{0} & \mathbf{4} & \mathbf{0}\end{array}\right]\left[\begin{array}{c}\mathbf{-1} \\ \mathbf{-1} \\ \mathbf{-1}\end{array}\right]\right\}=\left[\begin{array}{c}\mathbf{-1} \\ \mathbf{-1} \\ \mathbf{-1} \\ \mathbf{-1} \\ \mathbf{-1} \\ \mathbf{-1}\end{array}\right]$\] \[$\boldsymbol{X}_{3}=\operatorname{sign}\left(\boldsymbol{W} \boldsymbol{Y}_{3}\right)=\operatorname{sign}\left\{\left[\begin{array}{ccc}\mathbf{4} & \mathbf{0} & \mathbf{4} \\ \mathbf{4} & \mathbf{0} & \mathbf{4} \\ \mathbf{0} & \mathbf{4} & \mathbf{0} \\ \mathbf{0} & \mathbf{4} & \mathbf{0} \\ \mathbf{4} & \mathbf{0} & \mathbf{4} \\ \mathbf{0} & \mathbf{4} & \mathbf{0}\end{array}\right]\left[\begin{array}{c}\mathbf{1} \\ \mathbf{-1} \\ \mathbf{1}\end{array}\right]\right\}=\left[\begin{array}{c}\mathbf{1} \\ \mathbf{1} \\ \mathbf{-1} \\ \mathbf{-1} \\ \mathbf{1} \\ \mathbf{1}\end{array}\right]$\] \[$\boldsymbol{X}_{4}=\operatorname{sign}\left(\boldsymbol{W} \boldsymbol{Y}_{4}\right)=\operatorname{sign}\left\{\left[\begin{array}{ccc}\mathbf{4} & \mathbf{0} & \mathbf{4} \\ \mathbf{4} & \mathbf{0} & \mathbf{4} \\ \mathbf{0} & \mathbf{4} & \mathbf{0} \\ \mathbf{0} & \mathbf{4} & \mathbf{0} \\ \mathbf{4} & \mathbf{0} & \mathbf{4} \\ \mathbf{0} & \mathbf{4} & \mathbf{0}\end{array}\right]\left[\begin{array}{c}\mathbf{-1} \\ \mathbf{1} \\ \mathbf{-1}\end{array}\right]\right\}=\left[\begin{array}{c}\mathbf{-1} \\ \mathbf{-1} \\ \mathbf{1} \\ \mathbf{1} \\ \mathbf{-1} \\ \mathbf{-1}\end{array}\right]$\]

Here, for each of the input patterns, the BAM model will give correct target patterns and for target patterns, the model will also give corresponding input patterns. This signifies the bidirectional association in memory or model network.

Last Updated : 06 Oct, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads