[eigen] Advanced vectorization

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]

Hi all,

I'm trying to optimize the evaluation of a squared loss function and
its gradient. That is, I'd like to calculate

L = 0.5 ||Ax-b||^2
dL/dx = A'(Ax-b)

where A has more columns than rows, i.e. A'A would be huge and caching
it would be infeasible.

Right now, i have the following routine:

Scalar objfunc(const Matrix<Scalar, Dynamic, 1>& x, Matrix<Scalar,
Dynamic, 1>& g)
    e.noalias() = A * x - b;
    g.noalias() = A.adjoint() * e;
    return Scalar(0.5) * e.squaredNorm();

where /e/ is pre-allocated as a class member. When hand coding this,
instead of storing /e/, I would calculate it component-wise and
accumulate its squared norm along the way, thus avoiding iterating
twice. Is there a clever way to accomplish this with Eigen?


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/