Optional using of jacobians

47 views
Skip to first unread message

Andy

unread,
Feb 8, 2024, 2:15:51 PMFeb 8
to Ceres Solver
How to remove using jacobians in example curve_fitting (from ceres-solver.googlesource.com) or add using jacobians in example iteration_callback_example ?
Note: c_api example compiles good, whereas in examples with struct struct ExponentialResidual I must change
new ceres::AutoDiffCostFunction<ExponentialResidual, 1, 1, 1>(
                        data[2 * i], data[2 * i + 1]);

to

new ceres::AutoDiffCostFunction<ExponentialResidual, 1, 1, 1>(
                        new ExponentialResidual(data[2 * i], data[2 * i + 1]));

Sameer Agarwal

unread,
Feb 8, 2024, 5:07:55 PMFeb 8
to ceres-...@googlegroups.com
Andy,

I do not understand your question. 
What are you trying to do and what is not working?

What version of C++ are you using to compile your code?

Sameer


--
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/4c570cae-bad3-4c83-944f-944c6609f2den%40googlegroups.com.

Andy

unread,
Feb 10, 2024, 10:16:11 AMFeb 10
to Ceres Solver
I have two questions:
1:
I try compile curve_fitting.cc in my alone project. My CMakeLists.txt is
cmake_minimum_required(VERSION 3.12)
project(curve_fitting)

set(CMAKE_CXX_STANDARD 23)
find_package(glog REQUIRED)

include_directories(/usr/include/eigen3)

add_executable(${PROJECT_NAME} curve_fitting.cc)

target_link_libraries(${PROJECT_NAME} ceres glog::glog)

I can't compile line:  
    data[2 * i], data[2 * i + 1]),
is error:
curve_fitting.cc:145:13: error: no matching constructor for initialization of 'ceres::AutoDiffCostFunction<ExponentialResidual, 1, 1, 1>'

        new ceres::AutoDiffCostFunction<ExponentialResidual, 1, 1, 1>(
           
I compile with Clang
Is compiled when I change this line to
   new ExponentialResidual(data[2 * i], data[2 * i + 1])),

2:
I see, is C version curve_fitting.c and C++ version curve_fitting.cc
C version uses jacobians while C++ version not. When comparing, both programs found solution in the same amount of steps, but jacobians version runs 5x faster.
How to use jacobians in C++ version?
How to not use jacobians in C version?

Sameer Agarwal

unread,
Feb 10, 2024, 10:45:26 AMFeb 10
to ceres-...@googlegroups.com
What version of Ceres solver are you using? 
The change to autodiffcostfunction is recent (where you do not have to explicitly instantiate the functor). It is not part of a stable release yet.

You can continue to use the older syntax where you explicitly create and pass the functor to the constructor.

I am surprised that it has any impact on the performance.

Sameer 

--
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.

Andy

unread,
Feb 10, 2024, 11:25:08 AMFeb 10
to Ceres Solver
I install ceres by apt in Mint:
version:
libceres-dev/jammy,now 2.0.0+dfsg1-5 amd64 [installed]
libceres2/jammy,now 2.0.0+dfsg1-5 amd64 [installed,automatic]
where git has version 2.2.0

Oops, time difference was in debug , but in release time is comparable.

Sameer Agarwal

unread,
Feb 10, 2024, 11:45:02 AMFeb 10
to ceres-...@googlegroups.com
Okay then you are using an older version of Ceres which does not support the latest syntax. The online documentation refers to the version of the code at head. This can be confusing. Sorry about that.

so for your use case you should be using the classic syntax

new AutoDiffCostFunction<Functor,...>(new Functor(..)) syntax.

This syntax issue aside, 2.0.0 is a rather old version of Ceres, I would recommend using version 2.2.0, which was released late last year. 

Sameer


Reply all
Reply to author
Forward
0 new messages