<jupyter_start><jupyter_text>BPMF using posterior propagation Downloading the data filesIn these examples we use ChEMBL dataset for compound-proteins activities (IC50). The IC50 values and ECFP fingerprints can be downloaded using this smurff function:<jupyter_code>import smurff

ic50_train, ic50_test, ecfp = smurff.load_chembl()<jupyter_output><empty_output><jupyter_text>Running SMURFFFinally we run make a BPMF training session and call `run`. The `run` function builds the model andreturns the `predictions` of the test data.<jupyter_code>session = smurff.BPMFSession(
                       Ytrain     = ic50_train,
                       Ytest      = ic50_test,
                       num_latent = 16,
                       burnin     = 40,
                       nsamples   = 20,
                       verbose    = 1,
                       save_freq = 1,)

session.run()
import numpy as np

predict_session = session.makePredictSession()
# collect U for all samples
Us = [ s.latents[0] for s in predict_session.samples() ]

# stack them and compute mean
Ustacked = np.stack(Us)
mu = np.mean(Ustacked, axis = 0)

# Compute covariance, first unstack in different way
Uunstacked = np.squeeze(np.split(Ustacked, Ustacked.shape[2], axis = 2))
Ucov = [ np.cov(u, rowvar = False) for u in Uunstacked ]
# restack
Ucovstacked = np.stack(Ucov, axis = 2)
# reshape correctly
Lambda = Ucovstacked.reshape(Ucovstacked.shape[0]*Ucovstacked.shape[1], Ucovstacked.shape[2])

session2 = smurff.BPMFSession(
                       Ytrain     = ic50_train,
                       Ytest      = ic50_test,
                       num_latent = 16,
                       burnin     = 40,
                       nsamples   = 20,
                       verbose    = 1,
                       save_freq = 1,
                       )
session2.addPropagatedPosterior(0, mu, Lambda)
predictions = session2.run()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08108108108108109, 'fraction_numerical': 0.02286902286902287, 'mean_word_length': 2.1765676567656764, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '468871', 'license': 'MIT', 'n_tokens_mistral': 630, 'n_tokens_neox': 574, 'n_words': 155, 'path': 'docs/notebooks/bmf with posterior propagation.ipynb', 'repo_name': 'msteijaert/smurff', 'size': '1924'}