Browse documentation
aner.science · Reference

EvidenceTensor

Declared unknown, exact and source aware affine uncertainty with preserved calibration correlations, explicit projections and bounded CPU execution.

Implemented

EvidenceTensor is an opt in native scientific value with an explicit uncertainty model and retained source identity. Import aner.science. The initial implementation supports unknown uncertainty, explicitly exact values and a bounded source aware affine model. Unknown uncertainty is not zero uncertainty.

Shared calibration sensor fusion is the complete runnable introduction. Two sensor readings share a calibration term. Averaging them preserves that common term; subtracting them cancels it. Copying or gathering an observation does not create a new independent measurement.

Return to the aner.science module guide for the complete workflow, runnable introduction and API map. This page is the detailed value reference. It complements SemanticTensor, which covers coordinates and units without adding measurement uncertainty.

Constructor and readout contracts

All evidence constructors require frozen CPU Float64 values. A differentiable Tensor, accelerator resident value or Float32 value fails instead of being implicitly detached, moved or cast. The nominal SemanticTensor must have one homogeneous physical unit; contextual feature matrices with heterogeneous feature units are not one measurement quantity.

science.calibrated accepts an n × 1 Tensor and generates a row identity for each observation. It declares one independent reading noise source per row plus one common calibration source, with the noise and calibration mutually independent. Repeated calibrated calls have unrelated opaque source registries even when their display settings match. To combine related readings, gather from the one declaration.

science.exact(values) explicitly declares zero uncertainty. science.unknown(values) leaves it unspecified: item, unit, summary, explain, gathering and acknowledged nominal export remain useful, while variance, covariance, conversion and arithmetic that require quantified source propagation reject the unknown model. Passing 0.0 to a measurement constructor declares zero error; it does not mean unknown.

The no index item(), variance() and standard_uncertainty() forms require shape 1 × 1. Indexed variance and standard uncertainty accept a nonnegative zero based row and column. covariance reads the specified cells in its two operands; it requires a known joint source relationship but does not require those cells to have identical nominal values. mean(a, b) averages two compatible values elementwise rather than reducing all rows in one value.

Declared calibration model

science.calibrated(values, unit, noise_stddev, calibration_stddev) declares independent reading noise for each observation and one shared calibration source. Standard deviations must be finite and nonnegative, in the corresponding difference unit. This independence and shared calibration model is an explicit constructor assumption, not a conclusion inferred from the data.

For readings 20 and 22 degC, reading standard deviation 0.2 and calibration standard deviation 0.3:

  • Each variance is 0.2² + 0.3² = 0.13.
  • Shared covariance is 0.3² = 0.09.
  • Their mean is 21, with variance (0.13 + 0.13 + 2*0.09)/4 = 0.11.
  • Their difference is −2, with variance 0.13 + 0.13 − 2*0.09 = 0.08.

Source identity survives gather, copying and registered affine operations. The difference of an observation from itself has zero variance. The mean of the same observation twice retains variance 0.13; it does not gain independent information merely by being duplicated.

Supported propagation and units

Supported source aware addition, subtraction, mean and unit conversion use the joint affine source model. When values carry fitted scientific context, the same bounded 64 record registered operation history applies, including merged branches; exceeding it fails with E_RESOURCE_BUDGET without changing earlier values. This history does not replace a general replayable provenance graph. Absolute temperature arithmetic follows the SemanticTensor rules. Converting the fused mean to Kelvin gives 294.15 K and retains variance 0.11 K²: an offset does not change uncertainty, and a scale multiplies variance by its square.

The shared registry also supports scalar quantities and points through aner.units in Aner 0.0.4 or newer. 20.0@degC carries a checked scalar unit; it does not declare measurement uncertainty, source identity or coordinates. Packed unit bearing arrays likewise retain physical units without declaring measurement uncertainty; their population spread is not a source aware error model. Evidence constructors retain their explicit raw Float64/Tensor and unit String signatures. Exporting a scalar .value() or an evidence nominal value does not transfer an uncertainty model into that number.

The registry also supports cm, mm, degF and delta_degF. Fahrenheit standard deviations are intervals: science.calibrated(values, "degF", noise_stddev, calibration_stddev) interprets both deviations in delta_degF. Converting nominal Fahrenheit points to Celsius applies the offset, while uncertainty loadings scale by 5/9 and variances by 25/81. A standard deviation is never shifted by a temperature offset.

For example, these two readings use independent noise of 1.8 delta_degF and a shared calibration deviation of 0.9 delta_degF:

aner
import aner.tensor
import aner.science

let readings = science.calibrated([[32.0], [68.0]], "degF", 1.8, 0.9)
let first = readings.gather_rows(List(0))
let second = readings.gather_rows(List(1))
let fused = science.mean(first, second).convert("degC")
let difference = second.subtract(first).convert("delta_degC")

print(fused.item() > 9.999999999 && fused.item() < 10.000000001)
print(fused.variance() > 0.749999999 && fused.variance() < 0.750000001)
print(difference.item() > 19.999999999 && difference.item() < 20.000000001)
print(difference.variance() > 1.999999999 && difference.variance() < 2.000000001)
print(difference.unit())

Expected output is four true lines followed by delta_degC. Save the source as fahrenheit_evidence.aner, then run aner check fahrenheit_evidence.aner and aner run fahrenheit_evidence.aner. The converted point mean is 10 degC with variance 0.75 delta_degC²; the difference is 20 delta_degC with variance 2 delta_degC². The shared calibration remains in the mean and cancels in the difference. Source coefficient declarations require error_unit: "delta_degF" for Fahrenheit deviations; "degF" is an absolute point and is rejected as an error unit.

A declared affine relationship can propagate measurement uncertainty exactly under this model. The tutorial's frozen y = 2*x + 1 relationship uses a length input in meters, slope in N/m and output in N. Input mean 20 and variance 0.13 yield output mean 41 and variance 0.52. This result describes propagated input measurement noise, not uncertainty in trained model parameters.

Advanced source declarations and coefficient maps require explicit independence assumptions and compatible source definitions. Distinct unresolved source registries remain correlation unknown. The implementation must refuse operations whose correlations it cannot represent; it does not silently diagonalize a covariance or choose a probability distribution.

Explicit source coefficients

science.measurements accepts a homogeneous SemanticTensor, a List of unique source name Strings, a same length List of finite nonnegative Float64 standard deviations, and a frozen CPU Float64 coefficient Tensor. independence must be exactly "independent"; this is a declaration by the caller. The coefficient shape is (rows × columns) × source_count, with scalar values flattened in row major order. A coefficient is a dimensionless loading for its source. error_unit must be a supported difference unit with the same physical dimension as the measurement; use delta_degC for Celsius measurement error or delta_degF for Fahrenheit error, never absolute degC or degF.

For two readings and three sources, rows [1, 1, 0] and [1, 0, 1] retain the common calibration source while assigning each reading its own noise source. Gathered values keep the registry; separately constructing a registry with the same names does not establish a known cross correlation. Zero coefficients consume no active source map entry.

Run the complete source coefficient example:

sh
aner check examples/science_sources.aner
aner run examples/science_sources.aner
aner
// An explicit coefficient matrix declares which independent sources affect each value.
import aner.tensor
import aner.science

let nominal = tensor.semantic([[20.0], [22.0]], "sensor", List("A", "B"), "degC")
let measured = science.measurements(nominal,
    List("calibration", "reading_A", "reading_B"), List(0.3, 0.2, 0.2),
    [[1.0, 1.0, 0.0], [1.0, 0.0, 1.0]], "delta_degC", "independent")
print("Variance at sensor A is 0.13 within tolerance")
let variance = measured.variance(0, 0)
print(variance > 0.129999999999 && variance < 0.130000000001)
print("Shared covariance is 0.09 within tolerance")
let covariance = science.covariance(measured, 0, 0, measured, 1, 0)
print(covariance > 0.089999999999 && covariance < 0.090000000001)
print("Each value retains two active source coefficients")
print(measured.source_entries())
print("Exact and unknown declarations preserve the nominal value")
let exact = science.exact(nominal.gather_rows(List(0)))
let unknown = science.unknown(nominal.gather_rows(List(0)))
print(exact.item())
print(exact.variance())
print(unknown.item())
// unknown.variance() would fail: unknown uncertainty cannot be interpreted as zero.
let exported = measured.export_values("Inspect nominal values with a values-only numerical tool")
print("The acknowledged export has two numeric rows")
print(tensor.rows(exported.values()))
print(tensor.value(exported.values(), 1, 0))

Expected output:

text
Variance at sensor A is 0.13 within tolerance
true
Shared covariance is 0.09 within tolerance
true
Each value retains two active source coefficients
4
Exact and unknown declarations preserve the nominal value
20.0
0.0
20.0
The acknowledged export has two numeric rows
2
22.0

source_entries() is four because each of the two scalar readings retains two nonzero loadings. source_bytes() reports allocated vector storage, so its exact numeric value depends on the implementation and is not used as a portable output oracle.

Model and numerical boundaries

A normal numerical Tensor or ordinary NN objective does not consume uncertainty automatically. A values only projection requires an explicit reason and records that evidence was not consumed. Existing autodifferentiation computes optimization derivatives; it is separate from the evidence model.

A variance does not specify a Gaussian distribution, confidence interval, quality score or predictive probability. Quality flags, sampling weights and observation precision require separate contracts. No unsupported nonlinear model uncertainty or universal NN uncertainty propagation is claimed.

Native API signatures

Qualified functions and the corresponding recognized receiver methods use the same native contracts. self denotes the receiver in the qualified signature. Lists of names or units contain Strings; index lists contain Int64 values. Wrong List element types fail instead of coercing values.

Native signatureResult
science.summary(self: EvidenceTensor)String
science.explain(self: EvidenceTensor)String
science.calibrated(values: Tensor, unit: String, noise_stddev: Float64, calibration_stddev: Float64)EvidenceTensor
science.measurements(values: SemanticTensor, source_names: List, stddevs: List, coefficients: Tensor, error_unit: String, independence: String)EvidenceTensor
science.exact(values: SemanticTensor)EvidenceTensor
science.unknown(values: SemanticTensor)EvidenceTensor
science.item(self: EvidenceTensor)Float64
science.variance(self: EvidenceTensor)Float64
science.variance(self: EvidenceTensor, row: Int64, column: Int64)Float64
science.standard_uncertainty(self: EvidenceTensor)Float64
science.standard_uncertainty(self: EvidenceTensor, row: Int64, column: Int64)Float64
science.unit(self: EvidenceTensor)String
science.gather_rows(self: EvidenceTensor, indices: List)EvidenceTensor
science.add(self: EvidenceTensor, other: EvidenceTensor)EvidenceTensor
science.subtract(self: EvidenceTensor, other: EvidenceTensor)EvidenceTensor
science.mean(self: EvidenceTensor, other: EvidenceTensor)EvidenceTensor
science.convert(self: EvidenceTensor, unit: String)EvidenceTensor
science.affine(self: EvidenceTensor, slope: Float64, intercept: Float64, slope_unit: String, output_unit: String)EvidenceTensor
science.export_values(self: EvidenceTensor, reason: String)ContextExport
science.source_entries(self: EvidenceTensor)Int64
science.source_bytes(self: EvidenceTensor)Int64
science.covariance(self: EvidenceTensor, row: Int64, column: Int64, other: EvidenceTensor, other_row: Int64, other_column: Int64)Float64

Diagnosing rejected operations

Scientific runtime failures use a located R3503 diagnostic containing the semantic failure code. Static type/import errors are caught before execution. Use the constructor and operation contracts to fix the declared model rather than stripping evidence to suppress an error.

Semantic codeTypical cause and correction
E_AXIS_ALIGNMENTWrong coefficient shape, incompatible ordered coordinate domains or an out of range cell/row. Match the complete declared dimensions and domain. Untracked scalar evidence has a supported derived scalar compatibility rule; larger values require exact compatible axes.
E_UNIT_INCOMPATIBLEUnsupported unit name or incompatible physical dimensions. Use the bounded unit registry and explicitly compatible conversion/output units.
E_AFFINE_QUANTITYTreating an absolute temperature as a difference, adding two absolute temperatures, or using one in a physical affine map. Use the supported temperature mean/subtraction and difference units.
E_CORRELATION_UNKNOWNUnknown uncertainty, a missing explicit independence declaration, or combining distinct unresolved source registries. Keep related values in one source declaration.
E_EVIDENCE_UNSUPPORTEDNegative standard deviation or a differentiable constructor input. Declare nonnegative error scales and frozen values explicitly.
E_BACKEND_UNSUPPORTEDFloat32 or accelerator resident evidence input. Prepare CPU Float64 values deliberately.
E_ARTIFACT_INTEGRITYDuplicate or malformed source names, or control characters in scientific metadata. Supply unique valid bounded UTF-8 labels.
E_NUMERICNonfinite arithmetic, overflowing source variance or underflowing nonzero coefficients. Rescale the physical model explicitly.
E_RESOURCE_BUDGETCell, source, active loading, metadata or contextual operation limits. Reduce the operation to the supported bounded model.

The sensor fusion application includes an executable negative standard deviation example with its expected diagnostic. General error recovery is described by the language's normal program/runtime behavior; these operations do not return partially valid evidence.

Time and space complexity

Let n be scalar values, s declared base sources and a active sparse source coefficients. A full covariance matrix is not constructed by default.

OperationTimeAdditional space
Declare calibrated readingsO(n)O(n) values/source coefficients and source descriptors
Affine add/subtract/meanO(n + a) plus source compatibility checksO(n + a) output and retained source coefficients
Gather or duplicate selected rowsO(n + a) for selected outputO(n + a) selected values and coefficients
Unit conversion or frozen affine mapO(n + a)O(n + a) output values and scaled coefficients
Scalar varianceO(aᵢ) for that scalar's active sourcesO(1) reduction state
Covariance of two scalarsO(aᵢ + aⱼ) with sorted source mapsO(1) reduction state

The initial affine representation admits at most 65,536 cells and 262,144 active source coefficients. The general explicit source constructor admits at most 4,096 base sources. Nonzero uncertainty must not silently become exact through Float64 range loss. Unrepresentable source variances, overflowing variance arithmetic or underflowing nonzero scaled source coefficients fail rather than rounding a declared nonzero error model to certainty.

Source map memory is inspectable and bounded: source_bytes() reports allocated vector buffers including capacities, excluding source registry data, Strings, allocator bookkeeping and process RSS. A hypothetical dense covariance costs O(n²), but that is not a promise that arbitrary covariance matrices are supported by this release.

Dependencies, backends and limitations

Use Aner 0.0.4 or newer and VS Code helper 0.1.38 or newer. The current evidence kernels use CPU Float64; they require no external uncertainty service, GPU or stochastic sampler. The complete sensor fixture lives in its source program.

Native evidence/source-map persistence, GPU evidence kernels, general covariance operators, joint Monte Carlo, nonlinear uncertainty propagation and uncertainty aware neural training are future functionality. Ordinary compatible Tensor accelerator support does not imply support for these evidence operations. Unsupported propagation returns a clear diagnostic rather than discarding uncertainty.

Aner documentation · Reference and guides