class_docstr: Discrete BAM Network with associations.
  Network associate every input with some target value.
  
  Parameters
  ----------
  {DiscreteMemory.Parameters}
  
  Methods
  -------
  train(X, y)
      Train network and update network weights.
  
  predict_output(X, n_times=None)
      Using input data recover output data. Returns two arguments.
      First is an input data, second is an output data.
  
  predict(X, n_times=None)
      Alias to the ``predict_output`` method.
  
  predict_input(y, n_times=None)
      Using output data recover input data. Returns two arguments.
      First is input data, second is output data.
  
  energy(X, y)
      Calculate Hopfield Energy for the input and output data.
  
  Notes
  -----
  - Input and output vectors should contain only binary values.
  
  Examples
  --------
  >>> import numpy as np
  >>> from neupy import algorithms
  >>>
  >>> zero = np.matrix([
  ...     0, 1, 1, 1, 0,
  ...     1, 0, 0, 0, 1,
  ...     1, 0, 0, 0, 1,
  ...     1, 0, 0, 0, 1,
  ...     1, 0, 0, 0, 1,
  ...     0, 1, 1, 1, 0
  ... ])
  >>>
  >>> one = np.matrix([
  ...     0, 1, 1, 0, 0,
  ...     0, 0, 1, 0, 0,
  ...     0, 0, 1, 0, 0,
  ...     0, 0, 1, 0, 0,
  ...     0, 0, 1, 0, 0,
  ...     0, 0, 1, 0, 0
  ... ])
  >>> zero.reshape((5, 6))
  >>>
  >>> half_zero = np.matrix([
  ...     0, 1, 1, 1, 0,
  ...     1, 0, 0, 0, 1,
  ...     1, 0, 0, 0, 1,
  ...     0, 0, 0, 0, 0,
  ...     0, 0, 0, 0, 0,
  ...     0, 0, 0, 0, 0,
  ... ])
  >>>
  >>> zero_hint = np.matrix([[0, 1, 0, 0]])
  >>> one_hint = np.matrix([[1, 0, 0, 0]])
  >>>
  >>> data = np.concatenate([zero, one], axis=0)
  >>> hints = np.concatenate([zero_hint, one_hint], axis=0)
  >>>
  >>> bamnet = algorithms.DiscreteBAM(mode='sync')
  >>> bamnet.train(data, hints)
  >>>
  >>> recovered_zero, recovered_hint = bamnet.predict(half_zero)
  >>> recovered_hint
  matrix([[0, 1, 0, 0]])
  >>>
  >>> zero_hint
  matrix([[0, 1, 0, 0]])
class_docstr_tok: ["Discrete","BAM","Network","with","associations",".","Network","associate","every","input","with","some","target","value",".","Parameters","--","--","--","--","--","{","DiscreteMemory.Parameters","}","Methods","--","--","--","-","train","(","X",",","y",")","Train","network","and","update","network","weights",".","predict_output","(","X",",","n_times=None",")","Using","input","data","recover","output","data",".","Returns","two","arguments",".","First","is","an","input","data",",","second","is","an","output","data",".","predict","(","X",",","n_times=None",")","Alias","to","the","``","predict_output","``","method",".","predict_input","(","y",",","n_times=None",")","Using","output","data","recover","input","data",".","Returns","two","arguments",".","First","is","input","data",",","second","is","output","data",".","energy","(","X",",","y",")","Calculate","Hopfield","Energy","for","the","input","and","output","data",".","Notes","--","--","-","-","Input","and","output","vectors","should","contain","only","binary","values",".","Examples","--","--","--","--",">",">",">","import","numpy","as","np",">",">",">","from","neupy","import","algorithms",">",">",">",">",">",">","zero","=","np.matrix","(","[","...","0",",","1",",","1",",","1",",","0",",","...","1",",","0",",","0",",","0",",","1",",","...","1",",","0",",","0",",","0",",","1",",","...","1",",","0",",","0",",","0",",","1",",","...","1",",","0",",","0",",","0",",","1",",","...","0",",","1",",","1",",","1",",","0","...","]",")",">",">",">",">",">",">","one","=","np.matrix","(","[","...","0",",","1",",","1",",","0",",","0",",","...","0",",","0",",","1",",","0",",","0",",","...","0",",","0",",","1",",","0",",","0",",","...","0",",","0",",","1",",","0",",","0",",","...","0",",","0",",","1",",","0",",","0",",","...","0",",","0",",","1",",","0",",","0","...","]",")",">",">",">","zero.reshape","(","(","5",",","6",")",")",">",">",">",">",">",">","half_zero","=","np.matrix","(","[","...","0",",","1",",","1",",","1",",","0",",","...","1",",","0",",","0",",","0",",","1",",","...","1",",","0",",","0",",","0",",","1",",","...","0",",","0",",","0",",","0",",","0",",","...","0",",","0",",","0",",","0",",","0",",","...","0",",","0",",","0",",","0",",","0",",","...","]",")",">",">",">",">",">",">","zero_hint","=","np.matrix","(","[","[","0",",","1",",","0",",","0","]","]",")",">",">",">","one_hint","=","np.matrix","(","[","[","1",",","0",",","0",",","0","]","]",")",">",">",">",">",">",">","data","=","np.concatenate","(","[","zero",",","one","]",",","axis=0",")",">",">",">","hints","=","np.concatenate","(","[","zero_hint",",","one_hint","]",",","axis=0",")",">",">",">",">",">",">","bamnet","=","algorithms.DiscreteBAM","(","mode='sync","'",")",">",">",">","bamnet.train","(","data",",","hints",")",">",">",">",">",">",">","recovered_zero",",","recovered_hint","=","bamnet.predict","(","half_zero",")",">",">",">","recovered_hint","matrix","(","[","[","0",",","1",",","0",",","0","]","]",")",">",">",">",">",">",">","zero_hint","matrix","(","[","[","0",",","1",",","0",",","0","]","]",")"]
code: def train(self, X_bin, y_bin):
      self.discrete_validation(X_bin)
      self.discrete_validation(y_bin)
  
      X_sign = bin2sign(format_data(X_bin, is_feature1d=False))
      y_sign = bin2sign(format_data(y_bin, is_feature1d=False))
  
      _, weight_nrows = X_sign.shape
      _, weight_ncols = y_sign.shape
      weight_shape = (weight_nrows, weight_ncols)
  
      if self.weight is None:
          self.weight = np.zeros(weight_shape)
  
      if self.weight.shape != weight_shape:
          raise ValueError(
              "Invalid input shapes. Number of input "
              "features must be equal to {} and {} output "
              "features".format(weight_nrows, weight_ncols)
          )
  
      self.weight += X_sign.T.dot(y_sign)
  
file_path: neupy/neupy/algorithms/memory/bam.py
imports: import random
  import numpy
  from numpy.core.umath_tests import inner1d
  from neupy.utils import format_data
  from neupy.exceptions import NotTrained
  from .base import DiscreteMemory
label_desc: Use image node_id 5 for calling the DiscreteBAM obj's underlying member method code with example usage: obj.train(X_bin, y_bin) without return types