@@ -83,6 +83,7 @@ def __init__(
8383 n_groups : int = 50 ,
8484 detection_mean = 1 / 2 ,
8585 detection_alpha = 200.0 ,
86+ use_detection_probability : bool = False ,
8687 m_g_gene_level_prior = {"mean" : 1 , "mean_var_ratio" : 1.0 , "alpha_mean" : 3.0 },
8788 N_cells_per_location = 8.0 ,
8889 A_factors_per_location = 7.0 ,
@@ -117,6 +118,7 @@ def __init__(
117118 detection_hyp_prior ["mean" ] = detection_mean
118119 detection_hyp_prior ["alpha" ] = detection_alpha
119120 self .detection_hyp_prior = detection_hyp_prior
121+ self .use_detection_probability = use_detection_probability
120122
121123 if (init_vals is not None ) & (type (init_vals ) is dict ):
122124 self .np_init_vals = init_vals
@@ -323,27 +325,47 @@ def forward(self, x_data, idx, batch_index):
323325 ) # (self.n_obs, self.n_factors)
324326
325327 # =====================Location-specific detection efficiency ======================= #
326- # y_s with hierarchical mean prior
327- detection_mean_y_e = pyro .sample (
328- "detection_mean_y_e" ,
329- dist .Gamma (
330- self .ones * self .detection_mean_hyp_prior_alpha ,
331- self .ones * self .detection_mean_hyp_prior_beta ,
328+ if not self .use_detection_probability :
329+ # y_s with hierarchical mean prior
330+ detection_mean_y_e = pyro .sample (
331+ "detection_mean_y_e" ,
332+ dist .Gamma (
333+ self .ones * self .detection_mean_hyp_prior_alpha ,
334+ self .ones * self .detection_mean_hyp_prior_beta ,
335+ )
336+ .expand ([self .n_batch , 1 ])
337+ .to_event (2 ),
338+ )
339+ detection_hyp_prior_alpha = pyro .deterministic (
340+ "detection_hyp_prior_alpha" ,
341+ self .ones_n_batch_1 * self .detection_hyp_prior_alpha ,
332342 )
333- .expand ([self .n_batch , 1 ])
334- .to_event (2 ),
335- )
336- detection_hyp_prior_alpha = pyro .deterministic (
337- "detection_hyp_prior_alpha" ,
338- self .ones_n_batch_1 * self .detection_hyp_prior_alpha ,
339- )
340343
341- beta = (obs2sample @ detection_hyp_prior_alpha ) / (obs2sample @ detection_mean_y_e )
342- with obs_plate :
343- detection_y_s = pyro .sample (
344- "detection_y_s" ,
345- dist .Gamma (obs2sample @ detection_hyp_prior_alpha , beta ),
346- ) # (self.n_obs, 1)
344+ beta = (obs2sample @ detection_hyp_prior_alpha ) / (obs2sample @ detection_mean_y_e )
345+ with obs_plate :
346+ detection_y_s = pyro .sample (
347+ "detection_y_s" ,
348+ dist .Gamma (obs2sample @ detection_hyp_prior_alpha , beta ),
349+ ) # (self.n_obs, 1)
350+ else :
351+ # y_s with hierarchical mean prior
352+ detection_mean_y_e = pyro .sample (
353+ "detection_mean_y_e" ,
354+ dist .Beta (
355+ self .ones * self .detection_mean_hyp_prior_alpha ,
356+ self .ones * self .detection_mean_hyp_prior_beta ,
357+ )
358+ .expand ([self .n_batch , 1 ])
359+ .to_event (2 ),
360+ )
361+
362+ alpha = (obs2sample @ detection_mean_y_e ) * self .ones * self .detection_hyp_prior_alpha
363+ beta = (obs2sample @ (self .ones - detection_mean_y_e )) * self .ones * self .detection_hyp_prior_alpha
364+ with obs_plate :
365+ detection_y_s = pyro .sample (
366+ "detection_y_s" ,
367+ dist .Beta (alpha , beta ),
368+ ) # (self.n_obs, 1)
347369
348370 # =====================Gene-specific additive component ======================= #
349371 # per gene molecule contribution that cannot be explained by
0 commit comments