Re: [eigen] RcppEigen, providing bindings from R to Eigen through Rcpp, has been released

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


On Tue, Jun 28, 2011 at 4:03 PM, Christoph Hertzberg
<chtz@xxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> On 28.06.2011 22:51, Gael Guennebaud wrote:
>>
>> VectorXd   D = UDV.singularValues();
>> m_r          = std::count_if(D.data(), D.data() + m_p,
>>                      std::bind2nd(std::greater<double>(), threshold() *
>> D[0]));
>>
>> which can be written:
>>
>> m_r = (UDV.singularValues().array()>  threshold() * D[0]).count();
>
> Not that speed really matters at that point, but couldn't that also be
> replaced by a binary search?

I think that the purpose was to show clean up the code, not
necessarily to speed things up.  As you point out, by the time you
have calculated the SVD, operations on the vector of singular values
are a trivial time cost.

> Surely the time needed to compute the SVD in the first place is way above
> the potential time savings ...

Actually, the mechanism for constructing the model matrix from a model
specification in R almost always produces a matrix with full column
rank.  You have to work to come up with a "real life" example that is
systematically rank deficient (there is one in the help page for the
fastLm function, available at RcppEigen/man/fastLm.Rd).  So, better
than a binary search, is to start at the smallest singular value,
D[D.size() - 1] and iterate in reverse order until you get a value
that is larger than threshold() * D[0]



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