Пример #1
0
 def disc_to_unthinned(ref_set, generated):
     ## DISCREPANCIES TO UNTHINNED SET.
     ref_set_n = len(ref_set)
     n_sample = len(generated)
     # Compute MMD, Energy, and KL, between simulations and unthinned data.
     mmd_, _ = compute_mmd(
         generated, ref_set[np.random.choice(ref_set_n, n_sample)])
     energy_ = compute_energy(
         generated, ref_set[np.random.choice(ref_set_n, n_sample)])
     kl_ = compute_kl(generated,
                      ref_set[np.random.choice(ref_set_n, n_sample)],
                      k=5)
     return mmd_, energy_, kl_
Пример #2
0
 def compute_discrepancies(cand_set, ref_set):
     """Computes discrepancies between two sets."""
     cand_set_n = len(cand_set)
     ref_set_n = len(ref_set)
     n_sample = 1000
     assert ((cand_set_n >= n_sample) & (ref_set_n >= n_sample)), \
         'n_sample too high for one of the inputs.'
     # Compute MMD, Energy, and KL, between simulations and unthinned data.
     mmd_, _ = compute_mmd(cand_set[np.random.choice(cand_set_n, n_sample)],
                           ref_set[np.random.choice(ref_set_n, n_sample)])
     energy_ = compute_energy(
         cand_set[np.random.choice(cand_set_n, n_sample)],
         ref_set[np.random.choice(ref_set_n, n_sample)])
     kl_ = compute_kl(cand_set[np.random.choice(cand_set_n, n_sample)],
                      ref_set[np.random.choice(ref_set_n, n_sample)],
                      k=5)
     return mmd_, energy_, kl_
Пример #3
0
        g_out = sess.run(g, feed_dict={z: z_sample})
        generated_normed = g_out
        generated = np.array(generated_normed) * data_raw_std + data_raw_mean

        # Compute MMD between simulations and unthinned (target) data.
        mmd_gen_vs_unthinned, _ = compute_mmd(
            generated[np.random.choice(n_sample, 500)],
            data_raw_unthinned[np.random.choice(data_num_original, 500)])
        # Compute energy between simulations and unthinned (target) data.
        energy_gen_vs_unthinned = compute_energy(
            generated[np.random.choice(n_sample, 500)],
            data_raw_unthinned[np.random.choice(data_num_original, 500)])
        # Compute KL between simulations and unthinned (target) data.
        kl_gen_vs_unthinned = compute_kl(
            generated[np.random.choice(n_sample, 500)],
            data_raw_unthinned[np.random.choice(data_num_original, 500)],
            k=5)

        if data_dim == 2:
            fig = plot(generated, data_raw, data_raw_unthinned,
                       data_raw_upsampled, it, mmd_gen_vs_unthinned)

        if np.isnan(d_loss_):
            sys.exit('got nan')

        # Print diagnostics.
        print("#################")
        print('upsample_{}'.format(tag))
        print('Iter: {}'.format(it))
        print('  d_loss: {:.4}'.format(d_loss_))
        print('  g_loss: {:.4}'.format(g_loss_))
Пример #4
0
        g_out = sess.run(g, feed_dict={z: z_sample, label: label_sample})
        generated_normed = np.hstack((latent_sample, g_out))
        generated = np.array(generated_normed) * data_raw_std + data_raw_mean
        ####################################################

        # Compute MMD only between data dimensions, and not latent ones.
        mmd_gen_vs_unthinned, _ = compute_mmd(
            generated[np.random.choice(n_sample, 500), -data_dim:],
            data_raw_unthinned[np.random.choice(data_num, 500), -data_dim:])
        # Compute energy only between data dimensions, and not latent ones.
        energy_gen_vs_unthinned = compute_energy(
            generated[np.random.choice(n_sample, 500), -data_dim:],
            data_raw_unthinned[np.random.choice(data_num, 500), -data_dim:])
        # Compute KL only between data dimensions, and not latent ones.
        kl_gen_vs_unthinned = compute_kl(
            generated[np.random.choice(n_sample, 500), -data_dim:],
            data_raw_unthinned[np.random.choice(data_num, 500), -data_dim:], k=5)

        if data_dim == 2:
            fig = plot(generated, data_raw, data_raw_unthinned, it,
                mmd_gen_vs_unthinned)

        if np.isnan(d_loss_):
            sys.exit('got nan')

        # Print diagnostics.
        print("#################")
        print('cgan_{}'.format(tag))
        print('Iter: {}'.format(it))
        print('  d_loss: {:.4}'.format(d_loss_))
        print('  g_loss: {:.4}'.format(g_loss_))