Imputation of peptide abundances#
Data#
In this R Notebook, we illustrate how to use scVAEIT on R through peptide abundances data measured by mass spectrometer. These data are normally distributed (taking both positive and negative values) but missing at random.
[1]:
load("simulated_peptide.RData")
[2]:
raw.pep[1:5,1:5]
| -0.2697226 | NA | NA | -0.5640022 | NA |
| NA | NA | NA | NA | NA |
| NA | 0.1191803 | -0.4339813 | NA | 0.122774 |
| NA | -2.0202053 | NA | -0.7947332 | NA |
| 1.1508900 | NA | NA | -0.7329767 | NA |
[3]:
comp.pep[1:5,1:5]
| -0.2697226 | -0.5043728 | -0.5743020 | -0.56400219 | 1.69118295 |
| 0.9133593 | 0.0324714 | 1.1169943 | 1.68557128 | 0.58438257 |
| 1.4123398 | 0.1191803 | -0.4339813 | 0.03837133 | 0.12277400 |
| 1.6874292 | -2.0202053 | 1.5708989 | -0.79473315 | 0.00446075 |
| 1.1508900 | 1.0141109 | -0.1465066 | -0.73297667 | -0.45736804 |
[4]:
cat(dim(comp.pep), dim(raw.pep))
1000 500 1000 500
[5]:
# Randomly generated covariates
n <- nrow(raw.pep)
case <- sample(n,n/2); control=setdiff(c(1:n), case)
label <- rep(0,n); label[case]=1
batches_cate <- matrix(as.factor(label),ncol=1,byrow=F)
ls2 <- log(rowSums((raw.pep!=0) & (!is.na(raw.pep))))
batches_cont <- matrix(c(ls2),ncol=1,byrow=F)
data <- raw.pep; data[is.na(data)] <- 0.; data <- as.matrix(data)
masks <- - as.matrix(is.na(as.matrix(raw.pep)))
Loading Python Package from R#
[6]:
# import Python package (call after setting up python environment with reticulate)
# Use 'reticulate' to access Python environment
library(reticulate)
use_condaenv(condaenv = "tf")
# If the package is installed via PyPI in the Python environment,
# simply import it:
# scVAEIT <- import("scVAEIT")
# Otherwise, need to downloaded Github repo, set a proper path to import the module.
setwd('../../../../')
scVAEIT <- import("scVAEIT")
scVAEIT$`__version__`
Initialize scVAEIT model#
[7]:
config = list(
# A network stucture of
# x : dim_input -> 64 -> 16 -> z 4 -> 16 -> 64 -> dim_input
# | |
# masks : dim_input -> dim_embed -> ->
'dimensions'=c(16), # hidden layers
'dim_latent'=4L, # latent space
# Block structure for the input and output layer
'dim_block_enc'=c(64),
'dim_block_dec'=c(64),
'dist_block'=list('Gaussian'), # use Gaussian likelihood by default
'dim_block_embed'=128L,
# some hyperparameters
'beta_unobs'=0.5,
# prob of random maskings
'p_feat'=0.2,
'beta_reverse'=0.2,
# skip connection for improving imputation quality
'skip_conn'=T
)
scVAEIT$reset_random_seeds(as.integer(0))
cat('Initializing model...\n')
model <- scVAEIT$VAEIT(config, data, masks, NULL, batches_cate, batches_cont)
Initializing model...
[8]:
model$config
namespace(beta_kl=2.0, beta_unobs=0.5, beta_reverse=0.2, beta_modal=array([1.], dtype=float32), p_modal=None, p_feat=0.2, uni_block_names=array(['M-0'], dtype='<U23'), block_names=array(['M-0'], dtype='<U23'), dist_block=array(['Gaussian'], dtype='<U8'), dim_block=array([500], dtype=int32), dim_block_enc=array([64], dtype=int32), dim_block_dec=array([64], dtype=int32), skip_conn=True, mean_vals=<tf.Tensor: shape=(500,), dtype=float32, numpy=
array([0.44167346, 0.48984244, 0.5465714 , 0.46952555, 0.58617085,
0.3595247 , 0.5914804 , 0.44657955, 0.46613336, 0.5135204 ,
0.4015038 , 0.5733716 , 0.60520023, 0.43958527, 0.5650931 ,
0.5828378 , 0.5444924 , 0.5714362 , 0.3516288 , 0.44687292,
0.5197562 , 0.49680597, 0.43845636, 0.39757198, 0.4432136 ,
0.4323344 , 0.4887178 , 0.5314573 , 0.37781012, 0.5152997 ,
0.363956 , 0.5152584 , 0.4640951 , 0.41251922, 0.4628549 ,
0.4418806 , 0.4116188 , 0.46998972, 0.524338 , 0.4115528 ,
0.578989 , 0.37288243, 0.42849144, 0.5074455 , 0.5357366 ,
0.3910529 , 0.53785056, 0.44470683, 0.42382818, 0.32329348,
0.46237525, 0.49079412, 0.5935558 , 0.46526125, 0.4249745 ,
0.45748064, 0.4877372 , 0.4697292 , 0.43844187, 0.4872708 ,
0.5007588 , 0.4426675 , 0.5900256 , 0.48321936, 0.578675 ,
0.4863309 , 0.47052136, 0.47923714, 0.48017466, 0.57626325,
0.44643286, 0.46820912, 0.4171309 , 0.6249119 , 0.44286343,
0.4260803 , 0.5442024 , 0.4606753 , 0.58725494, 0.44231635,
0.5040751 , 0.46366876, 0.43885294, 0.41229737, 0.64073205,
0.4460965 , 0.4917642 , 0.5528737 , 0.5119443 , 0.48043954,
0.40812445, 0.45054817, 0.48885673, 0.48386854, 0.50450885,
0.48738486, 0.43848634, 0.40006897, 0.5716406 , 0.41676977,
0.47356898, 0.4223224 , 0.43327808, 0.46813238, 0.4150288 ,
0.42966357, 0.52196294, 0.56367564, 0.439713 , 0.56952155,
0.5230101 , 0.50206006, 0.5446369 , 0.53345627, 0.4242801 ,
0.41908252, 0.49697477, 0.53437495, 0.47868842, 0.56949574,
0.51492864, 0.38450935, 0.39691478, 0.4739909 , 0.4224833 ,
0.37701175, 0.43671468, 0.47100297, 0.43065375, 0.36012664,
0.5019166 , 0.44239438, 0.5876119 , 0.4521961 , 0.6064823 ,
0.50447494, 0.5359519 , 0.44469285, 0.4172007 , 0.5261351 ,
0.5251257 , 0.45096493, 0.4839476 , 0.4067544 , 0.4318826 ,
0.45432273, 0.47654808, 0.46657246, 0.48987502, 0.47946635,
0.45344937, 0.61418843, 0.47064787, 0.48420405, 0.57846934,
0.38904366, 0.4954298 , 0.3980896 , 0.4133926 , 0.4497321 ,
0.47223264, 0.47951135, 0.67438805, 0.48631427, 0.4664916 ,
0.49458838, 0.53364396, 0.43857995, 0.46493697, 0.48575547,
0.45585576, 0.40399233, 0.5175959 , 0.44508028, 0.58583987,
0.4931869 , 0.4654778 , 0.45242658, 0.51083046, 0.59824836,
0.44048953, 0.45706388, 0.42148554, 0.6373112 , 0.47820705,
0.35404885, 0.3939406 , 0.5303418 , 0.5925832 , 0.5153572 ,
0.4740743 , 0.45049754, 0.44460705, 0.46636787, 0.4031343 ,
0.46360973, 0.5357519 , 0.4553184 , 0.5326741 , 0.47295928,
0.41256285, 0.4902314 , 0.4574741 , 0.54228723, 0.456533 ,
0.5361408 , 0.4255597 , 0.5006543 , 0.4457953 , 0.520901 ,
0.5002002 , 0.5345333 , 0.5682128 , 0.4634213 , 0.5042421 ,
0.46494603, 0.49348217, 0.40956554, 0.47676364, 0.5101183 ,
0.5309284 , 0.41410598, 0.40544453, 0.3292099 , 0.46646318,
0.40257636, 0.48729295, 0.4590985 , 0.5089235 , 0.472744 ,
0.37316367, 0.4403795 , 0.45556235, 0.5287561 , 0.5440183 ,
0.447273 , 0.4634429 , 0.46747127, 0.45928472, 0.4162167 ,
0.433242 , 0.46973228, 0.4686215 , 0.48649183, 0.54964566,
0.5541102 , 0.64971083, 0.5385242 , 0.3551256 , 0.5396445 ,
0.38264436, 0.5176095 , 0.47652736, 0.4328104 , 0.5072322 ,
0.46884862, 0.4798264 , 0.47323132, 0.48234022, 0.5028467 ,
0.5091771 , 0.4415054 , 0.4843205 , 0.43487754, 0.49706724,
0.46597323, 0.47205573, 0.4308642 , 0.6106282 , 0.36423904,
0.4416624 , 0.47740915, 0.5018918 , 0.47686392, 0.43923366,
0.44050765, 0.45090422, 0.4273779 , 0.4186453 , 0.42859843,
0.45215046, 0.56449574, 0.3994119 , 0.45960572, 0.4107238 ,
0.52657324, 0.5347761 , 0.44827163, 0.47340629, 0.46423277,
0.46345985, 0.51009536, 0.46994734, 0.47237295, 0.5083045 ,
0.44077775, 0.43631625, 0.49488387, 0.6095564 , 0.59853184,
0.50270224, 0.443888 , 0.50998145, 0.41234925, 0.44906712,
0.39074358, 0.4270177 , 0.4437806 , 0.59212285, 0.40857363,
0.45152736, 0.44491643, 0.44879186, 0.43495604, 0.4902989 ,
0.41434687, 0.46035433, 0.46970755, 0.48891577, 0.583292 ,
0.44898874, 0.40372533, 0.52256066, 0.48853293, 0.5051092 ,
0.49806827, 0.40218613, 0.46869454, 0.43561473, 0.5035961 ,
0.4805384 , 0.46428555, 0.45951867, 0.4789506 , 0.41134298,
0.3903212 , 0.5379869 , 0.4515121 , 0.42675248, 0.41554293,
0.57891417, 0.4425422 , 0.4362718 , 0.49010056, 0.5027161 ,
0.41596824, 0.44784307, 0.5679541 , 0.51071966, 0.43766642,
0.49797648, 0.38964656, 0.46094492, 0.42745134, 0.45035645,
0.5003531 , 0.60477453, 0.44471005, 0.56104654, 0.43384808,
0.4857756 , 0.5115517 , 0.59881616, 0.4321364 , 0.4539542 ,
0.4921992 , 0.44710618, 0.4665064 , 0.42134392, 0.40772405,
0.5122471 , 0.41324514, 0.5076883 , 0.6538804 , 0.4676302 ,
0.5680538 , 0.45807177, 0.4846465 , 0.46308997, 0.45172316,
0.44012502, 0.4246387 , 0.520933 , 0.40181506, 0.5096415 ,
0.40603632, 0.43112853, 0.42344457, 0.4289771 , 0.46643052,
0.41397843, 0.414845 , 0.6019184 , 0.52737075, 0.48225012,
0.4464788 , 0.40843585, 0.44654727, 0.4304148 , 0.3992861 ,
0.45835778, 0.4455673 , 0.4590916 , 0.34738433, 0.5486083 ,
0.4252538 , 0.3612915 , 0.3634048 , 0.4382005 , 0.48553762,
0.45748988, 0.44039792, 0.39362675, 0.5681494 , 0.51097256,
0.49147972, 0.4255261 , 0.53887546, 0.43387797, 0.42871034,
0.37862977, 0.5560234 , 0.51769084, 0.42697015, 0.47894034,
0.52200425, 0.5186581 , 0.39381763, 0.47760582, 0.4614425 ,
0.4605042 , 0.34680563, 0.47774062, 0.45344302, 0.39859438,
0.40351933, 0.603205 , 0.39514112, 0.5187436 , 0.4450285 ,
0.4227744 , 0.36572862, 0.44116205, 0.53064585, 0.48946658,
0.48179853, 0.43616313, 0.4245024 , 0.4286588 , 0.5692155 ,
0.43669954, 0.51042527, 0.5566593 , 0.4704327 , 0.5643307 ,
0.5912577 , 0.48838222, 0.4528589 , 0.5953719 , 0.36073285,
0.63314414, 0.39377695, 0.6033216 , 0.5325172 , 0.41511196,
0.46098045, 0.5386408 , 0.54768544, 0.58914846, 0.5455567 ,
0.5075647 , 0.487652 , 0.57669663, 0.3960343 , 0.41376957,
0.42226028, 0.4854924 , 0.40281618, 0.48214912, 0.4287232 ,
0.3386856 , 0.36681563, 0.43240198, 0.63149524, 0.620778 ,
0.46251142, 0.3735041 , 0.40346634, 0.46900922, 0.51747507,
0.42143112, 0.47328028, 0.45430166, 0.4338397 , 0.6234785 ,
0.452747 , 0.56156504, 0.46362826, 0.42341414, 0.51844025],
dtype=float32)>, min_vals=<tf.Tensor: shape=(500,), dtype=float32, numpy=
array([-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643,
-4.2092643, -4.2092643, -4.2092643, -4.2092643, -4.2092643],
dtype=float32)>, max_vals=<tf.Tensor: shape=(500,), dtype=float32, numpy=
array([5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715, 5.034715, 5.034715, 5.034715, 5.034715,
5.034715, 5.034715], dtype=float32)>, max_disp=6.0, max_zi_prob=None, gamma=0.0, dimensions=array([16], dtype=int32), dim_latent=4, dim_block_embed=array([128], dtype=int32), dim_input_arr=array([500], dtype=int32))
Model training and inference#
[9]:
hist <- model$train(num_epoch=2000, verbose=FALSE)
# Save model if needed
# model$save_model('example/result/R/checkpoint/')
# Next time, load model without training again
# model$load_model('example/result/R/checkpoint/')
[10]:
plot(1:length(hist[['train']][['total']]), hist[['train']][['total']], type="l")
After the model is trained, we can get impouted and denoised abundances:
[11]:
imp.pep <- model$get_denoised_data(return_mean=TRUE)
One can also use pulgin estimate (only the missing values are imputed):
[12]:
blend.pep <- data
ina <- masks!=0
blend.pep[ina] <- imp.pep[ina]
rownames(blend.pep) <- rownames(data)
colnames(blend.pep) <- colnames(data)
Visualize#
[13]:
plot(comp.pep[is.na(raw.pep)], imp.pep[is.na(raw.pep)],
pch = 16, cex = .5, col = rgb(red = 0, green = 0, blue = 1, alpha = 0.1)
)
abline(0,1)
[14]:
cat(mean(((comp.pep - imp.pep)**2)[is.na(raw.pep)]))
0.04359538
[15]:
plot(comp.pep, imp.pep,
pch = 16, cex = .5, col = rgb(red = 0, green = 0, blue = 1, alpha = 0.1)
)
abline(0,1)
R function interface#
When the above procedure works properly, it is convenient to have a simple interface to iteratively the same procedure and to tune over different hyperparameters. For this purpose, we can create a wrapper function as R file (e.g. "R_wrapper.R" in the current directory) and load the wrapper function in any R program by the following commands:
source("R_wrapper.R")
When using the above command, make sure to use the correct path, or set up the workspace path properly.