neupy.algorithms.memory.cmac module

class neupy.algorithms.memory.cmac.CMAC[source]

CMAC Network based on memory.

Parameters:

quantization : int

Network transforms every input to discrete value. Quantization value contol number of total possible categories after quantization, defaults to 10.

associative_unit_size : int

Number of associative blocks in memory, defaults to 2.

step : float

Learning rate, defaults to 0.1.

show_epoch : int or str

This property controls how often the network will display information about training. There are two main syntaxes for this property.

  • You can define it as a positive integer number. It defines how offen would you like to see summary output in terminal. For instance, number 100 mean that network shows summary at 100th, 200th, 300th ... epochs.
  • String defines number of times you want to see output in terminal. For instance, value '2 times' mean that the network will show output twice with approximately equal period of epochs and one additional output would be after the finall epoch.

Defaults to 1.

shuffle_data : bool

If it’s True class shuffles all your training data before training your network, defaults to True.

epoch_end_signal : function

Calls this function when train epoch finishes.

train_end_signal : function

Calls this function when train process finishes.

verbose : bool

Property controls verbose output interminal. True enables informative output in the terminal and False - disable it. Defaults to False.

Notes

  • Network always use Mean Absolute Error (MAE).
  • Network works for multi dimensional target values.

Examples

>>> import numpy as np
>>> from neupy.algorithms import CMAC
>>>
>>> train_space = np.linspace(0, 2 * np.pi, 100)
>>> test_space = np.linspace(np.pi, 2 * np.pi, 50)
>>>
>>> input_train = np.reshape(train_space, (100, 1))
>>> input_test = np.reshape(test_space, (50, 1))
>>>
>>> target_train = np.sin(input_train)
>>> target_test = np.sin(input_test)
>>>
>>> cmac = CMAC(
...     quantization=100,
...     associative_unit_size=32,
...     step=0.2,
... )
...
>>> cmac.train(input_train, target_train, epochs=100)
>>>
>>> predicted_test = cmac.predict(input_test)
>>> cmac.error(target_test, predicted_test)
0.0023639417543036569

Attributes

weight (dict) Network’s weight that contains memorized patterns.

Methods

predict(input_data) Predicts output for the specified input.
train(input_train, target_train, input_test=None, target_test=None, epochs=100, epsilon=None) Train network. You can control network’s training procedure with epochs and epsilon parameters. The input_test and target_test should be presented both in case of you need to validate network’s training after each iteration.
fit(*args, **kwargs) Alias to the train method.
associative_unit_size = None[source]
get_memory_coords(quantized_value)[source]
get_result_by_coords(coords)[source]
options = {'verbose': Option(class_name='Verbose', value=VerboseProperty(name="verbose")), 'epoch_end_signal': Option(class_name='BaseNetwork', value=Property(name="epoch_end_signal")), 'shuffle_data': Option(class_name='BaseNetwork', value=Property(name="shuffle_data")), 'show_epoch': Option(class_name='BaseNetwork', value=ShowEpochProperty(name="show_epoch")), 'train_end_signal': Option(class_name='BaseNetwork', value=Property(name="train_end_signal")), 'step': Option(class_name='BaseNetwork', value=NumberProperty(name="step")), 'associative_unit_size': Option(class_name='CMAC', value=IntProperty(name="associative_unit_size")), 'quantization': Option(class_name='CMAC', value=IntProperty(name="quantization"))}[source]
predict(input_data)[source]

Return prediction results for the input data.

Parameters:input_data : array-like
Returns:array-like
prediction_error(input_data, target_data)[source]
quantization = None[source]
quantize(input_data)[source]
train(input_train, target_train, input_test=None, target_test=None, epochs=100, epsilon=None, summary='table')[source]

Method train neural network.

Parameters:

input_train : array-like

target_train : array-like or None

input_test : array-like or None

target_test : array-like or None

epochs : int

Defaults to 100.

epsilon : float or None

Defaults to None.

train_epoch(input_train, target_train)[source]