Message Boards Message Boards

0
|
4107 Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:
GROUPS:

Need extra explanation of FIT function

Posted 9 years ago

In the explanation of

Fit[data,funs,vars]

It states...

"The argument funs can be any list of functions that depend only on the objects vars."

What is "the objects vars"? What list of functions are they referring to.. functions that I write, or functions that are standard in mathematica?

In the examples it shows ....

line = Fit[data, {1, x}, x]

But how is {1, x} a list of functions? They look like a constant and a variable to me.

funs looks like a redundant parameter and I'm tempted to just plug in default values and not worry about what they mean.

How should this funs list really be applied and conceptualized?

POSTED BY: hugh fuve
4 Replies
Posted 9 years ago

Fit isn't restricted to polynomials. You should choose your basis functions to match the nature of the problem. For example, suppose I believe my data has a jump (of unknown height) at time 0, added to an unknown linear trend with an unknown offset and measurement noise. Something like this:

data = Table[{x, 
   3 UnitStep[x] - 0.3 x + 2 + 
    RandomVariate[NormalDistribution[]]}, {x, -10, 10}]

{{-10, 4.5653}, {-9, 4.72512}, {-8, 4.44479}, {-7, 4.18572}, {-6, 
  2.58606}, {-5, 3.00913}, {-4, 2.09279}, {-3, 3.71923}, {-2, 
  2.69165}, {-1, 1.55887}, {0, 4.69223}, {1, 3.07118}, {2, 
  5.43961}, {3, 3.50293}, {4, 2.9189}, {5, 3.70878}, {6, 3.57311}, {7,
   3.41627}, {8, 2.79404}, {9, 3.04386}, {10, 2.47882}}

You may ListPlot this if you like: my eyes can't easily see the underlying regularity in all of the noise. Nevertheless, Fit figures it out pretty well:

Fit[data, {1, UnitStep[x], x}, x]

2.10015 - 0.228675 x + 2.55593 UnitStep[x]

It works well here because my data represents a sum of known functions with unknown coefficients, and I fed those known functions to Fit as a basis. More phenomenological uses, like fitting a polynomial or Fourier series to data whose genesis is different, are trickier. High-order polynomials represented as power series (1,x^1,x^2,x^3,...) are especially tricky, as the results are generally numerically unstable.

POSTED BY: Updating Name
Posted 9 years ago

From this I am getting that the funs arguments are a guide that tell the Fit function how and what kind of polynomial equation to create given the variables... in the most basic example then..

Fit[data, {1, x},x]

The funs are requesting a binomial with a constant term given by "1" and a variable term "x" which implies a coefficient with that x term or in other words a basic linear line equation such as....

y = mx + b

Where the b is created because of the "1" and the mx is created because of the "x"

I have noticed that messing with the funs arguments such as... Fit[data,{2,3x},x] Will not make any difference to the resulting equation it will still be the same as {1,x}

And that adding {1, x, x^2} Will create a quadratic equation.

So I am guessing that these 'function' arguments are not literal parameters that are expanded into equations, instead they facilitate some kind of template.

POSTED BY: hugh fuve

"Function" in Mathematica has several different meanings. There are term rewriting formulae triggered by tags, like:

f[x_]:=x^2

Then there are "pure functions" made by wrapping Function around expressions built around Slot objects.

Function[Slot[1]^2]

For Fit, the "functions" are simply expressions containing zero or more undefined symbols that act as free variables. A "function" that lacks the free variable symbol(s) serves as a constant in the fit.

POSTED BY: John Doty

Hi,

I suppose that you can think of the "list of functions" as the building blocks which can be linearly combined to describe the data. Here's an example:

data = RandomReal[1, {10, 3}];
Fit[data, {1, x, y, x y, y^2, Sin[x y], x^2}, {x, y}]
(*-0.222278 + 0.975241 x - 2.88332 x^2 + 3.78614 y + 10.217 x y - 4.15174 y^2 - 8.63265 Sin[x y]*)

Hope this helps,

Marco

POSTED BY: Marco Thiel
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract