<jupyter_start><jupyter_text>Load Test Data and Trained APG Sampler<jupyter_code>%matplotlib inline
import torch
import numpy as np
from apgs.dmm.apg_training import init_apg_models, init_rws_models

CUDA = torch.cuda.is_available()
device = torch.device('cuda:1')
data_dir = '../../data/dmm/'
K, D = 4, 2
num_hidden_mu, num_nss, num_hidden_local, num_hidden_dec, recon_sigma = 32, 8, 32, 32, 1.5
data = torch.from_numpy(np.load(data_dir + 'ob_test.npy')).float() 
model_version = 'apg-dmm-num_sweeps=7-num_samples=10'
models = init_apg_models(K, D, num_hidden_mu, num_nss, num_hidden_local, num_hidden_dec, recon_sigma, CUDA, device, model_version, lr=None)<jupyter_output><empty_output><jupyter_text>Visualize Samples<jupyter_code># from apgs.resampler import Resampler
# from apgs.dmm.objectives import apg_objective
# from apgs.dmm.evaluation import viz_samples

# batch_size, num_sweeps = 5, 13
# batch_data = data[torch.randperm(data.shape[0])[:batch_size]].unsqueeze(0)
# if CUDA:
#     batch_data = batch_data.cuda().to(device)
# result_flags = {'loss_required' : False, 'ess_required' : False, 'mode_required' : True, 'density_required': False}
# trace = apg_objective(models, batch_data, K, result_flags, num_sweeps, Resampler('systematic', 1, CUDA, device))
# viz_samples(batch_data.cpu().squeeze(), trace, num_sweeps, K, save_name=None)<jupyter_output><empty_output><jupyter_text>Computing log joint across all methods<jupyter_code>from apgs.dmm.evaluation import density_all_instances
sample_size, num_sweeps = 1000, 20
lf_step_size, lf_num_steps, bpg_factor = 1e-4, [1, 5, 10], 100
density_all_instances(models, data, sample_size, K, num_sweeps, lf_step_size, lf_num_steps, bpg_factor, CUDA, device)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12335054503729202, 'fraction_numerical': 0.020654044750430294, 'mean_word_length': 7.549019607843137, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '248331', 'license': 'Apache-2.0', 'n_tokens_mistral': 714, 'n_tokens_neox': 672, 'n_words': 133, 'path': 'apgs/dmm/evaluation.ipynb', 'repo_name': 'hao-w/amortized', 'size': '1743'}