Looking for C/C++ library calculating max of Gaussian curve using discrete values

后端 未结 1 1250
伪装坚强ぢ
伪装坚强ぢ 2021-01-01 08:24

I have some discrete values and assumption, that these values lie on a Gaussian curve. There should be an algorithm for max-calculation using only 3 discrete values. Do you

相关标签:
1条回答
  • 2021-01-01 08:38

    You have three points that are supposed to be on a Gaussian curve; this means that they lie on the function:

    generic Gaussian function

    If you take the logarithm of this function, you get:

    log of the Gaussian function

    which is just a simple 2nd grade polynomial, i.e. a parabola with a vertical axis of simmetry:

    generic 2nd grade polynomial

    with

    coefficient definitions

    So, if you know the three coefficients of the parabola, you can derive the parameters of the Gaussian curve; incidentally, the only parameter of the Gaussian function that is of some interest to you is b, since it tells you where the center of the distribution, i.e. where is its maximum. It's immediate to find out that

    b from beta and alpha

    All that remains to do is to fit the parabola (with the "original" x and the logarithm of your values). Now, if you had more points, a polynomial fit would be involved, but, since you have just three points, the situation is really simple: there's one and only one parabola that goes through three points.

    You now just have to write the equation of the parabola for each of your points and solve the system:

    system of the three points

    (with y and z, where the zs are the actual values read at the corresponding x)

    This can be solved by hand (with some time), with some CAS or... looking on StackOverflow :) ; the solution thus is:

    solution of the parabola through three points

    So using these last equations (remember: the ys are the logarithm of your "real" values) and the other relations you can easily write a simple algebraic formula to get the parameter b of your Gaussian curve, i.e. its maximum.

    final result

    (I may have done some mess in the calculations, double-check them before using the results, anyhow the procedure should be correct)

    (thanks at http://www.codecogs.com/latex/eqneditor.php for the LaTeX equations)

    0 讨论(0)
提交回复
热议问题