Skip to content

Commit

Permalink
bring in changes to NXfit base classes from NIAC proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaspie committed Feb 18, 2025
1 parent b329727 commit 1d13e4c
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 279 deletions.
152 changes: 76 additions & 76 deletions contributed_definitions/NXfit.nxdl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,175 +24,175 @@
<definition xmlns="http://definition.nexusformat.org/nxdl/3.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" category="base" type="group" name="NXfit" extends="NXprocess" xsi:schemaLocation="http://definition.nexusformat.org/nxdl/3.1 ../nxdl.xsd">
<symbols>
<doc>
The symbols used in the schema to specify e.g. dimensions of arrays.
The symbols used in the schema to specify e.g. dimensions of arrays.
</doc>
<symbol name="dimRank">
<doc>
Rank of the dependent and independent data arrays (for
multidimensional/multivariate fit.)
Rank of the dependent and independent data arrays (for
multidimensional/multivariate fit.)
</doc>
</symbol>
</symbols>
<doc>
Description of a fit procedure.
Description of a fit procedure.
</doc>
<field name="label">
<doc>
Human-readable label for this fit procedure.
Human-readable label for this fit procedure.
</doc>
</field>
<group name="data" type="NXdata">
<doc>
Input data and results of the fit.
Input data and results of the fit.
</doc>
<field name="input_dependent" type="NX_NUMBER" units="NX_ANY">
<doc>
Position values along one or more data dimensions (to hold the
values for the independent variable for this fit procedure).
Position values along one or more data dimensions (to hold the
values for the independent variable for this fit procedure).
</doc>
<dimensions rank="dimRank">
<doc>
The ``input_dependent`` field must have the same rank (``dimRank``)
as the ``input_independent`` field. Each individual dimension of ``input_dependent``
must have the same number of points as the corresponding dimension in
the ``input_independent`` field.
The ``input_dependent`` field must have the same rank (``dimRank``)
as the ``input_independent`` field. Each individual dimension of ``input_dependent``
must have the same number of points as the corresponding dimension in
the ``input_independent`` field.
</doc>
</dimensions>
</field>
<field name="input_independent" type="NX_NUMBER" units="NX_ANY">
<doc>
Independent input axis for this fit procedure.
Independent input axis for this fit procedure.
</doc>
<dimensions rank="dimRank">
<doc>
The ``input_independent`` field must have the same rank (``dimRank``)
as the ``input_dependent`` field. Each individual dimension of ``input_independent``
must have the same number of points as the corresponding dimension in
the ``input_dependent`` field.
The ``input_independent`` field must have the same rank (``dimRank``)
as the ``input_dependent`` field. Each individual dimension of ``input_independent``
must have the same number of points as the corresponding dimension in
the ``input_dependent`` field.
</doc>
</dimensions>
</field>
<field name="envelope" type="NX_NUMBER" units="NX_ANY">
<doc>
Resulting envelope of applying the `global_fit_function` with its parameter to the data stored
in `input_independent`.
Resulting envelope of applying the `global_fit_function` with its parameter to the data stored
in `input_independent`.
</doc>
<dimensions rank="dimRank">
<doc>
The ``envelope`` field must have the same rank (``dimRank``)
as the ``input_independent`` field. Each individual dimension of ``envelope``
must have the same number of points as the corresponding dimension in
the ``input_independent`` field.
The ``envelope`` field must have the same rank (``dimRank``)
as the ``input_independent`` field. Each individual dimension of ``envelope``
must have the same number of points as the corresponding dimension in
the ``input_independent`` field.
</doc>
</dimensions>
</field>
<field name="residual" type="NX_NUMBER" units="NX_ANY">
<doc>
Difference between the envelope and the `input_independent` data to be fitted.
Difference between the envelope and the `input_independent` data to be fitted.
</doc>
<dimensions rank="dimRank">
<doc>
The ``residual`` field must have the same rank (``dimRank``)
as the ``input_independent`` field. Each individual dimension of ``residual``
must have the same number of points as the corresponding dimension in
the ``input_independent`` field.
The ``residual`` field must have the same rank (``dimRank``)
as the ``input_independent`` field. Each individual dimension of ``residual``
must have the same number of points as the corresponding dimension in
the ``input_independent`` field.
</doc>
</dimensions>
</field>
</group>
<group name="peakPEAK" type="NXpeak">
<doc>
One peak of the peak model.
If there is no characteristic name for each peak component, is envisioned that peaks
are labeled as peak_0, peak_1, and so on.
One peak of the peak model.
If there is no characteristic name for each peak component, is envisioned that peaks
are labeled as peak_0, peak_1, and so on.
</doc>
<field name="total_area" type="NX_NUMBER" units="NX_ANY">
<doc>
Total area under the curve (can also be used for the total area minus any
background values).
Total area under the curve (can also be used for the total area minus any
background values).
</doc>
</field>
<field name="relative_sensitivity_factor" type="NX_NUMBER" units="NX_UNITLESS">
<doc>
Relative sensitivity for this peak, to be used for quantification in
an NXprocess.
As an example, in X-ray spectroscopy could depend on the energy scale
(see position), the ionization cross section, and the element probed.
Relative sensitivity for this peak, to be used for quantification in
an NXprocess.

As an example, in X-ray spectroscopy could depend on the energy scale
(see position), the ionization cross section, and the element probed.
</doc>
</field>
<field name="relative_area" type="NX_NUMBER" units="NX_ANY">
<doc>
Relative area of this peak compared to other peaks.
The relative area can simply be derived by dividing the total_area by the
total area of all peaks or by a more complicated method (e.g., by
additionally dividing by the relative sensitivity factors). Details shall
be given in `global_fit_function`.
Relative area of this peak compared to other peaks.

The relative area can simply be derived by dividing the total_area by the
total area of all peaks or by a more complicated method (e.g., by
additionally dividing by the relative sensitivity factors). Details shall
be given in `global_fit_function`.
</doc>
</field>
</group>
<group name="backgroundBACKGROUND" type="NXfit_background">
<doc>
One fitted background (functional form, position, and intensities) of the peak fit.
If there is no characteristic name for each peak component, it is envisioned that backgrounds are labeled
as background_0, background_1, and so on.
One fitted background (functional form, position, and intensities) of the peak fit.
If there is no characteristic name for each peak component, it is envisioned that backgrounds are labeled
as background_0, background_1, and so on.
</doc>
</group>
<group name="global_fit_function" type="NXfit_function">
<doc>
Function used to describe the overall fit to the data, taking into account the parameters of the
individual `NXpeak` and `NXfit_background` components.
Function used to describe the overall fit to the data, taking into account the parameters of the
individual `NXpeak` and `NXfit_background` components.
</doc>
<field name="formula">
<doc>
Oftentimes, if the peaks and fit backgrounds are defined independently (i.e, with their own
parameter sets), the resulting global fit is a function of the form
:math:`model = peak_1(p_1) + peak2(p_2) + backgr(p_3).`, where each :math:`p_x` describes the
set of parameters for one peak/background.
Oftentimes, if the peaks and fit backgrounds are defined independently (i.e, with their own
parameter sets), the resulting global fit is a function of the form
:math:`model = peak_1(p_1) + peak2(p_2) + backgr(p_3).`, where each :math:`p_x` describes the
set of parameters for one peak/background.
</doc>
</field>
</group>
<group name="error_function" type="NXfit_function">
<doc>
Function used to optimize the parameters during peak fitting.
Function used to optimize the parameters during peak fitting.
</doc>
<field name="description">
<doc>
Description of the method used to optimize the parameters during peak fitting.
Examples:
- least squares
- non-linear least squares
- Levenberg-Marquardt algorithm (damped least-squares)
- linear regression
- Bayesian linear regression
Description of the method used to optimize the parameters during peak fitting.
Examples:
- least squares
- non-linear least squares
- Levenberg-Marquardt algorithm (damped least-squares)
- linear regression
- Bayesian linear regression
</doc>
</field>
<field name="formula">
<doc>
For the optimization, the formula is any optimization process on the `global_fit_function` given above.
As an example, for a linear least squared algorithm on independent components, the formula of the error_function
would be :math:`LLS(peak_1(p_1) + peak2(p_2) + backgr(p_3))`, where each :math:`p_x` describes the set
of parameters for one peak/background.
It is however also possible to supply more involved formulas (e.g., in the case of constrained fits).
For the optimization, the formula is any optimization process on the `global_fit_function` given above.
As an example, for a linear least squared algorithm on independent components, the formula of the error_function
would be :math:`LLS(peak_1(p_1) + peak2(p_2) + backgr(p_3))`, where each :math:`p_x` describes the set
of parameters for one peak/background.

It is however also possible to supply more involved formulas (e.g., in the case of constrained fits).
</doc>
</field>
</group>
<field name="figure_of_meritMETRIC" type="NX_NUMBER" units="NX_UNITLESS">
<doc>
Figure-of-merit to determine the goodness of fit, i.e., how well the peak model
fits the measured observations.
This value (which is a single number) is oftenused to guide adjustments to the
fitting parameters in the peak fitting process.
Figure-of-merit to determine the goodness of fit, i.e., how well the peak model
fits the measured observations.

This value (which is a single number) is oftenused to guide adjustments to the
fitting parameters in the peak fitting process.
</doc>
<attribute name="metric">
<doc>
Metric used to determine the goodness of fit. Examples include:
- :math:`\chi^2`, the squared sum of the sigma-weighted residuals
- reduced :math:`\chi^2`:, :math:`\chi^2`: per degree of freedom
- :math:`R^2`, the coefficient of determination
Metric used to determine the goodness of fit. Examples include:
- :math:`\chi^2`, the squared sum of the sigma-weighted residuals
- reduced :math:`\chi^2`:, :math:`\chi^2`: per degree of freedom
- :math:`R^2`, the coefficient of determination
</doc>
</attribute>
</field>
Expand Down
56 changes: 28 additions & 28 deletions contributed_definitions/NXfit_background.nxdl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
<definition xmlns="http://definition.nexusformat.org/nxdl/3.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" category="base" type="group" name="NXfit_background" extends="NXobject" xsi:schemaLocation="http://definition.nexusformat.org/nxdl/3.1 ../nxdl.xsd">
<symbols>
<doc>
The symbols used in the schema to specify e.g. dimensions of arrays.
The symbols used in the schema to specify e.g. dimensions of arrays.
</doc>
<symbol name="dimRank">
<doc>
Rank of the dependent and independent data arrays (for
multidimensional/multivariate fit.)
Rank of the dependent and independent data arrays (for
multidimensional/multivariate fit.)
</doc>
</symbol>
</symbols>
Expand All @@ -38,56 +38,56 @@
</doc>
<field name="label" type="NX_CHAR">
<doc>
Human-readable label which specifies which concept/entity
the background represents/identifies.
Human-readable label which specifies which concept/entity
the background represents/identifies.
</doc>
</field>
<group name="data" type="NXdata">
<field name="position" type="NX_NUMBER" units="NX_ANY">
<doc>
Position values along one or more data dimensions (to hold the
values for the independent variable).
Position values along one or more data dimensions (to hold the
values for the independent variable).
</doc>
<dimensions rank="dimRank">
<doc>
The ``position`` field must have the same rank (``dimRank``)
as the ``intensity`` field. Each individual dimension of ``position``
must have the same number of points as the corresponding dimension in
the ``intensity`` field.
The ``position`` field must have the same rank (``dimRank``)
as the ``intensity`` field. Each individual dimension of ``position``
must have the same number of points as the corresponding dimension in
the ``intensity`` field.
</doc>
</dimensions>
</field>
<field name="intensity" type="NX_NUMBER" units="NX_ANY">
<doc>
This array holds the intensity/count values of the fitted background
at each position.
This array holds the intensity/count values of the fitted background
at each position.
</doc>
<dimensions rank="dimRank">
<doc>
The ``intensity`` field must have the same rank (``dimRank``)
as the ``intensity`` field. Each individual dimension of ``position``
must have the same number of points as the corresponding dimension in
the ``position`` field.
The ``intensity`` field must have the same rank (``dimRank``)
as the ``intensity`` field. Each individual dimension of ``position``
must have the same number of points as the corresponding dimension in
the ``position`` field.
</doc>
</dimensions>
</field>
</group>
<group name="function" type="NXfit_function">
<doc>
The functional form of the background.
The functional form of the background.
</doc>
</group>
<attribute name="default">
<doc>
.. index:: plotting
Declares which child group contains a path leading
to a :ref:`NXdata` group.
It is recommended (as of NIAC2014) to use this attribute
to help define the path to the default dataset to be plotted.
See https://www.nexusformat.org/2014_How_to_find_default_data.html
for a summary of the discussion.
.. index:: plotting

Declares which child group contains a path leading
to a :ref:`NXdata` group.

It is recommended (as of NIAC2014) to use this attribute
to help define the path to the default dataset to be plotted.
See https://www.nexusformat.org/2014_How_to_find_default_data.html
for a summary of the discussion.
</doc>
</attribute>
</definition>
</definition>
Loading

0 comments on commit 1d13e4c

Please sign in to comment.