← All examples
48

Canonical Grid model

Weighted decay calibration

Compare known observation errors with relative weighting in a synthetic decay fit.

Scale
Small
Source
chemistry-weighted-decay.grid
Length
35 lines
Collection
Advanced language
Level
Intermediate
Runtime
Portable
chemistry-weighted-decay.grid
Get Grid
MODEL "Weighted decay calibration"
DESCRIPTION "Compare known observation errors with relative weighting in a synthetic decay fit."
TAGS "chemistry", "curve-fitting", "uncertainty"

# Synthetic heteroscedastic exponential-decay calibration.
# Time is in seconds; response and observation standard deviations are signal units.
# The generator used these known standard deviations. They are not inferred from
# residuals or a claim about experimental instrument calibration.
# Rate is per second; amplitude and baseline are signal units.
# Normal intervals are local individual-parameter approximations.
# Inspect Report, then compare RelativeReport: only the common error scale changes.

Time = [0.0, 0.15384615384615385, 0.3076923076923077, 0.46153846153846156, 0.6153846153846154, 0.7692307692307693, 0.9230769230769231, 1.076923076923077, 1.2307692307692308, 1.3846153846153846, 1.5384615384615385, 1.6923076923076925, 1.8461538461538463, 2.0, 2.153846153846154, 2.307692307692308, 2.4615384615384617, 2.6153846153846154, 2.769230769230769, 2.9230769230769234, 3.076923076923077, 3.230769230769231, 3.384615384615385, 3.5384615384615388, 3.6923076923076925, 3.8461538461538463, 4.0, 4.153846153846154, 4.307692307692308, 4.461538461538462, 4.615384615384616, 4.769230769230769, 4.923076923076923, 5.0769230769230775, 5.230769230769231, 5.384615384615385, 5.538461538461538, 5.6923076923076925, 5.846153846153847, 6.0]
Signal = [2.7168042491266204, 2.4449743613926893, 2.2521973195444067, 2.0463015607243915, 1.9300974212682391, 1.682437323906231, 1.595704384851531, 1.4196442901007624, 1.2627482743016663, 1.1325254539989023, 1.0621958806453282, 0.979542504240711, 0.9467771204089327, 0.8791731353710232, 0.804178765416521, 0.6987069834454824, 0.7054873364998074, 0.5844944746244288, 0.5837508278642196, 0.5783695092083989, 0.5848999423898574, 0.60654324611172, 0.5064690303396132, 0.4679731854720746, 0.39564067070388487, 0.4979534073394564, 0.3034110954131567, 0.34207136065810256, 0.4210586350881665, 0.41557411167428066, 0.3644151224818448, 0.5041871638270922, 0.38876718839522506, 0.3940530569397846, 0.5098147246724105, 0.49828430441606414, 0.45540661111751285, 0.2695582172414699, 0.4782370198923317, 0.41481075132622713]
ObservationSigma = [0.03, 0.031538461538461536, 0.03307692307692308, 0.03461538461538461, 0.03615384615384615, 0.03769230769230769, 0.03923076923076923, 0.04076923076923077, 0.04230769230769231, 0.04384615384615384, 0.045384615384615384, 0.04692307692307693, 0.04846153846153846, 0.049999999999999996, 0.05153846153846154, 0.05307692307692307, 0.05461538461538462, 0.05615384615384615, 0.05769230769230768, 0.05923076923076923, 0.06076923076923076, 0.0623076923076923, 0.06384615384615386, 0.06538461538461539, 0.06692307692307692, 0.06846153846153845, 0.06999999999999999, 0.07153846153846155, 0.07307692307692308, 0.07461538461538461, 0.07615384615384614, 0.07769230769230769, 0.07923076923076924, 0.08076923076923077, 0.0823076923076923, 0.08384615384615383, 0.08538461538461536, 0.08692307692307694, 0.08846153846153847, 0.09]

# Known observation errors: covariance is not rescaled by the residual scatter.
Report = CURVE_FIT.REPORT(
  (time, amplitude, rate, baseline) => amplitude*EXP(-rate*time)+baseline,
  Time, Signal, [1,1,0], 1e-12, 1000,
  {standard_deviations: ObservationSigma, uncertainty: "local_known", confidence: 0.95}
)

# Sensitivity comparison: same objective and fit, with an unknown common scale.
RelativeWeights = MAP(ObservationSigma, (sigma) => 1/(sigma*sigma))
RelativeReport = CURVE_FIT.REPORT(
  (time, amplitude, rate, baseline) => amplitude*EXP(-rate*time)+baseline,
  Time, Signal, [1,1,0], 1e-12, 1000,
  {weights: RelativeWeights, uncertainty: "local_relative", confidence: 0.95}
)

RatePerSecond = INDEX(Report.parameters, 1, 2)
RawRmse = Report.rmse
StandardizedLoss = Report.objective_value
END MODEL