Skip to content

Commit

Permalink
deploy: a8fdb34
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffjennings committed Dec 6, 2023
1 parent 1a271bd commit d5ca210
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 26 deletions.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 17 additions & 4 deletions _modules/mpol/crossval.html
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ <h1>Source code for mpol.crossval</h1><div class="highlight"><pre>
<span class="bp">self</span><span class="o">.</span><span class="n">_diagnostics</span><span class="p">[</span><span class="s2">&quot;models&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_model</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_diagnostics</span><span class="p">[</span><span class="s2">&quot;regularizers&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_regularizers</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_diagnostics</span><span class="p">[</span><span class="s2">&quot;loss_histories&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">loss_history</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_diagnostics</span><span class="p">[</span><span class="s2">&quot;train_figures&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_train_figure</span><span class="p">)</span>
<span class="c1"># self._diagnostics[&quot;train_figures&quot;].append(self._train_figure)</span>

<span class="c1"># average individual test scores to get the cross-val metric for chosen</span>
<span class="c1"># hyperparameters</span>
Expand Down Expand Up @@ -588,7 +588,7 @@ <h1>Source code for mpol.crossval</h1><div class="highlight"><pre>

<span class="nd">@property</span>
<span class="k">def</span> <span class="nf">diagnostics</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Dict containing diagnostics of the cross-validation loop across all kfolds: models, regularizers, loss values, training figures&quot;&quot;&quot;</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Dict containing diagnostics of the cross-validation loop across all kfolds: models, regularizers, loss values&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_diagnostics</span></div>


Expand Down Expand Up @@ -734,6 +734,7 @@ <h1>Source code for mpol.crossval</h1><div class="highlight"><pre>
<span class="n">k</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span>
<span class="n">dartboard</span><span class="p">:</span> <span class="n">Dartboard</span> <span class="o">|</span> <span class="kc">None</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
<span class="n">seed</span><span class="p">:</span> <span class="nb">int</span> <span class="o">|</span> <span class="kc">None</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
<span class="n">verbose</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span>
<span class="p">):</span>
<span class="k">if</span> <span class="n">k</span> <span class="o">&lt;=</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;k must be a positive integer&quot;</span><span class="p">)</span>
Expand All @@ -744,6 +745,7 @@ <h1>Source code for mpol.crossval</h1><div class="highlight"><pre>
<span class="bp">self</span><span class="o">.</span><span class="n">griddedDataset</span> <span class="o">=</span> <span class="n">gridded_dataset</span>
<span class="bp">self</span><span class="o">.</span><span class="n">k</span> <span class="o">=</span> <span class="n">k</span>
<span class="bp">self</span><span class="o">.</span><span class="n">dartboard</span> <span class="o">=</span> <span class="n">dartboard</span>
<span class="bp">self</span><span class="o">.</span><span class="n">verbose</span> <span class="o">=</span> <span class="n">verbose</span>

<span class="c1"># 2D mask for any UV cells that contain visibilities</span>
<span class="c1"># in *any* channel</span>
Expand Down Expand Up @@ -781,6 +783,7 @@ <h1>Source code for mpol.crossval</h1><div class="highlight"><pre>
<span class="n">q_edges</span><span class="p">:</span> <span class="n">NDArray</span><span class="p">[</span><span class="n">floating</span><span class="p">[</span><span class="n">Any</span><span class="p">]],</span>
<span class="n">phi_edges</span><span class="p">:</span> <span class="n">NDArray</span><span class="p">[</span><span class="n">floating</span><span class="p">[</span><span class="n">Any</span><span class="p">]],</span>
<span class="n">seed</span><span class="p">:</span> <span class="nb">int</span> <span class="o">|</span> <span class="kc">None</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
<span class="n">verbose</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">,</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="n">DartboardSplitGridded</span><span class="p">:</span>
<span class="w"> </span><span class="sa">r</span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Alternative method to initialize a DartboardSplitGridded object from Dartboard parameters.</span>
Expand All @@ -791,9 +794,10 @@ <h1>Source code for mpol.crossval</h1><div class="highlight"><pre>
<span class="sd"> q_edges (1D numpy array): an array of radial bin edges to set the dartboard cells in :math:`[\mathrm{k}\lambda]`. If ``None``, defaults to 12 log-linearly radial bins stretching from 0 to the :math:`q_\mathrm{max}` represented by ``coords``.</span>
<span class="sd"> phi_edges (1D numpy array): an array of azimuthal bin edges to set the dartboard cells in [radians]. If ``None``, defaults to 8 equal-spaced azimuthal bins stretched from :math:`0` to :math:`\pi`.</span>
<span class="sd"> seed (int): (optional) numpy random seed to use for the permutation, for reproducibility</span>
<span class="sd"> verbose (bool): whether to print notification messages</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">dartboard</span> <span class="o">=</span> <span class="n">Dartboard</span><span class="p">(</span><span class="n">gridded_dataset</span><span class="o">.</span><span class="n">coords</span><span class="p">,</span> <span class="n">q_edges</span><span class="p">,</span> <span class="n">phi_edges</span><span class="p">)</span>
<span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">gridded_dataset</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">dartboard</span><span class="p">,</span> <span class="n">seed</span><span class="p">)</span></div>
<span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">gridded_dataset</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">dartboard</span><span class="p">,</span> <span class="n">seed</span><span class="p">,</span> <span class="n">verbose</span><span class="p">)</span></div>

<span class="k">def</span> <span class="fm">__iter__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">DartboardSplitGridded</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">n</span> <span class="o">=</span> <span class="mi">0</span> <span class="c1"># the current k-slice we&#39;re on</span>
Expand All @@ -802,7 +806,16 @@ <h1>Source code for mpol.crossval</h1><div class="highlight"><pre>
<span class="k">def</span> <span class="fm">__next__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">tuple</span><span class="p">[</span><span class="n">GriddedDataset</span><span class="p">,</span> <span class="n">GriddedDataset</span><span class="p">]:</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">n</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">k</span><span class="p">:</span>
<span class="n">k_list</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">k_split_cell_list</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">cell_list_test</span> <span class="o">=</span> <span class="n">k_list</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">n</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">k</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">verbose</span> <span class="ow">is</span> <span class="kc">True</span><span class="p">:</span>
<span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot; DartboardSplitGridded: only 1 k-fold: splitting dataset as ~80/20 train/test&quot;</span><span class="p">)</span>
<span class="n">ntest</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span><span class="mf">0.2</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">k_list</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span>
<span class="c1"># put ~20% of cells into test set</span>
<span class="n">cell_list_test</span> <span class="o">=</span> <span class="n">k_list</span><span class="p">[</span><span class="mi">0</span><span class="p">][:</span><span class="n">ntest</span><span class="p">]</span>
<span class="c1"># remove cells in test set from train set</span>
<span class="n">k_list</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">delete</span><span class="p">(</span><span class="n">k_list</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="nb">range</span><span class="p">(</span><span class="n">ntest</span><span class="p">),</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">cell_list_test</span> <span class="o">=</span> <span class="n">k_list</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">n</span><span class="p">)</span>

<span class="c1"># put the remaining indices back into a full list</span>
<span class="n">cell_list_train</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">(</span><span class="n">k_list</span><span class="p">)</span>
Expand Down
Loading

0 comments on commit d5ca210

Please sign in to comment.