# Fitting on BornAgain

file:///usr/share/doc/bornagain/html/ref/fit/index.html Recent content in Fitting on BornAgain Hugo en-us

# Minimizer settings

file:///usr/share/doc/bornagain/html/ref/fit/minimizers.html Mon, 01 Jan 0001 00:00:00 +0000 file:///usr/share/doc/bornagain/html/ref/fit/minimizers.html <h2 id="minimizer-settings">Minimizer settings</h2> <p>The BornAgain minimizer interface was developed with the following ideas in mind:</p> <ul> <li>Provide an interface which looks more or less familiar for users of other Python minimization packages.</li> <li>Enable the use of our minimizer for optimization problems outside the BornAgain context.</li> <li>Allow the usage of other, possibly more advanced minimization libraries, for BornAgain fits.</li> </ul> <p>Particularly, we have been inspired by the <a href="https://lmfit.github.io/lmfit-py/">lmfit Python package</a>, so the BornAgain setup looks very similar. In the code snippet below we give an example of finding the minimum of the <a href="https://en.wikipedia.org/wiki/Rosenbrock_function">Rosenbrock function</a> using the BornAgain minimizer with default settings.</p>

# Multiple datasets

file:///usr/share/doc/bornagain/html/ref/fit/multiple-datasets.html Mon, 01 Jan 0001 00:00:00 +0000 file:///usr/share/doc/bornagain/html/ref/fit/multiple-datasets.html <h2 id="fitting-several-datasets-at-once">Fitting several datasets at once</h2> <p>Several datasets can be fitted simultaneously, either using the BornAgain fit facilities, or using external minimizers.</p> <h3 id="with-the-bornagain-fit-facilities">With the BornAgain fit facilities</h3> <p>Add different data and different fit models to an instance of class <a href="https://jugit.fz-juelich.de/mlz/bornagain/-/tree/r23/Sim/Fitting/FitObjective.h">FitObjective</a>:</p> <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-python" data-lang="python"><span class="line"><span class="cl"> <span class="n">fit_objective</span> <span class="o">=</span> <span class="n">ba</span><span class="o">.</span><span class="n">FitObjective</span><span class="p">()</span> </span></span><span class="line"><span class="cl"> <span class="n">fit_objective</span><span class="o">.</span><span class="n">addSimulationAndData</span><span class="p">(</span><span class="n">simulation1</span><span class="p">,</span> <span class="n">data1</span><span class="p">[,</span> <span class="n">stdv1</span><span class="p">][,</span> <span class="n">wgt1</span><span class="p">])</span> </span></span><span class="line"><span class="cl"> <span class="n">fit_objective</span><span class="o">.</span><span class="n">addSimulationAndData</span><span class="p">(</span><span class="n">simulation2</span><span class="p">,</span> <span class="n">data2</span><span class="p">[,</span> <span class="n">stdv2</span><span class="p">][,</span> <span class="n">wgt2</span><span class="p">])</span> </span></span></code></pre></div><p>The optional <code>stdv</code> arguments hold error estimates. The optional weights <code>wgt</code> are by default set to 1.</p> <p>For a full example, see <a href="file:///usr/share/doc/bornagain/html/ref/fit/ex/multiple-datasets">Examples &gt; Fitting &gt; Simultaneous fit</a>.</p> <h3 id="with-external-minimizer">With external minimizer</h3> <p>See the <a href="file:///usr/share/doc/bornagain/html/ref/fit/ex/reflectometry-honeycomb">honeycomb fit example</a>, where differential evolution is called with an objective function that has contributions from several reflectometry datasets and models:</p>