How to increase the acceptance ratio

Click For Summary

Discussion Overview

The discussion revolves around generating a random distribution using an exponential function and improving the acceptance ratio in a sampling method. The context includes technical aspects of programming in Python and mathematical reasoning related to probability distributions.

Discussion Character

  • Technical explanation, Homework-related, Mathematical reasoning, Debate/contested

Main Points Raised

  • One participant presents a method for generating an exponentially distributed random variable and calculates the acceptance ratio, seeking to improve it using a linear function.
  • Another participant questions whether the original post is a homework problem and suggests posting in a dedicated homework forum.
  • A similar response is echoed by another participant, who also expresses confusion regarding the previous comment about distributions.
  • The thread is ultimately closed due to a duplicate question being referenced.

Areas of Agreement / Disagreement

Participants do not reach a consensus, as there are differing views on whether the original question pertains to homework and confusion about the mathematical explanation provided.

Contextual Notes

There are limitations in clarity regarding the mathematical concepts discussed, particularly the relationship between the flat distribution and the proposed function. The discussion does not resolve these mathematical uncertainties.

Othman0111
Messages
27
Reaction score
0
I trying to generate a random distribution

λe-λy
Which distributed exponentially.
Python:
%matplotlib inline
import numpy as np
from matplotlib import pyplot

N = 1000
r = np.random.random(N)

xlambda = 0.1
x = -np.log(r)/xlambda

binwidth=xlambda*5
pyplot.hist(x,bins=np.arange(0.,100., binwidth),density=True);
pyplot.plot(np.arange(0.,100.,binwidth),xlambda*np.exp(-xlambda*np.arange(0.,100.,binwidth)),ls='-',c='red',lw=3);N = 10000

xmax = 100
ymax = xlambda

rx = np.random.random(N)*xmax
ry = np.random.random(N)*ymax

values = []

Nin = 0
for i in range(N):
    if(ry[i] <= xlambda*np.exp(-xlambda*rx[i])):
        # Accept
        values.append(rx[i])
        Nin += 1    

x = np.asarray(values)

print("Acceptance Ratio: ",Nin/float(N))

binwidth=xlambda*5
pyplot.hist(x,bins=np.arange(0.,100., binwidth),density=True);
pyplot.plot(np.arange(0.,100.,binwidth),xlambda*np.exp(-xlambda*np.arange(0.,100.,binwidth)),ls='-',c='red',lw=3);

I want to Improve the acceptance ratio by using a linear function f(x)=1-ax. is there a certain choice for a?
 
Technology news on Phys.org
This homework ? Then please post in the homework forum.

Do you know that if ##F'=f## then a flat distribution of F yields a distribution like ##f## ?
 
BvU said:
This homework ? Then please post in the homework forum.

Do you know that if ##F'=f## then a flat distribution of F yields a distribution like ##f## ?
I didn't get what you're saying
 
Thread closed. There's a duplicate of the question here: https://www.physicsforums.com/threads/how-to-increase-the-acceptance-ratio-in-python.966421/
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K