ANN – Bidirectional Associative Memory (BAM) Learning Algorithm
Prerequisite: ANN | Bidirectional Associative Memory (BAM)
There are three main steps to construct the BAM model.
- Learning
- Testing
- 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
![Rendered by QuickLaTeX.com \[$\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]$\]](https://web.archive.org/web/20220121124236im_/https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-f0a865968f7dfa655e72475ea21afd09_l3.png)
Set B: Corresponding Target Patterns
![Rendered by QuickLaTeX.com \[$\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]$\]](https://web.archive.org/web/20220121124236im_/https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-b56b74de259d1e71df556b2d10c52de9_l3.png)
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):
![Rendered by QuickLaTeX.com \[$\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}$\]](https://web.archive.org/web/20220121124236im_/https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-f2228d891c23523800ff9fec48e2335e_l3.png)
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-
![Rendered by QuickLaTeX.com \[Y_{m}=\operatorname{sign}\left(W^{T} X_{m}\right), \quad m=1.2, \ldots, M\]](https://web.archive.org/web/20220121124236im_/https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-ddf298ffdacb0fed59436348168d1bcf_l3.png)
![Rendered by QuickLaTeX.com \[$\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]$\]](https://web.archive.org/web/20220121124236im_/https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-07a08caa1947417f4d42cf627a3bcf26_l3.png)
- Test on target patterns (Set B) using-
![Rendered by QuickLaTeX.com \[X_{m}=\operatorname{sign}\left(W Y_{m}\right), \quad m=1.2, \ldots, M\]](https://web.archive.org/web/20220121124236im_/https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-d4b229b25710972a457eeb73eb4fb61f_l3.png)
![Rendered by QuickLaTeX.com \[$\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]$\]](https://web.archive.org/web/20220121124236im_/https://www.geeksforgeeks.org/wp-content/ql-cache/quicklatex.com-79e948b17771ba1467782c42426f3f40_l3.png)
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.




