Esempio n. 1
0
def get_timing_vs_ndata_at_const_nfreq(nvals,
                                       nharmonics,
                                       max_freq,
                                       filename=None,
                                       overwrite=True,
                                       time_slow=True):

    #if template is None:
    template = get_default_template(nharmonics=nharmonics)
    template.precompute()

    # load saved results
    results = {}
    if filename is None:
        filename = './saved_results/timing_results_nh%d_maxfrq%.1f.pkl' % (
            nharmonics, max_freq)
    if not filename is None and os.path.exists(filename):
        old_results = pickle.load(open(filename, 'rb'))
        results.update(old_results)

    for n in nvals:
        if n in results:
            continue

        x, y, dy = generate_random_signal(n)
        x[0] = 0
        x[-1] = 1

        # time FTP
        print("timing: n = %d, h = %d, ftp" % (n, nharmonics))

        model = FastTemplatePeriodogram(template=template)
        model.fit(x, y, dy)

        t0 = time()
        frq, p = model.autopower(maximum_frequency=max_freq)
        tftp = time() - t0

        print("   done in %.4f seconds" % (tftp))

        if time_slow:
            print("timing: n = %d, h = %d, slow" % (n, nharmonics))
            model = SlowTemplatePeriodogram(template=template)
            model.fit(x, y, dy)

            t0 = time()
            p = model.power(frq)
            tslow = time() - t0

            print("   done in %.4f seconds" % (tslow))
        else:
            tslow = -1

        results[n] = (tftp, tslow)

        # save
        if not filename is None and overwrite:
            pickle.dump(results, open(filename, 'wb'))

    return zip(*[results[n] for n in nvals])
Esempio n. 2
0
def get_timing_vs_ndata(nvals,
                        nharmonics,
                        filename=None,
                        overwrite=True,
                        time_gatspy=True,
                        only_use_saved_data=False,
                        time_lomb_scargle=False):
    #if template is None:
    template = get_default_template(nharmonics=nharmonics)
    #template.precompute()

    # load saved results
    results = {}
    if not filename is None and os.path.exists(filename):
        old_results = pickle.load(open(filename, 'rb'))
        results.update(old_results)
    else:
        results = {name: [] for name in ['nfreqs', 'ndata', 'tftp', 'tgats']}

    if only_use_saved_data:
        return select_from_dict(results, nvals)

    # return if nothing to do
    if all([n in results for n in nvals]):
        return [results[n] for n in nvals]

    for n in nvals:
        if n in results['ndata']:
            continue

        results['ndata'].append(n)

        x, y, dy = generate_random_signal(n)

        # time FTP
        print("timing: n = %d, h = %d, ftp" % (n, nharmonics))

        model = FastTemplatePeriodogram(template=template)
        model.fit(x, y, dy)

        t0 = time()
        frq, p = model.autopower()
        results['tftp'].append(time() - t0)

        print("   done in %.4f seconds" % (results['tftp'][-1]))
        results['nfreqs'].append(len(frq))

        if time_gatspy:
            # time GATSPY
            print("timing: n = %d, gatspy" % (n))

            model = SlowTemplatePeriodogram(template=template)
            model.fit(x, y, dy)

            t0 = time()
            p = model.power(frq)
            results['tgats'].append(time() - t0)

            print("   done in %.4f seconds" % (results['tgats'][-1]))
        else:
            results['tgats'].append(-1)

        # SORT results
        results = sort_timing_dict(results)

        # save
        if not filename is None and overwrite:
            pickle.dump(results, open(filename, 'wb'))

    return select_from_dict(results, nvals)