Now, let's look at another method that can be used to generate slightly more complex distributions. This is the inverse transfer method. This method uses the cumulative distribution function or the CDV and the inverse of the CDV to generate a desired distribution. If a variable Y is generated by applying a function after X such that we get Y equals F of X, this implies that we can apply an inverse transformation to Y if it exists to obtain X. Here, the function F has to be invertible. In this case, we call the function F to be bijective, which means we can apply F inverse to Y and retrieve X. Now, the steps required to generate the new distribution from existing distribution is shown below. Now, let's look at the derivation to understand how this works. You have a variable Y, which is a function of z, where the PDF of y is given by p of y and the PDF of z is given by p of z. P of y says that y equals f of z. What we're trying to accomplish here is we want to determine the function f of z such that the distribution of values given by y formed by this transformation y equals fz is our desired distribution. What we want essentially at the end is y. The distribution of y will adhere to the following formula. Its p of y equals p of z. The absolute value of dz or dy? Fz as a uniform distribution. This becomes py equals the absolute value of the derivative of z or dy. Now, if we innovate both sides, we get this term right here, that is py and it already, one in a negative dy. Which we can right as h of y. Now, if we look closely at this general, it is simply the CDF or the cumulative distribution function of y, which we would call h of y. If you apply the inverse of a CDF function that h inverse in both sides, we can retrieve y. The purpose of this transformation is simply to express y as a function of z. Now if sample, the z distribution, transformed the values with the inverse of the CDV, of the desired distribution, we get the values for y, which will have our desired distribution. Let us summarize that algorithm once again for clarity, what are distribution we want we just go ahead and compute the CDV of the desired distribution and then we compute the inverse of that CDF and denoted as F inverse. Now we sample from C, which is nothing with the uniform distribution between zero and one. Now we use those sample values that we just obtained in Step 2 as input to the inverse of the CDF such that Y is now sampling from F inverse of U or the uniform distribution. The limitation, however, with this approach is that it must be possible to compute the inverse of the CDF of the distribution. Now, let's look at an example and how to apply the inverse transform. We want to generate an exponential distribution by sampling from a uniform distribution. The PDF for the exponential distribution is as shown here. It's Lambda U raised to the negative Lambda y when y is greater than equal to zero. The CDF for the distribution can be competed to be this term here 1 minus e to the negative power of Lambda y. However, this is the same as h of y or transformation and we can write z equals to 1 minus e to the negative lambda y. What we want to do here is now transform this term right here to express Y in terms of C that is we actually applying the inverse of our CDF and it turns out to be Y equals negative log of 1 minus z of lambda. Now, what we want to do is sample from z, which is a uniform distribution, and plug those sample values into the equation about and then you get equivalent values for Y, which will have the desired distribution or the exponential distribution. Now let's see how we can do this in code, we can generate some samples for the uniform distribution as shown here. We're generating about 5,000 samples and the lambda for our exponential distribution. Is that to be 0.5? We're generating x, which is the same as y here, by taking these values sample from the uniform distribution and transforming, playing that inverse CDF to generate our desired samples. Then in order to get the distribution and now we compute the histogram and then we plotted. That's the histogram that we plotted for the generated distribution or the sample distribution. Now we can do the same by plotting the PDF for exponential distributions as we already know what that looks like. If we do that, we see that it's fairly similar to the two distribution, so I would encourage you to change the number of samples here and see how the general distribution changes and if it moves away from the true distribution or if it gets closer. Now that we have seen a worked out example of using the inverse transfer method, I would encourage you to try this evaluation problem. See if he can generate a value distribution using the inverse transfer method, the PDF for the Rayleigh distribution is shown here. The cumulative distribution function for the Rayleigh distribution is as shown here as well. Now feel free to use the template shown about to see if you can generate the Rayleigh distribution using the inverse transfer method.