Browse documentation
Guides

Shared calibration sensor fusion

A complete sensor example preserving shared calibration, independent reading noise, aliases and frozen affine measurement propagation.

Two temperature sensors share a calibration procedure. Averaging their readings can reduce independent reading noise, but cannot remove the calibration term they share. Treating copied or gathered readings as independent would give an unjustified variance.

The native EvidenceTensor retains an explicitly declared source model through supported affine operations. Unknown uncertainty, exact values and measured uncertainty are separate states; a variance is not a prediction confidence score or an inferred probability distribution.

Dataset and complete runnable program

The entire deterministic fixture is in the program. Readings are 20 and 22 degC. Each has independent reading standard deviation 0.2 and shared calibration standard deviation 0.3. The constructor explicitly declares that reading noises are mutually independent and independent of the shared calibration source.

sh
aner check examples/contextual_sensors.aner
aner run examples/contextual_sensors.aner
aner
// Independent reading noise and one shared calibration term are declared.
import aner.tensor
import aner.science

let readings = science.calibrated([[20.0], [22.0]], "degC",
    noise_stddev: 0.2, calibration_stddev: 0.3)
let first = readings.gather_rows(List(0))
let second = readings.gather_rows(List(1))
let fused = science.mean(first, second)
let difference = first.subtract(second)
let self_difference = first.subtract(first)
let duplicated_mean = science.mean(first, first)
let kelvin = fused.convert("K")

print("Fused mean in degrees Celsius")
print(fused.item())
print("Fused variance is 0.11 within tolerance")
print(fused.variance() > 0.109999999999 && fused.variance() < 0.110000000001)
print("Difference mean and variance 0.08 within tolerance")
print(difference.item())
print(difference.variance() > 0.079999999999 && difference.variance() < 0.080000000001)
print("The same observation cancels its own uncertainty")
print(self_difference.variance())
print("Duplicating one observation does not create independent noise")
print(duplicated_mean.variance() > 0.129999999999 && duplicated_mean.variance() < 0.130000000001)
print("Kelvin conversion preserves physical uncertainty")
print(kelvin.item() > 294.149999999 && kelvin.item() < 294.150000001)
print(kelvin.variance() > 0.109999999999 && kelvin.variance() < 0.110000000001)

// A frozen affine physical relationship propagates input measurement noise.
// This is neither training nor uncertainty in learned model parameters.
let length = science.calibrated([[20.0]], "m", 0.2, 0.3)
let force = length.affine(slope: 2.0, intercept: 1.0, slope_unit: "N/m", output_unit: "N")
print("Frozen relationship y = 2*x + 1")
print(force.item())
print(force.unit())
print("Propagated input-noise variance is 0.52 within tolerance")
print(force.variance() > 0.519999999999 && force.variance() < 0.520000000001)

Expected output

text
Fused mean in degrees Celsius
21.0
Fused variance is 0.11 within tolerance
true
Difference mean and variance 0.08 within tolerance
-2.0
true
The same observation cancels its own uncertainty
0.0
Duplicating one observation does not create independent noise
true
Kelvin conversion preserves physical uncertainty
true
true
Frozen relationship y = 2*x + 1
41.0
N
Propagated input-noise variance is 0.52 within tolerance
true

The fused mean is 21 with variance 0.11. The difference is −2 with variance 0.08. An observation cancels its own sources when subtracted from itself. Duplicating that observation preserves variance 0.13. Conversion of the fused mean to Kelvin gives 294.15 K and variance 0.11 K².

The final frozen physical relationship demonstrates the affine reference from the measurement aware regression case: mean length 20 m and variance 0.13 m² produce mean force 41 N and variance 0.52 N² under y = 2*x + 1. This propagates input measurement noise; it does not train a neural network or quantify uncertainty in learned parameters.

Intentional failure: invalid uncertainty

Download the negative program. It checks successfully and must fail at construction.

aner
// Intentional failure: a standard deviation is a finite nonnegative quantity.
import aner.tensor
import aner.science
let forbidden = science.calibrated([[20.0], [22.0]], "degC", -0.2, 0.3)

Expected diagnostic: a located error[R3503] containing standard deviation. Supply a finite nonnegative standard deviation in the appropriate difference unit; unknown uncertainty must be represented explicitly rather than using a negative sentinel.

Why the structure helps

The source relationship is part of the supported value, so gather, alias and affine arithmetic preserve the same calibration and reading identities. Shared error terms contribute covariance instead of being forgotten when a result crosses a numerical helper. The researcher sees which uncertainty was declared and which operations can propagate it.

Dependencies, backends and limitations

Use the compatible native development engine with aner.tensor, aner.science and VS Code helper 0.1.38 or newer. The initial evidence kernels run CPU Float64. Native evidence/source map persistence is future functionality; the fitted preprocessing/model persistence demonstrated in the building energy guide is a different supported artifact contract. No external dataset, network, GPU or stochastic sampler is needed. The EvidenceTensor reference specifies source model limits and time/space complexity.

General nonlinear propagation, arbitrary covariance operators, Monte Carlo distributions, GPU evidence kernels and uncertainty aware neural training remain future functionality. A values only model boundary requires explicit acknowledgement that evidence was not consumed. The complete source, expected output and intentional diagnostic above are checked in automated tests.

Aner documentation · Reference and guides