Skip to content

Commit

Permalink
deploy: 572374f
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Nov 20, 2024
1 parent 1da3225 commit 326cbbd
Show file tree
Hide file tree
Showing 30 changed files with 443 additions and 127 deletions.
6 changes: 5 additions & 1 deletion api/_modules/aepsych/models/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -382,14 +382,18 @@ <h1>Source code for aepsych.models.base</h1><div class="highlight"><pre>
<span class="n">optimizer_kwargs</span> <span class="o">=</span> <span class="p">{}</span> <span class="k">if</span> <span class="n">optimizer_kwargs</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="n">optimizer_kwargs</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">max_fit_time</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">"max_fit_time"</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_fit_time</span><span class="p">)</span>
<span class="k">if</span> <span class="n">max_fit_time</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">if</span> <span class="s2">"options"</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">optimizer_kwargs</span><span class="p">:</span>
<span class="n">optimizer_kwargs</span><span class="p">[</span><span class="s2">"options"</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>

<span class="c1"># figure out how long evaluating a single samp</span>
<span class="n">starttime</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
<span class="n">_</span> <span class="o">=</span> <span class="n">mll</span><span class="p">(</span><span class="bp">self</span><span class="p">(</span><span class="n">train_x</span><span class="p">),</span> <span class="n">train_y</span><span class="p">)</span>
<span class="n">single_eval_time</span> <span class="o">=</span> <span class="p">(</span>
<span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">-</span> <span class="n">starttime</span> <span class="o">+</span> <span class="mf">1e-6</span>
<span class="p">)</span> <span class="c1"># add an epsilon to avoid divide by zero</span>
<span class="n">n_eval</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">max_fit_time</span> <span class="o">/</span> <span class="n">single_eval_time</span><span class="p">)</span>
<span class="n">optimizer_kwargs</span><span class="p">[</span><span class="s2">"options"</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s2">"maxfun"</span><span class="p">:</span> <span class="n">n_eval</span><span class="p">}</span>

<span class="n">optimizer_kwargs</span><span class="p">[</span><span class="s2">"options"</span><span class="p">][</span><span class="s2">"maxfun"</span><span class="p">]</span> <span class="o">=</span> <span class="n">n_eval</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="sa">f</span><span class="s2">"fit maxfun is </span><span class="si">{</span><span class="n">n_eval</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span>

<span class="n">starttime</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
Expand Down
6 changes: 5 additions & 1 deletion api/_modules/aepsych/models/base/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -382,14 +382,18 @@ <h1>Source code for aepsych.models.base</h1><div class="highlight"><pre>
<span class="n">optimizer_kwargs</span> <span class="o">=</span> <span class="p">{}</span> <span class="k">if</span> <span class="n">optimizer_kwargs</span> <span class="ow">is</span> <span class="kc">None</span> <span class="k">else</span> <span class="n">optimizer_kwargs</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">max_fit_time</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">"max_fit_time"</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_fit_time</span><span class="p">)</span>
<span class="k">if</span> <span class="n">max_fit_time</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">if</span> <span class="s2">"options"</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">optimizer_kwargs</span><span class="p">:</span>
<span class="n">optimizer_kwargs</span><span class="p">[</span><span class="s2">"options"</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>

<span class="c1"># figure out how long evaluating a single samp</span>
<span class="n">starttime</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
<span class="n">_</span> <span class="o">=</span> <span class="n">mll</span><span class="p">(</span><span class="bp">self</span><span class="p">(</span><span class="n">train_x</span><span class="p">),</span> <span class="n">train_y</span><span class="p">)</span>
<span class="n">single_eval_time</span> <span class="o">=</span> <span class="p">(</span>
<span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">-</span> <span class="n">starttime</span> <span class="o">+</span> <span class="mf">1e-6</span>
<span class="p">)</span> <span class="c1"># add an epsilon to avoid divide by zero</span>
<span class="n">n_eval</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">max_fit_time</span> <span class="o">/</span> <span class="n">single_eval_time</span><span class="p">)</span>
<span class="n">optimizer_kwargs</span><span class="p">[</span><span class="s2">"options"</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s2">"maxfun"</span><span class="p">:</span> <span class="n">n_eval</span><span class="p">}</span>

<span class="n">optimizer_kwargs</span><span class="p">[</span><span class="s2">"options"</span><span class="p">][</span><span class="s2">"maxfun"</span><span class="p">]</span> <span class="o">=</span> <span class="n">n_eval</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="sa">f</span><span class="s2">"fit maxfun is </span><span class="si">{</span><span class="n">n_eval</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span>

<span class="n">starttime</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
Expand Down
22 changes: 18 additions & 4 deletions api/_modules/aepsych/models/gp_classification.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h1>Source code for aepsych.models.gp_classification</h1><div class="highlight">

<span class="kn">import</span> <span class="nn">warnings</span>
<span class="kn">from</span> <span class="nn">copy</span> <span class="kn">import</span> <span class="n">deepcopy</span>
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Optional</span><span class="p">,</span> <span class="n">Tuple</span><span class="p">,</span> <span class="n">Union</span>
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Any</span><span class="p">,</span> <span class="n">Dict</span><span class="p">,</span> <span class="n">Optional</span><span class="p">,</span> <span class="n">Tuple</span>

<span class="kn">import</span> <span class="nn">gpytorch</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
Expand All @@ -35,7 +35,7 @@ <h1>Source code for aepsych.models.gp_classification</h1><div class="highlight">
<span class="kn">from</span> <span class="nn">aepsych.factory.default</span> <span class="kn">import</span> <span class="n">default_mean_covar_factory</span>
<span class="kn">from</span> <span class="nn">aepsych.models.base</span> <span class="kn">import</span> <span class="n">AEPsychModelDeviceMixin</span>
<span class="kn">from</span> <span class="nn">aepsych.models.utils</span> <span class="kn">import</span> <span class="n">select_inducing_points</span>
<span class="kn">from</span> <span class="nn">aepsych.utils</span> <span class="kn">import</span> <span class="n">_process_bounds</span><span class="p">,</span> <span class="n">promote_0d</span>
<span class="kn">from</span> <span class="nn">aepsych.utils</span> <span class="kn">import</span> <span class="n">_process_bounds</span><span class="p">,</span> <span class="n">get_optimizer_options</span><span class="p">,</span> <span class="n">promote_0d</span>
<span class="kn">from</span> <span class="nn">aepsych.utils_logging</span> <span class="kn">import</span> <span class="n">getLogger</span>
<span class="kn">from</span> <span class="nn">gpytorch.likelihoods</span> <span class="kn">import</span> <span class="n">BernoulliLikelihood</span><span class="p">,</span> <span class="n">BetaLikelihood</span><span class="p">,</span> <span class="n">Likelihood</span>
<span class="kn">from</span> <span class="nn">gpytorch.models</span> <span class="kn">import</span> <span class="n">ApproximateGP</span>
Expand Down Expand Up @@ -75,6 +75,7 @@ <h1>Source code for aepsych.models.gp_classification</h1><div class="highlight">
<span class="n">inducing_size</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
<span class="n">max_fit_time</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">float</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
<span class="n">inducing_point_method</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">"auto"</span><span class="p">,</span>
<span class="n">optimizer_options</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Any</span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w"> </span><span class="sd">"""Initialize the GP Classification model</span>

Expand All @@ -96,12 +97,17 @@ <h1>Source code for aepsych.models.gp_classification</h1><div class="highlight">
<span class="sd"> If "pivoted_chol", selects points based on the pivoted Cholesky heuristic.</span>
<span class="sd"> If "kmeans++", selects points by performing kmeans++ clustering on the training data.</span>
<span class="sd"> If "auto", tries to determine the best method automatically.</span>
<span class="sd"> optimizer_options (Dict[str, Any], optional): Optimizer options to pass to the SciPy optimizer during</span>
<span class="sd"> fitting. Assumes we are using L-BFGS-B.</span>
<span class="sd"> """</span>
<span class="n">lb</span><span class="p">,</span> <span class="n">ub</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dim</span> <span class="o">=</span> <span class="n">_process_bounds</span><span class="p">(</span><span class="n">lb</span><span class="p">,</span> <span class="n">ub</span><span class="p">,</span> <span class="n">dim</span><span class="p">)</span>

<span class="bp">self</span><span class="o">.</span><span class="n">max_fit_time</span> <span class="o">=</span> <span class="n">max_fit_time</span>
<span class="bp">self</span><span class="o">.</span><span class="n">inducing_size</span> <span class="o">=</span> <span class="n">inducing_size</span> <span class="ow">or</span> <span class="mi">99</span>

<span class="bp">self</span><span class="o">.</span><span class="n">optimizer_options</span> <span class="o">=</span> <span class="p">(</span>
<span class="p">{</span><span class="s2">"options"</span><span class="p">:</span> <span class="n">optimizer_options</span><span class="p">}</span> <span class="k">if</span> <span class="n">optimizer_options</span> <span class="k">else</span> <span class="p">{</span><span class="s2">"options"</span><span class="p">:</span> <span class="p">{}}</span>
<span class="p">)</span>

<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">inducing_size</span> <span class="o">&gt;=</span> <span class="mi">100</span><span class="p">:</span>
<span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span>
<span class="p">(</span>
Expand Down Expand Up @@ -192,6 +198,8 @@ <h1>Source code for aepsych.models.gp_classification</h1><div class="highlight">
<span class="k">else</span><span class="p">:</span>
<span class="n">likelihood</span> <span class="o">=</span> <span class="kc">None</span> <span class="c1"># fall back to __init__ default</span>

<span class="n">optimizer_options</span> <span class="o">=</span> <span class="n">get_optimizer_options</span><span class="p">(</span><span class="n">config</span><span class="p">,</span> <span class="n">classname</span><span class="p">)</span>

<span class="k">return</span> <span class="bp">cls</span><span class="p">(</span>
<span class="n">lb</span><span class="o">=</span><span class="n">lb</span><span class="p">,</span>
<span class="n">ub</span><span class="o">=</span><span class="n">ub</span><span class="p">,</span>
Expand All @@ -202,6 +210,7 @@ <h1>Source code for aepsych.models.gp_classification</h1><div class="highlight">
<span class="n">max_fit_time</span><span class="o">=</span><span class="n">max_fit_time</span><span class="p">,</span>
<span class="n">inducing_point_method</span><span class="o">=</span><span class="n">inducing_point_method</span><span class="p">,</span>
<span class="n">likelihood</span><span class="o">=</span><span class="n">likelihood</span><span class="p">,</span>
<span class="n">optimizer_options</span><span class="o">=</span><span class="n">optimizer_options</span><span class="p">,</span>
<span class="p">)</span></div>

<span class="k">def</span> <span class="nf">_reset_hyperparameters</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
Expand Down Expand Up @@ -269,7 +278,10 @@ <h1>Source code for aepsych.models.gp_classification</h1><div class="highlight">
<span class="n">n</span> <span class="o">=</span> <span class="n">train_y</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">mll</span> <span class="o">=</span> <span class="n">gpytorch</span><span class="o">.</span><span class="n">mlls</span><span class="o">.</span><span class="n">VariationalELBO</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">likelihood</span><span class="p">,</span> <span class="bp">self</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_fit_mll</span><span class="p">(</span><span class="n">mll</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></div>
<span class="k">if</span> <span class="s2">"optimizer_kwargs"</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_fit_mll</span><span class="p">(</span><span class="n">mll</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_fit_mll</span><span class="p">(</span><span class="n">mll</span><span class="p">,</span> <span class="n">optimizer_kwargs</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">optimizer_options</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></div>

<div class="viewcode-block" id="GPClassificationModel.sample"><a class="viewcode-back" href="../../../models.html#aepsych.models.gp_classification.GPClassificationModel.sample">[docs]</a> <span class="k">def</span> <span class="nf">sample</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">:</span> <span class="n">torch</span><span class="o">.</span><span class="n">Tensor</span><span class="p">,</span> <span class="n">num_samples</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">torch</span><span class="o">.</span><span class="n">Tensor</span><span class="p">:</span>
<span class="w"> </span><span class="sd">"""Sample from underlying model.</span>
Expand Down Expand Up @@ -353,6 +365,7 @@ <h1>Source code for aepsych.models.gp_classification</h1><div class="highlight">
<span class="n">inducing_size</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
<span class="n">max_fit_time</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">float</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
<span class="n">inducing_point_method</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">"auto"</span><span class="p">,</span>
<span class="n">optimizer_options</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Any</span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">if</span> <span class="n">likelihood</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">likelihood</span> <span class="o">=</span> <span class="n">BetaLikelihood</span><span class="p">()</span>
Expand All @@ -366,6 +379,7 @@ <h1>Source code for aepsych.models.gp_classification</h1><div class="highlight">
<span class="n">inducing_size</span><span class="o">=</span><span class="n">inducing_size</span><span class="p">,</span>
<span class="n">max_fit_time</span><span class="o">=</span><span class="n">max_fit_time</span><span class="p">,</span>
<span class="n">inducing_point_method</span><span class="o">=</span><span class="n">inducing_point_method</span><span class="p">,</span>
<span class="n">optimizer_options</span><span class="o">=</span><span class="n">optimizer_options</span><span class="p">,</span>
<span class="p">)</span></div>
</pre></div>
</div>
Expand Down
Loading

0 comments on commit 326cbbd

Please sign in to comment.