I have real number n variables (I don’t know, I don’t really care), call them X[n] . I also have m >> n relationships between them, let's call them R[m] , of the form:
X[i] = alpha*X[j] , alpha is a nonzero positive real number, i and j different, but the pair (i, j) not necessarily unique (that is, between the same variables with different alpha -factor)
What I'm trying to do is find a set of alpha parameters that solve the redefined system in the least squares sense. The ideal solution would be to minimize the square of the sum of the differences between each parameter of the equation and the selected value, but I am satisfied with the following approximation:
If I turn m equations into an overridden system of n unknowns, any pseudo-reversible numerical solver will give me the obvious solution (all zeros). So, what I'm doing now is to add another equation to the mix, x[0] = 1 (virtually any constant will do) and solve the generated system in the sense of least squares using the Moore-Penrose pseudoinverse. Although this attempts to minimize the sum (x[0] - 1)^2 and the square sum x[i] - alpha*x[j] , I find this a good and numerically stable approximation to my problem. Here is an example:
a = 1 a = 2*b b = 3*c a = 5*c
in octave:
A = [ 1 0 0; 1 -2 0; 0 1 -3; 1 0 -5; ] B = [1; 0; 0; 0] C = pinv(A) * B or better yet: C = pinv(A)(:,1)
What gives the values for a , b , c : [0.99383; 0.51235; 0.19136] [0.99383; 0.51235; 0.19136] [0.99383; 0.51235; 0.19136] This gives me the following (reasonable) relationship:
a = 1.9398*b b = 2.6774*c a = 5.1935*c
So right now I need to implement this in C / C ++ / Java, and I have the following questions:
Is there a faster method to solve my problem, or am I on the right track with creating an overridden system and calculating a pseudo-inverse?
My current solution requires decomposing a singular value and three matrix multiplications, which depends a little on the fact that m can be 5000 or even 10000. Are there faster methods for calculating a pseudo-inverse (in fact, I only need the first one with its column, and not the whole matrix , given that B is zero, except for the first row), given the sparseness of the matrix (each row contains exactly two nonzero values, one of which is always one, and the other is always negative)
What math libraries do you propose to use for this? Is LAPACK OK?
I am also open to any other proposals, provided that they are numerically stable and asymptotically fast (say k*n^2 , where k can be large).