Why does `FindFit` fail so badly in this simple case?Why FindFit could not exactly fulfill condition?FindFit: why do I get negative value as result?How to solve this FindFit::nrlnum:Why does FindFit seem to have trouble fitting exponential data?Does FindFit use symbolic differentiation?Why does FindFit work and NonlinearModelFit does not?Findfit does not find the best fitWhy can't FindFit get the proper result in this problem?Making batch data fitting robust — why does `NonlinearModelFit` fail occasionally?
How many stack cables would be needed if we want to stack two 3850 switches
Is is possible to take a database offline when doing a backup using an sql job?
Worlds with different mathematics and logic
Can RPi4 run simultaneously on dual band (WiFi 2.4GHz / 5GHz)?
Beyond Futuristic Technology for an Alien Warship?
Garage door sticks on a bolt
What is the meaning of colored vials next to some passive skills
A cotton-y connection
Can you cure a Gorgon's Petrifying Breath before it finishes turning a target to stone?
What are one's options when facing religious discrimination at the airport?
Why does `FindFit` fail so badly in this simple case?
Pushing the e-pawn
How deep is the liquid in a half-full hemisphere?
What does it mean by "my days-of-the-week underwear only go to Thursday" in this context?
What would happen if I build a half bath without permits?
After viewing logs with journalctl, how do I exit the screen that says "lines 1-2/2 (END)"?
What is the climate impact of planting one tree?
How do my husband and I get over our fear of having another difficult baby?
Was the ruling that prorogation was unlawful only possible because of the creation of a separate supreme court?
Vilna Gaon's gematria for the number of kosher & non-kosher sukkot in Masechet Sukkah
How to compare integers in Tex?
Speed and Velocity in Russian
When did Unix stop storing passwords in clear text?
What would influence an alien race to map their planet in a way other than the traditional map of the Earth
Why does `FindFit` fail so badly in this simple case?
Why FindFit could not exactly fulfill condition?FindFit: why do I get negative value as result?How to solve this FindFit::nrlnum:Why does FindFit seem to have trouble fitting exponential data?Does FindFit use symbolic differentiation?Why does FindFit work and NonlinearModelFit does not?Findfit does not find the best fitWhy can't FindFit get the proper result in this problem?Making batch data fitting robust — why does `NonlinearModelFit` fail occasionally?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
Consider
data = -0.023, 0.019, -0.02, 0.019, -0.017, 0.018, -0.011, 0.016,
-0.0045, 0.0097, -0.0022, 0.0056, -0.0011, 0.003, -0.0006, 0.0016
Nothing extraordinary with this dataset:
ListPlot@data
Why does FindFit
provide such a bad identification?
FindFit[data, 1./(a + b/x), a, b, x]
(* a -> -3.81928*10^16, b -> 9.00824*10^14 *) <- completely off
FindFit[data, x/(a*x + b), a, b, x]
(* a -> -3.81928*10^16, b -> 9.00824*10^14 *) <- completely off
But if I do a least square fit manually (with an initial guess):
cost[a_, b_] := Norm[1/(a + b/#[[1]]) - #[[2]] & /@ data]
FindMinimum[cost[a, b], a, 51, b, -0.38]
(* 0.000969844, a -> 38.4916, b -> -0.29188 *) <- good !
I am even more surprised that MMA does not give any error (MMA 12.0 for Windows 10 Pro, 64 bits). Probably it finds a local minimum (cf documentation In the nonlinear case, it finds in general only a locally optimal fit.).
fitting
$endgroup$
add a comment
|
$begingroup$
Consider
data = -0.023, 0.019, -0.02, 0.019, -0.017, 0.018, -0.011, 0.016,
-0.0045, 0.0097, -0.0022, 0.0056, -0.0011, 0.003, -0.0006, 0.0016
Nothing extraordinary with this dataset:
ListPlot@data
Why does FindFit
provide such a bad identification?
FindFit[data, 1./(a + b/x), a, b, x]
(* a -> -3.81928*10^16, b -> 9.00824*10^14 *) <- completely off
FindFit[data, x/(a*x + b), a, b, x]
(* a -> -3.81928*10^16, b -> 9.00824*10^14 *) <- completely off
But if I do a least square fit manually (with an initial guess):
cost[a_, b_] := Norm[1/(a + b/#[[1]]) - #[[2]] & /@ data]
FindMinimum[cost[a, b], a, 51, b, -0.38]
(* 0.000969844, a -> 38.4916, b -> -0.29188 *) <- good !
I am even more surprised that MMA does not give any error (MMA 12.0 for Windows 10 Pro, 64 bits). Probably it finds a local minimum (cf documentation In the nonlinear case, it finds in general only a locally optimal fit.).
fitting
$endgroup$
add a comment
|
$begingroup$
Consider
data = -0.023, 0.019, -0.02, 0.019, -0.017, 0.018, -0.011, 0.016,
-0.0045, 0.0097, -0.0022, 0.0056, -0.0011, 0.003, -0.0006, 0.0016
Nothing extraordinary with this dataset:
ListPlot@data
Why does FindFit
provide such a bad identification?
FindFit[data, 1./(a + b/x), a, b, x]
(* a -> -3.81928*10^16, b -> 9.00824*10^14 *) <- completely off
FindFit[data, x/(a*x + b), a, b, x]
(* a -> -3.81928*10^16, b -> 9.00824*10^14 *) <- completely off
But if I do a least square fit manually (with an initial guess):
cost[a_, b_] := Norm[1/(a + b/#[[1]]) - #[[2]] & /@ data]
FindMinimum[cost[a, b], a, 51, b, -0.38]
(* 0.000969844, a -> 38.4916, b -> -0.29188 *) <- good !
I am even more surprised that MMA does not give any error (MMA 12.0 for Windows 10 Pro, 64 bits). Probably it finds a local minimum (cf documentation In the nonlinear case, it finds in general only a locally optimal fit.).
fitting
$endgroup$
Consider
data = -0.023, 0.019, -0.02, 0.019, -0.017, 0.018, -0.011, 0.016,
-0.0045, 0.0097, -0.0022, 0.0056, -0.0011, 0.003, -0.0006, 0.0016
Nothing extraordinary with this dataset:
ListPlot@data
Why does FindFit
provide such a bad identification?
FindFit[data, 1./(a + b/x), a, b, x]
(* a -> -3.81928*10^16, b -> 9.00824*10^14 *) <- completely off
FindFit[data, x/(a*x + b), a, b, x]
(* a -> -3.81928*10^16, b -> 9.00824*10^14 *) <- completely off
But if I do a least square fit manually (with an initial guess):
cost[a_, b_] := Norm[1/(a + b/#[[1]]) - #[[2]] & /@ data]
FindMinimum[cost[a, b], a, 51, b, -0.38]
(* 0.000969844, a -> 38.4916, b -> -0.29188 *) <- good !
I am even more surprised that MMA does not give any error (MMA 12.0 for Windows 10 Pro, 64 bits). Probably it finds a local minimum (cf documentation In the nonlinear case, it finds in general only a locally optimal fit.).
fitting
fitting
asked 8 hours ago
anderstoodanderstood
8,0351 gold badge20 silver badges60 bronze badges
8,0351 gold badge20 silver badges60 bronze badges
add a comment
|
add a comment
|
3 Answers
3
active
oldest
votes
$begingroup$
OK, I got it: the initial guess makes all the difference.
FindFit[data, 1./(a + b/x), a, 51, b, -.3, x]
(* a -> 38.4916, b -> -0.29188 *)
I was just surprised that MMA went "so far" to find a local minimum.
$endgroup$
add a comment
|
$begingroup$
You can override the default method by DifferentialEvolution
which is more robust at the cost of converging slower.
FindFit[data, 1./(a + b/x), a, b, x,
Method -> "NMinimize", Method -> "DifferentialEvolution"]
a -> 38.491561, b -> -0.29188008
$endgroup$
add a comment
|
$begingroup$
Try Method-> "NMinimize"
, no need to specify something else:
sol = FindFit[data, 1./(a + b/x), a, b, x, Method -> "NMinimize"]
Show[ListPlot[data],Plot[1./(a + b/x) /. sol, x, -.1, 0, PlotRange -> All]]
$endgroup$
add a comment
|
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f206768%2fwhy-does-findfit-fail-so-badly-in-this-simple-case%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
OK, I got it: the initial guess makes all the difference.
FindFit[data, 1./(a + b/x), a, 51, b, -.3, x]
(* a -> 38.4916, b -> -0.29188 *)
I was just surprised that MMA went "so far" to find a local minimum.
$endgroup$
add a comment
|
$begingroup$
OK, I got it: the initial guess makes all the difference.
FindFit[data, 1./(a + b/x), a, 51, b, -.3, x]
(* a -> 38.4916, b -> -0.29188 *)
I was just surprised that MMA went "so far" to find a local minimum.
$endgroup$
add a comment
|
$begingroup$
OK, I got it: the initial guess makes all the difference.
FindFit[data, 1./(a + b/x), a, 51, b, -.3, x]
(* a -> 38.4916, b -> -0.29188 *)
I was just surprised that MMA went "so far" to find a local minimum.
$endgroup$
OK, I got it: the initial guess makes all the difference.
FindFit[data, 1./(a + b/x), a, 51, b, -.3, x]
(* a -> 38.4916, b -> -0.29188 *)
I was just surprised that MMA went "so far" to find a local minimum.
answered 8 hours ago
anderstoodanderstood
8,0351 gold badge20 silver badges60 bronze badges
8,0351 gold badge20 silver badges60 bronze badges
add a comment
|
add a comment
|
$begingroup$
You can override the default method by DifferentialEvolution
which is more robust at the cost of converging slower.
FindFit[data, 1./(a + b/x), a, b, x,
Method -> "NMinimize", Method -> "DifferentialEvolution"]
a -> 38.491561, b -> -0.29188008
$endgroup$
add a comment
|
$begingroup$
You can override the default method by DifferentialEvolution
which is more robust at the cost of converging slower.
FindFit[data, 1./(a + b/x), a, b, x,
Method -> "NMinimize", Method -> "DifferentialEvolution"]
a -> 38.491561, b -> -0.29188008
$endgroup$
add a comment
|
$begingroup$
You can override the default method by DifferentialEvolution
which is more robust at the cost of converging slower.
FindFit[data, 1./(a + b/x), a, b, x,
Method -> "NMinimize", Method -> "DifferentialEvolution"]
a -> 38.491561, b -> -0.29188008
$endgroup$
You can override the default method by DifferentialEvolution
which is more robust at the cost of converging slower.
FindFit[data, 1./(a + b/x), a, b, x,
Method -> "NMinimize", Method -> "DifferentialEvolution"]
a -> 38.491561, b -> -0.29188008
answered 8 hours ago


CoolwaterCoolwater
16.3k3 gold badges25 silver badges54 bronze badges
16.3k3 gold badges25 silver badges54 bronze badges
add a comment
|
add a comment
|
$begingroup$
Try Method-> "NMinimize"
, no need to specify something else:
sol = FindFit[data, 1./(a + b/x), a, b, x, Method -> "NMinimize"]
Show[ListPlot[data],Plot[1./(a + b/x) /. sol, x, -.1, 0, PlotRange -> All]]
$endgroup$
add a comment
|
$begingroup$
Try Method-> "NMinimize"
, no need to specify something else:
sol = FindFit[data, 1./(a + b/x), a, b, x, Method -> "NMinimize"]
Show[ListPlot[data],Plot[1./(a + b/x) /. sol, x, -.1, 0, PlotRange -> All]]
$endgroup$
add a comment
|
$begingroup$
Try Method-> "NMinimize"
, no need to specify something else:
sol = FindFit[data, 1./(a + b/x), a, b, x, Method -> "NMinimize"]
Show[ListPlot[data],Plot[1./(a + b/x) /. sol, x, -.1, 0, PlotRange -> All]]
$endgroup$
Try Method-> "NMinimize"
, no need to specify something else:
sol = FindFit[data, 1./(a + b/x), a, b, x, Method -> "NMinimize"]
Show[ListPlot[data],Plot[1./(a + b/x) /. sol, x, -.1, 0, PlotRange -> All]]
answered 8 hours ago
Ulrich NeumannUlrich Neumann
14.3k7 silver badges23 bronze badges
14.3k7 silver badges23 bronze badges
add a comment
|
add a comment
|
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f206768%2fwhy-does-findfit-fail-so-badly-in-this-simple-case%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown