KADD 2022 Laboratorium 7 ENFrom Łukasz Graczykowski(Difference between revisions)
Revision as of 11:51, 11 April 2022
ExercisePart one: estimation of the Pi (1 pkt.) Please write a function which estimates the number Pi with the von Neumann (it is arguably one of the most simple examples of the use-case of a Monte Carlo method). In order to calculate the Pi, we randomly generate two numbers x and y from the uniform distribution [0,1] and we check whether the pair falls within the circle of the radius equal to 1. Next, by calculating the ratio of accepted pairs to all of them, you approximate the ratio of areas of the circle to the rectangle. By performing such a random generation, calculate the Pi number. In addition, draw the graph of the resulted points inside and outside the circle:
Part two: generation of pseudo random numbers from a any probability distribution using the acceptance rejection method of von Neumann (3 pkt.) The transformation method used a week ago has limited applications. You can do this when the analytical form of the cumulative function and its inverse function are known. The von Neumann method of generation of pseudo random numbers will work when you know only the g(y) distribution, but the drawback is that you have to generate two numbers, now one. This method will also work if the g(y) function is not a proper probability distribution (it even does not need to be normalized - every function you can always normalize). This allows for a very broad application of the von Neumann method - also to calculate definite integrals, when their analytical form does not exist. This is a typical example of a Monte Carlo method. Please prepare thee very similar functions taking as argument an object of type
Part three: acceptance rejection method of von Neumann with the helper function (1 pkt.) In order to improve the efficiency of the von Neumann function, we can limit the area of random points generation with the use of a helper function. In that case we can generate one number from the pair from the s(y) helper function, instead of a uniform distribution:
The function s(y) we choose always in a way it is above the function g(y) and so that you can easily generate a random number from the s(y) distribution (i.e. by applying the transformation of the inverse cumulative distribution, like last time). All calculations please fo for the following function:
Attention
ResultsPart one Output: The Pi number equals: 3.14392 Parts two and three Output: Integral: 0.199 Efficiency: 0.2072 Integral (method with the helper function): 0.198745 Efficiency (method with the helper function): 0.39749 Integral calculated using the ROOT method Integral: 0.198652 |