Real-time data reconciliation and gross error detection #367
Replies: 3 comments 5 replies
-
What you are trying to do should be possible in @model function error_correction(y)
x[1] ~ NormalMeanVariance(y[1], 1)
x[2] ~ NormalMeanVariance(y[2], 1)
x[3] ~ NormalMeanVariance(y[3], 1)
x[3] := x[1] + x[2]
end Here we have some noisy observations @model function error_correction(y, n_1_shape, n_1_rate, n_2_shape, n_2_rate, n_3_shape, n_3_rate)
n_1 ~ GammaShapeRate(n_1_shape, n_1_rate)
x[1] ~ NormalMeanPrecision(y[1], n_1)
n_2 ~ GammaShapeRate(n_2_shape, n_2_rate)
x[2] ~ NormalMeanPrecision(y[2], n_2)
n_3 ~ GammaShapeRate(n_3_shape, n_3_rate)
x[3] ~ NormalMeanPrecision(y[3], n_3)
x[3] := x[1] + x[2]
end I've added a lot of arguments to this model that govern the prior distribution over the noise distribution. That is because I want to move towards the real-time part of your question. I want to incorporate the example here , such that this model can perform inference on an infinite stream of data. For this we also need to define how the prior over noise is updated over time. Since we are also inferring noise of a Gaussian distribution now, we have to initialize constraints, and we have to give an initial value for the noise parameters in order to kickstart inference: updates = @autoupdates begin
n_1_shape = shape(q(n_1))
n_1_rate = rate(q(n_1))
n_2_shape = shape(q(n_2))
n_2_rate = rate(q(n_2))
n_3_shape = shape(q(n_3))
n_3_rate = rate(q(n_3))
end
initialization = @initialization begin
q(n_1) = GammaShapeRate(1, 1)
q(n_2) = GammaShapeRate(1, 1)
q(n_3) = GammaShapeRate(1, 1)
end
constraints = @constraints begin
q(n_1, n_2, n_3, x) = MeanField()
end
RxInfer.is_data(x::Vector{RxInfer.GraphVariableRef}) = RxInfer.is_data(first(x)) I snuck this last line in there to make this example work. This is a known issue in observations = [[rand(Normal(0, 1)) for _ in 1:2] for _ in 1:100]
for observation in observations
push!(observation, rand(Normal(sum(observation), 0.3)))
end
# create a stream from this static dataset, in your pipeline this would come from some real-time sensors, this is just to illustrate that RxInfer can handle these datastreams
static_datastream = from(observations) |> map(NamedTuple{(:y,), Tuple{Vector{Float64}}}, (d) -> (y = d, )); Now a call to infer(model = error_correction(),
datastream = static_datastream,
autoupdates = updates,
initialization = initialization,
constraints = constraints
) Additional options and visualisation options can be found here. I hope this answers your question! If there's anything else, feel free to ask. |
Beta Was this translation helpful? Give feedback.
-
Thank you, that is really helpful! Can you give an example of an implementation when I have a dynamical model? E.g. |
Beta Was this translation helpful? Give feedback.
-
I think your model, from a probabilistic sense, is a bit ill-defined; You define The main idea is that in |
Beta Was this translation helpful? Give feedback.
-
Is it possible to do real-time data reconciliation and gross error detection with RxInfer?
E.g. I have
y1
,y2
andy3
as noisy measurements and know thaty1 + y2 = y3
. Or If there is some redundancy in the measurements but one measures with non-zero mean error to detect it.Beta Was this translation helpful? Give feedback.
All reactions