scdesigner 0.0.3__py3-none-any.whl → 0.0.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of scdesigner might be problematic. Click here for more details.
- scdesigner/estimators/__init__.py +8 -3
- scdesigner/estimators/gaussian_copula_factory.py +222 -7
- scdesigner/estimators/negbin.py +24 -0
- scdesigner/estimators/poisson.py +24 -0
- scdesigner/minimal/composite.py +2 -2
- scdesigner/minimal/copula.py +178 -6
- scdesigner/minimal/marginal.py +24 -19
- scdesigner/minimal/negbin.py +1 -1
- scdesigner/minimal/scd3.py +1 -0
- scdesigner/minimal/scd3_instances.py +5 -5
- scdesigner/minimal/standard_copula.py +383 -0
- scdesigner/minimal/transform.py +27 -30
- scdesigner/samplers/glm_factory.py +66 -4
- scdesigner/transform/nullify.py +1 -1
- {scdesigner-0.0.3.dist-info → scdesigner-0.0.4.dist-info}/METADATA +1 -1
- {scdesigner-0.0.3.dist-info → scdesigner-0.0.4.dist-info}/RECORD +17 -17
- scdesigner/minimal/standard_covariance.py +0 -124
- {scdesigner-0.0.3.dist-info → scdesigner-0.0.4.dist-info}/WHEEL +0 -0
|
@@ -6,14 +6,14 @@ scdesigner/data/sparse.py,sha256=lMp8gI8sq_fUTj3HiAmia0YiCdMRS1QGyyRePmuq3zY,138
|
|
|
6
6
|
scdesigner/diagnose/__init__.py,sha256=XRBlc0_ns9Tbwq-aMWMIv1c-tcTOgRFQBywBFV46Gt4,3579
|
|
7
7
|
scdesigner/diagnose/aic_bic.py,sha256=9GmtxdEXbbmCvL__pm7jSvQeeCb8KjwawY3UebahVBs,5022
|
|
8
8
|
scdesigner/diagnose/plot.py,sha256=JP1vLbZVnMs171aOBawKbbCUgGiwIfCGKWrQyNh7Y2s,7225
|
|
9
|
-
scdesigner/estimators/__init__.py,sha256=
|
|
9
|
+
scdesigner/estimators/__init__.py,sha256=TDkbc25TvXJp5O4_U2QipM8tmEoJ0HpNG53rlYthsBk,1221
|
|
10
10
|
scdesigner/estimators/bernoulli.py,sha256=vnIETFbHjXErgkKps4ImgeM5W6nta0c-8-ZetYpqK8g,3324
|
|
11
11
|
scdesigner/estimators/gaussian.py,sha256=-CKumYQWw8KbshdCmCdFgpcH5dNbqY-3vNTXCyjJbqc,4311
|
|
12
|
-
scdesigner/estimators/gaussian_copula_factory.py,sha256=
|
|
12
|
+
scdesigner/estimators/gaussian_copula_factory.py,sha256=yeIx_C2fN2jiotTkJstV4pjQYW4aO6RJ-jMuuXR2HVs,14054
|
|
13
13
|
scdesigner/estimators/glm_factory.py,sha256=tjVlEfJwBPK_Vk4G4P_eTYnBqeI8Y0r5_u_iSYB7qfA,2618
|
|
14
|
-
scdesigner/estimators/negbin.py,sha256=
|
|
14
|
+
scdesigner/estimators/negbin.py,sha256=4q_XZOZA8gYHXOOY5Mz17cexs-kzadqB9JlxqWnZ7VQ,5639
|
|
15
15
|
scdesigner/estimators/pnmf.py,sha256=-0WDbwh0uU4V-eyl_0uQ3qLZpT2IuEo9Pa-GEC6vJYI,4781
|
|
16
|
-
scdesigner/estimators/poisson.py,sha256
|
|
16
|
+
scdesigner/estimators/poisson.py,sha256=FMYtkip2NDYmmkyEuO_9hSuM6gtM-AZpPa9GwFrFfD8,4174
|
|
17
17
|
scdesigner/estimators/zero_inflated_negbin.py,sha256=OeMbXf20wzhJUmll2meMXBdLfeHGSya2hikmXNRUKI4,7959
|
|
18
18
|
scdesigner/estimators/zero_inflated_poisson.py,sha256=2lrD2H4QMBxhNbak3gDUHVxPBURLS16IyfN5eCEbq9Q,3364
|
|
19
19
|
scdesigner/format/__init__.py,sha256=PR12wZFvixIqHEd--d1oZkuj6o8tAQx-rgnpUKkr03I,179
|
|
@@ -21,20 +21,20 @@ scdesigner/format/format.py,sha256=WLsGnfeM52Mg3fhKHwPx0XbkYJSXfehu2_HmQfUpHdY,5
|
|
|
21
21
|
scdesigner/format/print.py,sha256=HK3yLQcFw-f5-nSxMy52bD8Mixw_xxAYV2W9K4_ULwg,794
|
|
22
22
|
scdesigner/minimal/__init__.py,sha256=IdMK1a2iiYyJ1gsWoupc2_3wyEu3Udjbm_iC0U724kM,378
|
|
23
23
|
scdesigner/minimal/bernoulli.py,sha256=KvkXiS5aOYIT_L_xymaAWd92ZJyRXZowTcOv_b1RsJo,2304
|
|
24
|
-
scdesigner/minimal/composite.py,sha256=
|
|
25
|
-
scdesigner/minimal/copula.py,sha256=
|
|
24
|
+
scdesigner/minimal/composite.py,sha256=lOafmycSpW5U7Yrmm_NgRJx8Y9GvkuS0BVf8IGFse9c,4536
|
|
25
|
+
scdesigner/minimal/copula.py,sha256=nNnK9Pxrp4-jlYWFY4NBt0hiUXGVHjMQMH5P5EhxLVw,8884
|
|
26
26
|
scdesigner/minimal/formula.py,sha256=VFTadNxn-2elBvCkD_yuyh9O-vDZFiitSqjJkZYJy3Y,879
|
|
27
27
|
scdesigner/minimal/gaussian.py,sha256=CKsluKk_XduYMNNUZTtENzH3wf4iTRGRc4L2nzq7qYw,2351
|
|
28
28
|
scdesigner/minimal/kwargs.py,sha256=a32BLKNBj7ont5fR_uUpppYwel55dpP3fqaPeVbmCKM,979
|
|
29
29
|
scdesigner/minimal/loader.py,sha256=gufdcWWKo7MyZQ5e7lzia96ZDKV5Pz8v0WwhZGQEeYM,5947
|
|
30
|
-
scdesigner/minimal/marginal.py,sha256=
|
|
31
|
-
scdesigner/minimal/negbin.py,sha256=
|
|
30
|
+
scdesigner/minimal/marginal.py,sha256=Z_6eqZ6G6ua2Rckf65N1_S7CGkmv22SGzNQmdwSJiPo,5561
|
|
31
|
+
scdesigner/minimal/negbin.py,sha256=NorV0CQ_wmKwTWuWd-Y1mE3gWYmVPHgmjp3pgI86bEI,2563
|
|
32
32
|
scdesigner/minimal/positive_nonnegative_matrix_factorization.py,sha256=oMIC1aqdH4Cgn2pU446lh2-H3axEe-FSC_ZNcgSBrdk,7445
|
|
33
|
-
scdesigner/minimal/scd3.py,sha256=
|
|
34
|
-
scdesigner/minimal/scd3_instances.py,sha256=
|
|
33
|
+
scdesigner/minimal/scd3.py,sha256=4EKi6Wonc0LRfWjLdvn8HMhbuR-c5kZbmVNLGbJd7mw,3083
|
|
34
|
+
scdesigner/minimal/scd3_instances.py,sha256=vbCbF_SbCqyCUdi_STwV2ufn9ouoEk14_D9g4Wc9O14,1969
|
|
35
35
|
scdesigner/minimal/simulator.py,sha256=DmeT_uXswR9larJ_OuysXUt32BqIVwxS-2yYMk9PGQw,631
|
|
36
|
-
scdesigner/minimal/
|
|
37
|
-
scdesigner/minimal/transform.py,sha256=
|
|
36
|
+
scdesigner/minimal/standard_copula.py,sha256=-P7JIVxF4XgP2ZMK6Z7FEyzfasKESx-tNDlJ9EdByOU,16478
|
|
37
|
+
scdesigner/minimal/transform.py,sha256=j2sj2vHpFi3YdK9sz4Npl05i8UPGBcDU3kT-n72u28s,5459
|
|
38
38
|
scdesigner/minimal/zero_inflated_negbin.py,sha256=npDoyAGWs9n5rl3HwvAUvDG9UDG3DlwRMUGwkpeqvlc,3179
|
|
39
39
|
scdesigner/predictors/__init__.py,sha256=3ycFB7ifR2y-27Kx2GhESyfcyZsJ-6ds6vxgzwrl6ss,462
|
|
40
40
|
scdesigner/predictors/bernoulli.py,sha256=ln7GpOTh7nxCVX0nvARPXw0E-l3SalDwur0iUEz-SWQ,261
|
|
@@ -46,7 +46,7 @@ scdesigner/predictors/zero_inflated_poisson.py,sha256=Krr4r-9vkh7SVy3d45v226NVUY
|
|
|
46
46
|
scdesigner/samplers/__init__.py,sha256=ns3tA_Q7jYIPgnYPfItvHCUpBV9fDimUg0dEHcNB7wE,775
|
|
47
47
|
scdesigner/samplers/bernoulli.py,sha256=1GLOU69_D2sxcedmxC2dIj1MQbmX5D8i0ccvyxjTcR8,791
|
|
48
48
|
scdesigner/samplers/gaussian.py,sha256=H8DwD4XzzALFguxB1uiwUsUURF_G1B6d2j4r0up-srU,943
|
|
49
|
-
scdesigner/samplers/glm_factory.py,sha256=
|
|
49
|
+
scdesigner/samplers/glm_factory.py,sha256=aQvFTgBKAk7kV-SnFJ61aSHQGwemxW9Hl4ZXBmwGJug,3607
|
|
50
50
|
scdesigner/samplers/negbin.py,sha256=d9oWIDxfXl_kNOPCjYUvtVie3uQmBN6yHfxHbrQiX-I,930
|
|
51
51
|
scdesigner/samplers/poisson.py,sha256=_TxotqGuVDFRXJOIiBGqRE_qJK0XkXn96clkCDCRV1A,789
|
|
52
52
|
scdesigner/samplers/zero_inflated_negbin.py,sha256=Z9kUSEQL8Z-lf48wWBLAuz74FcK7mjsKmeIzyBE9ov4,1287
|
|
@@ -58,9 +58,9 @@ scdesigner/simulators/pnmf_regression.py,sha256=B_fMK7Q9D4q31HT77384EKZEST7XXVNC
|
|
|
58
58
|
scdesigner/transform/__init__.py,sha256=cuLIP0_tocIA3dupO7npH2mLFpL1ApLZlLWPudzPt6M,236
|
|
59
59
|
scdesigner/transform/amplify.py,sha256=aNxpuyoDpXI4xK5FyCaGKqLqUh4SxFCZhwZeW8XonEQ,351
|
|
60
60
|
scdesigner/transform/mask.py,sha256=z-NQ6xcnEzCFWvlfCRhQOrE-TWvtAwQ6Cs8KBPahBSk,1032
|
|
61
|
-
scdesigner/transform/nullify.py,sha256=
|
|
61
|
+
scdesigner/transform/nullify.py,sha256=pEtYNDVT2Z_BmVc5CKl3CoxB37KOvqMReoQGnvFYMKE,792
|
|
62
62
|
scdesigner/transform/split.py,sha256=AK3mU52DHSagdyW-d79tsZ12zMKc5xMF_MockUUvciE,741
|
|
63
63
|
scdesigner/transform/substitute.py,sha256=pozV7IVJLyUzJVKeaSX86v0bl9foSFIAQpZ0oC18xak,326
|
|
64
|
-
scdesigner-0.0.
|
|
65
|
-
scdesigner-0.0.
|
|
66
|
-
scdesigner-0.0.
|
|
64
|
+
scdesigner-0.0.4.dist-info/METADATA,sha256=PCO4zfyrfvvMsgtZ26iYqEf3cyyFYY6e912X547Qk4g,766
|
|
65
|
+
scdesigner-0.0.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
66
|
+
scdesigner-0.0.4.dist-info/RECORD,,
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
from .copula import Copula
|
|
2
|
-
from .formula import standardize_formula
|
|
3
|
-
from .kwargs import DEFAULT_ALLOWED_KWARGS, _filter_kwargs
|
|
4
|
-
from anndata import AnnData
|
|
5
|
-
from scipy.stats import norm, multivariate_normal
|
|
6
|
-
from tqdm import tqdm
|
|
7
|
-
from typing import Dict, Union, Callable, Tuple
|
|
8
|
-
import numpy as np
|
|
9
|
-
import pandas as pd
|
|
10
|
-
import torch
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class StandardCovariance(Copula):
|
|
14
|
-
def __init__(self, formula: str = "~ 1"):
|
|
15
|
-
formula = standardize_formula(formula, allowed_keys=['group'])
|
|
16
|
-
super().__init__(formula)
|
|
17
|
-
self.groups = None
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def setup_data(self, adata: AnnData, marginal_formula: Dict[str, str], **kwargs):
|
|
21
|
-
data_kwargs = _filter_kwargs(kwargs, DEFAULT_ALLOWED_KWARGS['data'])
|
|
22
|
-
super().setup_data(adata, marginal_formula, **data_kwargs)
|
|
23
|
-
_, obs_batch = next(iter(self.loader))
|
|
24
|
-
obs_batch_group = obs_batch.get("group")
|
|
25
|
-
|
|
26
|
-
# fill in group indexing variables
|
|
27
|
-
self.groups = self.loader.dataset.predictor_names["group"]
|
|
28
|
-
self.n_groups = len(self.groups)
|
|
29
|
-
self.group_col = {g: i for i, g in enumerate(self.groups)}
|
|
30
|
-
|
|
31
|
-
# check that obs_batch is a binary grouping matrix
|
|
32
|
-
unique_vals = torch.unique(obs_batch_group)
|
|
33
|
-
if (not torch.all((unique_vals == 0) | (unique_vals == 1)).item()):
|
|
34
|
-
raise ValueError("Only categorical groups are currently supported in copula covariance estimation.")
|
|
35
|
-
|
|
36
|
-
def fit(self, uniformizer: Callable, **kwargs):
|
|
37
|
-
sums = {g: np.zeros(self.n_outcomes) for g in self.groups}
|
|
38
|
-
second_moments = {g: np.eye(self.n_outcomes) for g in self.groups}
|
|
39
|
-
Ng = {g: 0 for g in self.groups}
|
|
40
|
-
|
|
41
|
-
for y, x_dict in tqdm(self.loader, desc="Estimating copula covariance"):
|
|
42
|
-
memberships = x_dict.get("group").numpy()
|
|
43
|
-
u = uniformizer(y, x_dict)
|
|
44
|
-
|
|
45
|
-
for g in self.groups:
|
|
46
|
-
ix = np.where(memberships[:, self.group_col[g]] == 1)
|
|
47
|
-
z = norm().ppf(u[ix])
|
|
48
|
-
second_moments[g] += z.T @ z
|
|
49
|
-
sums[g] += z.sum(axis=0)
|
|
50
|
-
Ng[g] += len(ix[0])
|
|
51
|
-
|
|
52
|
-
covariances = {}
|
|
53
|
-
for g in self.groups:
|
|
54
|
-
mean = sums[g] / Ng[g]
|
|
55
|
-
covariances[g] = second_moments[g] / Ng[g] - np.outer(mean, mean)
|
|
56
|
-
|
|
57
|
-
if len(self.groups) == 1:
|
|
58
|
-
covariances = list(covariances.values())[0]
|
|
59
|
-
self.parameters = self.format_parameters(covariances)
|
|
60
|
-
|
|
61
|
-
def format_parameters(self, covariances: Union[Dict, np.array]):
|
|
62
|
-
var_names = self.adata.var_names
|
|
63
|
-
def to_df(mat):
|
|
64
|
-
return pd.DataFrame(mat, index=var_names, columns=var_names)
|
|
65
|
-
|
|
66
|
-
if isinstance(covariances, dict):
|
|
67
|
-
formatted = {}
|
|
68
|
-
for k, v in covariances.items():
|
|
69
|
-
formatted[k] = to_df(v)
|
|
70
|
-
covariances = formatted
|
|
71
|
-
return covariances
|
|
72
|
-
|
|
73
|
-
if isinstance(covariances, (np.ndarray, list, tuple)):
|
|
74
|
-
covariances = to_df(covariances)
|
|
75
|
-
return covariances
|
|
76
|
-
|
|
77
|
-
def pseudo_obs(self, x_dict: Dict):
|
|
78
|
-
# convert one-hot encoding memberships to a map
|
|
79
|
-
# {"group1": [indices of group 1], "group2": [indices of group 2]}
|
|
80
|
-
memberships = x_dict.get("group").numpy()
|
|
81
|
-
group_ix = {g: np.where(memberships[:, self.group_col[g] == 1])[0] for g in self.groups}
|
|
82
|
-
|
|
83
|
-
# initialize the result
|
|
84
|
-
u = np.zeros((len(memberships), self.n_outcomes))
|
|
85
|
-
parameters = self.parameters
|
|
86
|
-
if type(parameters) is not dict:
|
|
87
|
-
parameters = {group: parameters}
|
|
88
|
-
|
|
89
|
-
# loop over groups and sample each part in turn
|
|
90
|
-
for group, sigma in parameters.items():
|
|
91
|
-
z = np.random.multivariate_normal(
|
|
92
|
-
mean=np.zeros(self.n_outcomes),
|
|
93
|
-
cov=sigma,
|
|
94
|
-
size=len(group_ix[group])
|
|
95
|
-
)
|
|
96
|
-
normal_distn = norm(0, np.diag(sigma) ** 0.5)
|
|
97
|
-
u[group_ix[group]] = normal_distn.cdf(z)
|
|
98
|
-
return u
|
|
99
|
-
|
|
100
|
-
def likelihood(self, uniformizer: Callable, batch: Tuple[torch.Tensor, Dict[str, torch.Tensor]]):
|
|
101
|
-
# uniformize the observations
|
|
102
|
-
y, x_dict = batch
|
|
103
|
-
u = uniformizer(y, x_dict)
|
|
104
|
-
z = norm().ppf(u)
|
|
105
|
-
|
|
106
|
-
# same group manipulation as for pseudobs
|
|
107
|
-
parameters = self.parameters
|
|
108
|
-
if type(parameters) is not dict:
|
|
109
|
-
parameters = {group: parameters}
|
|
110
|
-
|
|
111
|
-
memberships = x_dict.get("group").numpy()
|
|
112
|
-
group_ix = {g: np.where(memberships[:, self.group_col[g] == 1])[0] for g in self.groups}
|
|
113
|
-
ll = np.zeros(len(z))
|
|
114
|
-
for group, sigma in parameters.items():
|
|
115
|
-
ix = group_ix[group]
|
|
116
|
-
if len(ix) > 0:
|
|
117
|
-
copula_ll = multivariate_normal.logpdf(z[ix], np.zeros(sigma.shape[0]), sigma)
|
|
118
|
-
ll[ix] = copula_ll - norm.logpdf(z[ix]).sum(axis=1)
|
|
119
|
-
return ll
|
|
120
|
-
|
|
121
|
-
def num_params(self, **kwargs):
|
|
122
|
-
S = self.parameters
|
|
123
|
-
per_group = [(np.sum(S[g].values != 0) - S[g].shape[0]) / 2 for g in self.groups]
|
|
124
|
-
return sum(per_group)
|
|
File without changes
|