-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ea44f71
Showing
50 changed files
with
21,694 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Sphinx build info version 1 | ||
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. | ||
config: 615379cae50c477b7afb720896ec93a3 | ||
tags: 645f666f9bcd5a90fca523b33c5a78b7 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
|
||
<!DOCTYPE html> | ||
|
||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Overview: module code — regLM unknown documentation</title> | ||
<link rel="stylesheet" type="text/css" href="../_static/pygments.css" /> | ||
<link rel="stylesheet" type="text/css" href="../_static/alabaster.css" /> | ||
<script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script> | ||
<script src="../_static/jquery.js"></script> | ||
<script src="../_static/underscore.js"></script> | ||
<script src="../_static/doctools.js"></script> | ||
<link rel="index" title="Index" href="../genindex.html" /> | ||
<link rel="search" title="Search" href="../search.html" /> | ||
|
||
<link rel="stylesheet" href="../_static/custom.css" type="text/css" /> | ||
|
||
|
||
|
||
|
||
|
||
</head><body> | ||
|
||
|
||
<div class="document"> | ||
<div class="documentwrapper"> | ||
<div class="bodywrapper"> | ||
|
||
|
||
<div class="body" role="main"> | ||
|
||
<h1>All modules for which code is available</h1> | ||
<ul><li><a href="reglm/dataset.html">reglm.dataset</a></li> | ||
<li><a href="reglm/evolve.html">reglm.evolve</a></li> | ||
<li><a href="reglm/interpret.html">reglm.interpret</a></li> | ||
<li><a href="reglm/lightning.html">reglm.lightning</a></li> | ||
<li><a href="reglm/metrics.html">reglm.metrics</a></li> | ||
<li><a href="reglm/regression.html">reglm.regression</a></li> | ||
<li><a href="reglm/utils.html">reglm.utils</a></li> | ||
</ul> | ||
|
||
</div> | ||
|
||
</div> | ||
</div> | ||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation"> | ||
<div class="sphinxsidebarwrapper"> | ||
<h1 class="logo"><a href="../index.html">regLM</a></h1> | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<h3>Navigation</h3> | ||
<ul> | ||
<li class="toctree-l1"><a class="reference internal" href="../readme.html">Overview</a></li> | ||
<li class="toctree-l1"><a class="reference internal" href="../license.html">License</a></li> | ||
<li class="toctree-l1"><a class="reference internal" href="../authors.html">Authors</a></li> | ||
<li class="toctree-l1"><a class="reference internal" href="../api/modules.html">Module Reference</a></li> | ||
</ul> | ||
|
||
<div class="relations"> | ||
<h3>Related Topics</h3> | ||
<ul> | ||
<li><a href="../index.html">Documentation overview</a><ul> | ||
</ul></li> | ||
</ul> | ||
</div> | ||
<div id="searchbox" style="display: none" role="search"> | ||
<h3 id="searchlabel">Quick search</h3> | ||
<div class="searchformwrapper"> | ||
<form class="search" action="../search.html" method="get"> | ||
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/> | ||
<input type="submit" value="Go" /> | ||
</form> | ||
</div> | ||
</div> | ||
<script>$('#searchbox').show(0);</script> | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
</div> | ||
</div> | ||
<div class="clearer"></div> | ||
</div> | ||
<div class="footer"> | ||
©2023, Genentech, Inc.. | ||
|
||
| | ||
Powered by <a href="https://www.sphinx-doc.org/">Sphinx 4.5.0</a> | ||
& <a href="https://alabaster.readthedocs.io">Alabaster 0.7.16</a> | ||
|
||
</div> | ||
|
||
|
||
|
||
|
||
</body> | ||
</html> |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
|
||
<!DOCTYPE html> | ||
|
||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>reglm.metrics — regLM unknown documentation</title> | ||
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css" /> | ||
<link rel="stylesheet" type="text/css" href="../../_static/alabaster.css" /> | ||
<script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script> | ||
<script src="../../_static/jquery.js"></script> | ||
<script src="../../_static/underscore.js"></script> | ||
<script src="../../_static/doctools.js"></script> | ||
<link rel="index" title="Index" href="../../genindex.html" /> | ||
<link rel="search" title="Search" href="../../search.html" /> | ||
|
||
<link rel="stylesheet" href="../../_static/custom.css" type="text/css" /> | ||
|
||
|
||
|
||
|
||
|
||
</head><body> | ||
|
||
|
||
<div class="document"> | ||
<div class="documentwrapper"> | ||
<div class="bodywrapper"> | ||
|
||
|
||
<div class="body" role="main"> | ||
|
||
<h1>Source code for reglm.metrics</h1><div class="highlight"><pre> | ||
<span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> | ||
|
||
<span class="kn">from</span> <span class="nn">reglm.dataset</span> <span class="kn">import</span> <span class="n">CharDataset</span> | ||
|
||
|
||
<div class="viewcode-block" id="compute_accuracy"><a class="viewcode-back" href="../../api/reglm.html#reglm.metrics.compute_accuracy">[docs]</a><span class="k">def</span> <span class="nf">compute_accuracy</span><span class="p">(</span><span class="n">model</span><span class="p">,</span> <span class="n">seqs</span><span class="p">,</span> <span class="n">shuffle_labels</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">batch_size</span><span class="o">=</span><span class="mi">64</span><span class="p">,</span> <span class="n">num_workers</span><span class="o">=</span><span class="mi">8</span><span class="p">):</span> | ||
<span class="w"> </span><span class="sd">"""</span> | ||
<span class="sd"> Compute per-base accuracy of a trained regLM model on labeled sequences</span> | ||
|
||
<span class="sd"> Args:</span> | ||
<span class="sd"> model (pl.LightningModule): Trained regLM model</span> | ||
<span class="sd"> seqs (pd.DataFrame): Dataframe containing sequences under 'Sequence'</span> | ||
<span class="sd"> and labels under 'label'.</span> | ||
<span class="sd"> shuffle_labels (bool): Whether to shuffle the labels among sequences</span> | ||
<span class="sd"> before computing accuracy.</span> | ||
<span class="sd"> batch_size (int): Batch size for inference</span> | ||
<span class="sd"> num_workers (int): Number of workers for inference</span> | ||
|
||
<span class="sd"> Returns:</span> | ||
<span class="sd"> seqs (pd.DataFrame): original dataframe with added columns for per-</span> | ||
<span class="sd"> base and average accuracy.</span> | ||
<span class="sd"> """</span> | ||
<span class="c1"># Extract labels</span> | ||
<span class="n">labels</span> <span class="o">=</span> <span class="n">seqs</span><span class="o">.</span><span class="n">label</span> | ||
|
||
<span class="c1"># Shuffle labels if needed</span> | ||
<span class="k">if</span> <span class="n">shuffle_labels</span><span class="p">:</span> | ||
<span class="n">labels</span> <span class="o">=</span> <span class="n">seqs</span><span class="o">.</span><span class="n">label</span><span class="o">.</span><span class="n">sample</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">seqs</span><span class="p">))</span> | ||
|
||
<span class="n">labels</span> <span class="o">=</span> <span class="n">labels</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span> | ||
|
||
<span class="c1"># Create dataset</span> | ||
<span class="n">ds</span> <span class="o">=</span> <span class="n">CharDataset</span><span class="p">(</span><span class="n">seqs</span><span class="o">=</span><span class="n">seqs</span><span class="o">.</span><span class="n">Sequence</span><span class="o">.</span><span class="n">tolist</span><span class="p">(),</span> <span class="n">labels</span><span class="o">=</span><span class="n">labels</span><span class="p">)</span> | ||
|
||
<span class="c1"># Compute per-base accuracy</span> | ||
<span class="n">acc</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">compute_accuracy_on_dataset</span><span class="p">(</span> | ||
<span class="n">ds</span><span class="p">,</span> <span class="n">batch_size</span><span class="o">=</span><span class="n">batch_size</span><span class="p">,</span> <span class="n">num_workers</span><span class="o">=</span><span class="n">num_workers</span> | ||
<span class="p">)</span> | ||
|
||
<span class="c1"># Add results to dataframe</span> | ||
<span class="k">if</span> <span class="n">shuffle_labels</span><span class="p">:</span> | ||
<span class="n">seqs</span><span class="p">[</span><span class="s2">"acc_shuf"</span><span class="p">]</span> <span class="o">=</span> <span class="n">acc</span> | ||
<span class="n">seqs</span><span class="p">[</span><span class="s2">"acc_shuf_mean"</span><span class="p">]</span> <span class="o">=</span> <span class="n">seqs</span><span class="p">[</span><span class="s2">"acc_shuf"</span><span class="p">]</span><span class="o">.</span><span class="n">apply</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">)</span> | ||
<span class="n">avg_acc</span> <span class="o">=</span> <span class="n">seqs</span><span class="p">[</span><span class="s2">"acc_shuf_mean"</span><span class="p">]</span><span class="o">.</span><span class="n">mean</span><span class="p">()</span> | ||
<span class="k">else</span><span class="p">:</span> | ||
<span class="n">seqs</span><span class="p">[</span><span class="s2">"acc"</span><span class="p">]</span> <span class="o">=</span> <span class="n">acc</span> | ||
<span class="n">seqs</span><span class="p">[</span><span class="s2">"acc_mean"</span><span class="p">]</span> <span class="o">=</span> <span class="n">seqs</span><span class="p">[</span><span class="s2">"acc"</span><span class="p">]</span><span class="o">.</span><span class="n">apply</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">)</span> | ||
<span class="n">avg_acc</span> <span class="o">=</span> <span class="n">seqs</span><span class="p">[</span><span class="s2">"acc_mean"</span><span class="p">]</span><span class="o">.</span><span class="n">mean</span><span class="p">()</span> | ||
|
||
<span class="c1"># Print overall mean</span> | ||
<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Mean accuracy: </span><span class="si">{</span><span class="n">avg_acc</span><span class="si">:</span><span class="s2">.3f</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> | ||
|
||
<span class="k">return</span> <span class="n">seqs</span></div> | ||
</pre></div> | ||
|
||
</div> | ||
|
||
</div> | ||
</div> | ||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation"> | ||
<div class="sphinxsidebarwrapper"> | ||
<h1 class="logo"><a href="../../index.html">regLM</a></h1> | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<h3>Navigation</h3> | ||
<ul> | ||
<li class="toctree-l1"><a class="reference internal" href="../../readme.html">Overview</a></li> | ||
<li class="toctree-l1"><a class="reference internal" href="../../license.html">License</a></li> | ||
<li class="toctree-l1"><a class="reference internal" href="../../authors.html">Authors</a></li> | ||
<li class="toctree-l1"><a class="reference internal" href="../../api/modules.html">Module Reference</a></li> | ||
</ul> | ||
|
||
<div class="relations"> | ||
<h3>Related Topics</h3> | ||
<ul> | ||
<li><a href="../../index.html">Documentation overview</a><ul> | ||
<li><a href="../index.html">Module code</a><ul> | ||
</ul></li> | ||
</ul></li> | ||
</ul> | ||
</div> | ||
<div id="searchbox" style="display: none" role="search"> | ||
<h3 id="searchlabel">Quick search</h3> | ||
<div class="searchformwrapper"> | ||
<form class="search" action="../../search.html" method="get"> | ||
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/> | ||
<input type="submit" value="Go" /> | ||
</form> | ||
</div> | ||
</div> | ||
<script>$('#searchbox').show(0);</script> | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
</div> | ||
</div> | ||
<div class="clearer"></div> | ||
</div> | ||
<div class="footer"> | ||
©2023, Genentech, Inc.. | ||
|
||
| | ||
Powered by <a href="https://www.sphinx-doc.org/">Sphinx 4.5.0</a> | ||
& <a href="https://alabaster.readthedocs.io">Alabaster 0.7.16</a> | ||
|
||
</div> | ||
|
||
|
||
|
||
|
||
</body> | ||
</html> |
Oops, something went wrong.