代写代考

import numpy as np

Copyright By PowCoder代写 加微信 powcoder

from scipy.stats import uniform

Two continuous random variables $X$ and $Y$ have the following bi-variatate (unnormalized) probability density function which is defined over the unit-square:

f_{X,Y}^{unnormalized}(x,y)=\begin{cases}
e^{(1-2x-3y+4xy)},& \text{if } 0\leq x<1 , 0\leq y<1\\ 0,& \text{otherwise} \end{cases} Q1. [10 Points]¶ Normalizing constant is a constant multiplier that makes the pdf integrate out to 1. For example, for the standard normal distribution, the normalized pdf is $\frac{1}{\sqrt{2\pi}}exp(-\frac{x^2}{2})$. An unnormalized pdf can be $exp(-\frac{x^2}{2})$. In this case, the corresponding normalizing constant is $\frac{1}{\sqrt{2\pi}}$. For a bi-variate distribution, we need to ensure the normalized pdf follows: $\int\int f_{X,Y}^{normalized}(x,y) dx dy=1$ Use Monte-Carlo integration to estimate the normalizing constant given in the setting. Use seed=1000, assign the first 1,000,000 samples to $x$, and the next 1,000,000 random numbers to $y$. np.random.seed(1_000) U = uniform.rvs(size=1_000_000) x = U[:,0] y = U[:,1] def f_unnormalized(x, y): return np.exp(1-2*x-3*y+4*x*y) normalizing_constant = 1/np.mean(f_unnormalized(x, y)) normalizing_constant 1.4945497606950764 def f(x, y): # this is now the normalized pdf return normalizing_constant * f_unnormalized(x, y) Q2. [15 Points]¶ Use Monte-Carlo simulation to approximate the probability of $0CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com