MATLAB Is it possible to solve for a directly without using the inverse?

  • Thread starter Thread starter feenaboccles
  • Start date Start date
  • Tags Tags
    Matlab
AI Thread Summary
The discussion centers on optimizing the calculation of the expression a = x' * inv(X * X') * X in MATLAB, particularly as new column vectors are added to the matrix X. The user seeks a faster method than direct implementation, noting that the problem does not conform to standard forms solvable by built-in solvers. Suggestions include exploring factorization or decomposition techniques that could leverage optimized solvers in MATLAB or linear algebra libraries like BLAS. The conversation highlights the distinction between the user's problem and standard linear regression equations, emphasizing that while traditional methods involve a different arrangement of data points, the user's goal is to express a new data point as a linear combination of previous ones. The user is specifically looking for ways to avoid calculating the inverse directly to enhance computational efficiency.
feenaboccles
Messages
3
Reaction score
0
I'm working on a project where the following has to be solved on a regular basis, as new column vectors are added to the matrix X.

a = x' * inv (X * X') * X

where
m is the number of examples
d is the dimensionality of the vector x
x is d x 1 and norm2(x) <= 1
X is d x m, consisting of m "x" vectors arranged column-wise (not row-wise as is typically the case)
and
a should be m x 1

I'm wondering is there a faster way to calculate in Matlab, other than a direct implementation of the above. It's not an equation in the usual form Xw = y, so the built-in solver won't work. I'm wondering are there any decompositions that might help, but bear in mind that the equation is solved, then X is changed, then we return to solve the equation once more for a different x.

Thanks
 
Physics news on Phys.org
Why don't you write your own Matlab function?
 
whs said:
Why don't you write your own Matlab function?

The code in my original post is Matlab code which does solve the equation. My question is not particularly Matlab-centric: it's whether the problem can be re-phrased, through some factorisation or decomposition, which would expedite its solution. Particularly, I'm wondering can it be rephrased in such as way that I can employ the heavily optimised solvers one finds in Matlab and various lin alg libraries like BLAS.
 
Ah, I don't know the answer, but you might want to try posting this (or getting it moved) to the computers/math software section where there are lots of matlab/mathematica type questions.
 
why don't you just take the transpose, then everything goes back to normal ?
 
trambolin said:
why don't you just take the transpose, then everything goes back to normal ?

Actually it won't.

Take a standard linear regression problem
X * w = y
where
m is the number of training samples
d is the dimensionality of each training sample xm
X is m x d the datapoints xm arranged row-wise
y is m x 1
w is d x 1

The standard equations are (less regularization) are
w = inv(X' * X) * X' * y

Or

w' = y' * X * inv (X' * X)'

If you say Z = X' (i.e datapoints are arranged column wise, rather than row-wise), you get

w' = y * Z' * inv (Z * Z')'Now consider my example. In my example I'm expression a new datapoint as a linear combination (the vector a) of all previous datapoints. This is different to the standard regression problem. Hence, whereas w above is d x 1, a is m x 1. So, if we have a new datapoint z, and we want to express it as a linear combination of previous datapoints arranged column-wise in Z. We minimise ||a||2 subject to z = Z * a and thereby get

a = z' * inv (Z * Z') * Z

My question is is there any way of rephrasing this so the inverse can be avoided, and the problem solved directly.

The key diffence in the equations for a and w' is the first term, y is m x 1, but z is d x 1
 

Similar threads

Replies
2
Views
2K
Replies
1
Views
3K
Replies
6
Views
2K
Replies
9
Views
2K
Replies
16
Views
14K
Back
Top