Skip to content

Latest commit

 

History

History
75 lines (61 loc) · 2.97 KB

README.md

File metadata and controls

75 lines (61 loc) · 2.97 KB

Covar.jl

Introduction

Covar.jl allows for the representation of correlated variables with uncertainties, which are described by their covariance matrices. It allows for easy propagation of these uncertainties, thanks to Julia's convenient method overloading, even for different covariant systems and also supports different types of floating-point numbers.

Usage

The easiest way to construct a covariant system is with the @covar_system macro. The following creates a CovariantSystem with values [2., 3.] and covariance matrix [.3 .1; .1 .4] and assignes a and b their corresponding CovariantVar:

julia> a, b = @covar_system [2., 3.] [.3 .1; .1 .4]
2-element Array{CovariantVar{Float64},1}:
 x_1 = 2.0 ± 0.5477225575051661
  Vₘ = [0.3 0.1; 0.1 0.4]
 x_2 = 3.0 ± 0.6324555320336759
  Vₘ = [0.3 0.1; 0.1 0.4]

All basic operations on these variables are supported:

julia> a^2 + 2b + 1
f({xᵢ}) = 11.0 ± 2.8284271247461903

Operations on CovariantVars automatically generate a DerivedVar, which contains the corresponding value, the gradients with respect to their systems and the CovariantSystems themselves. The gradients propagate according to the chain rule:

The error is then calculated with the following formula:

Covar.jl also supports operations between multiple different CovariantSystems. The variables in one system are then treated as independent from the ones from other systems:

julia> c, d, e = @covar_system [5., 2., 3.] [1.2 .3 .1; .3 .5 .2; .1 .2 .6]
3-element Array{CovariantVar{Float64},1}:
 x_1 = 5.0 ± 1.0954451150103321
  Vₘ = [1.2 0.3 0.1; 0.3 0.5 0.2; 0.1 0.2 0.6]
 x_2 = 2.0 ± 0.7071067811865476
  Vₘ = [1.2 0.3 0.1; 0.3 0.5 0.2; 0.1 0.2 0.6]
 x_3 = 3.0 ± 0.7745966692414834
  Vₘ = [1.2 0.3 0.1; 0.3 0.5 0.2; 0.1 0.2 0.6]

julia> a * c - sin(d + b) * e
f({xᵢ}) = 12.876772823989416 ± 2.1793998471976033

The following also works like you would expect:

julia> sin(a * c)^2 + cos(c * a)^2
f({xᵢ}) = 1.0 ± 0.0

The methods val and err return the value or error of either a CovariantVar or DerivedVar:

julia> x = a^2 + 3b
f({xᵢ}) = 13.0 ± 3.286335345030997

julia> val(x), err(x)
(13.0, 3.286335345030997)

TODO

  • Write Tests
  • Add support for SpecialFunctions and NaNMath via Require.jl
  • Interoperability with Measurements.jl?