osl_dynamics.simulation.OscillatoryMVN#
- class osl_dynamics.simulation.OscillatoryMVN(frequencies, sampling_frequency, covariances, means='zero', peak_width=2.0, n_channels=None, n_covariances_act=1, observation_error=0.0, aperiodic_covariance=None, aperiodic_exponent=1.0, aperiodic_knee=1.0)#
Bases:
MVNMultivariate normal observation model with oscillatory states or modes.
Each state or mode \(k\) has a spectral peak at its own frequency. The data are
\[x_t = \sum_k \alpha_{kt} m_k + \sum_k \sqrt{\alpha_{kt}} L_k y^{(k)}_t + L_a b_t + \epsilon_t\]where \(L_k\) is the Cholesky factor of the covariance \(C_k\), \(\epsilon_t\) is white noise and \(y^{(k)}_t\) contains independent, unit-variance AR(2) processes (one per channel). The AR(2) process for frequency \(f\) and peak width \(w\) (in Hz) has poles at \(r e^{\pm i \omega}\), with \(r = e^{-\pi w / f_s}\) and \(\omega = 2 \pi f / f_s\). The spectral peak is close to \(f\) when \(w\) is small compared to \(f\). The processes run through the whole recording and are started from their stationary distribution.
\(L_a b_t\) is optional aperiodic (\(1/f\)) background activity, which is the same in every state or mode. \(L_a\) is the Cholesky factor of
aperiodic_covarianceand \(b_t\) contains independent, unit-variance Gaussian processes with power spectral density proportional to \(1 / (f_{knee}^\chi + f^\chi)\), where \(\chi\) isaperiodic_exponentand \(f_{knee}\) isaperiodic_knee: the spectrum is flat below the knee and falls as \(1/f^\chi\) above it.With mutually exclusive states, the covariance of state \(k\) is \(C_k\) (plus the aperiodic covariance) and its spectrum peaks at its frequency. With modes, the zero-lag covariance at time \(t\) is \(\sum_k \alpha_{kt} C_k\) (plus the aperiodic covariance), as in
MVN.- Parameters:
- frequenciesnp.ndarray or list
Peak frequency (Hz) of each state or mode, shape (n,), or of each state or mode and channel, shape (n, n_channels).
- sampling_frequencyfloat
Sampling frequency in Hz.
- covariancesnp.ndarray or str
Covariance matrix for each state or mode, shape (n, n_channels, n_channels). Either a numpy array or
'random'.- meansnp.ndarray or str, optional
Mean vector for each state or mode, shape (n, n_channels). Either a numpy array or
'zero'or'random'.- peak_widthfloat or np.ndarray, optional
Width (Hz) of the spectral peaks. A float, or one value per state or mode, shape (n,).
- n_channelsint, optional
Number of channels. Needed if it can’t be inferred from the other arguments.
- n_covariances_actint, optional
Number of iterations to add activations to covariance matrices.
- observation_errorfloat, optional
Standard deviation of the white noise added to the generated data.
- aperiodic_covariancenp.ndarray, optional
Covariance of the aperiodic background activity, shape (n_channels, n_channels).
Nonefor no background.- aperiodic_exponentfloat, optional
Exponent \(\chi\) of the aperiodic power spectrum.
- aperiodic_kneefloat, optional
Knee frequency \(f_{knee}\) (Hz) of the aperiodic power spectrum.
- frequencies#
- peak_width#
- sampling_frequency#
- aperiodic_exponent = 1.0#
- aperiodic_knee = 1.0#
- aperiodic_covariance = None#
- simulate_data(time_course)#
Simulate time series data.
- Parameters:
- time_coursenp.ndarray
State or mode time course. Shape must be (n_samples, n).
- Returns:
- datanp.ndarray
Time series data. Shape is (n_samples, n_channels).
- get_instantaneous_covariances(time_course)#
Get the ground truth covariance at each time point.
Includes the aperiodic covariance.
- Parameters:
- time_coursenp.ndarray
State or mode time course. Shape must be (n_samples, n).
- Returns:
- inst_covsnp.ndarray
Instantaneous covariances. Shape is (n_samples, n_channels, n_channels).
- power_spectra(frequencies)#
Ground truth cross power spectral density of each state or mode.
The spectra are one-sided: integrating the power spectral density from 0 Hz to the Nyquist frequency gives the variance.
- Parameters:
- frequenciesnp.ndarray
Frequencies (Hz) to evaluate the spectra at.
- Returns:
- cpsdnp.ndarray
Cross power spectral densities. Shape is (n, n_frequencies, n_channels, n_channels).
- rescale(mu, sigma)#
Update the parameters after the data are standardized.
- Parameters:
- munp.ndarray
Mean subtracted from each channel.
- sigmanp.ndarray
Standard deviation each channel was divided by.
- n_covariances_act = 1#
- observation_error = 0.0#
- means#
- covariances#
- create_means(option, mu=0, sigma=0.2)#
- create_covariances(option, activation_strength=1, eps=1e-06)#
- initialize(n=None)#
Set the number of states or modes and generate random parameters.
- Parameters:
- nint, optional
Number of states or modes. Must match the parameter arrays if they were passed.