class brainpy.OfflineTrainer(target, fit_method=None, **kwargs)[source]#

Offline trainer for models with recurrent dynamics.

For more parameters, users should refer to DSRunner.

  • target (DynamicalSystem) – The target model to train.

  • fit_method (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 through get_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 see DSRunner.

fit(train_data, reset_state=False, shared_args=None)[source]#

Fit the target model according to the given training and testing data.

  • train_data (sequence of data) –

    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:


predict(inputs, reset_state=False, shared_args=None, eval_time=False)[source]#

Prediction function.

What’s different from predict() function in DynamicalSystem is that the inputs_are_batching is default True.

  • inputs (ArrayType) – The input values.

  • reset_state (bool) – Reset the target state before running.

  • eval_time (bool) – Whether we evaluate the running time or not?

  • shared_args (dict) – The shared arguments across nodes.


output – The running output.

Return type: