Ejemplo n.º 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_
Ejemplo n.º 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_
Ejemplo n.º 3
0
    if it % log_iter == 0:
        n_sample = 10000
        z_sample = get_sample_z(n_sample, noise_dim)

        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.
Ejemplo n.º 4
0
        # Get only the label dimension, to pass to Generator.
        label_sample =  latent_sample[:, :label_dim]

        # Conditionally generate new sample.
        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("#################")