Re: [math] Pivoting in QR decomposition

2011-08-07 Thread Chris Nix
Thanks, Greg, for looking more at this. Apologies I've not been able to focus on this too much recently. Yes, the approach above works, however the solvers also require a change so that they don't unexpectedly solve for a permuted matrix. Additionally, a getRank() method can now be implemented

Re: [math] Pivoting in QR decomposition

2011-08-07 Thread Chris Nix
Oooops, the * below should read MATH-630. Chris On 7 August 2011 13:28, Chris Nix chris@gmail.com wrote: Thanks, Greg, for looking more at this. Apologies I've not been able to focus on this too much recently. Yes, the approach above works, however the solvers also require a

Re: [math] Pivoting in QR decomposition

2011-08-07 Thread Greg Sterijevski
Chris, In regard to the pivoting, do you think that it would be useful to allow subclasses to pivot using other strategies? The pivoting I have looks for the next column with the largest norm. For most garden variety problems this will be okay. However, you can (I am not sure how effective this

Re: [math] Pivoting in QR decomposition

2011-08-07 Thread Chris Nix
To avoid having the strategy method being overriden in the constructor, we could instead implement a constructor that takes a column Comparator that determines if two columns should be exchanged at each stage. In the interest of maintaining a clean interface, I don't know if this constructor

Re: [math] Pivoting in QR decomposition

2011-08-07 Thread Greg Sterijevski
Your selection methodology might be more complicated than pairwise comparison. So I think you would have to pass the entire set of remaining columns. That is an implementation detail, however. On the interface, yes the public face should not expose the constructor which takes the

Re: [math] Pivoting in QR decomposition

2011-08-06 Thread Greg Sterijevski
Hello All, Not sure if this is stepping on toes, but here is what I thought of to deal with pivoting. I would only need to modify the constructor of the QRDecompImpl class: public QRDecompositionPivotImpl(RealMatrix matrix) { final int m = matrix.getRowDimension(); final int n

Re: [math] Pivoting in QR decomposition

2011-07-23 Thread Phil Steitz
On 7/22/11 11:40 AM, Greg Sterijevski wrote: Sorry, public ConstrainedOLSMultipleRegression extends OLSMultipleRegression{} should read: public ConstrainedOLSMultipleRegression extends OLSMultipleRegression{ @Override public void newSampleData(double[] data, double[][]

Re: [math] Pivoting in QR decomposition

2011-07-23 Thread Greg Sterijevski
I agree about refactoring, was just experimenting to see what sorts of changes would need to be made in order to support restrictions. In the next week or so, I will introduce yet another regression algorithm, the so-called sweep algorithm. Once we have that, we will cover both normal equation

Re: [math] Pivoting in QR decomposition

2011-07-23 Thread Greg Sterijevski
Chris, you had an algorithm in mind? -Greg On Sat, Jul 23, 2011 at 11:29 AM, Phil Steitz phil.ste...@gmail.com wrote: On 7/22/11 11:40 AM, Greg Sterijevski wrote: Sorry, public ConstrainedOLSMultipleRegression extends OLSMultipleRegression{} should read: public

Re: [math] Pivoting in QR decomposition

2011-07-23 Thread Chris Nix
We can do this with the current Householder reflection implementation, except instead of just obtaining reflections from columns in sequence across the input matrix, we select the column with the greatest L2-norm at each iteration. The resulting permutation matrix is thus built and can be

Re: [math] Pivoting in QR decomposition

2011-07-23 Thread Ted Dunning
Also, if the QRDecomposition interface *is* extended with getP, it is the work of a moment to change it to an abstract class instead of an interface and provide a default method for getP that throws UnsupportedOperationException. Since there are very unlikely to be any user extensions of

Re: [math] Pivoting in QR decomposition

2011-07-23 Thread Phil Steitz
On 7/23/11 1:37 PM, Ted Dunning wrote: Also, if the QRDecomposition interface *is* extended with getP, it is the work of a moment to change it to an abstract class instead of an interface and provide a default method for getP that throws UnsupportedOperationException. Since there are very

Re: [math] Pivoting in QR decomposition

2011-07-23 Thread Greg Sterijevski
I second +1. On Sat, Jul 23, 2011 at 4:06 PM, Phil Steitz phil.ste...@gmail.com wrote: On 7/23/11 1:37 PM, Ted Dunning wrote: Also, if the QRDecomposition interface *is* extended with getP, it is the work of a moment to change it to an abstract class instead of an interface and provide a

Re: [math] Pivoting in QR decomposition

2011-07-22 Thread Phil Steitz
On 7/21/11 6:56 PM, Greg Sterijevski wrote: If a pivoting QR decomp was to be included, I see it as existing in addition to the current nonpivoting version. I don't see this as an addition to the current QRDecompositionImpl. We would not be exposing more of the inner workings of the

Re: [math] Pivoting in QR decomposition

2011-07-22 Thread Greg Sterijevski
On the need for pivoting: Here is my first approach for changing OLSMultipleRegression to do constrained estimation: public double[] calculateBeta(double[][] coeff, double[] rhs) { if (rhs.length != coeff.length) { throw new IllegalArgumentException(); }

Re: [math] Pivoting in QR decomposition

2011-07-22 Thread Greg Sterijevski
Sorry, public ConstrainedOLSMultipleRegression extends OLSMultipleRegression{} should read: public ConstrainedOLSMultipleRegression extends OLSMultipleRegression{ @Override public void newSampleData(double[] data, double[][] coeff, double[] rhs, int nob, int nvars) {

Re: [math] Pivoting in QR decomposition

2011-07-21 Thread Chris Nix
Looking at the current implementation, there is no column pivoting and so the pivot matrix is the identity. I have just written a small patch that does QR Decomposition with column pivoting and has a getP() method to get the resulting permutation matrix. If this is useful, I can open a JIRA

Re: [math] Pivoting in QR decomposition

2011-07-21 Thread Ted Dunning
This is upside down. Opening the JIRA and putting the patch up is the best way to determine if this is useful. On Thu, Jul 21, 2011 at 3:17 AM, Chris Nix chris@gmail.com wrote: I have just written a small patch that does QR Decomposition with column pivoting and has a getP() method to get

Re: [math] Pivoting in QR decomposition

2011-07-21 Thread Phil Steitz
On 7/21/11 8:07 AM, Ted Dunning wrote: This is upside down. Opening the JIRA and putting the patch up is the best way to determine if this is useful. On Thu, Jul 21, 2011 at 3:17 AM, Chris Nix chris@gmail.com wrote: I have just written a small patch that does QR Decomposition with

Re: [math] Pivoting in QR decomposition

2011-07-21 Thread Greg Sterijevski
Sorry, did not mean to touch off a debate. There are two ways (that I know of) to project linear restrictions through the data when running a regression using the QR decomposition. I need to review my notes, but I distinctly remember needing to get the pivots so that I know which columns are

Re: [math] Pivoting in QR decomposition

2011-07-21 Thread Ted Dunning
Also, pivoting is a good thing in a general QR decomposition since it extends the applicability of the code to nearly rank deficient inputs. On Thu, Jul 21, 2011 at 3:17 PM, Greg Sterijevski gsterijev...@gmail.comwrote: Sorry, did not mean to touch off a debate. There are two ways (that I know

Re: [math] Pivoting in QR decomposition

2011-07-21 Thread Greg Sterijevski
If a pivoting QR decomp was to be included, I see it as existing in addition to the current nonpivoting version. I don't see this as an addition to the current QRDecompositionImpl. We would not be exposing more of the inner workings of the QRDecomposition, just a different view? -Greg On Thu,

[math] Pivoting in QR decomposition

2011-07-20 Thread Greg Sterijevski
Hello, In attempting to build constrained ols into the OLSMultipleLinearRegression class, I rediscovered the fact that to keep the regression coefficients in their canonical order, I need to know how the QR decomposition pivoted. In other words, while I get the correct constrained parameters,

Re: [math] Pivoting in QR decomposition

2011-07-20 Thread Ted Dunning
Sounds like you need a new method. It also sounds like the Q and R components of the decomposition (if accessible) will be rendered in permuted order. Is there such an accessor? If so, is the doc up to snuff on this caveat? On Wed, Jul 20, 2011 at 9:27 PM, Greg Sterijevski

Re: [math] Pivoting in QR decomposition

2011-07-20 Thread Phil Steitz
On 7/20/11 9:27 PM, Greg Sterijevski wrote: Hello, In attempting to build constrained ols into the OLSMultipleLinearRegression class, I rediscovered the fact that to keep the regression coefficients in their canonical order, I need to know how the QR decomposition pivoted. In other words,