How to determine the coefficient from the argmin function ?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Bjorn Gustavsson
2021-9-22
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
更多回答(2 个)
Walter Roberson
2021-9-25
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 个评论
Walter Roberson
2021-9-27
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
2021-9-27
编辑:John D'Errico
2021-9-27
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.)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Number Theory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!