neupy.algorithms.DiscreteBAM
- class neupy.algorithms.DiscreteBAM[source]
Discrete BAM Network with associations. Network associate every input with some target value.
Parameters: - mode : {sync, async}
Specifies pattern recovery mode.
- sync mode tries to recover pattern using all values from the input vector.
- async mode choose randomly some values from the input vector and iteratively repeat this procedure. Number of iterations defines by the n_times parameter.
Defaults to sync.
- n_times : int
Available only in async mode. Identify number of random trials. Defaults to 100.
- verbose : bool
Property controls verbose output in terminal. The True value enables informative output in the terminal and False - disable it. Defaults to False.
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]])
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. - apply_async_process(X_sign, y_sign, n_times=None)[source]
- energy(X_bin, y_bin)[source]
- options = {'mode': Option(class_name='DiscreteMemory', value=ChoiceProperty(name="mode")), 'n_times': Option(class_name='DiscreteMemory', value=IntProperty(name="n_times")), 'verbose': Option(class_name='Verbose', value=VerboseProperty(name="verbose"))}[source]
- predict(X_bin, n_times=None)[source]
- predict_input(y_bin, n_times=None)[source]
- predict_output(X_bin, n_times=None)[source]
- train(X_bin, y_bin)[source]