Beispiel #1
0
def dar_no_fit(ortho,
               normalize,
               sigdriv=_sigdriv,
               sigdriv_imag=_sigdriv_imag,
               **model_params):
    dar = DAR(ortho=ortho, normalize=normalize, **model_params)
    dar.sigin = _sigin[None, :]
    dar.sigdriv = sigdriv[None, :]
    dar.sigdriv_imag = sigdriv_imag[None, :]
    dar.make_basis()
    return dar
Beispiel #2
0
def fast_delay(low_sig=signal,
               high_sig=None,
               mask=None,
               fs=fs,
               low_fq=low_fq,
               *args,
               **kwargs):
    dar_model = DAR(ordar=10, ordriv=2)
    return DelayEstimator(fs=fs,
                          dar_model=dar_model,
                          low_fq=low_fq,
                          low_fq_width=low_fq_width,
                          random_state=0,
                          max_delay=0.01 / low_fq,
                          *args,
                          **kwargs).fit(low_sig=low_sig,
                                        high_sig=high_sig,
                                        mask=mask)
Beispiel #3
0
def fit_dar_and_plot(sig, ax_logl, ax_phase, phi_0, random_state=None):
    dar_model = DAR(ordar=10, ordriv=2)
    est = DelayEstimator(fs,
                         dar_model=dar_model,
                         low_fq=low_fq,
                         low_fq_width=bandwidth,
                         random_state=random_state)
    est.fit(sig)
    est.plot(ax=ax_logl)

    # plot the modulation of the best model
    est.best_model_.plot(ax=ax_phase, mode='c', frange=plot_fq_range)

    ax_phase.set_title('')
    ticks = [-np.pi, phi_0, np.pi]
    ax_phase.set_xticks(ticks)
    ax_phase.set_xticklabels([r'$%s$' % phase_string(d) for d in ticks])
    ax_phase.grid('on')
    ax_phase.grid(color=(0.5, 0.5, 0.5))
Beispiel #4
0
# Prepare the plot for the two figures
fig, axs = plt.subplots(1, 2, figsize=(10, 4))
axs = axs.ravel()

# Extract a low frequency band
sigdriv, sigin, sigdriv_imag = extract_driver(sigs=signal,
                                              fs=fs,
                                              low_fq=low_fq,
                                              bandwidth=low_fq_width,
                                              extract_complex=True,
                                              random_state=0,
                                              fill=2)

# Create a DAR model
# Here we use BIC selection to get optimal hyperparameters (ordar, ordriv)
dar = DAR(ordar=20, ordriv=2, criterion='bic')
# Fit the DAR model
dar.fit(sigin=sigin, sigdriv=sigdriv, sigdriv_imag=sigdriv_imag, fs=fs)

# Plot the BIC selection
bic_array = dar.model_selection_criterions_['bic']
lines = axs[0].plot(bic_array)
axs[0].legend(lines, ['ordriv=%d' % d for d in [0, 1, 2]])
axs[0].set_xlabel('ordar')
axs[0].set_ylabel('BIC / T')
axs[0].set_title('BIC order selection')
axs[0].plot(dar.ordar_, bic_array[dar.ordar_, dar.ordriv_], 'ro')

# Plot the modulation extracted by the optimal model
dar.plot(ax=axs[1])
axs[1].set_title(dar.get_title(name=True))