예제 #1
0
def run_plot(if_fast: bool, if_me: bool, if_simu: bool, latency_ms,
             latency_serv, performance):
    eval_type = 'sdr'
    # 设定x axis
    source_list = []
    # 设定 ms_MeICA
    time_list_ms_MeICA = []
    snr_list_ms_MeICA = []
    # 设定 Me_ICA
    time_list_MeICA = []
    snr_list_MeICA = []
    # 设定 Fast_ICA
    time_list_FastICA = []
    snr_list_FastICA = []
    for s in PGB(range(2, source_number + 1, 1)):
        print(f'starting for source_number:{s}')
        print('running Ms_MeICA...')
        source_list.append(s)
        Source_controller = hop_Source_controller(folder_address, duration, s,
                                                  mixing_type, max_min,
                                                  mu_sigma)
        B_Manager = hop_B_Manager(Source_controller)
        # use same init B
        B_init = B_Manager.get_B()

        # Part MS_MeICA
        pyfbss_tb.timer_start()
        MeICA_controller = hop_MeICA_controller(max_iter, tol, break_coef,
                                                ext_multi_ica,
                                                Source_controller, B_Manager)
        hat_S_ms = MeICA_controller.get_hat_S()
        time_ms_MeICA = pyfbss_tb.timer_value()
        # Time simulator
        if if_simu:
            # reset time for ms_MeICA
            # 算法:
            # client发送接受Source_Controller和B_Manager的信息,latency*4
            # client将信息发送MeICA_Controller最后接受S,latency*2
            # MeICA_Controller接受B,最后更新B,latency*2*(grad+1)
            # MeICA_Controller发送接收B_temp到iter,latency*2*(grad+1)
            time_ms_MeICA = time_ms_MeICA + \
                (4+2+4*MeICA_controller.get_grad()+4)*latency_ms

        time_list_ms_MeICA.append(time_ms_MeICA)
        snr_list_ms_MeICA.append(
            pyfbss_tb.bss_evaluation(Source_controller.get_S(), hat_S_ms,
                                     eval_type))

        # Part FastICA
        if if_fast:
            print('running FastICA...')
            pyfbss_tb.timer_start()
            X = Source_controller.get_X()
            X, V = pyfbss.whiten(X)
            B1 = B_init
            B2 = pyfbss.newton_iteration(B1, X, max_iter, tol)[0]
            hat_S_Fast = np.dot(B2, X)
            time_Fast = pyfbss_tb.timer_value()

            # Time Simulator
            if if_simu:
                # 算法:
                # 中间的运算时间根据性能比线性缩短,之后latency*2
                time_Fast = time_Fast / performance + latency_serv * 2
                pass

            time_list_FastICA.append(time_Fast)
            snr_list_FastICA.append(
                pyfbss_tb.bss_evaluation(Source_controller.get_S(), hat_S_Fast,
                                         eval_type))

        # Part MeICA
        if if_me:
            print('running MeICA...')
            pyfbss_tb.timer_start()
            X = Source_controller.get_X()
            pyfbss.Stack = []
            B1 = B_init
            B2 = pyfbss.multi_level_extraction_newton_iteration(
                X, B1, max_iter, tol, break_coef, ext_multi_ica)
            hat_S_MeICA = np.dot(B2, X)
            time_MeICA = pyfbss_tb.timer_value()
            # Time Simulator
            if if_simu:
                # 算法和FastICA一样
                time_MeICA = time_MeICA / 10 + latency_serv * 2
            time_list_MeICA.append(time_MeICA)
            snr_list_MeICA.append(
                pyfbss_tb.bss_evaluation(Source_controller.get_S(),
                                         hat_S_MeICA, eval_type))

    # plot
    plt.figure()
    plt.subplot(1, 2, 1)
    plt.plot(np.array(source_list),
             np.array(time_list_ms_MeICA),
             'o-',
             label='MircoService_MeICA')
    if if_fast:
        plt.plot(np.array(source_list),
                 np.array(time_list_FastICA),
                 'o-',
                 label='FastICA')
    if if_me:
        plt.plot(np.array(source_list),
                 np.array(time_list_MeICA),
                 'o-',
                 label='MeICA')
    plt.title(f'Time Use, base on Simulator:{if_simu}')
    plt.xlabel('Source Number')
    plt.ylabel('Time[ms]')
    # 添加图例
    plt.legend(loc='best')

    plt.subplot(1, 2, 2)
    plt.plot(np.array(source_list),
             np.array(snr_list_ms_MeICA),
             'o-',
             label='MircoService_MeICA')
    if if_fast:
        plt.plot(np.array(source_list),
                 np.array(snr_list_FastICA),
                 'o-',
                 label='FastICA')
    if if_me:
        plt.plot(np.array(source_list),
                 np.array(snr_list_MeICA),
                 'o-',
                 label='MeICA')
    plt.title(f'SNR')
    plt.xlabel('Source Number')
    plt.ylabel('SNR[dB]')
    # 添加图例
    plt.legend(loc='best')
    plt.show()
예제 #2
0
        tmp_fastica = [source_number]
        tmp_cdica = [source_number]
        tmp_aeica = [source_number]
        tmp_meica = [source_number]

        for test_i in np.arange(1, 2, 1):
            S, A, X = pyfbss_tb.generate_matrix_S_A_X(
                folder_address, duration, source_number, mixing_type="normal", max_min=(1, 0.01), mu_sigma=(0, 1))
            print('type        eval_dB            time(ms) for       ' +
                  str(source_number)+' sources, ' + str(test_i) + '-th test.')
            print(
                '--------------------------------------------------------------------------------')
            eval_type = 'sdr'

            # time and accuracy of FastICA
            pyfbss_tb.timer_start()
            hat_S = pyfbss.fastica(X, max_iter=100, tol=1e-04)
            time = pyfbss_tb.timer_value()
            Eval_dB = pyfbss_tb.bss_evaluation(S, hat_S, eval_type)
            tmp_fastica.extend([Eval_dB, time])
            print('FastICA: ', Eval_dB, '; ', time)

            # time and accuracy of CdICA
            pyfbss_tb.timer_start()
            hat_S = pyfbss.cdica(
                X, max_iter=100, tol=1e-04, ext_initial_matrix=0)
            time = pyfbss_tb.timer_value()
            Eval_dB = pyfbss_tb.bss_evaluation(S, hat_S, eval_type)
            tmp_cdica.extend([Eval_dB, time])
            print('CdICA:   ', Eval_dB, '; ', time)