neupy.algorithms.ConjugateGradient
- class neupy.algorithms.ConjugateGradient[source]
Conjugate Gradient algorithm.
Parameters: - update_function : fletcher_reeves, polak_ribiere, hentenes_stiefel, dai_yuan, liu_storey
Update function. Defaults to fletcher_reeves.
- epsilon : float
Ensures computational stability during the division in update_function when denominator is very small number. Defaults to 1e-7.
- wolfe_maxiter : int
Controls maximum number of iteration during the line search that identifies optimal step size during the weight update stage. Defaults to 20.
- wolfe_c1 : float
Parameter for Armijo condition rule. It’s used during the line search that identifies optimal step size during the weight update stage. Defaults 1e-4.
- wolfe_c2 : float
Parameter for curvature condition rule. It’s used during the line search that identifies optimal step size during the weight update stage. Defaults 0.9.
- network : 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)].
- Constructed layers. For instance, Input(2) >> Tanh(4) >> Relu(1).
- loss : 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
- show_epoch : int
This property controls how often the network will display information about training. It has to be defined as positive integer. For instance, number 100 mean that network shows summary at 1st, 100th, 200th, 300th … and last epochs.
Defaults to 1.
- shuffle_data : bool
If it’s True than training data will be shuffled before the training. Defaults to True.
- signals : dict, list or function
Function that will be triggered after certain events during the training.
- verbose : bool
Property controls verbose output in terminal. The True value enables informative output in the terminal and False - disable it. Defaults to False.
- regularizer : function or None
Network’s regularizer.
References
- [1] Jorge Nocedal, Stephen J. Wright, Numerical Optimization.
- Chapter 5, Conjugate Gradient Methods, p. 101-133
Examples
>>> from sklearn import datasets, preprocessing >>> from sklearn.model_selection import train_test_split >>> from neupy import algorithms, layers >>> >>> dataset = datasets.load_boston() >>> data, target = dataset.data, dataset.target >>> >>> data_scaler = preprocessing.MinMaxScaler() >>> target_scaler = preprocessing.MinMaxScaler() >>> >>> x_train, x_test, y_train, y_test = train_test_split( ... data_scaler.fit_transform(data), ... target_scaler.fit_transform(target), ... test_size=0.15 ... ) >>> >>> cgnet = algorithms.ConjugateGradient( ... network=[ ... layers.Input(13), ... layers.Sigmoid(50), ... layers.Sigmoid(1), ... ], ... update_function='fletcher_reeves', ... verbose=False ... ) >>> >>> cgnet.train(x_train, y_train, epochs=100) >>> y_predict = cgnet.predict(x_test).round(1) >>> >>> real = target_scaler.inverse_transform(y_test) >>> predicted = target_scaler.inverse_transform(y_predict)
Attributes: - errors : list
Information about errors. It has two main attributes, namely train and valid. These attributes provide access to the training and validation errors respectively.
- last_epoch : int
Value equals to the last trained epoch. After initialization it is equal to 0.
- n_updates_made : int
Number of training updates applied to the network.
Methods
predict(X) Predicts output for the specified input. train(X_train, y_train, X_test=None, y_test=None, epochs=100) Train network. You can control network’s training procedure with epochs parameter. The X_test and y_test should be presented both in case network’s validation required after each training epoch. fit(*args, **kwargs) Alias to the train method. - epsilon = None[source]
- init_functions()[source]
- init_train_updates()[source]
- options = {'epsilon': Option(class_name='ConjugateGradient', value=NumberProperty(name="epsilon")), 'loss': Option(class_name='BaseOptimizer', value=FunctionWithOptionsProperty(name="loss")), 'regularizer': Option(class_name='BaseOptimizer', value=Property(name="regularizer")), 'show_epoch': Option(class_name='BaseNetwork', value=IntProperty(name="show_epoch")), 'shuffle_data': Option(class_name='BaseNetwork', value=Property(name="shuffle_data")), 'signals': Option(class_name='BaseNetwork', value=Property(name="signals")), 'target': Option(class_name='BaseOptimizer', value=Property(name="target")), 'update_function': Option(class_name='ConjugateGradient', value=ChoiceProperty(name="update_function")), 'verbose': Option(class_name='Verbose', value=VerboseProperty(name="verbose")), 'wolfe_c1': Option(class_name='WolfeLineSearchForStep', value=NumberProperty(name="wolfe_c1")), 'wolfe_c2': Option(class_name='WolfeLineSearchForStep', value=NumberProperty(name="wolfe_c2")), 'wolfe_maxiter': Option(class_name='WolfeLineSearchForStep', value=IntProperty(name="wolfe_maxiter"))}[source]
- step = None[source]
- update_function = None[source]