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()
- device
torch.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:
- u
intorTensor 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_num
int length of num_windows for resting
- transient_num
int The number of initial time points to exclude from some metrics
- ———–
- u
- save(filename)#
- Parameters:
- filename: String
filename to use when saving object to file
- 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:
- model
AbstractNMM The model which has parameters to be trained.
- cost
AbstractLoss The objective function that will be used to calculate a loss.
- trainingStats
TrainingStats An object that will keep track of optimization/machine learning statistics during training.
- lastSerial
Recording The simulated data from the last serial run (FNG)
- lastRec
Recording The simulated data from the last parallel run (FPG)
- device
torch.device Whether the fitting is to run on CPU or GPU
- model
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:
- stim
IntorTensor The input into the NMM (is 0 for the resting state case).
- empDatas
ListofRecordingor otherobject The empirical data compared to in the objective function.
- num_epochs
Int Number of epochs for training.
- block_len
Int The number of simulation steps per block. Total number of steps should be divisable by this number.
- learningrate
Float Learning rate used by backpropagation optimizer.
- resetIC
Bool Whether to reset the models initial condition after every backpropagation
- stim
- 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:
- model
AbstractNMM The model which has parameters to be trained.
- cost
AbstractLoss The objective function that will be used to calculate a loss.
- trainingStats
TrainingStats An object that will keep track of optimization/machine learning statistics during training.
- lastRec
Recording The simulated data from the last batch run
- device
torch.device Whether the fitting is to run on CPU or GPU
- model
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:
- stim
IntorTensor The input into the NMM (is 0 for the resting state case).
- empDatas
ListofRecordingor otherobject The empirical data compared to in the objective function.
- num_epochs
Int Number of epochs for training.
- batch_size
Int The number of simulations run that will be backpropagated through simultaneously.
- learningrate
Float Learning rate used by backpropagation optimizer.
- staticIC
Bool Whether to reset the models initial condition after every backpropagation
- staticNoise
Bool Whether to use the same noise for each epoch
- stim