Qu

estimate

Builtin index · Statistics & ML

result = state.estimate()

Input: no input · Output: result

What it is

Estimation-family only: reads a point estimate off a filter state Record state with no arguments.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = state.estimate()no input
result vector
Returns the particle filter's weighted-mean particle vector, or a Kalman/EKF/UKF filter's state.x vector directly.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

process(p) := p + 0.05*randn()                       # process_fn injects its

                                                        # own noise, like monte_carlo

likelihood(p, z) := exp(-(p[0]-z[0])^2 / (2*0.25))    # Gaussian likelihood, sigma=0.5


pf = particle_filter_init([0], 200, spread=2.0, seed=1)   # 200 particles around x0=0

for i = 1 to 10
    pf = pf.predict("process")
    pf = pf.update("likelihood", [2])    # repeatedly measuring z=2

end for
est = pf.estimate()   # weighted-mean point estimate, converges toward 2

from numerics-dsp

truth = zeros(60)
meas = zeros(60)
for t = 0 to 59
    truth[t] = 0.5 * t
    meas[t] = truth[t] + randn() * 2
end for

F = [1, 0, 1, 1] as matrix(2, 2)     # column-major: rows are [1, 1] and [0, 1]

Q = [0.01, 0, 0, 0.01] as matrix(2, 2)
H = [1, 0] as matrix(1, 2)
R = [4] as matrix(1, 1)

s = kalman_init([0, 0], [10, 0, 0, 10] as matrix(2, 2))
est = zeros(60)
for t = 0 to 59
    s = s.predict(F, Q)
    s = s.update(H, [meas[t]], R)
    est[t] = s.estimate()[0]
end for

print("measurement error: {round(rmse(truth, meas), 3)}")
print("filtered error:    {round(rmse(truth, est), 3)}")
scatter(0 to 59, meas, color = "#94a3b8", label = "measured")
plot(0 to 59, truth, color = "#0f172a", label = "truth")
plot(0 to 59, est, color = "#e11d48", width = 2, label = "Kalman")
legend()
title("constant-velocity Kalman filter")
output
measurement error: 2.197
filtered error:    1.193
· scatter: figure 11 (60 points)
· plot: figure 12 (60 points)
· plot: figure 13 (60 points)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 knn tree forest bayes x=-1.058, y=-0.826 x=0.594, y=0.636 x=0.88, y=1.305 x=-0.379, y=-0.489 x=0.152, y=1.215 x=1.407, y=0.754 x=0.231, y=-0.942 x=-1.291, y=-0.12 x=-0.085, y=-0.627 x=0.304, y=-0.101 x=0.037, y=0.004 x=-0.705, y=-0.429 x=0.241, y=-0.559 x=-0.582, y=-1.167 x=-0.277, y=-0.685 x=-1.636, y=-1.342 x=-0.865, y=-0.799 x=0.131, y=0.029 x=-1.581, y=-1.773 x=-2.048, y=-2.111 x=2.947, y=2.32 x=-0.456, y=-1.875 x=0.908, y=0.097 x=0.85, y=1.1 x=0.517, y=0.032 x=0.003, y=0.246 x=-0.201, y=0.212 x=0.466, y=-0.074 x=0.426, y=1.096 x=-0.066, y=-0.164 x=1.021, y=1.029 x=0.113, y=0.035 x=-0.998, y=-0.494 x=-0.066, y=-0.991 x=2.823, y=0.731 x=-0.046, y=-0.746 x=-0.029, y=-0.9 x=-0.031, y=0.196 x=-0.616, y=0.539 x=-1.349, y=-0.313 x=-1.085, y=-1.65 x=-1.452, y=-1.608 x=0.973, y=0.867 x=0.737, y=0.242 x=-0.185, y=0.468 x=1.175, y=1.485 x=-1.836, y=-0.822 x=-0.157, y=-0.076 x=0.407, y=0.307 x=-1.365, y=-1.022 x=-0.847, y=1.143 x=-0.762, y=0.021 x=-1.044, y=-0.505 x=0.478, y=1.123 x=0.316, y=-0.102 x=0.965, y=0.825 x=-0.751, y=-0.957 x=-0.988, y=-0.033 x=-1.22, y=-0.385 x=-0.681, y=-0.432 x=-0.621, y=0.256 x=0.918, y=0.744 x=1.182, y=-0.477 x=-0.039, y=0.425 x=0.585, y=-0.031 x=0.297, y=-0.535 x=0.112, y=-0.357 x=0.039, y=0.8 x=0.16, y=0.201 x=1.261, y=-0.955 x=0.95, y=0.238 x=-0.013, y=0.393 x=-1.577, y=-0.343 x=-0.67, y=-0.101 x=-0.631, y=-1.302 x=-0.84, y=-0.949 x=1.692, y=0.99 x=0.389, y=0.473 x=-0.261, y=-0.509 x=-0.491, y=-0.033 x=0.634, y=0.806 x=-0.342, y=0.622 x=-1.674, y=-1.63 x=0.039, y=-0.203 x=0.175, y=-0.688 x=0.206, y=0.293 x=1.405, y=0.994 x=-0.644, y=-0.672 x=-0.623, y=-0.7 x=1.569, y=0.384 x=-0.533, y=-0.154 x=0.682, y=-0.014 x=1.089, y=1.13 x=0.342, y=0.984 x=1.161, y=0.991 x=-0.232, y=0.289 x=-0.607, y=-0.737 x=0.295, y=0.07 x=0.275, y=0.25 x=-1.141, y=-0.456 x=0.461, y=0.554 x=-0.671, y=-0.906 x=0.513, y=1.154 x=0.499, y=-0.224 x=1.753, y=1.474 x=0.103, y=0.61 x=-0.351, y=0.258 x=0.553, y=-0.788 x=0.298, y=0.904 x=0.472, y=0.843 x=-0.94, y=-0.939 x=-1.062, y=-1.629 x=0.467, y=0.806 x=-0.653, y=-1.083 x=1.172, y=1.15 x=0.206, y=0.15 x=-1.077, y=-0.827 x=0.153, y=-0.987 x=0.202, y=0.439 x=0.011, y=-0.385 x=-0.67, y=0.029 x=1.367, y=0.502 x=0.955, y=0.531 x=0.352, y=0.238 x=1.543, y=0.703 x=-1.029, y=-0.474 x=0.104, y=0.508 x=0.877, y=-0.209 x=-1.366, y=-1.921 x=-1.583, y=-1.15 x=1.748, y=0.901 x=0.359, y=0.563 x=0.309, y=-0.002 x=1.322, y=1.929 x=-0.57, y=-0.79 x=-0.857, y=0.127 x=0.177, y=-0.37 x=-1.161, y=-1.563 x=0.371, y=1.281 x=-0.811, y=-1.39 x=0.168, y=1.089 x=-0.599, y=0.823 x=-0.452, y=-1.067 x=-1.241, y=-1.344 x=-0.711, y=-0.72 x=-0.233, y=-0.53 x=-0.344, y=0.761 x=1.152, y=0.27 x=0.989, y=0.896 x=0.308, y=0.67 x=-1.851, y=-1.723 x=0.866, y=0.926 x=-0.586, y=0.32 x=-0.204, y=-0.76 x=1.617, y=1.863 x=-0.897, y=-1.095 x=1.375, y=0.119 x=0.027, y=0.911 x=-0.268, y=-0.958 x=-0.58, y=-0.581 x=1.263, y=0.222 x=0.021, y=0.109 x=0.228, y=-0.664 x=0.002, y=-0.26 x=-0.301, y=0.237 x=0.646, y=0.863 x=0.272, y=-1.038 x=-0.432, y=-0.686 x=-0.123, y=1.22 x=0.844, y=1.163 x=-1.237, y=-1.157 x=2, y=1.132 x=-0.836, y=0.309 x=-0.332, y=-0.738 x=0.17, y=0.198 x=-0.327, y=0.587 x=-1.737, y=-1.131 x=-0.054, y=0.877 x=0.317, y=0.75 x=-1.406, y=-1.905 x=0.04, y=0.092 x=1.456, y=0.878 x=0.373, y=0.985 x=-0.912, y=-0.551 x=-0.104, y=0.042 x=0.349, y=0.549 x=1.098, y=0.24 x=0.588, y=-0.011 x=-0.164, y=-0.854 x=0.235, y=-0.679 x=-0.713, y=0.139 x=0.252, y=-0.404 x=-0.029, y=-0.281 x=-0.988, y=-0.818 x=0.223, y=-0.99 x=-0.591, y=0.839 x=-0.36, y=-0.088 x=-0.006, y=-0.156 x=-0.054, y=-0.158 x=0.644, y=-0.111 x=-3, y=-4.018 x=-2.75, y=-6.388 x=-2.5, y=-5.262 x=-2.25, y=0.293 x=-2, y=1.587 x=-1.75, y=1.194 x=-1.5, y=1.829 x=-1.25, y=2.719 x=-1, y=-0.145 x=-0.75, y=0.779 x=-0.5, y=-0.837 x=-0.25, y=2.101 x=0, y=0.378 x=0.25, y=1.148 x=0.5, y=1.019 x=0.75, y=-3.978 x=1, y=-3.731 x=1.25, y=-0.191 x=1.5, y=-1.178 x=1.75, y=-2.55 x=2, y=-0.452 x=2.25, y=4.657 x=2.5, y=0.591 x=2.75, y=5.418 x=3, y=6.826 x=-4.221, y=-3.675 x=-4.749, y=-4.599 x=-4.378, y=-5.049 x=-4.908, y=-2.938 x=-3.111, y=-4.705 x=-4.7, y=-3.185 x=-4.948, y=-4.24 x=-5.087, y=-4.991 x=-3.755, y=-2.658 x=-4.866, y=-3.893 x=-3.202, y=-4.799 x=-3.536, y=-4.59 x=-4.643, y=-4.655 x=-4.223, y=-3.8 x=-4.771, y=-4.791 x=-5.162, y=-3.624 x=-2.644, y=-3.501 x=-5.565, y=-4.823 x=-3.561, y=-2.64 x=-4.529, y=-4.524 x=-5.6, y=-5.042 x=-3.048, y=-3.184 x=-4.283, y=-4.206 x=-5.239, y=-4.032 x=-2.871, y=-5.062 x=-2.117, y=-2.96 x=-3.794, y=-3.873 x=-3.245, y=-4.153 x=-4.242, y=-4.691 x=-3.935, y=-4.681 x=-2.991, y=-2.757 x=-4.498, y=-3.651 x=-4.482, y=-5.712 x=-3.324, y=-4.723 x=-5.062, y=-5.077 x=-4.34, y=-4.914 x=-4.945, y=-5.731 x=-4.523, y=-3.545 x=-2.907, y=-3.457 x=-4.38, y=-3.659 x=3.22, y=4.412 x=3.089, y=4.062 x=2.827, y=3.584 x=3.848, y=5.345 x=4.196, y=4.669 x=3.111, y=4.336 x=2.961, y=3.91 x=5.036, y=4.596 x=5.339, y=4.031 x=4.874, y=2.505 x=4.357, y=2.791 x=3.318, y=5.241 x=2.544, y=3.948 x=6.731, y=3.889 x=4.101, y=4.456 x=3.18, y=2.902 x=4.415, y=7.292 x=3.9, y=6.008 x=3.342, y=4.252 x=2.138, y=4.074 x=3.304, y=4.752 x=4.53, y=4.152 x=3.264, y=4.913 x=3.885, y=2.94 x=5.542, y=3.917 x=1.488, y=3.061 x=2.847, y=3.236 x=3.93, y=3.488 x=2.913, y=2.598 x=3.839, y=4.13 x=2.508, y=3.961 x=2.846, y=4.195 x=4.278, y=4.197 x=4.971, y=5.339 x=4.568, y=5.297 x=3.797, y=3.895 x=3.459, y=4.494 x=4.285, y=3.369 x=3.836, y=2.999 x=2.123, y=1.312 x=-0.678, y=-0.737 x=-0.734, y=0.333 x=-0.016, y=1.204 x=0.605, y=0.633 x=0.426, y=-0.995 x=-0.383, y=0.403 x=-0.064, y=0.253 x=-1.862, y=-0.361 x=0.298, y=0.52 x=-1.481, y=-1.025 x=0.719, y=0.808 x=1.151, y=-0.726 x=-0.082, y=-0.357 x=-0.401, y=0.791 x=-0.182, y=0.737 x=0.394, y=0.021 x=0.954, y=0.671 x=0.405, y=0.336 x=-1.617, y=-0.65 x=-0.669, y=-1.147 x=-2.452, y=1.586 x=1.709, y=-0.65 x=0.122, y=-0.171 x=1.066, y=-1.195 x=0.053, y=-0.57 x=-0.396, y=-0.235 x=0.819, y=-0.788 x=0.012, y=0.012 x=-2.723, y=0.397 x=1.545, y=0.484 x=-1.119, y=0.98 x=-0.22, y=-0.804 x=-1.564, y=-1.293 x=-1.811, y=-0.276 x=0.774, y=-1.055 x=0.575, y=1.214 x=-0.348, y=-1.078 x=0.015, y=-0.404 x=0.245, y=-1.466 x=0.436, y=1.71 x=0, y=0.983 0.983 x=1, y=0.95 0.95 x=2, y=0.967 0.967 x=3, y=0.917 0.917 x=0, y=0.209 x=1, y=-0.789 x=2, y=0.181 x=3, y=3.319 x=4, y=0.973 x=5, y=1.711 x=6, y=1.379 x=7, y=0.441 x=8, y=6.776 x=9, y=5.163 x=10, y=1.275 x=11, y=5.11 x=12, y=4.859 x=13, y=2.881 x=14, y=3.871 x=15, y=6.271 x=16, y=8.817 x=17, y=6.083 x=18, y=8.405 x=19, y=9.285 x=20, y=9.319 x=21, y=10.964 x=22, y=6.751 x=23, y=11.568 x=24, y=13.342 x=25, y=16.469 x=26, y=14.154 x=27, y=15.639 x=28, y=12.311 x=29, y=10.938 x=30, y=17.006 x=31, y=14.186 x=32, y=13.236 x=33, y=13.894 x=34, y=17.924 x=35, y=16.379 x=36, y=14.548 x=37, y=16.145 x=38, y=20.246 x=39, y=19.397 x=40, y=19.613 x=41, y=24.115 x=42, y=18.843 x=43, y=25.23 x=44, y=21.187 x=45, y=22.486 x=46, y=24.405 x=47, y=22.59 x=48, y=22.557 x=49, y=23.677 x=50, y=28.284 x=51, y=28.544 x=52, y=24.99 x=53, y=26.047 x=54, y=23.037 x=55, y=22.826 x=56, y=27.742 x=57, y=25.787 x=58, y=27.48 x=59, y=32.635 constant-velocity Kalman filter a test accuracy measured cubic fit measured forecast cluster 0 cluster 1 cluster 2 centroids measured truth Kalman

from statistics-ml

How it works

estimate(state) — callable as state.estimate(). The particle filter's weighted-mean point estimate (plain mean(state.particles) would silently ignore the weights); for the linear/EKF/UKF filters this is just state.x, kept here too so every estimation-theory state answers the same question the same way.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.