Data Types#
- class whobpyt.datatypes.timeseries.Timeseries(data, step_size, modality='')#
- This class is responsible for holding timeseries of empirical and simulated data. It is:
Part of the input and output of Model_fitting and Model_simulation[future].
It is the format expected by the visualization function of whobpyt.
However, the Recording class is not used within and across the NMM and Modals, as a simpler dictionary of tensors is used in those contexts.
Numerical simulation internals don’t necessarily use this data structure, as calculations may be more efficient as the transpose: ts_length x num_regions.
- Attributes:
- data
Numpy
Array
orTensor
of
dimensions
num_regions
x
ts_length
The time series data, either empirical or simulated
- step_size
Float
The step size of the time points in the data class
- modality
String
The name of the modality of the time series
- numNodes
Int
The number of nodes it time series.
length
Int
Returns
- data
Methods
length
()This outputs resampled data used for figures (TODO: Not yet implemented)
npTS
()pyTS
()windowedTensor
(TPperWindow)This method is called by the Model_fitting Class during training to reshape the data into windowed segments (adds another dimension).
- __init__(data, step_size, modality='')#
- Parameters:
- data
Numpy
Array
orTensor
of
dimensions
num_regions
x
ts_length
The time series data, either empirical or simulated
- step_size
Float
The step size of the time points in the data class
- modality
String
The name of the modality of the time series
- data
- npNodeByTime()#
- Returns:
Numpy
Array
of
num_regions
x
ts_length
- npResample()#
This outputs resampled data used for figures (TODO: Not yet implemented)
- npTS()#
- Returns:
Numpy
Array
of
num_regions
x
ts_length
- npTimeByNodes()#
- Returns:
Numpy
Array
of
ts_length
x
num_regions
- pyTS()#
- Returns:
Tensor
of
num_regions
x
ts_length
- windowedTensor(TPperWindow)#
This method is called by the Model_fitting Class during training to reshape the data into windowed segments (adds another dimension).
- Parameters:
- TPperWindow
Int
The number of time points in the window that will be back propagated
- TPperWindow
- Returns:
- Tensor:
num_windows
x
num_regions
x
window_length
The time series data in a windowed format
- Tensor:
- class whobpyt.datatypes.parameter.Parameter(val, prior_mean=None, prior_std=None, fit_par=False, asLog=False, asRand=True, lb=0, device=device(type='cpu'))#
- Features of this class:
This class contains a global parameter value or array of values (one per node)
It can also contain associated priors (mean and variance)
It also has attributes for whether the parameter and/or priors should be fit during training
It has a method to return the parameter as numpy value
It has a method to set a random val using based on priors
It has functionality to represent val as log(val) so that during training val will be constrained to be positive
- Attributes:
- val
Tensor
The parameter value (or an array of node specific parameter values)
- prior_mean
Tensor
Prior mean of the data value
- prior_precision
Tensor
Prior inverse of variance of the value
- fit_par: Bool
Whether the parameter value should be set to as a PyTorch Parameter
- fit_hyper
Bool
Whether the parameter prior mean and prior variance should be set as a PyTorch Parameter
- asLog
Bool
Whether the log of the parameter value will be stored instead of the parameter itself (will prevent parameter from being negative).
- val
Methods
to
- __init__(val, prior_mean=None, prior_std=None, fit_par=False, asLog=False, asRand=True, lb=0, device=device(type='cpu'))#
- Parameters:
- val
Float
(or
Array
) The parameter value (or an array of node specific parameter values)
- prior_mean
Float
Prior mean of the data value
- prior_std
Float
Prior std of the value
- fit_par: Bool
Whether the parameter value should be set to as a PyTorch Parameter
- device: torch.device
Whether to run on CPU or GPU
- val
- npValue()#
- Returns:
NumPy
of
Value
The parameter value(s) as a NumPy Array
- to(device)#
- value()#
- Returns:
Tensor
of
Value
The parameter value(s) as a PyTorch Tensor
- class whobpyt.datatypes.outputs.TrainingStats(model)#
- This class is responsible for recording stats during training (it replaces OutputNM) including:
The training and validation losses over time
The change in model parameters over time
changing hyper parameters over time like learing rates TODO
These are things typically recorded on a per window/epoch basis
- Attributes:
- model_info
Dict
Information about model being tracked during training.
- track_params
List
List of parameter names being tracked during training.
- loss
List
A list of loss values over training.
- connectivity
List
A list of connectivity values over training.
- leadfield
List
A list of leadfield matrices over training.
- fit_params
Dict
A dictionary of lists where the key is the parameter name and the value is the list of parameter values over training.
- model_info
Methods
appendLF
(newValue)Append Lead Field Loss
appendLoss
(newValue)Append Trainig Loss
appendParam
(newValues)Append Fit Parameters
appendSC
(newValue)Append Network Connections
appendSC_p2e
(newValue)Append Network Connections
appendSC_p2i
(newValue)Append Network Connections
appendSC_p2p
(newValue)Append Network Connections
reset
()Resets the attributes of the model to a pre-training state.
save
(filename)- __init__(model)#
- Parameters:
- model
AbstractNMM
A model for which stats will be recorded during training.
- model
- appendLF(newValue)#
Append Lead Field Loss
- Parameters:
- newValue
Array
Current state of a lead field matrix being tracked.
- newValue
- appendLoss(newValue)#
Append Trainig Loss
- Parameters:
- newValue
Float
The loss value of objective function being tracked.
- newValue
- appendParam(newValues)#
Append Fit Parameters
- Parameters:
- newValues
Dict
Dictionary with current states of each model parameter being tracked.
- newValues
- appendSC(newValue)#
Append Network Connections
- Parameters:
- newValue
Array
Current state of the structural connectivity being tracked.
- newValue
- appendSC_p2e(newValue)#
Append Network Connections
- Parameters:
- newValue
Array
Current state of the structural connectivity being tracked.
- newValue
- appendSC_p2i(newValue)#
Append Network Connections
- Parameters:
- newValue
Array
Current state of the structural connectivity being tracked.
- newValue
- appendSC_p2p(newValue)#
Append Network Connections
- Parameters:
- newValue
Array
Current state of the structural connectivity being tracked.
- newValue
- reset()#
Resets the attributes of the model to a pre-training state.
- save(filename)#
- Parameters:
- filename
String
The filename to use to save the TrainingStats as a pickle object.
- filename