nan jacobian for pow(x, b) where b is the parameter. Is this problem feasible?

21 views
Skip to first unread message

Isaac Tian

unread,
Jun 30, 2022, 4:05:58 PM6/30/22
to Ceres Solver
I'm writing a test problem in Ceres of the form y = ax^b + c. If y=ax+c is the linear regression optimal solution, then I am initializing b to 1 and trying to see if there is an exponential value that produces a better fit than a straight line.  Vectorized it looks like y = a1x1^b + a2x2^b + a2x2^b... 
When b = 1 it is just the linear regression solution. Problem is as soon as I try to do pow(x, b) where b is a parameter I get a nan jacobian even if I make all the b_i equal.

Parameter Block 1, size: 1

           1 |         -nan

The cost function is simple enough to just show here. a b and c are the parameters. If I set b to constant, the problem converges immediately as expected because the least squares solution is globally optimal.

        T costfunc = T(0.0);

        for (int i = 0; i < w.cols(); i++ ) {
            VectorXd ith_person = w.col(i);
            T p = T(0.0);
            //y = ax^b + c
            for (int j = 0; j < ith_person.size(); j++) {
                p += (ceres::pow(ith_person[j], b[0]) * a[j]);
            }
            costfunc += ceres::pow(ys[i] - (p + c[0]) ,2);
        }

        residual[0] = costfunc;
        return true;

Is optimizing for an exponential parameter not tractable in Ceres or is there a way to make this work? Thanks.

Sameer Agarwal

unread,
Jul 11, 2022, 7:48:02 AM7/11/22
to ceres-...@googlegroups.com
sorry for the late reply,
have you checked what the value of x1 and x2 is for which you are getting nan? 
the pow function's derivatives are complicated.
you should look at the three variants of the pow function starting at 


to see which one you are using and where the nan is being generated.

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/a390771f-ef4e-45aa-b3a3-66a26d1e4ef8n%40googlegroups.com.

Isaac Tian

unread,
Jul 13, 2022, 6:07:45 PM7/13/22
to Ceres Solver
The problems start at x_3, which is the first value that can be zero or negative. I should be implicitly calling the version with a constant base and variable exponent, and it looks like that one has problems when the base is not positive. I've switched over to using gaussian process regression to try and estimate a similar function without explicitly defining the parameterized regression equation. Thanks for helping me identify the problem.
Reply all
Reply to author
Forward
0 new messages