|
a |
|
b/docs/inference.html |
|
|
1 |
<!doctype html> |
|
|
2 |
<html lang="en"> |
|
|
3 |
<head> |
|
|
4 |
<meta charset="utf-8"> |
|
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1"> |
|
|
6 |
<meta name="generator" content="pdoc3 0.11.1"> |
|
|
7 |
<title>VITAE.inference API documentation</title> |
|
|
8 |
<meta name="description" content=""> |
|
|
9 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/sanitize.min.css" integrity="sha512-y1dtMcuvtTMJc1yPgEqF0ZjQbhnc/bFhyvIyVNb9Zk5mIGtqVaAB1Ttl28su8AvFMOY0EwRbAe+HCLqj6W7/KA==" crossorigin> |
|
|
10 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/typography.min.css" integrity="sha512-Y1DYSb995BAfxobCkKepB1BqJJTPrOp3zPL74AWFugHHmmdcvO+C48WLrUOlhGMc0QG7AE3f7gmvvcrmX2fDoA==" crossorigin> |
|
|
11 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css" crossorigin> |
|
|
12 |
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:1.5em;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:2em 0 .50em 0}h3{font-size:1.4em;margin:1.6em 0 .7em 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .2s ease-in-out}a:visited{color:#503}a:hover{color:#b62}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900;font-weight:bold}pre code{font-size:.8em;line-height:1.4em;padding:1em;display:block}code{background:#f3f3f3;font-family:"DejaVu Sans Mono",monospace;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em 1em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> |
|
|
13 |
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul ul{padding-left:1em}.toc > ul > li{margin-top:.5em}}</style> |
|
|
14 |
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> |
|
|
15 |
<script type="text/x-mathjax-config">MathJax.Hub.Config({ tex2jax: { inlineMath: [ ['$','$'], ["\\(","\\)"] ], processEscapes: true } });</script> |
|
|
16 |
<script async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS_CHTML" integrity="sha256-kZafAc6mZvK3W3v1pHOcUix30OHQN6pU/NO2oFkqZVw=" crossorigin></script> |
|
|
17 |
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js" integrity="sha512-D9gUyxqja7hBtkWpPWGt9wfbfaMGVt9gnyCvYa+jojwwPHLCzUm5i8rpk7vD7wNee9bA35eYIjobYPaQuKS1MQ==" crossorigin></script> |
|
|
18 |
<script>window.addEventListener('DOMContentLoaded', () => { |
|
|
19 |
hljs.configure({languages: ['bash', 'css', 'diff', 'graphql', 'ini', 'javascript', 'json', 'plaintext', 'python', 'python-repl', 'rust', 'shell', 'sql', 'typescript', 'xml', 'yaml']}); |
|
|
20 |
hljs.highlightAll(); |
|
|
21 |
})</script> |
|
|
22 |
</head> |
|
|
23 |
<body> |
|
|
24 |
<main> |
|
|
25 |
<article id="content"> |
|
|
26 |
<header> |
|
|
27 |
<h1 class="title">Module <code>VITAE.inference</code></h1> |
|
|
28 |
</header> |
|
|
29 |
<section id="section-intro"> |
|
|
30 |
</section> |
|
|
31 |
<section> |
|
|
32 |
</section> |
|
|
33 |
<section> |
|
|
34 |
</section> |
|
|
35 |
<section> |
|
|
36 |
</section> |
|
|
37 |
<section> |
|
|
38 |
<h2 class="section-title" id="header-classes">Classes</h2> |
|
|
39 |
<dl> |
|
|
40 |
<dt id="VITAE.inference.Inferer"><code class="flex name class"> |
|
|
41 |
<span>class <span class="ident">Inferer</span></span> |
|
|
42 |
<span>(</span><span>n_states: int)</span> |
|
|
43 |
</code></dt> |
|
|
44 |
<dd> |
|
|
45 |
<div class="desc"><p>The class for doing inference based on posterior estimations.</p> |
|
|
46 |
<h2 id="parameters">Parameters</h2> |
|
|
47 |
<dl> |
|
|
48 |
<dt><strong><code>n_states</code></strong> : <code>int</code></dt> |
|
|
49 |
<dd>The number of vertices in the latent space.</dd> |
|
|
50 |
</dl></div> |
|
|
51 |
<details class="source"> |
|
|
52 |
<summary> |
|
|
53 |
<span>Expand source code</span> |
|
|
54 |
</summary> |
|
|
55 |
<pre><code class="python">class Inferer(object): |
|
|
56 |
''' |
|
|
57 |
The class for doing inference based on posterior estimations. |
|
|
58 |
''' |
|
|
59 |
|
|
|
60 |
def __init__(self, n_states: int): |
|
|
61 |
''' |
|
|
62 |
Parameters |
|
|
63 |
---------- |
|
|
64 |
n_states : int |
|
|
65 |
The number of vertices in the latent space. |
|
|
66 |
''' |
|
|
67 |
self.n_states = n_states |
|
|
68 |
self.n_categories = int(n_states*(n_states+1)/2) |
|
|
69 |
# self.A, self.B = np.nonzero(np.triu(np.ones(n_states))) |
|
|
70 |
## indicator of the catagories |
|
|
71 |
self.C = np.triu(np.ones(n_states)) |
|
|
72 |
self.C[self.C>0] = np.arange(self.n_categories) |
|
|
73 |
self.C = self.C.astype(int) |
|
|
74 |
|
|
|
75 |
def build_graphs(self, w_tilde, pc_x, method: str = 'mean', thres: float = 0.5, no_loop: bool = False, |
|
|
76 |
cutoff = 0): |
|
|
77 |
'''Build the backbone. |
|
|
78 |
|
|
|
79 |
Parameters |
|
|
80 |
---------- |
|
|
81 |
pc_x : np.array |
|
|
82 |
\([N, K]\) The estimated \(p(c_i|Y_i,X_i)\). |
|
|
83 |
method : string, optional |
|
|
84 |
'mean', 'modified_mean', 'map', or 'modified_map'. |
|
|
85 |
thres : float, optional |
|
|
86 |
The threshold used for filtering edges \(e_{ij}\) that \((n_{i}+n_{j}+e_{ij})/N<thres\), only applied to mean method. |
|
|
87 |
|
|
|
88 |
Retruns |
|
|
89 |
---------- |
|
|
90 |
G : nx.Graph |
|
|
91 |
The graph of edge scores. |
|
|
92 |
''' |
|
|
93 |
self.no_loop = no_loop |
|
|
94 |
# self.w_tilde = w_tilde |
|
|
95 |
|
|
|
96 |
graph = np.zeros((self.n_states,self.n_states)) |
|
|
97 |
if method=='mean': |
|
|
98 |
for i in range(self.n_states-1): |
|
|
99 |
for j in range(i+1,self.n_states): |
|
|
100 |
idx = np.sum(pc_x[:,self.C[[i,i,j],[i,j,j]]], axis=1)>=thres |
|
|
101 |
if np.sum(idx)>0: |
|
|
102 |
graph[i,j] = np.mean(pc_x[idx,self.C[i,j]]/np.sum(pc_x[idx][:,self.C[[i,i,j],[i,j,j]]], axis=-1)) |
|
|
103 |
elif method=='modified_mean': |
|
|
104 |
for i in range(self.n_states-1): |
|
|
105 |
for j in range(i+1,self.n_states): |
|
|
106 |
idx = np.sum(pc_x[:,self.C[[i,i,j],[i,j,j]]], axis=1)>=thres |
|
|
107 |
if np.sum(idx)>0: |
|
|
108 |
graph[i,j] = np.sum(pc_x[idx,self.C[i,j]])/np.sum(pc_x[idx][:,self.C[[i,i,j],[i,j,j]]]) |
|
|
109 |
elif method=='map': |
|
|
110 |
c = np.argmax(pc_x, axis=-1) |
|
|
111 |
for i in range(self.n_states-1): |
|
|
112 |
for j in range(i+1,self.n_states): |
|
|
113 |
if np.sum(c==self.C[i,j])>0: |
|
|
114 |
graph[i,j] = np.sum(c==self.C[i,j])/np.sum((c==self.C[i,j])|(c==self.C[i,i])|(c==self.C[j,j])) |
|
|
115 |
elif method=='modified_map': |
|
|
116 |
c = np.argmax(pc_x, axis=-1) |
|
|
117 |
for i in range(self.n_states-1): |
|
|
118 |
for j in range(i+1,self.n_states): |
|
|
119 |
graph[i,j] = np.sum(c==self.C[i,j])/(np.sum((w_tilde[:,i]>0.5)|(w_tilde[:,j]>0.5))+1e-16) |
|
|
120 |
elif method=='raw_map': |
|
|
121 |
c = np.argmax(pc_x, axis=-1) |
|
|
122 |
for i in range(self.n_states-1): |
|
|
123 |
for j in range(i+1,self.n_states): |
|
|
124 |
if np.sum(c==self.C[i,j])>0: |
|
|
125 |
graph[i,j] = np.sum(c==self.C[i,j])/np.sum(np.isin(c, np.diagonal(self.C)) == False) |
|
|
126 |
elif method == "w_base": |
|
|
127 |
for i in range(self.n_states): |
|
|
128 |
for j in range(i+1,self.n_states): |
|
|
129 |
two_vertice_max_w = w_tilde[(np.argmax(w_tilde, axis=1) == i) | (np.argmax(w_tilde, axis=1) == j),:] |
|
|
130 |
num_two_vertice = two_vertice_max_w.shape[0] |
|
|
131 |
if num_two_vertice > 0: |
|
|
132 |
graph[i, j] = np.sum( |
|
|
133 |
np.abs(two_vertice_max_w[:, i] - two_vertice_max_w[:, j]) < 0.1) / num_two_vertice |
|
|
134 |
elif method == "modified_w_base": |
|
|
135 |
top2_idx = np.argpartition(w_tilde, -2, axis=1)[:, -2:] |
|
|
136 |
for i in range(self.n_states): |
|
|
137 |
for j in range(i + 1, self.n_states): |
|
|
138 |
two_vertice_max_w = np.all(top2_idx == [i, j], axis=1) | np.all(top2_idx == [j, i], axis=1) |
|
|
139 |
two_vertice_max_w = w_tilde[two_vertice_max_w, :] |
|
|
140 |
vertice_count = w_tilde[(np.argmax(w_tilde, axis=1) == i) | (np.argmax(w_tilde, axis=1) == j), :] |
|
|
141 |
vertice_count = vertice_count.shape[0] |
|
|
142 |
if vertice_count > 0: |
|
|
143 |
edge_count = \ |
|
|
144 |
np.max((two_vertice_max_w[:, i], two_vertice_max_w[:, j]), axis=0) \ |
|
|
145 |
/ (two_vertice_max_w[:, i] + two_vertice_max_w[:, j]) |
|
|
146 |
edge_count = np.sum(edge_count < 0.55) |
|
|
147 |
graph[i, j] = edge_count / vertice_count |
|
|
148 |
else: |
|
|
149 |
raise ValueError("Invalid method, must be one of 'mean', 'modified_mean', 'map', 'modified_map','raw_map','w_base', and 'modified_w_base'.") |
|
|
150 |
|
|
|
151 |
graph[graph<=cutoff] = 0 |
|
|
152 |
G = nx.from_numpy_array(graph) |
|
|
153 |
|
|
|
154 |
if self.no_loop and not nx.is_tree(G): |
|
|
155 |
# prune if there are no loops |
|
|
156 |
G = nx.maximum_spanning_tree(G) |
|
|
157 |
|
|
|
158 |
return G |
|
|
159 |
|
|
|
160 |
def modify_wtilde(self, w_tilde, edges): |
|
|
161 |
'''Project \(\\tilde{w}\) to the estimated backbone. |
|
|
162 |
|
|
|
163 |
Parameters |
|
|
164 |
---------- |
|
|
165 |
w_tilde : np.array |
|
|
166 |
\([N, k]\) The estimated \(\\tilde{w}\). |
|
|
167 |
edges : np.array |
|
|
168 |
\([|\\mathcal{E}(\\widehat{\\mathcal{B}})|, 2]\). |
|
|
169 |
|
|
|
170 |
Retruns |
|
|
171 |
---------- |
|
|
172 |
w : np.array |
|
|
173 |
The projected \(\\tilde{w}\). |
|
|
174 |
''' |
|
|
175 |
w = np.zeros_like(w_tilde) |
|
|
176 |
|
|
|
177 |
# projection on nodes |
|
|
178 |
best_proj_err_node = np.sum(w_tilde**2, axis=-1) - 2*np.max(w_tilde, axis=-1) +1 |
|
|
179 |
best_proj_err_node_ind = np.argmax(w_tilde, axis=-1) |
|
|
180 |
|
|
|
181 |
if len(edges)>0: |
|
|
182 |
# projection on edges |
|
|
183 |
idc = np.tile(np.arange(w.shape[0]), (2,1)).T |
|
|
184 |
ide = edges[np.argmax(np.sum(w_tilde[:,edges], axis=-1)**2 - |
|
|
185 |
4 * np.prod(w_tilde[:,edges], axis=-1) + |
|
|
186 |
2 * np.sum(w_tilde[:,edges], axis=-1), axis=-1)] |
|
|
187 |
w[idc, ide] = w_tilde[idc, ide] + (1-np.sum(w_tilde[idc, ide], axis=-1, keepdims=True))/2 |
|
|
188 |
best_proj_err_edge = np.sum(w_tilde**2, axis=-1) - np.sum(w_tilde[idc, ide]**2, axis=-1) + (1-np.sum(w_tilde[idc, ide], axis=-1))**2/2 |
|
|
189 |
|
|
|
190 |
idc = (best_proj_err_node<best_proj_err_edge) |
|
|
191 |
w[idc,:] = np.eye(w_tilde.shape[-1])[best_proj_err_node_ind[idc]] |
|
|
192 |
else: |
|
|
193 |
idc = np.arange(w.shape[0]) |
|
|
194 |
w[idc, best_proj_err_node_ind] = 1 |
|
|
195 |
return w |
|
|
196 |
|
|
|
197 |
|
|
|
198 |
def build_milestone_net(self, subgraph, init_node: int): |
|
|
199 |
'''Build the milestone network. |
|
|
200 |
|
|
|
201 |
Parameters |
|
|
202 |
---------- |
|
|
203 |
subgraph : nx.Graph |
|
|
204 |
The connected component of the backbone given the root vertex. |
|
|
205 |
init_node : int |
|
|
206 |
The root vertex. |
|
|
207 |
|
|
|
208 |
Returns |
|
|
209 |
---------- |
|
|
210 |
df_subgraph : pd.DataFrame |
|
|
211 |
The milestone network. |
|
|
212 |
''' |
|
|
213 |
if len(subgraph)==1: |
|
|
214 |
warnings.warn('Singular node.') |
|
|
215 |
return [] |
|
|
216 |
elif nx.is_directed_acyclic_graph(subgraph): |
|
|
217 |
milestone_net = [] |
|
|
218 |
for edge in list(subgraph.edges): |
|
|
219 |
if edge[0]==init_node: |
|
|
220 |
dist = 1 |
|
|
221 |
elif edge[1]==init_node: |
|
|
222 |
paths_0 = nx.all_simple_paths(subgraph, source=init_node, target=edge[0]) |
|
|
223 |
dist = - (np.max([len(p) for p in paths_1]) - 1) |
|
|
224 |
else: |
|
|
225 |
paths_0 = nx.all_simple_paths(subgraph, source=init_node, target=edge[0]) |
|
|
226 |
paths_1 = nx.all_simple_paths(subgraph, source=init_node, target=edge[1]) |
|
|
227 |
dist = np.max([len(p) for p in paths_1]) - np.max([len(p) for p in paths_0]) |
|
|
228 |
milestone_net.append([edge[0], edge[1], dist]) |
|
|
229 |
else: |
|
|
230 |
# Dijkstra's Algorithm to find the shortest path |
|
|
231 |
unvisited = {node: {'parent':None, |
|
|
232 |
'score':np.inf, |
|
|
233 |
'distance':np.inf} for node in subgraph.nodes} |
|
|
234 |
current = init_node |
|
|
235 |
currentScore = 0 |
|
|
236 |
currentDistance = 0 |
|
|
237 |
unvisited[current]['score'] = currentScore |
|
|
238 |
|
|
|
239 |
milestone_net = [] |
|
|
240 |
while True: |
|
|
241 |
for neighbour in subgraph.neighbors(current): |
|
|
242 |
if neighbour not in unvisited: continue |
|
|
243 |
newScore = currentScore + subgraph[current][neighbour]['weight'] |
|
|
244 |
if unvisited[neighbour]['score'] > newScore: |
|
|
245 |
unvisited[neighbour]['score'] = newScore |
|
|
246 |
unvisited[neighbour]['parent'] = current |
|
|
247 |
unvisited[neighbour]['distance'] = currentDistance+1 |
|
|
248 |
|
|
|
249 |
if len(unvisited)<len(subgraph): |
|
|
250 |
milestone_net.append([unvisited[current]['parent'], |
|
|
251 |
current, |
|
|
252 |
unvisited[current]['distance']]) |
|
|
253 |
del unvisited[current] |
|
|
254 |
if not unvisited: break |
|
|
255 |
current, currentScore, currentDistance = \ |
|
|
256 |
sorted([(i[0],i[1]['score'],i[1]['distance']) for i in unvisited.items()], |
|
|
257 |
key = lambda x: x[1])[0] |
|
|
258 |
return np.array(milestone_net) |
|
|
259 |
|
|
|
260 |
|
|
|
261 |
def comp_pseudotime(self, milestone_net, init_node: int, w): |
|
|
262 |
'''Compute pseudotime. |
|
|
263 |
|
|
|
264 |
Parameters |
|
|
265 |
---------- |
|
|
266 |
milestone_net : pd.DataFrame |
|
|
267 |
The milestone network. |
|
|
268 |
init_node : int |
|
|
269 |
The root vertex. |
|
|
270 |
w : np.array |
|
|
271 |
\([N, k]\) The projected \(\\tilde{w}\). |
|
|
272 |
|
|
|
273 |
Returns |
|
|
274 |
---------- |
|
|
275 |
pseudotime : np.array |
|
|
276 |
\([N, k]\) The estimated pseudtotime. |
|
|
277 |
''' |
|
|
278 |
pseudotime = np.empty(w.shape[0]) |
|
|
279 |
pseudotime.fill(np.nan) |
|
|
280 |
pseudotime[w[:,init_node]==1] = 0 |
|
|
281 |
|
|
|
282 |
if len(milestone_net)>0: |
|
|
283 |
for i in range(len(milestone_net)): |
|
|
284 |
_from, _to = milestone_net[i,:2] |
|
|
285 |
_from, _to = int(_from), int(_to) |
|
|
286 |
|
|
|
287 |
idc = ((w[:,_from]>0)&(w[:,_to]>0)) | (w[:,_to]==1) |
|
|
288 |
pseudotime[idc] = w[idc,_to] + milestone_net[i,-1] - 1 |
|
|
289 |
|
|
|
290 |
return pseudotime</code></pre> |
|
|
291 |
</details> |
|
|
292 |
<h3>Methods</h3> |
|
|
293 |
<dl> |
|
|
294 |
<dt id="VITAE.inference.Inferer.build_graphs"><code class="name flex"> |
|
|
295 |
<span>def <span class="ident">build_graphs</span></span>(<span>self, w_tilde, pc_x, method: str = 'mean', thres: float = 0.5, no_loop: bool = False, cutoff=0)</span> |
|
|
296 |
</code></dt> |
|
|
297 |
<dd> |
|
|
298 |
<div class="desc"><p>Build the backbone.</p> |
|
|
299 |
<h2 id="parameters">Parameters</h2> |
|
|
300 |
<dl> |
|
|
301 |
<dt><strong><code>pc_x</code></strong> : <code>np.array</code></dt> |
|
|
302 |
<dd><span><span class="MathJax_Preview">[N, K]</span><script type="math/tex">[N, K]</script></span> The estimated <span><span class="MathJax_Preview">p(c_i|Y_i,X_i)</span><script type="math/tex">p(c_i|Y_i,X_i)</script></span>.</dd> |
|
|
303 |
<dt><strong><code>method</code></strong> : <code>string</code>, optional</dt> |
|
|
304 |
<dd>'mean', 'modified_mean', 'map', or 'modified_map'.</dd> |
|
|
305 |
<dt><strong><code>thres</code></strong> : <code>float</code>, optional</dt> |
|
|
306 |
<dd>The threshold used for filtering edges <span><span class="MathJax_Preview">e_{ij}</span><script type="math/tex">e_{ij}</script></span> that <span><span class="MathJax_Preview">(n_{i}+n_{j}+e_{ij})/N<thres</span><script type="math/tex">(n_{i}+n_{j}+e_{ij})/N<thres</script></span>, only applied to mean method.</dd> |
|
|
307 |
</dl> |
|
|
308 |
<h2 id="retruns">Retruns</h2> |
|
|
309 |
<p>G : nx.Graph |
|
|
310 |
The graph of edge scores.</p></div> |
|
|
311 |
</dd> |
|
|
312 |
<dt id="VITAE.inference.Inferer.modify_wtilde"><code class="name flex"> |
|
|
313 |
<span>def <span class="ident">modify_wtilde</span></span>(<span>self, w_tilde, edges)</span> |
|
|
314 |
</code></dt> |
|
|
315 |
<dd> |
|
|
316 |
<div class="desc"><p>Project <span><span class="MathJax_Preview">\tilde{w}</span><script type="math/tex">\tilde{w}</script></span> to the estimated backbone.</p> |
|
|
317 |
<h2 id="parameters">Parameters</h2> |
|
|
318 |
<dl> |
|
|
319 |
<dt><strong><code>w_tilde</code></strong> : <code>np.array</code></dt> |
|
|
320 |
<dd><span><span class="MathJax_Preview">[N, k]</span><script type="math/tex">[N, k]</script></span> The estimated <span><span class="MathJax_Preview">\tilde{w}</span><script type="math/tex">\tilde{w}</script></span>.</dd> |
|
|
321 |
<dt><strong><code>edges</code></strong> : <code>np.array</code></dt> |
|
|
322 |
<dd><span><span class="MathJax_Preview">[|\mathcal{E}(\widehat{\mathcal{B}})|, 2]</span><script type="math/tex">[|\mathcal{E}(\widehat{\mathcal{B}})|, 2]</script></span>.</dd> |
|
|
323 |
</dl> |
|
|
324 |
<h2 id="retruns">Retruns</h2> |
|
|
325 |
<p>w : np.array |
|
|
326 |
The projected <span><span class="MathJax_Preview">\tilde{w}</span><script type="math/tex">\tilde{w}</script></span>.</p></div> |
|
|
327 |
</dd> |
|
|
328 |
<dt id="VITAE.inference.Inferer.build_milestone_net"><code class="name flex"> |
|
|
329 |
<span>def <span class="ident">build_milestone_net</span></span>(<span>self, subgraph, init_node: int)</span> |
|
|
330 |
</code></dt> |
|
|
331 |
<dd> |
|
|
332 |
<div class="desc"><p>Build the milestone network.</p> |
|
|
333 |
<h2 id="parameters">Parameters</h2> |
|
|
334 |
<dl> |
|
|
335 |
<dt><strong><code>subgraph</code></strong> : <code>nx.Graph</code></dt> |
|
|
336 |
<dd>The connected component of the backbone given the root vertex.</dd> |
|
|
337 |
<dt><strong><code>init_node</code></strong> : <code>int</code></dt> |
|
|
338 |
<dd>The root vertex.</dd> |
|
|
339 |
</dl> |
|
|
340 |
<h2 id="returns">Returns</h2> |
|
|
341 |
<dl> |
|
|
342 |
<dt><strong><code>df_subgraph</code></strong> : <code>pd.DataFrame </code></dt> |
|
|
343 |
<dd>The milestone network.</dd> |
|
|
344 |
</dl></div> |
|
|
345 |
</dd> |
|
|
346 |
<dt id="VITAE.inference.Inferer.comp_pseudotime"><code class="name flex"> |
|
|
347 |
<span>def <span class="ident">comp_pseudotime</span></span>(<span>self, milestone_net, init_node: int, w)</span> |
|
|
348 |
</code></dt> |
|
|
349 |
<dd> |
|
|
350 |
<div class="desc"><p>Compute pseudotime.</p> |
|
|
351 |
<h2 id="parameters">Parameters</h2> |
|
|
352 |
<dl> |
|
|
353 |
<dt><strong><code>milestone_net</code></strong> : <code>pd.DataFrame</code></dt> |
|
|
354 |
<dd>The milestone network.</dd> |
|
|
355 |
<dt><strong><code>init_node</code></strong> : <code>int</code></dt> |
|
|
356 |
<dd>The root vertex.</dd> |
|
|
357 |
<dt><strong><code>w</code></strong> : <code>np.array</code></dt> |
|
|
358 |
<dd><span><span class="MathJax_Preview">[N, k]</span><script type="math/tex">[N, k]</script></span> The projected <span><span class="MathJax_Preview">\tilde{w}</span><script type="math/tex">\tilde{w}</script></span>.</dd> |
|
|
359 |
</dl> |
|
|
360 |
<h2 id="returns">Returns</h2> |
|
|
361 |
<dl> |
|
|
362 |
<dt><strong><code>pseudotime</code></strong> : <code>np.array</code></dt> |
|
|
363 |
<dd><span><span class="MathJax_Preview">[N, k]</span><script type="math/tex">[N, k]</script></span> The estimated pseudtotime.</dd> |
|
|
364 |
</dl></div> |
|
|
365 |
</dd> |
|
|
366 |
</dl> |
|
|
367 |
</dd> |
|
|
368 |
</dl> |
|
|
369 |
</section> |
|
|
370 |
</article> |
|
|
371 |
<nav id="sidebar"> |
|
|
372 |
<div class="toc"> |
|
|
373 |
<ul></ul> |
|
|
374 |
</div> |
|
|
375 |
<ul id="index"> |
|
|
376 |
<li><h3>Super-module</h3> |
|
|
377 |
<ul> |
|
|
378 |
<li><code><a title="VITAE" href="index.html">VITAE</a></code></li> |
|
|
379 |
</ul> |
|
|
380 |
</li> |
|
|
381 |
<li><h3><a href="#header-classes">Classes</a></h3> |
|
|
382 |
<ul> |
|
|
383 |
<li> |
|
|
384 |
<h4><code><a title="VITAE.inference.Inferer" href="#VITAE.inference.Inferer">Inferer</a></code></h4> |
|
|
385 |
<ul class=""> |
|
|
386 |
<li><code><a title="VITAE.inference.Inferer.build_graphs" href="#VITAE.inference.Inferer.build_graphs">build_graphs</a></code></li> |
|
|
387 |
<li><code><a title="VITAE.inference.Inferer.modify_wtilde" href="#VITAE.inference.Inferer.modify_wtilde">modify_wtilde</a></code></li> |
|
|
388 |
<li><code><a title="VITAE.inference.Inferer.build_milestone_net" href="#VITAE.inference.Inferer.build_milestone_net">build_milestone_net</a></code></li> |
|
|
389 |
<li><code><a title="VITAE.inference.Inferer.comp_pseudotime" href="#VITAE.inference.Inferer.comp_pseudotime">comp_pseudotime</a></code></li> |
|
|
390 |
</ul> |
|
|
391 |
</li> |
|
|
392 |
</ul> |
|
|
393 |
</li> |
|
|
394 |
</ul> |
|
|
395 |
</nav> |
|
|
396 |
</main> |
|
|
397 |
<footer id="footer"> |
|
|
398 |
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.11.1</a>.</p> |
|
|
399 |
</footer> |
|
|
400 |
</body> |
|
|
401 |
</html> |