Пример #1
0
def test_multi_fid(t_array, params):

    data = multi_fid(t_array=t_array, params=params)

    fid_0 = fid(t_array, *params[0])
    fid_1 = fid(t_array, *params[1])

    assert fid_0 + fid_1 == pytest.approx(data)
Пример #2
0
def calculate_freq_domain_rmse(data, params_est, dwell):
    N = len(data)

    t_array, freq_array = gen_t_freq_arrays(N=N, dwell=dwell)

    data_est = multi_fid(t_array=t_array, params=params_est)

    data_est_fft = np.fft.fft(data_est) / np.sqrt(N)
    data_fft = np.fft.fft(data) / np.sqrt(N)

    return np.sqrt(mean_squared_error(data_fft.real, data_est_fft.real))
Пример #3
0
def test_llc_kbdm(t_array, data_brain_sim, dwell, params_brain_sim, N):
    m_range = range(250, 260, 1)

    results = llc_kbdm(
        data=data_brain_sim,
        dwell=dwell,
        m_range=m_range,
        p=1,
        l=30,
    )

    line_list = results.line_list

    line_list = filter_samples(line_list, amplitude_tol=1e-3)

    assert len(line_list) == len(params_brain_sim)

    est_data = multi_fid(t_array, line_list)

    assert np.std(est_data.real - data_brain_sim.real) < 1e-3
    assert np.std(est_data.imag - data_brain_sim.imag) < 1e-3
Пример #4
0
def data_brain_sim(df_params_brain_sim, t):
    data = sig_gen.multi_fid(t, df_params_brain_sim.values)

    return data
Пример #5
0
def iterative_llc_kbdm(data,
                       dwell,
                       m_range,
                       p=1,
                       l=None,
                       q=0.0,
                       max_iterations=5,
                       silhouette_threshold=0.6):
    if max_iterations < 1:
        raise ValueError("'max_iterations must be greater than zero")

    curr_data_est = np.zeros_like(data)

    line_lists = []
    silhouettes = []

    t_array, _ = gen_t_freq_arrays(N=len(data), dwell=dwell)

    n_peaks = 0

    silhouette_thresholds = np.linspace(silhouette_threshold, 0,
                                        max_iterations)

    for i in range(max_iterations):
        print(f'Iteration #{i}')
        curr_res = data - curr_data_est

        results = llc_kbdm(data=curr_res,
                           dwell=dwell,
                           m_range=m_range,
                           p=p,
                           l=l,
                           q=q)

        if len(results.line_list) == 0:
            logging.info('No more peaks can be fitted. Stopping.')
            break

        filtered_index = np.nonzero((results.silhouette > np.percentile(
            results.silhouette, silhouette_thresholds[i])))

        line_list = results.line_list[filtered_index]

        curr_data_est_i = multi_fid(t_array=t_array, params=line_list)

        curr_data_est += curr_data_est_i

        line_lists.append(line_list)
        silhouettes.append(results.silhouette[filtered_index])

        n_peaks += len(line_list)

        print(f'Found {len(line_list)} peaks. Total: {n_peaks} peaks.')

    line_lists = np.r_[line_lists]
    line_list = np.concatenate(line_lists)
    silhouettes = np.r_[silhouettes]

    rmse = calculate_freq_domain_rmse(data=curr_data_est,
                                      params_est=line_list,
                                      dwell=dwell)

    return IterativeLlcKbdmResult(line_list=line_list,
                                  line_lists=line_lists,
                                  silhouettes=silhouettes,
                                  rmse=rmse)