optmat.solid.fitting#
Fitting a solid’s universal dispersion model to the curated data.
A fit starts from a published UDM formula of a source record (its newAD2 parameter file’s values) and frees a chosen set of its parameters. It adjusts them, by least squares, to curated n and k at their stated uncertainties:
n: refractive_index, or a refractive_index_deviation from a named formula, which the fit adds back to that formula; an index relative to room air (
parameters.index_medium = "air") is taken to vacuum with the index of that air (TC-398);k: extinction_coefficient, compared in log k, since k spans many decades;
offsets: each fitted n dataset may carry a free additive offset with a prior (its grade and temperature: silica grades differ by ~1e-5 in n, and dn/dT is ~1e-5 per kelvin);
priors: free parameters may carry priors.
The model stays causal, passive and sum-rule normalised whatever the parameters, so the
fitted dielectric function is analytic like the published one. The configuration is
data/solid/fits/<name>.toml; the result is stored as
data/solid/models/fitted/<name>.json with its covariance (TC-322).
Module Attributes
The solid fit configurations. |
Functions
|
Serialise a fit result as JSON text. |
|
Fit the configuration's free UDM parameters to its datasets. |
|
Load a solid fit configuration. |
|
Compare the fitted model with each validator dataset. |
Classes
|
How one curated dataset enters a fit. |
|
A solid fit's configuration. |
|
A fitted model with its statistics. |
- class optmat.solid.fitting.DatasetOptions(key, range_nm=(0.0, inf), sigma=None, extra=0.0, offset_sigma=None, offset_group='', reference='', thermo_optic='', temperature_k=None)[source]#
Bases:
objectHow one curated dataset enters a fit.
- Attributes:
- keystr
source/dataset.- range_nmtuple of float
The vacuum-wavelength window used, nm.
- sigmafloat or None
Uncertainty used where the dataset states none (n: absolute; k: relative).
- extrafloat
Added in quadrature to every point’s uncertainty (same units as
sigma).- offset_sigmafloat or None
The prior (one sigma) of a free additive offset in n; None for no offset.
- offset_groupstr
Datasets naming the same group share one offset (a common reference level, such as whether a source’s n is relative to air); empty for the dataset’s own.
- referencestr
For a refractive_index_deviation, the formula model it is relative to.
- thermo_opticstr
A thermo_optic_coefficient dataset (
source/dataset) that takes the values from their sample temperature totemperature_k, interpolated in wavelength; empty for none.- temperature_kfloat or None
The temperature the fit refers to, K, for
thermo_optic.
- optmat.solid.fitting.FIT_DIRECTORY: Final = PosixPath('/home/docs/checkouts/optmat/checkouts/7/src/optmat/data/solid/fits')#
The solid fit configurations.
- class optmat.solid.fitting.FitConfig(name, material, description, range_nm, start, free, scales=<factory>, added_attributes=(), added_values=<factory>, priors=<factory>, fitted=(), validators=(), digest='')[source]#
Bases:
objectA solid fit’s configuration.
- Attributes:
- namestr
The configuration’s name (its file stem).
- materialstr
The material’s id.
- descriptionstr
What the fit is and why.
- range_nmtuple of float
The range the fitted model supports, nm.
- startstr
The starting UDM formula,
<source>/<formula id>of a curated source whose formula holds a newAD2 parameter file’s values as its terms.- freetuple of str
The freed parameters, in newAD2’s names.
- scalesdict of str to tuple of str
Groups of parameters multiplied by one fitted factor each (the OH bands of a grade, say), by the group’s name.
- added_attributestuple of str
Terms added to the start model (
loc=1adds one Gaussian peak).- added_valuesdict of str to float
The added terms’ starting parameters.
- priorsdict of str to tuple of float
Priors (value, sigma) on free parameters.
- fitted, validatorstuple of DatasetOptions
The fitted datasets and the datasets only compared.
- digeststr
The configuration file’s SHA-256.
- fitted: tuple[DatasetOptions, ...] = ()#
- validators: tuple[DatasetOptions, ...] = ()#
- class optmat.solid.fitting.FitResult(config, attributes, values, covariance, offsets, chi2, dof, dataset_chi2)[source]#
Bases:
objectA fitted model with its statistics.
- Attributes:
- configFitConfig
The configuration.
- attributestuple of str
The UDM’s attributes.
- valuesdict of str to float
Every UDM parameter, fitted or fixed.
- covariancenumpy.ndarray
The covariance of the free parameters, then of the group scales, then of the offsets (in their own units), Birge-scaled when the reduced chi-squared exceeds 1.
- offsetsdict of str to float
The fitted n offset of each dataset that has one.
- chi2float
The total chi-squared, priors included.
- dofint
Degrees of freedom.
- dataset_chi2dict of str to tuple
Points and chi-squared of each fitted dataset.
- covariance: Float[ndarray, 'p p']#
- property model: UniversalDispersionModel#
The fitted UDM.
- Returns:
- UniversalDispersionModel
The model at the fitted parameters.
- optmat.solid.fitting.dumps(result)[source]#
Serialise a fit result as JSON text.
- Parameters:
- resultFitResult
The result.
- Returns:
- str
Indented JSON: the full parameter set, the covariance of the free parameters, the statistics and the configuration’s digest.
- optmat.solid.fitting.fit(config)[source]#
Fit the configuration’s free UDM parameters to its datasets.
- Parameters:
- configFitConfig
The configuration.
- Returns:
- FitResult
The fitted model, covariance and statistics.