scHPF
scHPF copied to clipboard
Posterior predictive checks?
I've been using this package for a class project. It's great!
In the paper you discuss running posterior predictive checks with scHPF, but I didn't find anything in the documentation about how to do it. I hunted around the source without success either. After running a job, I figured that if I loaded the joblib model I could retrieve the learned parameters and then I could maybe figure it out from there, but I couldn't sort that out either. Am I missing something, or will this be a future release? Any workarounds in the meantime would be much appreciated, I'm quite new to this stuff!
Thanks! Matt
Glad you have found scHPF useful!
You can do a PPC as follows:
import numpy as np
import schpf
# load the model
model_file = '/path/to/joblib.joblib'
model = schpf.load_model(model_file)
# sample an arbitrary number of samples (here 5) from variational distributions
nsamples = 5
theta_sample = model.theta.sample(nsamples) # has shape (ncells, nfactors, nsamples)
beta_sample = model.beta.sample(nsamples) # has shape (ngenes, nfactors, nsamples)
# calculate the Poisson rate and sample
# have to do some reshaping first--a more elegant way probably exists, but this works
# both rate and pois_samples have shape (ncells, ngenes, nsamples)
rate = np.matmul(np.moveaxis(beta_sample,-1,0),theta_sample.T).T
pois_samples = np.random.poisson(rate)