Fit - inequality constraint
[1]:
import nexus as nx
#import numpy as np
[2]:
# load example spectrum
detuning, intensity = nx.data.Load("spectrum_equality.txt",
x_index = 0,
intensity_index = 1)
[3]:
#setup fit parameters
isomer = nx.Var(0.8, min = 0, max = 2, fit = True, id="isomer")
# assign to sites
site1 = nx.Hyperfine(
id = "site 1",
weight = 0.5,
isomer = isomer,
magnetic_field = nx.Var(value = 32, min = 0, max = 35, fit = True, id = "mag field 1"),
isotropic = False)
site2 = nx.Hyperfine(
id = "site 2",
weight = 0.5,
isomer = isomer,
magnetic_field = nx.Var(value = 14, min = 0, max = 35, fit = True, id = "mag field 2"),
isotropic = False)
mat_Fe = nx.Material.Template(nx.lib.material.Fe_enriched)
mat_Fe.hyperfine_sites = [site1, site2]
#create sample
lay_Fe = nx.Layer(id = "Fe",
material = mat_Fe,
thickness = 2800)
sample = nx.Sample(id = "sample",
layers = [lay_Fe],
geometry = "f")
beam = nx.Beam()
beam.LinearSigma()
exp = nx.Experiment(beam = beam,
objects = [sample],
isotope = nx.moessbauer.Fe57,
id = "my exp")
energy_spec = nx.EnergySpectrum(exp,
detuning,
intensity_data = intensity,
id = "energy spec")
[4]:
fit = nx.Fit([energy_spec],
inequalities = [lambda: site1.magnetic_field.value < site2.magnetic_field.value])
fit.options.method = "PagmoDiffEvol"
fit()
Run Fit instance with id:
Starting fit with 1 measurement data set(s) and 5 fit parameter(s):
no. | id | initial value | min | max
0 | ES scaling | 88229.4 | 1e-16 | 8.82294e+06
1 | ES backgr | 7794.22 | 0 | 779422
2 | isomer | 0.8 | 0 | 2
3 | mag field 1 | 32 | 0 | 35
4 | mag field 2 | 14 | 0 | 35
Using 0 equality constraint(s) on parameter(s):
Using 1 inequality constraint(s).
Calling Pagmo solver with fit method PagmoDiffEvol
population: 60
iterations: 100
cost = 9.002691e+02
Calling ceres solver with fit method LevMar
Ceres Solver Report: Iterations: 5, Initial cost: 9.002691e+02, Final cost: 3.548515e+02, Termination: CONVERGENCE
Gradient error analysis.
Fit performed with algorithm:
PagmoDiffEvol
Local algorithm:
LevMar
Error analysis:
Gradient
Using 5 fit parameter(s):
no. | id | fit value | +/- std dev | initial value | min | max
0 | ES scaling | 100296 | 229.737 | 88229.4 | 1e-16 | 8.82294e+06
1 | ES backgr | 0 | 175.298 | 7794.22 | 0 | 779422
2 | isomer | 1.00025 | 0.000493408 | 0.8 | 0 | 2
3 | mag field 1 | 9.99384 | 0.00649243 | 32 | 0 | 35
4 | mag field 2 | 33.0021 | 0.00655228 | 14 | 0 | 35
Values at boundaries:
ES backgr at LOWER boundary: 0
Correlation matrix:
no. | 0 1 2 3 4
-----|---------------------------------------------
0 | 1.000 -0.978 0.001 0.052 -0.002
1 | -0.978 1.000 -0.001 -0.054 0.003
2 | 0.001 -0.001 1.000 0.002 0.001
3 | 0.052 -0.054 0.002 1.000 0.009
4 | -0.002 0.003 0.001 0.009 1.000
Using 0 equality constraint(s) on parameter(s):
and 1 inequality constraint(s).
Total cost = 1.770e+00
cost for each FitMeasurement is:
no. | id | cost | %
0 | energy spec | 1.770e+00 | 100.000
Fit instance with id "" finished.
[5]:
energy_spec.Plot()