|
a |
|
b/docs/utils.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.utils 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.utils</code></h1> |
|
|
28 |
</header> |
|
|
29 |
<section id="section-intro"> |
|
|
30 |
</section> |
|
|
31 |
<section> |
|
|
32 |
</section> |
|
|
33 |
<section> |
|
|
34 |
</section> |
|
|
35 |
<section> |
|
|
36 |
<h2 class="section-title" id="header-functions">Functions</h2> |
|
|
37 |
<dl> |
|
|
38 |
<dt id="VITAE.utils.reset_random_seeds"><code class="name flex"> |
|
|
39 |
<span>def <span class="ident">reset_random_seeds</span></span>(<span>seed)</span> |
|
|
40 |
</code></dt> |
|
|
41 |
<dd> |
|
|
42 |
<div class="desc"></div> |
|
|
43 |
</dd> |
|
|
44 |
<dt id="VITAE.utils.get_embedding"><code class="name flex"> |
|
|
45 |
<span>def <span class="ident">get_embedding</span></span>(<span>z, dimred='umap', **kwargs)</span> |
|
|
46 |
</code></dt> |
|
|
47 |
<dd> |
|
|
48 |
<div class="desc"><p>Get low-dimensional embeddings for visualizations.</p> |
|
|
49 |
<h2 id="parameters">Parameters</h2> |
|
|
50 |
<dl> |
|
|
51 |
<dt><strong><code>z</code></strong> : <code>np.array</code></dt> |
|
|
52 |
<dd><span><span class="MathJax_Preview">[N, d]</span><script type="math/tex">[N, d]</script></span> The latent variables.</dd> |
|
|
53 |
<dt><strong><code>dimred</code></strong> : <code>str</code>, optional</dt> |
|
|
54 |
<dd>'pca', 'tsne', or umap'.</dd> |
|
|
55 |
<dt><strong><code>**kwargs</code></strong> : <code> </code></dt> |
|
|
56 |
<dd>Extra key-value arguments for dimension reduction algorithms.</dd> |
|
|
57 |
</dl> |
|
|
58 |
<h2 id="returns">Returns:</h2> |
|
|
59 |
<p>embed : np.array |
|
|
60 |
<span><span class="MathJax_Preview">[N, 2]</span><script type="math/tex">[N, 2]</script></span> The latent variables after dimension reduction.</p></div> |
|
|
61 |
</dd> |
|
|
62 |
<dt id="VITAE.utils.get_igraph"><code class="name flex"> |
|
|
63 |
<span>def <span class="ident">get_igraph</span></span>(<span>z, random_state=0)</span> |
|
|
64 |
</code></dt> |
|
|
65 |
<dd> |
|
|
66 |
<div class="desc"><p>Get igraph for running Leidenalg clustering.</p> |
|
|
67 |
<h2 id="parameters">Parameters</h2> |
|
|
68 |
<dl> |
|
|
69 |
<dt><strong><code>z</code></strong> : <code>np.array</code></dt> |
|
|
70 |
<dd><span><span class="MathJax_Preview">[N, d]</span><script type="math/tex">[N, d]</script></span> The latent variables.</dd> |
|
|
71 |
<dt><strong><code>random_state</code></strong> : <code>int</code>, optional</dt> |
|
|
72 |
<dd>The random state.</dd> |
|
|
73 |
</dl> |
|
|
74 |
<h2 id="returns">Returns:</h2> |
|
|
75 |
<p>g : igraph |
|
|
76 |
The igraph object of connectivities.</p></div> |
|
|
77 |
</dd> |
|
|
78 |
<dt id="VITAE.utils.leidenalg_igraph"><code class="name flex"> |
|
|
79 |
<span>def <span class="ident">leidenalg_igraph</span></span>(<span>g, res, random_state=0)</span> |
|
|
80 |
</code></dt> |
|
|
81 |
<dd> |
|
|
82 |
<div class="desc"><p>Leidenalg clustering on an igraph object.</p> |
|
|
83 |
<h2 id="parameters">Parameters</h2> |
|
|
84 |
<dl> |
|
|
85 |
<dt><strong><code>g</code></strong> : <code>igraph</code></dt> |
|
|
86 |
<dd>The igraph object of connectivities.</dd> |
|
|
87 |
<dt><strong><code>res</code></strong> : <code>float</code></dt> |
|
|
88 |
<dd>The resolution parameter for Leidenalg clustering.</dd> |
|
|
89 |
<dt><strong><code>random_state</code></strong> : <code>int</code>, optional</dt> |
|
|
90 |
<dd>The random state.</dd> |
|
|
91 |
</dl> |
|
|
92 |
<h2 id="returns">Returns</h2> |
|
|
93 |
<dl> |
|
|
94 |
<dt><strong><code>labels</code></strong> : <code>np.array |
|
|
95 |
</code></dt> |
|
|
96 |
<dd><span><span class="MathJax_Preview">[N, ]</span><script type="math/tex">[N, ]</script></span> The clustered labels.</dd> |
|
|
97 |
</dl></div> |
|
|
98 |
</dd> |
|
|
99 |
<dt id="VITAE.utils.plot_clusters"><code class="name flex"> |
|
|
100 |
<span>def <span class="ident">plot_clusters</span></span>(<span>embed_z, labels, plot_labels=False, path=None)</span> |
|
|
101 |
</code></dt> |
|
|
102 |
<dd> |
|
|
103 |
<div class="desc"><p>Plot the clustering results.</p> |
|
|
104 |
<h2 id="parameters">Parameters</h2> |
|
|
105 |
<dl> |
|
|
106 |
<dt><strong><code>embed_z</code></strong> : <code>np.array</code></dt> |
|
|
107 |
<dd><span><span class="MathJax_Preview">[N, 2]</span><script type="math/tex">[N, 2]</script></span> The latent variables after dimension reduction.</dd> |
|
|
108 |
<dt><strong><code>labels</code></strong> : <code>np.array |
|
|
109 |
</code></dt> |
|
|
110 |
<dd><span><span class="MathJax_Preview">[N, ]</span><script type="math/tex">[N, ]</script></span> The clustered labels.</dd> |
|
|
111 |
<dt><strong><code>plot_labels</code></strong> : <code>boolean</code>, optional</dt> |
|
|
112 |
<dd>Whether to plot text of labels or not.</dd> |
|
|
113 |
<dt><strong><code>path</code></strong> : <code>str</code>, optional</dt> |
|
|
114 |
<dd>The path to save the figure.</dd> |
|
|
115 |
</dl></div> |
|
|
116 |
</dd> |
|
|
117 |
<dt id="VITAE.utils.plot_marker_gene"><code class="name flex"> |
|
|
118 |
<span>def <span class="ident">plot_marker_gene</span></span>(<span>expression, gene_name: str, embed_z, path=None)</span> |
|
|
119 |
</code></dt> |
|
|
120 |
<dd> |
|
|
121 |
<div class="desc"><p>Plot the marker gene.</p> |
|
|
122 |
<h2 id="parameters">Parameters</h2> |
|
|
123 |
<dl> |
|
|
124 |
<dt><strong><code>expression</code></strong> : <code>np.array</code></dt> |
|
|
125 |
<dd><span><span class="MathJax_Preview">[N, ]</span><script type="math/tex">[N, ]</script></span> The expression of the marker gene.</dd> |
|
|
126 |
<dt><strong><code>gene_name</code></strong> : <code>str</code></dt> |
|
|
127 |
<dd>The name of the marker gene.</dd> |
|
|
128 |
<dt><strong><code>embed_z</code></strong> : <code>np.array</code></dt> |
|
|
129 |
<dd><span><span class="MathJax_Preview">[N, 2]</span><script type="math/tex">[N, 2]</script></span> The latent variables after dimension reduction.</dd> |
|
|
130 |
<dt><strong><code>path</code></strong> : <code>str</code>, optional</dt> |
|
|
131 |
<dd>The path to save the figure.</dd> |
|
|
132 |
</dl></div> |
|
|
133 |
</dd> |
|
|
134 |
<dt id="VITAE.utils.plot_uncertainty"><code class="name flex"> |
|
|
135 |
<span>def <span class="ident">plot_uncertainty</span></span>(<span>uncertainty, embed_z, path=None)</span> |
|
|
136 |
</code></dt> |
|
|
137 |
<dd> |
|
|
138 |
<div class="desc"><p>Plot the uncertainty for all selected cells.</p> |
|
|
139 |
<h2 id="parameters">Parameters</h2> |
|
|
140 |
<dl> |
|
|
141 |
<dt><strong><code>uncertainty</code></strong> : <code>np.array</code></dt> |
|
|
142 |
<dd><span><span class="MathJax_Preview">[N, ]</span><script type="math/tex">[N, ]</script></span> The uncertainty of the all cells.</dd> |
|
|
143 |
<dt><strong><code>embed_z</code></strong> : <code>np.array</code></dt> |
|
|
144 |
<dd><span><span class="MathJax_Preview">[N, 2]</span><script type="math/tex">[N, 2]</script></span> The latent variables after dimension reduction.</dd> |
|
|
145 |
<dt><strong><code>path</code></strong> : <code>str</code>, optional</dt> |
|
|
146 |
<dd>The path to save the figure.</dd> |
|
|
147 |
</dl></div> |
|
|
148 |
</dd> |
|
|
149 |
<dt id="VITAE.utils.DE_test"><code class="name flex"> |
|
|
150 |
<span>def <span class="ident">DE_test</span></span>(<span>Y, X, gene_names, i_test, alpha: float = 0.05)</span> |
|
|
151 |
</code></dt> |
|
|
152 |
<dd> |
|
|
153 |
<div class="desc"><p>Differential gene expression test.</p> |
|
|
154 |
<h2 id="parameters">Parameters</h2> |
|
|
155 |
<dl> |
|
|
156 |
<dt><strong><code>Y</code></strong> : <code>numpy.array</code></dt> |
|
|
157 |
<dd><span><span class="MathJax_Preview">n,</span><script type="math/tex">n,</script></span> the expression matrix.</dd> |
|
|
158 |
<dt><strong><code>X</code></strong> : <code>numpy.array</code></dt> |
|
|
159 |
<dd><span><span class="MathJax_Preview">n,1+1+s</span><script type="math/tex">n,1+1+s</script></span> the constant term, the pseudotime and the covariates.</dd> |
|
|
160 |
<dt><strong><code>gene_names</code></strong> : <code>numpy.array</code></dt> |
|
|
161 |
<dd><span><span class="MathJax_Preview">n,</span><script type="math/tex">n,</script></span> the names of all genes.</dd> |
|
|
162 |
<dt><strong><code>i_test</code></strong> : <code>numpy.array</code></dt> |
|
|
163 |
<dd>The indices of covariates to be tested.</dd> |
|
|
164 |
<dt><strong><code>alpha</code></strong> : <code>float</code>, optional</dt> |
|
|
165 |
<dd>The cutoff of p-values.</dd> |
|
|
166 |
</dl> |
|
|
167 |
<h2 id="returns">Returns</h2> |
|
|
168 |
<dl> |
|
|
169 |
<dt><strong><code>res_df</code></strong> : <code>pandas.DataFrame</code></dt> |
|
|
170 |
<dd>The test results of expressed genes with two columns, |
|
|
171 |
the estimated coefficients and the adjusted p-values.</dd> |
|
|
172 |
</dl></div> |
|
|
173 |
</dd> |
|
|
174 |
<dt id="VITAE.utils.load_data"><code class="name flex"> |
|
|
175 |
<span>def <span class="ident">load_data</span></span>(<span>path, file_name, return_dict=False)</span> |
|
|
176 |
</code></dt> |
|
|
177 |
<dd> |
|
|
178 |
<div class="desc"><p>Load h5df data.</p> |
|
|
179 |
<h2 id="parameters">Parameters</h2> |
|
|
180 |
<dl> |
|
|
181 |
<dt><strong><code>path</code></strong> : <code>str</code></dt> |
|
|
182 |
<dd>The path of the h5 files.</dd> |
|
|
183 |
<dt><strong><code>file_name</code></strong> : <code>str</code></dt> |
|
|
184 |
<dd>The dataset name.</dd> |
|
|
185 |
<dt><strong><code>return_dict</code></strong> : <code>boolean</code>, optional</dt> |
|
|
186 |
<dd>Whether to return the dict of the dataset or not.</dd> |
|
|
187 |
</dl> |
|
|
188 |
<h2 id="returns">Returns:</h2> |
|
|
189 |
<p>data : dict |
|
|
190 |
The dict containing count, grouping, etc. of the dataset. |
|
|
191 |
dd : anndata.AnnData |
|
|
192 |
The AnnData object of the dataset.</p></div> |
|
|
193 |
</dd> |
|
|
194 |
<dt id="VITAE.utils.compute_kernel"><code class="name flex"> |
|
|
195 |
<span>def <span class="ident">compute_kernel</span></span>(<span>x, y, kernel='rbf', **kwargs)</span> |
|
|
196 |
</code></dt> |
|
|
197 |
<dd> |
|
|
198 |
<div class="desc"><p>Computes RBF kernel between x and y.</p> |
|
|
199 |
<h2 id="parameters">Parameters</h2> |
|
|
200 |
<pre><code>x: Tensor |
|
|
201 |
Tensor with shape [batch_size, z_dim] |
|
|
202 |
y: Tensor |
|
|
203 |
Tensor with shape [batch_size, z_dim] |
|
|
204 |
</code></pre> |
|
|
205 |
<h2 id="returns">Returns</h2> |
|
|
206 |
<pre><code>The computed RBF kernel between x and y |
|
|
207 |
</code></pre></div> |
|
|
208 |
</dd> |
|
|
209 |
<dt id="VITAE.utils.squared_distance"><code class="name flex"> |
|
|
210 |
<span>def <span class="ident">squared_distance</span></span>(<span>x, y)</span> |
|
|
211 |
</code></dt> |
|
|
212 |
<dd> |
|
|
213 |
<div class="desc"><p>Compute the pairwise euclidean distance.</p> |
|
|
214 |
<h2 id="parameters">Parameters</h2> |
|
|
215 |
<dl> |
|
|
216 |
<dt><strong><code>x</code></strong> : <code>Tensor</code></dt> |
|
|
217 |
<dd>Tensor with shape [batch_size, z_dim]</dd> |
|
|
218 |
<dt><strong><code>y</code></strong> : <code>Tensor</code></dt> |
|
|
219 |
<dd>Tensor with shape [batch_size, z_dim]</dd> |
|
|
220 |
</dl> |
|
|
221 |
<h2 id="returns">Returns</h2> |
|
|
222 |
<p>The pairwise euclidean distance between x and y.</p></div> |
|
|
223 |
</dd> |
|
|
224 |
<dt id="VITAE.utils.compute_mmd"><code class="name flex"> |
|
|
225 |
<span>def <span class="ident">compute_mmd</span></span>(<span>x, y, kernel, **kwargs)</span> |
|
|
226 |
</code></dt> |
|
|
227 |
<dd> |
|
|
228 |
<div class="desc"><p>Computes Maximum Mean Discrepancy(MMD) between x and y.</p> |
|
|
229 |
<h2 id="parameters">Parameters</h2> |
|
|
230 |
<dl> |
|
|
231 |
<dt><strong><code>x</code></strong> : <code>Tensor</code></dt> |
|
|
232 |
<dd>Tensor with shape [batch_size, z_dim]</dd> |
|
|
233 |
<dt><strong><code>y</code></strong> : <code>Tensor</code></dt> |
|
|
234 |
<dd>Tensor with shape [batch_size, z_dim]</dd> |
|
|
235 |
<dt><strong><code>kernel</code></strong> : <code>str</code></dt> |
|
|
236 |
<dd>The kernel type used in MMD. It can be 'rbf', 'multi-scale-rbf' or 'raphy'.</dd> |
|
|
237 |
<dt><strong><code>**kwargs</code></strong> : <code>dict</code></dt> |
|
|
238 |
<dd>The parameters used in kernel function.</dd> |
|
|
239 |
</dl> |
|
|
240 |
<h2 id="returns">Returns</h2> |
|
|
241 |
<dl> |
|
|
242 |
<dt><code>The computed MMD between x and y</code></dt> |
|
|
243 |
<dd> </dd> |
|
|
244 |
</dl></div> |
|
|
245 |
</dd> |
|
|
246 |
<dt id="VITAE.utils.sample_z"><code class="name flex"> |
|
|
247 |
<span>def <span class="ident">sample_z</span></span>(<span>args)</span> |
|
|
248 |
</code></dt> |
|
|
249 |
<dd> |
|
|
250 |
<div class="desc"><p>Samples from standard Normal distribution with shape [size, z_dim] and |
|
|
251 |
applies re-parametrization trick. It is actually sampling from latent |
|
|
252 |
space distributions with N(mu, var) computed in <code>_encoder</code> function.</p> |
|
|
253 |
<h2 id="parameters">Parameters</h2> |
|
|
254 |
<dl> |
|
|
255 |
<dt><strong><code>args</code></strong> : <code>list</code></dt> |
|
|
256 |
<dd>List of [mu, log_var] computed in <code>_encoder</code> function.</dd> |
|
|
257 |
</dl> |
|
|
258 |
<h2 id="returns">Returns</h2> |
|
|
259 |
<p>The computed Tensor of samples with shape [size, z_dim].</p></div> |
|
|
260 |
</dd> |
|
|
261 |
</dl> |
|
|
262 |
</section> |
|
|
263 |
<section> |
|
|
264 |
<h2 class="section-title" id="header-classes">Classes</h2> |
|
|
265 |
<dl> |
|
|
266 |
<dt id="VITAE.utils.Early_Stopping"><code class="flex name class"> |
|
|
267 |
<span>class <span class="ident">Early_Stopping</span></span> |
|
|
268 |
<span>(</span><span>warmup=0, patience=10, tolerance=0.001, relative=False, is_minimize=True)</span> |
|
|
269 |
</code></dt> |
|
|
270 |
<dd> |
|
|
271 |
<div class="desc"><p>The early-stopping monitor.</p></div> |
|
|
272 |
<details class="source"> |
|
|
273 |
<summary> |
|
|
274 |
<span>Expand source code</span> |
|
|
275 |
</summary> |
|
|
276 |
<pre><code class="python">class Early_Stopping(): |
|
|
277 |
''' |
|
|
278 |
The early-stopping monitor. |
|
|
279 |
''' |
|
|
280 |
def __init__(self, warmup=0, patience=10, tolerance=1e-3, |
|
|
281 |
relative=False, is_minimize=True): |
|
|
282 |
self.warmup = warmup |
|
|
283 |
self.patience = patience |
|
|
284 |
self.tolerance = tolerance |
|
|
285 |
self.is_minimize = is_minimize |
|
|
286 |
self.relative = relative |
|
|
287 |
|
|
|
288 |
self.step = -1 |
|
|
289 |
self.best_step = -1 |
|
|
290 |
self.best_metric = np.inf |
|
|
291 |
|
|
|
292 |
if not self.is_minimize: |
|
|
293 |
self.factor = -1.0 |
|
|
294 |
else: |
|
|
295 |
self.factor = 1.0 |
|
|
296 |
|
|
|
297 |
def __call__(self, metric): |
|
|
298 |
self.step += 1 |
|
|
299 |
|
|
|
300 |
if self.step < self.warmup: |
|
|
301 |
return False |
|
|
302 |
elif (self.best_metric==np.inf) or \ |
|
|
303 |
(self.relative and (self.best_metric-metric)/self.best_metric > self.tolerance) or \ |
|
|
304 |
((not self.relative) and self.factor*metric<self.factor*self.best_metric-self.tolerance): |
|
|
305 |
self.best_metric = metric |
|
|
306 |
self.best_step = self.step |
|
|
307 |
return False |
|
|
308 |
elif self.step - self.best_step>self.patience: |
|
|
309 |
print('Best Epoch: %d. Best Metric: %f.'%(self.best_step, self.best_metric)) |
|
|
310 |
return True |
|
|
311 |
else: |
|
|
312 |
return False</code></pre> |
|
|
313 |
</details> |
|
|
314 |
</dd> |
|
|
315 |
</dl> |
|
|
316 |
</section> |
|
|
317 |
</article> |
|
|
318 |
<nav id="sidebar"> |
|
|
319 |
<div class="toc"> |
|
|
320 |
<ul></ul> |
|
|
321 |
</div> |
|
|
322 |
<ul id="index"> |
|
|
323 |
<li><h3>Super-module</h3> |
|
|
324 |
<ul> |
|
|
325 |
<li><code><a title="VITAE" href="index.html">VITAE</a></code></li> |
|
|
326 |
</ul> |
|
|
327 |
</li> |
|
|
328 |
<li><h3><a href="#header-functions">Functions</a></h3> |
|
|
329 |
<ul class="two-column"> |
|
|
330 |
<li><code><a title="VITAE.utils.reset_random_seeds" href="#VITAE.utils.reset_random_seeds">reset_random_seeds</a></code></li> |
|
|
331 |
<li><code><a title="VITAE.utils.get_embedding" href="#VITAE.utils.get_embedding">get_embedding</a></code></li> |
|
|
332 |
<li><code><a title="VITAE.utils.get_igraph" href="#VITAE.utils.get_igraph">get_igraph</a></code></li> |
|
|
333 |
<li><code><a title="VITAE.utils.leidenalg_igraph" href="#VITAE.utils.leidenalg_igraph">leidenalg_igraph</a></code></li> |
|
|
334 |
<li><code><a title="VITAE.utils.plot_clusters" href="#VITAE.utils.plot_clusters">plot_clusters</a></code></li> |
|
|
335 |
<li><code><a title="VITAE.utils.plot_marker_gene" href="#VITAE.utils.plot_marker_gene">plot_marker_gene</a></code></li> |
|
|
336 |
<li><code><a title="VITAE.utils.plot_uncertainty" href="#VITAE.utils.plot_uncertainty">plot_uncertainty</a></code></li> |
|
|
337 |
<li><code><a title="VITAE.utils.DE_test" href="#VITAE.utils.DE_test">DE_test</a></code></li> |
|
|
338 |
<li><code><a title="VITAE.utils.load_data" href="#VITAE.utils.load_data">load_data</a></code></li> |
|
|
339 |
<li><code><a title="VITAE.utils.compute_kernel" href="#VITAE.utils.compute_kernel">compute_kernel</a></code></li> |
|
|
340 |
<li><code><a title="VITAE.utils.squared_distance" href="#VITAE.utils.squared_distance">squared_distance</a></code></li> |
|
|
341 |
<li><code><a title="VITAE.utils.compute_mmd" href="#VITAE.utils.compute_mmd">compute_mmd</a></code></li> |
|
|
342 |
<li><code><a title="VITAE.utils.sample_z" href="#VITAE.utils.sample_z">sample_z</a></code></li> |
|
|
343 |
</ul> |
|
|
344 |
</li> |
|
|
345 |
<li><h3><a href="#header-classes">Classes</a></h3> |
|
|
346 |
<ul> |
|
|
347 |
<li> |
|
|
348 |
<h4><code><a title="VITAE.utils.Early_Stopping" href="#VITAE.utils.Early_Stopping">Early_Stopping</a></code></h4> |
|
|
349 |
</li> |
|
|
350 |
</ul> |
|
|
351 |
</li> |
|
|
352 |
</ul> |
|
|
353 |
</nav> |
|
|
354 |
</main> |
|
|
355 |
<footer id="footer"> |
|
|
356 |
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.11.1</a>.</p> |
|
|
357 |
</footer> |
|
|
358 |
</body> |
|
|
359 |
</html> |