measure

    Physical measurement & uncertainty evaluation library for MoonBit

    measurement
    uncertainty
    physics
    error-propagation
    sigfig
    lab-report
    Download zip
    Author
    Version
    0.1.2
    License
    Apache-2.0
    Last updated
    2 months ago
    Downloads
    41

    No dependencies

    #moonbit-measure

    MoonBit License CI

    moonbit-measure is a MoonBit library for physical measurement, uncertainty evaluation, calibration, scientific regression, and reproducible laboratory reports. It combines a small high-level measurement API with reusable numerical packages for applications that need checked results rather than ad-hoc scripts.

    #Highlights

    • Type A and Type B uncertainty evaluation, coverage factors, and Welch–Satterthwaite effective degrees of freedom.
    • Deterministic Monte Carlo propagation with normal, uniform, and triangular distributions.
    • Linear, weighted, and polynomial regression with residual and confidence-band helpers.
    • Dense matrix operations, pivoted solves, QR least squares, Cholesky decomposition, and symmetric eigenvalue estimation.
    • Linear, Newton, cubic-spline, barycentric, bilinear, and trilinear interpolation.
    • Descriptive, weighted, robust, covariance, correlation, histogram, and model error statistics.
    • Monotonic piecewise-linear and polynomial calibration models with diagnostics, tolerance checks, and leave-one-out quality estimates.
    • Markdown, LaTeX, and HTML measurement-table exporters.

    #Package map

    PackagePurpose
    src/measureFacade API for common measurement workflows
    src/typesQuantities, instruments, uncertainty components, and shared records
    src/uncertaintyPropagation, Monte Carlo simulation, and effective degrees of freedom
    src/regressionLinear, weighted, polynomial, and confidence-band fitting
    src/matrixChecked dense linear algebra and decompositions
    src/interpolationOne-dimensional, grid, spline, and barycentric interpolation
    src/statisticsSummaries, robust statistics, covariance, and model metrics
    src/calibrationInstrument response calibration and diagnostics
    src/unitsSI dimensions, unit parsing, and conversions
    src/sigfigSignificant-figure rounding and formatted results
    src/exporterMarkdown, LaTeX, and HTML report tables

    #Quick start

    The facade package keeps the common path concise:

    let readings = [5.01, 5.02, 5.00, 5.03]
    let result = @measure.measure_sample(
    "Voltage",
    readings,
    resolution=0.01,
    unit="V",
    )
    println(@measure.format_result(result))

    The numerical packages can be used independently for calibration and analysis:

    let reference = [0.0, 10.0, 20.0]
    let observed = [0.0, 10.5, 19.0]
    let curve = @calibration.CalibrationCurve::fit(reference, observed).unwrap()
    let corrected = curve.correct(10.5).unwrap()
    let quality = curve.diagnostics(0.75).unwrap()

    For a matrix-backed polynomial calibration:

    let model = @calibration.PolynomialCalibration::fit(
    [0.0, 1.0, 2.0, 3.0],
    [1.0, 2.1, 5.2, 10.3],
    2,
    ).unwrap()
    let predicted = model.predict(1.5)

    Package imports are declared in moon.pkg; the default aliases follow the package names shown in the package map.

    #Installation

    Add the published module to a MoonBit project with:

    moon add wjyupl/measure@0.1.2

    The module is also usable directly from a checkout for development and experimentation.

    #Validation

    The project is checked with the stable MoonBit toolchain:

    moon fmt --check moon info moon check --deny-warn moon test --deny-warn

    To validate all available backends when supported by the installed toolchain:

    moon check --target all --deny-warn moon test --target all --deny-warn

    The deterministic native benchmark can be reproduced locally:

    powershell -NoProfile -ExecutionPolicy Bypass -File .\tools\run-benchmarks.ps1 -Runs 5

    See docs/benchmarks.md for benchmark reproducibility and docs/benchmark-results.md for the latest generated measurement record. Benchmark timings are specific to the machine and toolchain that produced them.

    #Repository layout

    moonbit-measure/ ├── .github/workflows/check.yml # cross-platform formatting, checks, tests, coverage ├── cmd/benchmarks/ # deterministic native benchmark workload ├── docs/ # reproducibility and benchmark records ├── src/ # library packages and tests ├── tools/ # local benchmark scripts ├── LICENSE # Apache License 2.0 ├── moon.mod # MoonBit module metadata └── README.md

    #Development notes

    New numerical APIs should return a typed error when an input is malformed, document assumptions at the public boundary, and include tests for empty, degenerate, out-of-range, and mismatched inputs. Keep generated package interfaces in sync with moon info, and run the local benchmark after changing hot numerical paths.

    #License

    This project is distributed under the Apache License 2.0.