Model fitting and simulation#

class whobpyt.run.ModelFitting(model: AbstractNeuralModel, cost: AbstractLoss, device=torch.device('cpu'))#

This Model_fitting class is able to fit resting state data or evoked potential data for which the input training data is empty or some stimulus to one or more NMM nodes, and the label is an associated empirical neuroimaging recording.

Studies which consider different kinds of input, such as if SC or some other variable is associated with an empirical recording, must use a different fitting class.

Attributes:
model: AbstractNMM

Whole Brain Model to Simulate

cost: AbstractLoss

A particular objective function which the model will be optimized for.

trainingStats: TrainingStats

Information about objective function loss and parameter values over training windows/epochs

lastRec: Recording

The last simulation of fitting(), evaluation(), or simulation()

devicetorch.device

Whether the fitting is to run on CPU or GPU

Methods

evaluate(u, empRec, TPperWindow[, ...])

save(filename)

simulate(u, numTP[, base_window_num, ...])

train(u, empRecs, num_epochs, TPperWindow[, ...])

evaluate(u, empRec: list, TPperWindow: int, base_window_num: int = 0, transient_num: int = 10)#
Parameters:
uint or Tensor

external or stimulus

empRec: list of Recording

This is the ML “Training Labels”

TPperWindow: int

Number of Empirical Time Points per window. model.forward does one window at a time.

base_window_numint

length of num_windows for resting

transient_numint

The number of initial time points to exclude from some metrics

———–
save(filename)#
Parameters:
filename: String

filename to use when saving object to file

simulate(u, numTP: int, base_window_num: int = 0, transient_num: int = 10)#
Parameters:
uint or Tensor

external or stimulus

numTPint

The number of time points ot simulate

base_window_numint

length of num_windows for resting

transient_numint

The number of initial time points to exclude from some metrics

———–
train(u, empRecs: list, num_epochs: int, TPperWindow: int, warmupWindow: int = 0, learningrate: float = 0.05, lr_2ndLevel: float = 0.05, lr_scheduler: bool = False)#
Parameters:
u: type

This stimulus is the ML “Training Input”

empRec: list of Recording

This is the ML “Training Labels”

num_epochs: int

the number of times to go through the entire training data set

TPperWindow: int

Number of Empirical Time Points per window. model.forward does one window at a time.

learningrate: float

rate of gradient descent

lr_2ndLevel: float

learning rate for priors of model parameters, and possibly others

lr_scheduler: bool

Whether to use the learning rate scheduler

Specialised fitting paradigms#

class whobpyt.run.FittingFNGFPG(model, cost, device=torch.device('cpu'))#

Fitting Forward No Gradient Forward Parallel Gradient (FNG-FPG)

This is a specalized model fitting class to:
  • backpropagate through time of the duration of 10’s of seconds of real time scale simulation

  • learn generalized NMM parameters such that given a SC the model predicts the corresponding FC

  • the label can be a fixed value (example a FC matrix, instead of a neuroimaging recording)

Attributes:
modelAbstractNMM

The model which has parameters to be trained.

costAbstractLoss

The objective function that will be used to calculate a loss.

trainingStatsTrainingStats

An object that will keep track of optimization/machine learning statistics during training.

lastSerialRecording

The simulated data from the last serial run (FNG)

lastRecRecording

The simulated data from the last parallel run (FPG)

devicetorch.device

Whether the fitting is to run on CPU or GPU

Methods

evaluate(stim, empData)

Not implemented yet.

simulate(stim, numTP)

Not implemented yet.

train(stim, empDatas, num_epochs, block_len)

Method to train the model.

evaluate(stim, empData)#

Not implemented yet.

simulate(stim, numTP)#

Not implemented yet.

train(stim, empDatas, num_epochs, block_len, learningrate=0.05, resetIC=True)#

Method to train the model.

Parameters:
stimInt or Tensor

The input into the NMM (is 0 for the resting state case).

empDatasList of Recording or other object

The empirical data compared to in the objective function.

num_epochsInt

Number of epochs for training.

block_lenInt

The number of simulation steps per block. Total number of steps should be divisable by this number.

learningrateFloat

Learning rate used by backpropagation optimizer.

resetICBool

Whether to reset the models initial condition after every backpropagation

class whobpyt.run.FittingBatch(model, cost, device=torch.device('cpu'))#

Fitting Batch

This is a specalized model fitting class to train using a batched approach.

Attributes:
modelAbstractNMM

The model which has parameters to be trained.

costAbstractLoss

The objective function that will be used to calculate a loss.

trainingStatsTrainingStats

An object that will keep track of optimization/machine learning statistics during training.

lastRecRecording

The simulated data from the last batch run

devicetorch.device

Whether the fitting is to run on CPU or GPU

Methods

evaluate(stim, empData)

Not implemented yet.

simulate(stim, numTP)

Not implemented yet.

train(stim, empDatas, num_epochs, batch_size)

Method to train the model.

evaluate(stim, empData)#

Not implemented yet.

simulate(stim, numTP)#

Not implemented yet.

train(stim, empDatas, num_epochs, batch_size, learningrate=0.05, staticIC=True, staticNoise=False)#

Method to train the model.

Parameters:
stimInt or Tensor

The input into the NMM (is 0 for the resting state case).

empDatasList of Recording or other object

The empirical data compared to in the objective function.

num_epochsInt

Number of epochs for training.

batch_sizeInt

The number of simulations run that will be backpropagated through simultaneously.

learningrateFloat

Learning rate used by backpropagation optimizer.

staticICBool

Whether to reset the models initial condition after every backpropagation

staticNoiseBool

Whether to use the same noise for each epoch