0
$\begingroup$

Say I have a function function $f(x)$ returning any real between 0 and 1, for a $x$ between 0 and 1.

I want to get $n$ randomly generated values of $x$, based the probablity they occur from $f(x)$.

Example: If $n=5$, and $f(x)$ described a direct ascending line from 0 to 1, I could get $x_1=0.8$, $x_2=0.7$, $x_3=0.75$, $x_4=0.4$, $x_5=0.3$.

Basically, the higher $f(x)$, the more the random value tends to $x$.

Any idea how to achieve that?

  • 1
    Do you intend $f$ to be proportional to a probability distribution? Are you looking for an implementable algorithm or just an abstract definition (with perhaps nicer theoretical properties)?2012-01-15
  • 0
    Question makes no sense to me. You write "$x$ between $0$ and $1$," and $f(x)$ returns a "real between $0$ and $1$," so where are you getting $x_1=4$, $x_2=3.5$, etc.? Those numbers are not between $0$ and $1$.2012-01-15
  • 0
    I'm looking for an implementable algorithm. I think I do intend $f$ to be proportional to a probability distribution, but I'm not sure what any other option would be?2012-01-15
  • 0
    Oops, you're right Gerry. I'll divide these by 5.2012-01-15
  • 0
    So do you just want to normalize $f(x)$ on $[0,1]$ and then use that as a probability distribution?2012-01-15
  • 0
    What does normalizing $f(x)$ imply? And yes, I believe I want a probability distribution.2012-01-15
  • 0
    OK, now everything's between zero and one, but the question still needs work. What do you mean by "the higher $f(x)$, the more the random value tends to $x$"? How (if at all) is this illustrated by your example with $x_1=0.8$, $x_2=0.7$, etc.?2012-01-15
  • 1
    If you can find the antiderivative of $f$, you can use [inverse transform sampling](http://en.wikipedia.org/wiki/Inverse_transform_sampling) (after appropriately rescaling it so that the antiderivative goes from $0$ to $1$ over $[0,1]$).2012-01-15
  • 0
    @GerryMyerson More values tend to to be located at the end of $f(x)$ (i.e., towards 1), because $f(x)$ is ascending.2012-01-16

1 Answers 1