<s> import numpy as np <EOL> from scipy . optimize import minimize_scalar <EOL> from neupy . utils import asfloat <EOL> from neupy . core . properties import BoundedProperty , ChoiceProperty <EOL> from . base import SingleStepConfigurable <EOL> __all__ = ( '<STR_LIT>' , ) <EOL> class LinearSearch ( SingleStepConfigurable ) : <EOL> """<STR_LIT>""" <EOL> tol = BoundedProperty ( default = <NUM_LIT:0.1> , minval = <NUM_LIT:0> ) <EOL> maxiter = BoundedProperty ( default = <NUM_LIT:10> , minval = <NUM_LIT:1> ) <EOL> search_method = ChoiceProperty ( choices = [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> default = '<STR_LIT>' ) <EOL> def train_epoch ( self , input_train , target_train ) : <EOL> train_epoch = self . methods . train_epoch <EOL> prediction_error = self . methods . prediction_error <EOL> params = [ param for param , _ in self . init_train_updates ( ) ] <EOL> param_defaults = [ param . get_value ( ) for param in params ] <EOL> def setup_new_step ( new_step ) : <EOL> for param_default , param in zip ( param_defaults , params ) : <EOL> param . set_value ( param_default ) <EOL> self . variables . step . set_value ( asfloat ( new_step ) ) <EOL> train_epoch ( input_train , target_train ) <EOL> error = prediction_error ( input_train , target_train ) <EOL> return np . where ( np . isnan ( error ) , np . inf , error ) <EOL> options = { '<STR_LIT>' : self . tol } <EOL> if self . search_method == '<STR_LIT>' : <EOL> options [ '<STR_LIT>' ] = self . maxiter <EOL> res = minimize_scalar ( <EOL> setup_new_step , <EOL> tol = self . tol , <EOL> method = self . search_method , <EOL> options = options , <EOL> ) <EOL> return setup_new_step ( res . x ) </s>
