.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/inverse/fit_linear_scale.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_inverse_fit_linear_scale.py: Fit a scalar scale factor ========================= Fit one bounded parameter to a small analytic forward model. This is the smallest complete inverse-problem setup: a callable, an observation, and one or more ``FitParameter`` objects. The fitted ``scale`` is approximately 2.0 (dimensionless). Predictions and residuals have shape ``(3,)``. With these exact synthetic observations, the residuals approach zero. .. GENERATED FROM PYTHON SOURCE LINES 13-33 .. rst-class:: sphx-glr-script-out .. code-block:: none converged (42 model evaluations) objective = 0.000000 {'scale': 2.0} | .. code-block:: Python import numpy as np from PyMieSim import FitParameter, MeasuredData, fit_parameters x = np.array([1.0, 2.0, 3.0]) observation = MeasuredData(values=np.array([2.0, 4.0, 6.0])) def model(parameters): return parameters["scale"] * x result = fit_parameters( model=model, observation=observation, parameters=[FitParameter(name="scale", initial=0.8, bounds=(0.0, 4.0))], ) print(result.summary()) print(result.parameters) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.002 seconds) .. _sphx_glr_download_gallery_inverse_fit_linear_scale.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: fit_linear_scale.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: fit_linear_scale.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: fit_linear_scale.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_