-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Retrieve posterior uncertainty after optimisation? #667
Comments
After optimization has been run, one can retrieve the estimate of the uncertainty (as approximated by the Hessian) via computeMarginals on the SparseOptimizer class. The class below shows research code for computing a condensed graph given a set of nodes/edges Furthermore, note that computing the inverse takes significantly more time as just solving the system. |
Thanks! I'll have a look and see if I can reach that through the python wrapper. |
Hi @miquelmassot ! Did you end up finding a solution to you problem with the python wrapper? I am interested as well |
In #685 I fixed the slam2d example for the master branch. It shows how to pass the sparse matrix for storage of the covariance and retrieving it again afterwards. |
Thanks @RainerKuemmerle, I'll see if I can do the same through the python wrapper. |
This is what I came up with: from g2o import SparseBlockMatrixX
vertices = graph_slam.optimizer.vertices()
cov_vertices = []
covariances = SparseBlockMatrixX()
for vertex_idx in vertices:
v = vertices[vertex_idx]
if not v.fixed():
cov_vertices.append((v.hessian_index(), v.hessian_index()))
print("Sparse pattern contains", len(cov_vertices), "blocks")
print("Computing covariance matrix...")
m = graph_slam.optimizer.compute_marginals(covariances, cov_vertices)
print("Done,", m)
print("Covariance matrix:")
for vertex_idx in vertices:
print("Working on vertex idx:", vertex_idx)
v = vertices[vertex_idx]
if not v.fixed():
print("Hessian idx is:", v.hessian_index())
covariance = covariances.block(v.hessian_index(), v.hessian_index());
print("Covariance is:", covariance) and the results I see are:
In the example I have, there are 100 2D vertices and 15 PointXY observations.
|
Full working example (that is not capable to retrieve the covariance) here: https://github.com/miquelmassot/g2o-python-examples/blob/main/g2o%20covariance%20retrieval.ipynb |
@miquelmassot I updated https://github.com/RainerKuemmerle/g2o/blob/pymem/python/examples/notebook_slam2d.ipynb accordingly to plot the covariance of a PoseGraph. |
Thanks, @RainerKuemmerle that's brilliant! With the current setup, I get the following error when loading the
|
For me the loading by the factory works because I link all types to the g2opy SO. Is this different in the g2o-python build? |
I am calling the same CMakeLists to wrap g2opy as g2o-python, so there shouldn't be any difference, but there is. I am still trying to find out why. |
Ha, I referenced a wrong issue in the above commit :( @miquelmassot I added also some wrapper for the factory itself. Does this report empty lists for you? |
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days. |
This issue was closed because it has been stalled for 14 days with no activity. |
Hi!
I'd like to know if there's a way to retrieve the posterior uncertainty (or information matrix) after optimisation has been done. I can't seem to find information about this, although some old documentation seemed to state the method
.covariance()
on BaseVertex class, which no longer exists. Does anyone have information about this?The text was updated successfully, but these errors were encountered: