Find a functional equation which results values for a gaussian distribution graph

36 Views Asked by At

This is an example for a small dataset with 17 values. The graph to this values looks a bit like a gaussian distribution.

0
0.05
0.1
0.2
0.4
0.7
0.85
0.95
1
0.95
0.85
0.7
0.4
0.2
0.1
0.05
0

graph

Unfortunatly I also need to get values in between. So I need to find a formula, which describes nearly this kind of values - it doesn't have to fit the values exactly.

If I use f(2), I do get 0.1, if I do f(3) I do get 0.2, so obviously f(2.5) should be 0.15.

I tried to start with a parabola function:

f(x) = -x ** 2 + 1

But I would have to move it one to the right and also it doesn't work for the lower y values. I think this attempt will not work...

Update

const getValue = (x) => {
  const u = Math.floor(x)
  const res = (1 + u - x) * u + (x - u) * (u + 1)
  console.log(res)
  return res
}
1

There are 1 best solutions below

5
On BEST ANSWER

You said $f(2)=.1$ and $f(3)=.2$, so $f(2.5)$ should be $.15$. So it sounds like you want linear interpolation. Fix $x$ between $1$ and $17$ and pick $u$ to be one of the points $1,2,\ldots,17$ such that $u\leqslant x\leqslant u+1$. Then $$x=(1+u-x)u+(x-u)(u+1),$$ so linear interpolation between $f(u)$ and $f(u+1)$ is $$f(x)=(1+u-x)f(u)+(x-u)f(u+1).$$

Since your datapoints at which you already know the functions are integers, if you actually want to code this up, once you have $x$, $u$ should be the floor of $x$.

In general, suppose we have two points $(u,u')$ and $(v,v')$ ($u\neq v$) and we want $f(x)$, where $f$ is a line going through $(u,u')$ and $(v,v')$. We can write $$x=\Bigl(\frac{v-x}{v-u}\Bigr)u+\Bigl(\frac{x-u}{v-u}\Bigr)v$$ and get $$f(x)=\Bigl(\frac{v-x}{v-u}\Bigr)u'+\Bigl(\frac{x-u}{v-u}\Bigr)v'.$$

If you're coding in python, numpy has a built in linear interpolation function (numpy.interp). This requires inputting an $x$ where you want the function value, an array of input values (for you, $(1,\ldots,17)$), and a list of output values (for you, $(0,.05,\ldots,0)$).

If you want a function that just takes $x$, you can use this code.

import numpy
ylist = [0,0.05,0.1,0.2,0.4,0.7,0.85,0.95,1,0.95,0.85,0.7,0.4,0.2,0.1,0.05,0]
xlist = range(1,1+len(ylist))
f = lambda x:np.interp(x,xlist,ylist)

You can specify values outside of the bounds (ie $x<1$ and $x>17$ in this case).

Instead of a single input $x$, you can pass in an array of $x$-values. The output will be the array of output values.