0

I am working on a project where I would like to take a weighted average of values in a set, with the weights decreasing exponentially. To do this, I am trying to find a function $f$ such that $\int_0^1 f = 1$. $f$ will be used in the following formula:

$$\sum_{n=0}^{|S|}S_n * \frac{f\left(\frac{n}{|S|}\right) + f\left(\frac{n + 1}{|S|}\right)}{2} * \frac{1}{|S|} $$

I would appreciate help with two aspects of this.

  1. It has been a while since I took calculus, so I am at a bit of a loss as to how to move forward with finding a function $f$ suitable for these purposes, generally. I have been able to find a few functions which have integrals close to 1, but have only been able to use guess-and-check to find these approximations.
  2. I wonder if I am on the right track here with doing this weighted average, and am curious if I am over-complicating it.

Thanks!

Erik
  • 103
  • 3
  • I am probably confused, so please forgive me for asking, but doesn't $\int_0^1{e^{-x}} = -\frac{1}{e} + 1$? – Erik Dec 01 '18 at 00:08
  • 1
    Indeed it does! Hence I removed my comment and (hopefully) answered your question below. – Godfather Dec 01 '18 at 00:11
  • If you do it this way, the weights will not sum to 1. – eyeballfrog Dec 01 '18 at 00:25
  • Can you elaborate @eyeballfrog? I understand that it is only an approximation of the integral, but with larger values of $|S|$, the error should be reasonably small, no? Is there another approach that you can recommend? – Erik Dec 01 '18 at 00:31
  • 1
    The error is proportional to $1/|S|$, which may not be good enough unless $S$ is very large. Still, you can just use the fact that $\sum_0^n a^i = (1 - a^n)/(1-a)$ to quickly normalize the weights without needing the integral at all. – eyeballfrog Dec 01 '18 at 00:52

1 Answers1

2

You can start with the function $f(x) = ae^{-x}$ for some $a > 0$. Now, you have:

$\int_0^1 f(x)dx = a\int_0^1 e^{-x} dx = a\left(1 - \frac{1}{e} \right) = 1$. This implies a = $\frac{e}{e-1}$ and

$f(x) = \frac{e^{1-x}}{e-1}$.

Godfather
  • 2,355