\-operator to perform least squares fit on multiple sample-sets

Is there a matrix expansion of the \-operator that enables least squares fit of y = M\x where M is an m-by-n-by-p matrix and x is an m-length vector m=[3 .. 10]; n =3 for order 2?

Antworten (2)

bym
bym am 14 Jan. 2012

0 Stimmen

3 Kommentare

Thanks. I'll look at the code.
It appears that this code has 3 sets of x and 3 sets of y. My issues is many-sets of x, but only one set of y. If I understand the code correctly it requires that the y's not overlap each other in order to get the 3-distinct curves. If I try replicating the y-values then I only get 1 set of coeffs.
Somehow I need to get the operator to take the data n-values at a time without a for-loop. Any thoughts would be appreciated
Thanks
Since I'm trying to fit multiple samples to multiple targets, the fact that y can be a matrix is very helpful but not everything I would like. If the operator could parse the data as a function of the order and the size of y that might work.
thanks

Melden Sie sich an, um zu kommentieren.

Andrew Newell
Andrew Newell am 19 Jan. 2012
If I understand your question, you are trying to estimate y given multiple measurements of x. Note that if M were a matrix, the correct least squares estimate would be
yhat = (M'*M)\(M'*x);
(see also this answer).
You would be well advised to recast your problem. Instead of several vectors x, make one vector X containing all the data. Then reshape M so
y = M*X;
and then use the above expression.

6 Kommentare

Thank you for the suggestion. Let me see if I can get there.
Thanks. I tried recasting per your suggestion but was unsuccessful in attaining my desired result. I believe I have not
posed my question well so here is a numeric example.
y is the target to which all x's need to be adjusted. In my original post I discribed y as being an m x 3 matrix, but y as
a single vector would also be acceptable.
{
y = 2360; 6805; 11877; 15238;
}
Here are 4 examples of x-values; each row is an x.
{
X = [ ...
3313.272 7651.640 12685.088 16030.168;
3260.816 7591.840 12632.344 15971.112;
3225.880 7548.640 12567.560 15900.824;
3205.088 7562.496 12626.608 15983.656];
}
Putting these into Vondermonde (V) matricies (done in parallel of course):
{
V1 = [ ...
10977771.3459840 3313.27200000000 1;
58547594.6896000 7651.64000000000 1;
160911457.567744 12685.0880000000 1;
256966286.108224 16030.1680000000 1];
V2 = [ ...
10632920.9858560 3260.81600000000 1;
57636034.5856000 7591.84000000000 1;
159576114.934336 12632.3440000000 1;
255076418.516544 15971.1120000000 1];
V3 = [ ...
10406301.7744000 3225.88000000000 1;
56981965.8496000 7548.64000000000 1;
157943564.353600 12567.5600000000 1;
252836203.878976 15900.8240000000 1];
V4 = [ ...
10272589.0877440 3205.08800000000 1;
57191345.7500160 7562.49600000000 1;
159431229.585664 12626.6080000000 1;
255477259.126336 15983.6560000000 1];
}
Using p = V\y gives four sets of p-values (this is where I have used a for-loop):
p1 = [ ...
-1.19794168760304e-06;
1.03531698605336;
-1054.41785901502;
];
p2 = [ ...
-1.22990697430811e-06;
1.03605999963114;
-1001.23771919361;
];
p3 = [ ...
-1.21854840069794e-06;
1.03874536729461;
-975.178458457347;
];
p4 = [ ...
-1.16835324217934e-06
1.02950561368923
-924.033546502190
];
so the four results where Vn*pn:
yo =
2362.71819206764 6797.31839976274 11885.9066739332 15234.0567342364
2364.08580088584 6793.47706749778 11890.3648240961 15232.0723075203
2363.00886460663 6796.50108756282 11886.8543919961 15233.6356558344
2363.62052909954 6794.77884476849 11888.8582773600 15232.7423487719
compared to
y = 2360; 6805; 11877; 15238;
This 'fits' the x's to y.
I need to accomplish the same thing on thousands of x's.
Hopefully this explains my question better. Any further suggestions would be much appreciated.
So what you're really trying to do is to fit second order polynomials y=a*x^2+b*x+c to the data?
I'm really trying to fit the data, using individual second order polynomials to the same (desired) target-curve. To me, this means there is a different a,b, & c for each data-set. If that is what you meant, I apologize for being so dense.
I'm not sure what you mean by "curve". To me, a set of (x,y) values represents points on a curve - in the example above, you would have four curves, one for each row of X.
Yes an (x,y) set are points on a curve. In this case y is also a curve (a set of data with respect to (wrt), say z) and all four rows of X are also wrt z and we are trying to find the quadratic coefficients that when applied to each row in X, that will cause each row in X to closely match y.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Descriptive Statistics finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 14 Jan. 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by