<!-- Generated by pkgdown: do not edit by hand -->
<!DOCTYPE html>
<html lang="en">
  <head>
  <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Define Problems for Experiments — addProblem • batchtools</title>


<!-- jquery -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<!-- Bootstrap -->

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha256-bZLfwXAP04zRMK2BjiO8iu9pf4FbLqX6zitd+tIvLhE=" crossorigin="anonymous" />

<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha256-nuL8/2cJ5NDSSwnKD8VqreErSWHtnEP9E7AySL+1ev4=" crossorigin="anonymous"></script>

<!-- bootstrap-toc -->
<link rel="stylesheet" href="../bootstrap-toc.css">
<script src="../bootstrap-toc.js"></script>

<!-- Font Awesome icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous" />

<!-- clipboard.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script>

<!-- headroom.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script>

<!-- pkgdown -->
<link href="../pkgdown.css" rel="stylesheet">
<script src="../pkgdown.js"></script>




<meta property="og:title" content="Define Problems for Experiments — addProblem" />
<meta property="og:description" content="Problems may consist of up to two parts: A static, immutable part (data in addProblem)
and a dynamic, stochastic part (fun in addProblem).
For example, for statistical learning problems a data frame would be the static problem part while
a resampling function would be the stochastic part which creates problem instance.
This instance is then typically passed to a learning algorithm like a wrapper around a statistical model
(fun in addAlgorithm).
This function serialize all components to the file system and registers the problem in the ExperimentRegistry.
removeProblem removes all jobs from the registry which depend on the specific problem.
reg$problems holds the IDs of already defined problems." />




<!-- mathjax -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script>

<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->



  </head>

  <body data-spy="scroll" data-target="#toc">
    <div class="container template-reference-topic">
      <header>
      <div class="navbar navbar-default navbar-fixed-top" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <span class="navbar-brand">
        <a class="navbar-link" href="../index.html">batchtools</a>
        <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.9.14</span>
      </span>
    </div>

    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
        <li>
  <a href="../index.html">
    <span class="fas fa fas fa-home fa-lg"></span>
     
  </a>
</li>
<li>
  <a href="../articles/batchtools.html">Get started</a>
</li>
<li>
  <a href="../reference/index.html">Reference</a>
</li>
<li>
  <a href="../news/index.html">Changelog</a>
</li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li>
  <a href="https://github.com/mllg/batchtools/">
    <span class="fab fa fab fa-github fa-lg"></span>
     
  </a>
</li>
      </ul>
      
    </div><!--/.nav-collapse -->
  </div><!--/.container -->
</div><!--/.navbar -->

      

      </header>

<div class="row">
  <div class="col-md-9 contents">
    <div class="page-header">
    <h1>Define Problems for Experiments</h1>
    <small class="dont-index">Source: <a href='https://github.com/mllg/batchtools/blob/master/R/Problem.R'><code>R/Problem.R</code></a></small>
    <div class="hidden name"><code>addProblem.Rd</code></div>
    </div>

    <div class="ref-description">
    <p>Problems may consist of up to two parts: A static, immutable part (<code>data</code> in <code>addProblem</code>)
and a dynamic, stochastic part (<code>fun</code> in <code>addProblem</code>).
For example, for statistical learning problems a data frame would be the static problem part while
a resampling function would be the stochastic part which creates problem instance.
This instance is then typically passed to a learning algorithm like a wrapper around a statistical model
(<code>fun</code> in <code><a href='addAlgorithm.html'>addAlgorithm</a></code>).</p>
<p>This function serialize all components to the file system and registers the problem in the <code><a href='makeExperimentRegistry.html'>ExperimentRegistry</a></code>.</p>
<p><code>removeProblem</code> removes all jobs from the registry which depend on the specific problem.
<code>reg$problems</code> holds the IDs of already defined problems.</p>
    </div>

    <pre class="usage"><span class='fu'>addProblem</span><span class='op'>(</span>
  <span class='va'>name</span>,
  data <span class='op'>=</span> <span class='cn'>NULL</span>,
  fun <span class='op'>=</span> <span class='cn'>NULL</span>,
  seed <span class='op'>=</span> <span class='cn'>NULL</span>,
  cache <span class='op'>=</span> <span class='cn'>FALSE</span>,
  reg <span class='op'>=</span> <span class='fu'><a href='getDefaultRegistry.html'>getDefaultRegistry</a></span><span class='op'>(</span><span class='op'>)</span>
<span class='op'>)</span>

<span class='fu'>removeProblems</span><span class='op'>(</span><span class='va'>name</span>, reg <span class='op'>=</span> <span class='fu'><a href='getDefaultRegistry.html'>getDefaultRegistry</a></span><span class='op'>(</span><span class='op'>)</span><span class='op'>)</span></pre>

    <h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2>
    <table class="ref-arguments">
    <colgroup><col class="name" /><col class="desc" /></colgroup>
    <tr>
      <th>name</th>
      <td><p>[<code><a href='https://rdrr.io/r/base/character.html'>character(1)</a></code>]<br />
Unique identifier for the problem.</p></td>
    </tr>
    <tr>
      <th>data</th>
      <td><p>[<code>ANY</code>]<br />
Static problem part. Default is <code>NULL</code>.</p></td>
    </tr>
    <tr>
      <th>fun</th>
      <td><p>[<code>function</code>]<br />
The function defining the stochastic problem part.
The static part is passed to this function with name &#8220;data&#8221; and the <code><a href='makeJob.html'>Job</a></code>/<code><a href='makeJob.html'>Experiment</a></code>
is passed as &#8220;job&#8221;.
Therefore, your function must have the formal arguments &#8220;job&#8221; and &#8220;data&#8221; (or dots <code>...</code>).
If you do not provide a function, it defaults to a function which just returns the data part.</p></td>
    </tr>
    <tr>
      <th>seed</th>
      <td><p>[<code><a href='https://rdrr.io/r/base/integer.html'>integer(1)</a></code>]<br />
Start seed for this problem. This allows the &#8220;synchronization&#8221; of a stochastic
problem across algorithms, so that different algorithms are evaluated on the same stochastic instance.
If the problem seed is defined, the seeding mechanism works as follows:
(1) Before the dynamic part of a problem is instantiated,
the seed of the problem + [replication number] - 1 is set, i.e. the first
replication uses the problem seed. (2) The stochastic part of the problem is
instantiated. (3) From now on the usual experiment seed of the registry is used,
see <code><a href='makeExperimentRegistry.html'>ExperimentRegistry</a></code>.
If <code>seed</code> is set to <code>NULL</code> (default), the job seed is used to instantiate the problem and
different algorithms see different stochastic instances of the same problem.</p></td>
    </tr>
    <tr>
      <th>cache</th>
      <td><p>[<code><a href='https://rdrr.io/r/base/logical.html'>logical(1)</a></code>]<br />
If <code>TRUE</code> and <code>seed</code> is set, problem instances will be cached on the file system.
This assumes that each problem instance is deterministic for each combination of hyperparameter setting
and each replication number.
This feature is experimental.</p></td>
    </tr>
    <tr>
      <th>reg</th>
      <td><p>[<code><a href='makeExperimentRegistry.html'>ExperimentRegistry</a></code>]<br />
Registry. If not explicitly passed, uses the last created registry.</p></td>
    </tr>
    </table>

    <h2 class="hasAnchor" id="value"><a class="anchor" href="#value"></a>Value</h2>

    <p>[<code>Problem</code>]. Object of class &#8220;Problem&#8221; (invisibly).</p>
    <h2 class="hasAnchor" id="see-also"><a class="anchor" href="#see-also"></a>See also</h2>

    <div class='dont-index'><p><code><a href='addAlgorithm.html'>Algorithm</a></code>, <code><a href='addExperiments.html'>addExperiments</a></code></p></div>

    <h2 class="hasAnchor" id="examples"><a class="anchor" href="#examples"></a>Examples</h2>
    <pre class="examples"><div class='input'> <span class='fu'>batchtools</span><span class='fu'>:::</span><span class='fu'>example_push_temp</span><span class='op'>(</span><span class='fl'>1</span><span class='op'>)</span> 
<span class='va'>tmp</span> <span class='op'>=</span> <span class='fu'><a href='makeExperimentRegistry.html'>makeExperimentRegistry</a></span><span class='op'>(</span>file.dir <span class='op'>=</span> <span class='cn'>NA</span>, make.default <span class='op'>=</span> <span class='cn'>FALSE</span><span class='op'>)</span>
</div><div class='output co'>#&gt; <span class='message'>No readable configuration file found</span></div><div class='output co'>#&gt; <span class='message'>Created registry in '/tmp/batchtools-example/reg' using cluster functions 'Interactive'</span></div><div class='input'><span class='fu'>addProblem</span><span class='op'>(</span><span class='st'>"p1"</span>, fun <span class='op'>=</span> <span class='kw'>function</span><span class='op'>(</span><span class='va'>job</span>, <span class='va'>data</span><span class='op'>)</span> <span class='va'>data</span>, reg <span class='op'>=</span> <span class='va'>tmp</span><span class='op'>)</span>
</div><div class='output co'>#&gt; <span class='message'>Adding problem 'p1'</span></div><div class='input'><span class='fu'>addProblem</span><span class='op'>(</span><span class='st'>"p2"</span>, fun <span class='op'>=</span> <span class='kw'>function</span><span class='op'>(</span><span class='va'>job</span>, <span class='va'>data</span><span class='op'>)</span> <span class='va'>job</span>, reg <span class='op'>=</span> <span class='va'>tmp</span><span class='op'>)</span>
</div><div class='output co'>#&gt; <span class='message'>Adding problem 'p2'</span></div><div class='input'><span class='fu'><a href='addAlgorithm.html'>addAlgorithm</a></span><span class='op'>(</span><span class='st'>"a1"</span>, fun <span class='op'>=</span> <span class='kw'>function</span><span class='op'>(</span><span class='va'>job</span>, <span class='va'>data</span>, <span class='va'>instance</span><span class='op'>)</span> <span class='va'>instance</span>, reg <span class='op'>=</span> <span class='va'>tmp</span><span class='op'>)</span>
</div><div class='output co'>#&gt; <span class='message'>Adding algorithm 'a1'</span></div><div class='input'><span class='fu'><a href='addExperiments.html'>addExperiments</a></span><span class='op'>(</span>repls <span class='op'>=</span> <span class='fl'>2</span>, reg <span class='op'>=</span> <span class='va'>tmp</span><span class='op'>)</span>
</div><div class='output co'>#&gt; <span class='message'>Adding 2 experiments ('p1'[1] x 'a1'[1] x repls[2]) ...</span></div><div class='output co'>#&gt; <span class='message'>Adding 2 experiments ('p2'[1] x 'a1'[1] x repls[2]) ...</span></div><div class='input'>
<span class='co'># List problems, algorithms and job parameters:</span>
<span class='va'>tmp</span><span class='op'>$</span><span class='va'>problems</span>
</div><div class='output co'>#&gt; [1] "p1" "p2"</div><div class='input'><span class='va'>tmp</span><span class='op'>$</span><span class='va'>algorithms</span>
</div><div class='output co'>#&gt; [1] "a1"</div><div class='input'><span class='fu'><a href='getJobTable.html'>getJobPars</a></span><span class='op'>(</span>reg <span class='op'>=</span> <span class='va'>tmp</span><span class='op'>)</span>
</div><div class='output co'>#&gt;    job.id problem prob.pars algorithm algo.pars
#&gt; 1:      1      p1 &lt;list[0]&gt;        a1 &lt;list[0]&gt;
#&gt; 2:      2      p1 &lt;list[0]&gt;        a1 &lt;list[0]&gt;
#&gt; 3:      3      p2 &lt;list[0]&gt;        a1 &lt;list[0]&gt;
#&gt; 4:      4      p2 &lt;list[0]&gt;        a1 &lt;list[0]&gt;</div><div class='input'>
<span class='co'># Remove one problem</span>
<span class='fu'>removeProblems</span><span class='op'>(</span><span class='st'>"p1"</span>, reg <span class='op'>=</span> <span class='va'>tmp</span><span class='op'>)</span>
</div><div class='output co'>#&gt; <span class='message'>Removing Problem 'p1' and 2 corresponding jobs ...</span></div><div class='input'>
<span class='co'># List problems and algorithms:</span>
<span class='va'>tmp</span><span class='op'>$</span><span class='va'>problems</span>
</div><div class='output co'>#&gt; [1] "p2"</div><div class='input'><span class='va'>tmp</span><span class='op'>$</span><span class='va'>algorithms</span>
</div><div class='output co'>#&gt; [1] "a1"</div><div class='input'><span class='fu'><a href='getJobTable.html'>getJobPars</a></span><span class='op'>(</span>reg <span class='op'>=</span> <span class='va'>tmp</span><span class='op'>)</span>
</div><div class='output co'>#&gt;    job.id problem prob.pars algorithm algo.pars
#&gt; 1:      3      p2 &lt;list[0]&gt;        a1 &lt;list[0]&gt;
#&gt; 2:      4      p2 &lt;list[0]&gt;        a1 &lt;list[0]&gt;</div></pre>
  </div>
  <div class="col-md-3 hidden-xs hidden-sm" id="pkgdown-sidebar">
    <nav id="toc" data-toggle="toc" class="sticky-top">
      <h2 data-toc-skip>Contents</h2>
    </nav>
  </div>
</div>


      <footer>
      <div class="copyright">
  <p>Developed by Michel Lang, Bernd Bischl.</p>
</div>

<div class="pkgdown">
  <p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.6.1.</p>
</div>

      </footer>
   </div>

  


  </body>
</html>


