Sharing parameter blocks between residuals

117 views
Skip to first unread message

Yernar

unread,
Jul 12, 2022, 9:00:55 AM7/12/22
to Ceres Solver
Hi, 

I am trying to share parameters block between multiple residuals. I've tried to do something like this:

std::vector<double *> parameters; 
// initialize parameters with some values
for(int i{1}; i < 10; ++i)
{
// I will have 9 residuals and want to share parameter blocks
  ceres::CostFunction *cost_function =
  new ceres::AutoDiffCostFunction<CostFunctorAutoSmoothing, 1, 2, 2, 2>(new       CostFunctorAutoSmoothing());  
  problem.AddResidualBlock(cost_function, nullptr, parameters[i], parameters[i-1],     parameters[i+1]);
}

So far I couldn't get sensible results, is my approach correct?

Thanks

Sameer Agarwal

unread,
Jul 12, 2022, 10:24:10 AM7/12/22
to ceres-...@googlegroups.com
yes this seems fine. I am assuming that the double* in your parameters vector point to size 2 parameter blocks and those parameter blocks do not overlap.
What do you mean by you can't get sensible results?
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/7ae18db6-e73d-4c8f-86f8-b1c039a8ffa8n%40googlegroups.com.

Yernar

unread,
Jul 12, 2022, 12:59:56 PM7/12/22
to Ceres Solver
Since I am receiving initial values from another source, I store a parameter block in double[2] then push into parameters, i.e.:
double par1[] = {init_x, init_y};
parameters.push_back(par1); 

I've also tried with all scalar parameters and getting different results.

Sameer Agarwal

unread,
Jul 12, 2022, 1:02:09 PM7/12/22
to ceres-...@googlegroups.com
On Tue, Jul 12, 2022 at 9:59 AM Yernar <n.ye...@gmail.com> wrote:
Since I am receiving initial values from another source, I store a parameter block in double[2] then push into parameters, i.e.:
double par1[] = {init_x, init_y};
parameters.push_back(par1); 

That sounds fine.

Is the optimizer reducing the error? have you checked to see that your costfunctor is computing the right residuals? does the initial cost make sense?

Sameer

 
I've also tried with all scalar parameters and getting different results.

On Tuesday, July 12, 2022 at 4:24:10 PM UTC+2 sameer...@google.com wrote:
yes this seems fine. I am assuming that the double* in your parameters vector point to size 2 parameter blocks and those parameter blocks do not overlap.
What do you mean by you can't get sensible results?
Sameer


On Tue, Jul 12, 2022 at 6:00 AM Yernar <n.ye...@gmail.com> wrote:
Hi, 

I am trying to share parameters block between multiple residuals. I've tried to do something like this:

std::vector<double *> parameters; 
// initialize parameters with some values
for(int i{1}; i < 10; ++i)
{
// I will have 9 residuals and want to share parameter blocks
  ceres::CostFunction *cost_function =
  new ceres::AutoDiffCostFunction<CostFunctorAutoSmoothing, 1, 2, 2, 2>(new       CostFunctorAutoSmoothing());  
  problem.AddResidualBlock(cost_function, nullptr, parameters[i], parameters[i-1],     parameters[i+1]);
}

So far I couldn't get sensible results, is my approach correct?

Thanks

--
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/7ae18db6-e73d-4c8f-86f8-b1c039a8ffa8n%40googlegroups.com.

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

Yernar

unread,
Jul 12, 2022, 4:07:39 PM7/12/22
to Ceres Solver
Seems to be giving working now, I was returning wrong values for the answer. 
Reply all
Reply to author
Forward
0 new messages