How to determine the coefficient from the argmin function ?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Lyhour Chhay
le 22 Sep 2021
Commenté : Lyhour Chhay
le 28 Sep 2021
Hello everyone! I want to determine the coefficient from the function (equation) as shown in the figure attachement. I have the value X and Z in vector form, How can I determine a,b,c coefficient ? Thank you very much.
0 commentaires
Réponse acceptée
Bjorn Gustavsson
le 22 Sep 2021
This is a standard minimization-problem, for that matlab has the fminsearch function (and possibly a couple more in the optimization toolbox), have a look at the help and documentation for that function.
HTH
4 commentaires
Plus de réponses (2)
Walter Roberson
le 25 Sep 2021
n = 5;
syms X [1 n] real
syms Z [1 n] real
syms a1 b1 c1
eqn1 = sum((Z + (a1*X + c1)/b1).^2)
parta1 = simplify(solve(diff(eqn1, a1),a1))
eqn2 = simplify(subs(eqn1, a1, parta1))
partc1 = simplify(solve(diff(eqn2, c1),c1))
eqn3 = simplify(subs(eqn2, c1, partc1))
symvar(eqn3)
bestc1 = partc1
besta1 = simplify(subs(parta1, c1, bestc1))
minval = simplify(subs(eqn1, {a1, c1}, {besta1, bestc1}))
x = randi([-9 9], 1, n)
z = randi([-9 9], 1, n)
vpa(subs(besta1, [X, Z], [x, z]))
vpa(subs(bestc1, [X, Z], [x, z]))
vpa(subs(minval, [X, Z], [x, z]))
F = matlabFunction(subs(eqn1, [X,Z], [x,z]), 'vars', {[a1, b1, c1]})
abc0 = [-1 0 1]
[bestarg, fval] = fminsearch(F, abc0)
What does this tell you? It tells you that the best a1 and c1 to use are linear multiples of b1, with the multiples depending upon the exact X and Z values, and that for any given non-zero b1, you will arrive at the same minimum sum-of-squares compared to using the formulas with different non-zero b1.
4 commentaires
Walter Roberson
le 27 Sep 2021
I choose 5 because it 5 terms is large enough to have problems finding an exact root if the problem turned out to involve roots of a polynomial. (Though I guess 6 would have been even better for that.) If I choose too small of a number, then there might hypothetically have been exact solutions that could not generalize to large number of terms.
I did not need more than 5 in order to illustrate the pattern. There was no information in the original problem to suggest that the vector lengths were 10... or 20... or 2713503 ... And I needed to choose some number in order to have a pattern that MATLAB could take the derivatives of.
does this number use for find the best coeff. a1,b1,c1
No, 5 is standing in for length(X) and length(Z) and has nothing to do with starting points for searches.
The starting point, abc0, does affect the values that are returned by fminsearch(). fminsearch() is deterministic, and will use the initial value to guess directions to search in. However, whatever locations are probed by fminsearch, the outcome will still be that the first value divided by the second value will be a constant that depends upon the X and Z values, and the third value divided by the second value will be a (different) constant that depends upon the X and Z values. The besta1 and bestc1 formulas show how you would calculate the ratios.
John D'Errico
le 27 Sep 2021
Modifié(e) : John D'Errico
le 27 Sep 2021
What you need to unerstand is there is NO simple solution. There are no unique set of values a1, b1, c1 that solve the problem. Suppose there was? So just imagine we had a solution that was the best possible. Call them a1,b1,c1.
Then we can arbitrarily choose, for ANY non-zero k:
a2 = k*a1
b2 = k*b1
c2 = k*c1
Now you need to see that
(a1*x + b1)/c1 == (a2*x + b2)/c2
since the value of k will factor out. So for ANY non-zero value of k, we can get a new, equally valid solution, if one exists. That means there is no unique optimal set.
What does that tell me? It says that if you use an optimizatin tool, and choose a different set of starting vcalues for a1,b1,c1, then you will find a different solution from the optimizer. What behavior are you seeing when you try to solve it using an optimzer? EXACTLY THAT. The solution is dependent on the starting values.
What is the resolution to this problem? Arbitrarily fix one of those three parameters to be 1. c1 is the most logical. So now your problem reduces to
argmin{(zi - (a1*xi+b1))^2}
over paramneters a1 and b1. This is especially nice, because you already have a simple tool to achieve that, in the form of polyfit.
ab = polyfit(x,z,1);
a1 = ab(1);
b1 = ab(2);
There is no need for any optimization, no starting values needed. Polyfit is blazingly fast. Every time you use it on the same data, you will get the same answer - the unique optimum. This is true as long as you have at least two distinct points. (They cannot be vertically oriented, since then the slope, thus a1 would be undefined.)
Voir également
Catégories
En savoir plus sur Number Theory dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!