OfflineTrainer#
- class brainpy.OfflineTrainer(target, fit_method=None, **kwargs)[source]#
Offline trainer for models with recurrent dynamics.
For more parameters, users should refer to
DSRunner.- Parameters:
target (
DynamicalSystem) – The target model to train.fit_method (
Union[OfflineAlgorithm,Callable,Dict,str]) –The fitting method applied to the target model. - It can be a string, which specify the shortcut name of the training algorithm.
Like,
fit_method='ridge'means using the Ridge regression method. All supported fitting methods can be obtained throughget_supported_offline_methods().It can be a dict, whose “name” item specifies the name of the training algorithm, and the others parameters specify the initialization parameters of the algorithm. For example,
fit_method={'name': 'ridge', 'alpha': 0.1}.It can be an instance of
brainpy.algorithms.OfflineAlgorithm. For example,fit_meth=bp.algorithms.RidgeRegression(alpha=0.1).It can also be a callable function, which receives three arguments “targets”, “x” and “y”. For example,
fit_method=lambda targets, x, y: numpy.linalg.lstsq(x, targets)[0].
kwargs (
Any) – Other general parameters please seeDSRunner.
- fit(train_data, reset_state=False, shared_args=None)[source]#
Fit the target model according to the given training and testing data.
- Parameters:
train_data (
Sequence) –It should be a pair of (X, Y) train set. -
X: should be a tensor or a dict of tensors with the shape of(num_sample, num_time, num_feature), where num_sample is the number of samples, num_time is the number of the time step, and num_feature is the number of features.
Y: Target values. A tensor or a dict of tensors. - If the shape of each tensor is (num_sample, num_feature),then we will only fit the model with the only last output.
If the shape of each tensor is (num_sample, num_time, num_feature), then the fitting happens on the whole data series.
reset_state (
bool) – Whether reset the initial states of the target model.shared_args (
Dict) – The shared keyword arguments for the target models.
- Return type:
TypeVar(Output)
- predict(inputs, reset_state=False, shared_args=None, eval_time=False)[source]#
Prediction function.
What’s different from predict() function in
DynamicalSystemis that the inputs_are_batching is default True.- Parameters:
- Return type:
TypeVar(Output)- Returns:
output (
ArrayType) – The running output.