Re: [Rcpp-devel] Detecting Singular Matrices in RcppArmadillo

2022-01-31 Thread Dirk Eddelbuettel
On 31 January 2022 at 11:25, Alex Ilich wrote: | Thank you Zé and Dirk! That helped clarify exactly what solve is doing | which I was having trouble tracking down in just the standard docs page. The `solve()` function in Armadillo does exactly what it sets out to do. Yet what Prof Bates has been

Re: [Rcpp-devel] Detecting Singular Matrices in RcppArmadillo

2022-01-31 Thread Alex Ilich
Thank you Zé and Dirk! That helped clarify exactly what solve is doing which I was having trouble tracking down in just the standard docs page. On Sun, Jan 30, 2022 at 11:26 PM Zé Vinícius wrote: > Very interesting, Dirk. Thanks! > > On Mon, Jan 31, 2022 at 12:18 PM Dirk Eddelbuettel wrote: > >

Re: [Rcpp-devel] Detecting Singular Matrices in RcppArmadillo

2022-01-30 Thread Zé Vinícius
Very interesting, Dirk. Thanks! On Mon, Jan 31, 2022 at 12:18 PM Dirk Eddelbuettel wrote: > > On 31 January 2022 at 09:13, Zé Vinícius wrote: > | Yes, quoting the paper on which ‘solve’ is based on ( > | http://arma.sourceforge.net/armadillo_solver_2020.pdf): > | > | “The SVD-based solver uses t

Re: [Rcpp-devel] Detecting Singular Matrices in RcppArmadillo

2022-01-30 Thread Dirk Eddelbuettel
On 31 January 2022 at 09:13, Zé Vinícius wrote: | Yes, quoting the paper on which ‘solve’ is based on ( | http://arma.sourceforge.net/armadillo_solver_2020.pdf): | | “The SVD-based solver uses the xGELSD set of functions, which find a | minimum-norm solution to a linear least squares problem.” Y

Re: [Rcpp-devel] Detecting Singular Matrices in RcppArmadillo

2022-01-30 Thread Zé Vinícius
Yes, quoting the paper on which ‘solve’ is based on ( http://arma.sourceforge.net/armadillo_solver_2020.pdf): “The SVD-based solver uses the xGELSD set of functions, which find a minimum-norm solution to a linear least squares problem.” On Mon, Jan 31, 2022 at 12:12 AM Alex Ilich wrote: > Thank

Re: [Rcpp-devel] Detecting Singular Matrices in RcppArmadillo

2022-01-30 Thread Alex Ilich
Thanks for the advice Douglas. Just using B = solve(X,Y) works and it outputs a warning that an approximate solution is attempted when the matrix is nearly singular. To suppress the warning I've just included #define ARMA_WARN_LEVEL 1 at the top of my cpp code. Also, no longer getting some odd out

Re: [Rcpp-devel] Detecting Singular Matrices in RcppArmadillo

2022-01-28 Thread Alex Ilich
Thanks! I'll use if(rcf <= std::numeric_limits::epsilon()) instead of rcf==0. On Fri, Jan 28, 2022 at 7:32 PM Dirk Eddelbuettel wrote: > > On 28 January 2022 at 13:25, Alex Ilich wrote: > | Thank you Neal and Dirk. Based on these comments I think using > arma::rcond > > Ah, yes, of course. Shoul

Re: [Rcpp-devel] Detecting Singular Matrices in RcppArmadillo

2022-01-28 Thread Dirk Eddelbuettel
On 28 January 2022 at 13:25, Alex Ilich wrote: | Thank you Neal and Dirk. Based on these comments I think using arma::rcond Ah, yes, of course. Should have remembered arma::rcond. | to get the reciprocal of the condition factor, and checking if that is zero | rather than the determinant may be t

Re: [Rcpp-devel] Detecting Singular Matrices in RcppArmadillo

2022-01-28 Thread Alex Ilich
Thank you Neal and Dirk. Based on these comments I think using arma::rcond to get the reciprocal of the condition factor, and checking if that is zero rather than the determinant may be the route to go. At least for this example that works. library(Rcpp) cppFunction(depends="RcppArmadillo", "Nume

Re: [Rcpp-devel] Detecting Singular Matrices in RcppArmadillo

2022-01-28 Thread Dirk Eddelbuettel
On 28 January 2022 at 09:16, Neal Fultz wrote: | There's an R object that has the machine precision, which could be a | reasonable threshold. | | .Machine$double.eps | | I believe there is a similar constant in the C++ standard library. | | You might also try checking the condition of the matri

Re: [Rcpp-devel] Detecting Singular Matrices in RcppArmadillo

2022-01-28 Thread Neal Fultz
There's an R object that has the machine precision, which could be a reasonable threshold. .Machine$double.eps I believe there is a similar constant in the C++ standard library. You might also try checking the condition of the matrix instead of the determinant, but you might take a performance h

[Rcpp-devel] Detecting Singular Matrices in RcppArmadillo

2022-01-28 Thread Alex Ilich
Hi, I have some code I've written to calculate regression parameters using ordinarily least squares using RcppArmadillo. This is meant to be performed iteratively over many small subsets (sliding window over spatial raster data) so I'd like to automatically detect when the regression can't be perfo