macro_eeg_model.simulation.stationary_model_developer#
Classes#
A class to develop a stationary vector autoregression (VAR) model from given parameters. |
Module Contents#
- class macro_eeg_model.simulation.stationary_model_developer.StationaryModelDeveloper(nr_lags, nr_nodes, nodes, distances, connectivity_weights, sample_rate, delay_calculator)[source]#
A class to develop a stationary vector autoregression (VAR) model from given parameters.
- _nr_lags#
The number of lags (p) in the VAR(p) model.
- Type:
int
- _nr_nodes#
The number of nodes in the model.
- Type:
int
- _nodes#
The list of node names.
- Type:
list[str]
- _distances#
A matrix containing the distances between nodes.
- Type:
numpy.ndarray
- _connectivity_weights#
The initial connectivity weights between nodes.
- Type:
numpy.ndarray
- _sample_rate#
The sample rate used for the model.
- Type:
int
- _delay_calculator#
An instance of the
src.simulation.delay_calculator.DelayCalculatorclass used to calculate delay distributions.- Type:
- _tempx#
The array of lag indices.
- Type:
numpy.ndarray
- _delays_x#
The array of delay values based on the sample rate.
- Type:
numpy.ndarray
- __init__(nr_lags, nr_nodes, nodes, distances, connectivity_weights, sample_rate, delay_calculator)[source]#
Initializes the StationaryModelDeveloper with the provided parameters.
- Parameters:
nr_lags (int) – The number of lags (p) in the VAR(p) model.
nr_nodes (int) – The number of nodes in the model.
nodes (list[str]) – The list of node names.
distances (numpy.ndarray) – A matrix containing the distances between nodes.
connectivity_weights (numpy.ndarray) – The initial connectivity weights between nodes.
sample_rate (int) – The sample rate used for the model.
delay_calculator (DelayCalculator) – An instance of the
src.simulation.delay_calculator.DelayCalculatorclass used to calculate delay distributions.
- develop(verbose=False)[source]#
Develops a stationary VAR(p) model.
It calculates the lag connectivity weights using
_calculate_lag_connectivity_weights(), and adjusts the overall connectivity weights using_adjust_connectivity_weights()until the model becomes stationary (check with_is_stationary()).- Parameters:
verbose (bool, optional) – If True, displays progress information during the model development (default is False).
- Returns:
The lag connectivity weights matrix for the stationary model.
- Return type:
numpy.ndarray
- _adjust_connectivity_weights()[source]#
Adjusts the connectivity weights by scaling them down (preserving the relative weights).
- _is_stationary(lag_connectivity_weights)[source]#
Determines whether the model is stationary.
It constructs an augmented matrix from the lag connectivity weights and checks if all eigenvalues are within the unit circle.
- Parameters:
lag_connectivity_weights (numpy.ndarray) – The matrix of lag connectivity weights.
- Returns:
True if the model is stationary (i.e., all eigenvalues are within the unit circle), False otherwise.
- Return type:
bool
- _calculate_lag_connectivity_weights()[source]#
Computes the connectivity weights for each lag between all pairs of nodes using
_get_lag_distribution().- Returns:
The matrix of lag connectivity weights.
- Return type:
numpy.ndarray
- _get_lag_distribution(node1, node2)[source]#
Calculates the lag distribution (using :py:attr:_delay_calculator and :py:meth:src.simulation.delay_calculator.DelayCalculator.get_delays_distribution) between two nodes based on their delays and connectivity weights. If the nodes are the same, the distribution is set to zero.
- Parameters:
node1 (int) – The index of the first node.
node2 (int) – The index of the second node.
- Returns:
The lag distribution values, or 0 if the nodes are the same.
- Return type:
numpy.ndarray or int
- plot_connectivity(lag_connectivity_weights, plots_dir)[source]#
Visualizes the lag connectivity weights between nodes as a line plot, showing the relative strength of connections over different delays.
- Parameters:
lag_connectivity_weights (numpy.ndarray) – The matrix of lag connectivity weights to be plotted.
plots_dir (pathlib.Path) – The directory where the plots are saved.
- Raises:
AssertionError – If the plots directory does not exist.