Autodifferentiation rules?

156 views
Skip to first unread message

Thomas Sharpless

unread,
Mar 30, 2014, 4:07:19 PM3/30/14
to ceres-...@googlegroups.com
Is there a list of rules for writing code that will be auto-differentiable?  In particular I am wondering whether it is feasible to include solving small linear systems with Eigen, also taking averages.

Sameer Agarwal

unread,
Mar 30, 2014, 5:22:26 PM3/30/14
to ceres-...@googlegroups.com
Hi Thomas,
Most standard math expressions should work. Automatic differentiation of linear system solution is not a great idea, because of conditioning issues of the underlying linear system. Averages are easy. Can you describe the cost function you are trying to construct?
Sameer



On Sun, Mar 30, 2014 at 1:07 PM, Thomas Sharpless <tksha...@gmail.com> wrote:
Is there a list of rules for writing code that will be auto-differentiable?  In particular I am wondering whether it is feasible to include solving small linear systems with Eigen, also taking averages.

--
You received this message because you are subscribed to the Google Groups "Ceres Solver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceres-solver...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceres-solver/8372591a-1b5b-4fb3-9693-a68a843ac78f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thomas Sharpless

unread,
Mar 31, 2014, 11:39:46 AM3/31/14
to ceres-...@googlegroups.com
Hi Sameer

I'm basically interested in handling very wide-angle cameras, including stitched panoramas, where the rectilinear projection is not an appropriate model.  I refer everything to spheres centered at camera pupils and at the 3D origin (which is an adjustable "panocenter" in my scheme) so make heavy use of spherical coordinates -- unit 3-vectors and (azimuth,altitude) angle pairs -- as well as spherical polar coordinates.

Just now I am working on using straight line segments as image features. Those project to sectors of 3D planes, whose pairwise intersections define 3D line segments. I represent those as parts of ideal lines, defined by a unit polar vector and an equatorial normal, as in Hough transform. Computing a line involves solving a 3x3 linear system.  Then I average the poles and normals over all pairs that putatively represent the same line.

When I posted I was thinking about evaluating residuals and Jacobians in the "forward" direction (camera -> 3D).  But now I realize it is far more sensible to map the averaged 3D lines back to cameras and evaluate the errors there.  That mapping is simpler and more easily auto-differentiated.  At first I am just optimizing camera rotation and translation using the errors in the normals to the plane sectors at the camera position; which is no problem at all.

-- Tom


--
You received this message because you are subscribed to a topic in the Google Groups "Ceres Solver" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ceres-solver/YM5dq6u1_Rs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ceres-solver...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceres-solver/CABqdRUC2eYFK4HrQK48OjtA5bs6r-%3DqOp1LtDwvRdCz63Lko%3DA%40mail.gmail.com.

Sameer Agarwal

unread,
Mar 31, 2014, 12:01:03 PM3/31/14
to ceres-...@googlegroups.com
Thomas,
Thanks for sharing the details. Everything that you describe sounds reasonable and doable in Ceres.
Sameer

Thomas Sharpless

unread,
Mar 31, 2014, 12:14:17 PM3/31/14
to ceres-...@googlegroups.com
Am I correct in assuming that the basic requirement for auto-differentiation is that the compiler has access to the source code of all used functions apart from standard math fns?  I was puzzled by this phrase in your ceres tutorial: 
"... involves a call to a library function that you do not have control over." 
Do you really mean "do not have source code of"?



Sameer Agarwal

unread,
Mar 31, 2014, 12:19:09 PM3/31/14
to ceres-...@googlegroups.com
it means that suppose you are calling a function for which a templated implementation is not possible. Like a library function which does say a coordinate transformation.

Sameer



Thomas Sharpless

unread,
Apr 1, 2014, 11:25:36 AM4/1/14
to ceres-...@googlegroups.com
So I have to rewrite any such functions in a templated style?  Are there written rules for this?  Must I declare specific templated variables?


Sameer Agarwal

unread,
Apr 1, 2014, 11:28:00 AM4/1/14
to ceres-...@googlegroups.com
Thomas,
Yes any functions you use should be templated. We have the basic math functions already templatized/autodiff friendly. Have a look at simple_bundle_adjuster.cc in the examples code and in particular SnavelyReprojectionError.

Sameer



Henrique Mendonça

unread,
Apr 3, 2014, 4:09:02 AM4/3/14
to ceres-...@googlegroups.com

Hi guys,

I was about to ask something very similar. What would be an efficient and Jet friendly way of solving the mentioned 3x3 linear systems?
My matrices [for ray triangulation] are symmetric, if it makes a difference.

Cheers,
Henrique

Sameer Agarwal

unread,
Apr 3, 2014, 9:03:27 AM4/3/14
to ceres-...@googlegroups.com
I understand that for computing an initial ray triangulation you have to invert a matrix, but why do you need to invert a matrix for minimizing the reprojection error?
Sameer



Henrique Mendonça

unread,
Apr 3, 2014, 9:50:59 AM4/3/14
to ceres-...@googlegroups.com

Hi Sameer,
Thanks for your answer and sorry if this is a stupid question. But I was more interested in knowing what the possibilities are, as I'm modelling some different variants.
As I don't really need the 3D points, I thought on trying to model the error function directly from the camera parameters. In this way, I'd have half of the parameter blocks. Obviously, the Jacobians would get much larger too...
Anyway, like Thomas I want to know what kind of stuff can be done inside the error function.
In this case the eigen inversion would be ok? or better use pure analytical methods? The pseudo-inverse from SVD is probably not a good idea, right?

Thanks heaps,
Henrique

Sameer Agarwal

unread,
Apr 3, 2014, 10:16:19 AM4/3/14
to ceres-...@googlegroups.com
On Thu, Apr 3, 2014 at 6:50 AM, Henrique Mendonça <hmen...@gmail.com> wrote:

Hi Sameer,
Thanks for your answer and sorry if this is a stupid question. But I was more interested in knowing what the possibilities are, as I'm modelling some different variants.
As I don't really need the 3D points, I thought on trying to model the error function directly from the camera parameters. In this way, I'd have half of the parameter blocks. Obviously, the Jacobians would get much larger too...

Are you talking about structureless bundle adjustment ? which use two view and three view constraints?

Anyway, like Thomas I want to know what kind of stuff can be done inside the error function.
In this case the eigen inversion would be ok? or better use pure analytical methods? The pseudo-inverse from SVD is probably not a good idea, right?

Depends on the actual expression and the algorithm being used to do it. If you have a concrete example I can say more.

Sameer

 

Henrique Mendonça

unread,
Apr 4, 2014, 3:20:22 AM4/4/14
to ceres-...@googlegroups.com

Yes, structureless bundle adjustment sounds like it. It's a different topic but would you perhaps have a quick reference or a sample for it?
Thanks heaps!

Pierre Moulon

unread,
Apr 4, 2014, 5:28:53 AM4/4/14
to ceres-...@googlegroups.com
Hi,

You can read the followings papers:


Rodríguez, A.L., López de Teruel, P.E., Ruiz, A. (2011). "Reduced Epipolar Cost for Accelerated Incremental SfM". 24th IEEE Conference on Computer Vision and Pattern Recognition, CVPR 2011, Colorado Springs, june 2011.

But be carefull that some of such approaches cannot handle colinear camera motions.

Regards,




For more options, visit https://groups.google.com/d/optout.



--
Regards/Cordialement,
Pierre M
Reply all
Reply to author
Forward
0 new messages