Ejemplo n.º 1
0
    n_batches = loc['n_batches']
    if np.mod((ii-iter_offset)/int(n_batches), n_iter) == 0:
        # Compute distance only every 5 iterations, as in previous case
        d = loc['dict_obj']
        d.wasserstein.append(emd(loc['dictionary'], d.generating_dict, 
                                 'chordal', scale=True))
        d.detect_rate.append(detection_rate(loc['dictionary'],
                                              d.generating_dict, 0.99))
        d.objective_error.append(loc['current_cost']) 

# reinitializing the random generator
learned_dict2 = MiniBatchMultivariateDictLearning(n_kernels=n_kernels, 
                                batch_size=batch_size, n_iter=max_iter*n_iter,
                                n_nonzero_coefs=n_nonzero_coefs,
                                callback=callback_distance,
                                n_jobs=n_jobs, learning_rate=learning_rate,
                                kernel_init_len=kernel_init_len, verbose=1,
                                dict_init=dict_init, random_state=rng_global)
learned_dict2.generating_dict = list(generating_dict)
learned_dict2.wasserstein = list()
learned_dict2.detect_rate = list()
learned_dict2.objective_error = list()

learned_dict2 = learned_dict2.fit(X)

plot_univariate(array(learned_dict2.objective_error),
                array(learned_dict2.detect_rate),
                array(learned_dict2.wasserstein),
                n_iter=1, figname='univariate-case-callback')
    
    hfb = zeros((n_snr, n_experiments, n_iter))
    dr99 = zeros((n_snr, n_experiments, n_iter))
    dr97 = zeros((n_snr, n_experiments, n_iter))

    for i, s in enumerate(snr):
        for e in range(n_experiments):
            g, X, code = _generate_testbed(kernel_init_len,
                n_nonzero_coefs, n_kernels, n_samples, n_features,
                n_dims, s)
            d = MiniBatchMultivariateDictLearning(n_kernels=n_kernels, 
                batch_size=batch_size, n_iter=n_iter,
                n_nonzero_coefs=n_nonzero_coefs, callback=callback_recovery,
                n_jobs=n_jobs, learning_rate=learning_rate,
                kernel_init_len=kernel_init_len, verbose=1,
                random_state=rng_global)
            d.generating_dict = list(g)
            d.wc, d.wfs, d.hc, d.hfs = list(), list(), list(), list()
            d.wcpa, d.wbc, d.wg, d.wfb = list(), list(), list(), list()
            d.hcpa, d.hbc, d.hg, d.hfb = list(), list(), list(), list()
            d.dr99, d.dr97 = list(), list()
            print ('\nExperiment', e+1, 'on', n_experiments)
            d = d.fit(X)
            wc[i, e, :] = array(d.wc); wfs[i, e, :] = array(d.wfs)
            hc[i, e, :] = array(d.hc); hfs[i, e, :] = array(d.hfs)
            wcpa[i, e, :] = array(d.wcpa); wbc[i, e, :] = array(d.wbc)
            wg[i, e, :] = array(d.wg); wfb[i, e, :] = array(d.wfb)
            hcpa[i, e, :] = array(d.hcpa); hbc[i, e, :] = array(d.hbc)
            hg[i, e, :] = array(d.hg); hfb[i, e, :] = array(d.hfb)
            dr99[i, e, :] = array(d.dr99); dr97[i, e, :] = array(d.dr97)
    with open(backup_fname, "w") as f:
        o = {'wc':wc, 'wfs':wfs, 'hc':hc, 'hfs':hfs, 'dr99':dr99, 'dr97':dr97,
Ejemplo n.º 3
0
    n_batches = loc['n_batches']
    if np.mod((ii-iter_offset)/int(n_batches), n_iter) == 0:
        # Compute distance only every 5 iterations, as in previous case
        d = loc['dict_obj']
        d.wasserstein.append(emd(loc['dictionary'], d.generating_dict, 
                                 'chordal', scale=True))
        d.detection_rate.append(detectionRate(loc['dictionary'],
                                              d.generating_dict, 0.99))
        d.objective_error.append(loc['current_cost']) 

# reinitializing the random generator
learned_dict2 = MiniBatchMultivariateDictLearning(n_kernels=n_kernels, 
                                batch_size=batch_size, n_iter=max_iter*n_iter,
                                n_nonzero_coefs=n_nonzero_coefs,
                                callback=callback_distance,
                                n_jobs=n_jobs, learning_rate=learning_rate,
                                kernel_init_len=kernel_init_len, verbose=1,
                                dict_init=dict_init, random_state=rng_global)
learned_dict2.generating_dict = list(generating_dict)
learned_dict2.wasserstein = list()
learned_dict2.detection_rate = list()
learned_dict2.objective_error = list()

learned_dict2 = learned_dict2.fit(X)

plot_multivariate(array(learned_dict2.objective_error),
                array(learned_dict2.detection_rate),
                100.-array(learned_dict2.wasserstein),
                n_iter=1, figname='multivariate-case-callback')