<jupyter_start><jupyter_text>Loading pre-trained model This part is optional if you want to load pre-trained model. The name of the file where the model was saved appears as the last line of the output the train_compert().<jupyter_code>import torch
from compert.train import prepare_compert

model_name = '../pretrained_models/GSM/sweep_GSM_new_logsigm_model_seed=60_epoch=1120.pt'
state, args, history = torch.load(model_name, map_location=torch.device('cpu'))
args['dataset_path'] = '../datasets/GSM_new.h5ad'

# load the dataset and model pre-trained weights
autoencoder, datasets = prepare_compert(args, state_dict=state)
compert_api = ComPertAPI(datasets, autoencoder)
%load_ext autoreload
%autoreload 2
_ = pl.plot_uncertainty_dose(
        compert_api,
        cov='A549',
        pert='SAHA',
        N=101,
        measured_points=compert_api.measured_points['all'],
        cond_key='condition',
        log=True,
        metric='cosine',
        figsize=(4, 4),
        filename='unc_1.svg'
)
_ = pl.plot_uncertainty_comb_dose(
        compert_api,
        cov='A549',
        pert='SAHA+BMS',
        N=101,
        cond_key='condition',
        metric='cosine',
        filename='unc_2.svg'
)
_, _, _, _, cos_dist, eucl_dist = compert_api.compute_uncertainty(cov='A549', pert='SAHA', dose='0.5')
df_dist = pd.DataFrame({
    'cos_dist': cos_dist, 
    'eucl_dist': eucl_dist,
    'cov/pert': compert_api.comb_emb.obs.cov_pert.apply(lambda x: x.split('_')[1])
})
import seaborn as sns
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1, figsize=(6, 4))
sns.histplot(x='cos_dist', hue='cov/pert', data=df_dist, bins=15, multiple='stack', ax=ax)
ax.set_xlabel('Cosine distance')
ax.set_title('SAHA (dose=0.5)')
sns.despine()
fig.savefig('unc_3.svg')
fig, ax = plt.subplots(1, 1, figsize=(6, 4))
sns.histplot(x='eucl_dist', hue='cov/pert', data=df_dist, bins=15, multiple='stack', ax=ax)
ax.set_xlabel('Eucl distance')
sns.despine()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14393939393939395, 'fraction_numerical': 0.022727272727272728, 'mean_word_length': 4.472375690607735, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '85411', 'license': 'MIT', 'n_tokens_mistral': 764, 'n_tokens_neox': 728, 'n_words': 142, 'path': 'notebooks/figure_sup_uncertainty.ipynb', 'repo_name': 'scottgigante-immunai/CPA', 'size': '1980'}