0

I know function form:
enter image description here
and have some measured data:

[x, y]
[1, 13.5]
[2, 13.25]
[3, 13.167]
[4, 12.125]
[5, 13.1]
[6, 13.083]

Now I have to find a and b. Brute-force way is obviously not very elegant :-). I found that it is possible to do this type of calculation with regression analysis, but I am not sure, because real measured data are really measured so there could be some errors (I posted simplified version, where a = 2 and b = 13 and I rounded values so not all of them are accurate). I found article about measurement error models, but I am a bit confused from it.
Can someone please point me to the right direction? Maybe show me some relevant C# code, or at least the right list of steps, what I should do?
I tried semi-brute-force way - solving six equations with two variables and then select the best combination (least distance from all measured values) from given intervals.

Community
  • 1
  • 1
Artholl
  • 1,291
  • 1
  • 19
  • 38
  • 1
    This seems more like an algorithm question than a programming question; you *might* get a good answer, but stackoverflow is usually better suited to "and I'm having this specific implementation problem" questions. – Marc Gravell Jan 14 '16 at 09:11
  • The method of least squares is the standard approach. A web search for that term should turn up a lot of hits. In summary: let SSE = sum((y[i] - (1/(a*x[i]) + b))^2, i, 1, n). Note that SSE is a function of a and b. Derive d(SSE)/da and d(SSE)/db. Look for stationary points of those partial derivatives. The minima of SSE (i.e., the values of a and b which give the least squared error) are among the stationary points. – Robert Dodier Jan 14 '16 at 17:15
  • Since 1/x = x^(-1) you might try adapting a least square polynomial fit... (http://mathworld.wolfram.com/LeastSquaresFittingPolynomial.html) – andand Jan 14 '16 at 17:23
  • I would use [approximation search](http://stackoverflow.com/q/29166819/2521214). If the function plot is strictly monotonous (in case `x,y` are constants and one of `a,b` is variables) then binary search usable and faster. – Spektre Jan 15 '16 at 08:26

1 Answers1

0

You may try these libraries:

They would do the job of applying statistic models for you. In RStan you may desribe the formula let is guess a and b out of your data. I think in Infer.NET it works simmilary.

Pavel Evdokimov
  • 806
  • 1
  • 6
  • 15