# neupy.algorithms.gd.base module

Parameters: connection : list, tuple or LayerConnection instance Network’s architecture. There are a few ways to define it. List of layers. For instance, [Input(2), Tanh(4), Relu(1)]. Construct layer connections. For instance, Input(2) > Tanh(4) > Relu(1). Tuple of integers. Each integer defines Sigmoid layer and it’s input size. For instance, value (2, 4, 1) means that network has 3 layers with 2 input units, 4 hidden units and 1 output unit. error : str or function Error/loss function. Defaults to mse. mae - Mean Absolute Error. mse - Mean Squared Error. rmse - Root Mean Squared Error. msle - Mean Squared Logarithmic Error. rmsle - Root Mean Squared Logarithmic Error. categorical_crossentropy - Categorical cross entropy. binary_crossentropy - Binary cross entropy. binary_hinge - Binary hinge entropy. categorical_hinge - Categorical hinge entropy. Custom function which accepts two mandatory arguments. The first one is expected value and the second one is predicted value. Example: def custom_func(expected, predicted): return expected - predicted  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. addons : list or None The list of addon algortihms. None by default. If this option is not empty it will generate new class which will inherit all from this list. Support two types of addon algorithms: weight update and step update.

Examples

>>> import numpy as np
>>>
>>> x_train = np.array([[1, 2], [3, 4]])
>>> y_train = np.array([[1], [0]])
>>>
>>> bpnet = GradientDescent((2, 3, 1), verbose=False, step=0.1)
>>> bpnet.train(x_train, y_train)


Attributes

 errors (ErrorHistoryList) Contains list of training errors. This object has the same properties as list and in addition there are three additional useful methods: last, previous and normalized. train_errors (ErrorHistoryList) Alias to the errors attribute. validation_errors (ErrorHistoryList) The same as errors attribute, but it contains only validation errors. last_epoch (int) Value equals to the last trained epoch. After initialization it is equal to 0.

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.
class_name()[source]
get_params(deep=False, with_connection=True)[source]

Parameters: layer : object Any layer that inherit from BaseLayer class. parameter : object Usualy it is a weight or bias. list List of updates related to the specified parameter.
options = {'verbose': Option(class_name='Verbose', value=VerboseProperty(name="verbose")), 'step': Option(class_name='BaseNetwork', value=NumberProperty(name="step")), 'show_epoch': Option(class_name='BaseNetwork', value=ShowEpochProperty(name="show_epoch")), 'shuffle_data': Option(class_name='BaseNetwork', value=Property(name="shuffle_data")), 'epoch_end_signal': Option(class_name='BaseNetwork', value=Property(name="epoch_end_signal")), 'train_end_signal': Option(class_name='BaseNetwork', value=Property(name="train_end_signal")), 'error': Option(class_name='ConstructibleNetwork', value=ErrorFunctionProperty(name="error")), 'addons': Option(class_name='GradientDescent', value=Property(name="addons"))}[source]

Parameters: batch_size : int or {None, -1, ‘all’, ‘*’, ‘full’} Set up min-batch size. If mini-batch size is equal to one of the values from the list (like full) then it’s just a batch that equal to number of samples. Defaults to 128. connection : list, tuple or LayerConnection instance Network’s architecture. There are a few ways to define it. List of layers. For instance, [Input(2), Tanh(4), Relu(1)]. Construct layer connections. For instance, Input(2) > Tanh(4) > Relu(1). Tuple of integers. Each integer defines Sigmoid layer and it’s input size. For instance, value (2, 4, 1) means that network has 3 layers with 2 input units, 4 hidden units and 1 output unit. error : str or function Error/loss function. Defaults to mse. mae - Mean Absolute Error. mse - Mean Squared Error. rmse - Root Mean Squared Error. msle - Mean Squared Logarithmic Error. rmsle - Root Mean Squared Logarithmic Error. categorical_crossentropy - Categorical cross entropy. binary_crossentropy - Binary cross entropy. binary_hinge - Binary hinge entropy. categorical_hinge - Categorical hinge entropy. Custom function which accepts two mandatory arguments. The first one is expected value and the second one is predicted value. Example: def custom_func(expected, predicted): return expected - predicted  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. addons : list or None The list of addon algortihms. None by default. If this option is not empty it will generate new class which will inherit all from this list. Support two types of addon algorithms: weight update and step update.

Examples

>>> import numpy as np
>>> from neupy import algorithms
>>>
>>> x_train = np.array([[1, 2], [3, 4]])
>>> y_train = np.array([[1], [0]])
>>>
...     (2, 3, 1), batch_size=1
... )
>>> mgdnet.train(x_train, y_train)


Attributes

 errors (ErrorHistoryList) Contains list of training errors. This object has the same properties as list and in addition there are three additional useful methods: last, previous and normalized. train_errors (ErrorHistoryList) Alias to the errors attribute. validation_errors (ErrorHistoryList) The same as errors attribute, but it contains only validation errors. last_epoch (int) Value equals to the last trained epoch. After initialization it is equal to 0.

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.
options = {'batch_size': Option(class_name='MinibatchTrainingMixin', value=BatchSizeProperty(name="batch_size")), 'verbose': Option(class_name='Verbose', value=VerboseProperty(name="verbose")), 'step': Option(class_name='BaseNetwork', value=NumberProperty(name="step")), 'show_epoch': Option(class_name='BaseNetwork', value=ShowEpochProperty(name="show_epoch")), 'shuffle_data': Option(class_name='BaseNetwork', value=Property(name="shuffle_data")), 'epoch_end_signal': Option(class_name='BaseNetwork', value=Property(name="epoch_end_signal")), 'train_end_signal': Option(class_name='BaseNetwork', value=Property(name="train_end_signal")), 'error': Option(class_name='ConstructibleNetwork', value=ErrorFunctionProperty(name="error")), 'addons': Option(class_name='GradientDescent', value=Property(name="addons"))}[source]
predict(input_data)[source]

Makes a raw prediction.

Parameters: input_data : array-like array-like
prediction_error(input_data, target_data)[source]

Check the prediction error for the specified input samples and their targets.

Parameters: input_data : array-like target_data : array-like float Prediction error.
train_epoch(input_train, target_train)[source]

Train one epoch.

Parameters: input_train : array-like Training input dataset. target_train : array-like Training target dataset. float Training error.