Statistical Computing: Random Number Generation, Simulation, and Monte Carlo

Hyacehila

Simulate Random Variables

Generates a flat distribution of random numbers between 01s

And the larger range, all random numbers generated by different distributions, are based on a flat distribution of random numbers in the 1st. Go, go, go! There are many ways to produce evenly distributed random numbers.

  • Imbalance in distribution
  • Long cycles, no quick cycles.
  • Simple calculation. Generating random numbers doesn't require too much of an operation. There are three basic methods for generating random numbers, one that uses random numbers (which are basically obsolete) to study random physical processes (used only in small crowds) and the other that is mathematically retrogressive. The math is a pseudo-random, and he's going to experience a certain amount of calculations and it's going to be a zero or a bad turn.

Natural Mode

The core is to take the base seed squared and remove the middle N-bit and divide it by the following:$10^{N}$ Random number of areas to reach 01

The questions in this article can also be addressedLinear regression base: linear model, minimum 2x2 estimate and regression diagnosisStatistical decision-making: decision-making issues, risk-based decision-making and uncertainty-based decision-makingHow the concept of a relatively close read together is developed in different contexts.

Multiplier Mode

Natural Middle Derivative, changing the original square to fixed number to middle as follows: Check$位数N=4;倍积K=5678;w_{0}=1234$ $Kw_{0}$Take four places and divide by$10^{N}$ (a) A random number of areas to 01; The N bit that you will remove as the next torrent of the iterative repeats the multiple harvest Medium

First-class linear membrane

It's an iterative formula. $$w_{n}=k_{1}*w_{n-1}~~(modm)$$ of which$k_{1},m$ It's an iterative number. $w_{0}$ It's given the seeds, the sequences produced in an iterative manner need to be divided by$m$And then we can return to the target zone. Nature can promote higher linear dilution. $$w_{n}=k_{1}*w_{n-1}+k_{2}*w_{n-2}~~~~(modm)$$

Reverse Variable (The Inverse Transform Method)

The distribution function must be monotonous. $$F_{X}^{-1}(u)=\inf{x;F_{X}(x)\geqslant u},0\leqslant u\leqslant1.$$ We can easily give a theory that's the basis for our reverse mutation to generate random variables. $$\text{定理:设 }U{\sim}U(0\text{,1),则}Y{=}F_X^{-1}(U)\text{的分布函数为}F_X(x).$$

The dispersed form may be complicated. We can do this by sampling it in the following ways. $X=\begin{cases}x 0,U<p_0,\x_1,p_0\leqslant U<p_0+p_1,\\vdots\x_j,\sum_{i=0}^{j-1}p_i\leqslant U<\sum_{i=0}^{j}p_i,\\vdots\end{cases}$$

Normal discrete random variable

Let's start with a simulation of discrete random variables that can easily be written in the distribution column. For this limited possible discrete random variable, each value has a probability of being matched.$sample$Function sample

Irrefinable extraction of potential discrete random distribution

Geometric distribution. Both distributions are the same. In this case, we can use an infinite cycle to deal with the constant and cumulative probability until conditions are met.

Continuous random variable

It's a matter of the theory we gave you. The core is how to find inverse functions.

Selective (The Access-Rejection Method)

Inverse transformation requires a study of a broad inverse, which is not easily handled in many cases. If you need a random variable to simulate$X$density function$f(x)$It's complicated, so we can find a random variable with the same X as the one.$Y$ He has density functions.$g(x)$ Here.$f(Y)/g(Y)$The value that is accepted proportionally to the accepted simulation, and thus to the correct value$X$Simulation The direct principle of this algorithm is not difficult to understand.

Algorithmic principles

It's very obvious that we can't accept a probability greater than one, which means we need to guarantee the molecules.$f(Y)$Smaller. So we first demand that there be a constant.$C$Satisfactory, i.e. magnifying the auxiliary probability density function. $$\frac{f\left(t\right)}g\left(t\right)}\leqslant C,\forallt\left (\text{enable)}f\left(t\right)>Yeah, right. Algorithm Process

  1. From$g(x)$. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .$Y$
  2. From$(0,1)$Generate random numbers above$U$
  3. If you're not gonna get it,<\frac{f(Y)}{Cg(Y)}$ 则接受$Y$ or no, and then back to the first step to continue generating random numbers.

Algorithmic principles The probability that a selected value will be accepted is $$00\ \midY=y\right)& =p\Big(U<\frac{f(Y)}{Cg(Y)}|Y=y\Big) \ &=p\Big(U<\frac{f(y)}{Cg\left(y\right)}\Big)=\frac{f(y)}{Cg\left(y\right)}. \end{aligned}$$ 那么被接受的概率可以使用全概率公式计算 $$p(\mathrm{accept})=\sum_{y}p\left(\mathrm{accept}\mid y\right)p(Y=y)=\sum_{y}\frac{f\left(y\right)}{\mathrm{Cg}\left(y\right)}g(y)=\frac{1}{\mathrm{C}}.$$ 最后我们可以知道每个被接受的值对应的概率就是符合密度函数的 $$\begin{aligned} p(k\mid\mathrm{accepted})& =\frac{p(\operatorname{accepted}\mid k)\operatorname{g}(k)}{p(\operatorname{accepted})} \ &=\frac{\left[f(k)/(\operatorname{Cg}(k))\right]g(k)}{1/C} \ &=f(k). I'm sorry, I'm sorry. That's the whole thing. The continuous thrust is omitted.

Attention

For the optout, select our auxiliary functions.$g(x)$It's very important. If we want our samples to be more effective, that is, the value that's being extracted is more acceptable, we need to try to control it.$C$Size This means that when selecting auxiliary functions, we need to not only combine the common distributions that we have learned before, but also find a consistent distribution of the range of values taken, based on the following method.$C$ $$C=\max\left{\frac{f(x)}{g(x)}\colon x>Yeah, right. This formula is not difficult to understand. For the selection of a support function, you can first find a cumulative function between the target ranges.$t(x)$ Then you can normalize this function, which is to divide it by the fraction on the target function.

Synthesis (The Common Approach)

Conditional Probability Synthesis

The idea of synthesizing is the probability distribution of the target function (including distribution column and function forms).$p(x)$It's not good to sample, but it's a condition distribution. $p(x|y)$ and conditions$g(y)$ It's easy to determine, so we can use the conditions to sample. $$p(x)=p(x|y)g(y)$$ In fact, the condition sampling work is not different from the way it is done. The target sample will be subject to a change in the outcome of the condition sample, but the essence of the sample is a normal sample.

Mixed distribution

In fact, we often use synthetic methods for hybrid normal simulations, which is one of the elements we're going to present below. For distributions that match the following forms: $$p{X=j}=\alpha p_j^{(1)}+(1-\alpha)p_j^{(2)}.$$ $$f(x)=\alpha f_1(x)+(1-\alpha)f_2(x).$$ This random variable can be found below. $$\left.X=\left{array}ll}X 1,&\\quad\text{in probability}\alpha\X 2,&\blur0 \text{in probability}1-\alpha\end{array}\right.\right.\right.$$ 这种问题可以直接进行推广到更多初选可能的情况 可以理解为每一个函数对最终函数的影响份额 $$F(x)=sum\limites P i}x.\text{inter alia}P i}\ge0\sum\limites P i}=$1$ The distribution function is the same. The mix we've seen in other books is an important sort of distribution.

Function synthesis of random variables

Sometimes the random variables we need to study are the functions of another random variable, like, $$e^{X};X+Y,UV$$ And we can extract it from the original random variable. And then we get the random numbers we need by function.

Convert

There are lots of distributions that can be used to change distribution patterns, and this can be used for our samples. Here are a few examples. $$00\&1. \\text{(0,1),\text{,}V=Z^2\sim\chi^2(1). \&2. \\text{(m), V\sim\chi^2(n), \\text{n), {F=frac{U/m}{V/n}\simF(m, n). \&\text{3. \simN(0,1), V\sim\chi^2(n), \text{n}T=\frac Z{\sqrt{V/n}\sim t(n).\end{aligned} I'm sorry. Besides, the normal distribution itself can be achieved by the Box Muller conversion. Some distributions can be sampled by the absolute transformation and then restore the absolute value effect for some distribution ranges in the range of the distributions.$(-\infty,\infty)$ Distribution is more common

Box Muller Change

A very common variable that generates a normal distribution random number.

Difference between expectations and conditions

The difference between expectations and differences is to solve some of the problems that we need to study after the creation of the random vectors, and, apart from those that are independent, the expectations and differences between the many random variables that are relevant are worth our study under certain conditions; here we add something that we have not been able to describe in the probabilistic theory. Conditional expectations are in fact a random variable, a random variable of changing conditions, and by changing conditions we can divide the original space. What we need to understand here is that the whole-spectrum formula is a very important link after the condition is set, just like the full-probability formula we've studied before, and we can now divide the original sample space into a scale and then look for expectations, and the idea of partition is at the heart of this formula.

We need a sort of order or a division of conditions to divide, and the following is an example to help us understand this idea. Theoretics is already sufficiently described in probabilistic theory.

Expectations

The issue of miners

$$\begin{gathered} \text{一名矿工被困在有三个门的矿井里,第一个门通往一个坑道,} \ \text{沿此坑道走3个小时可以到达安全地点;第二个门会使他走5个小时后又} \ \text{回到原处;第三个门会使他走7个小时后也回到原处。假定该矿工在任何} \ \text{时刻等可能地选定其中一个门. 求他到达安全地点平均需要多长时间}? \end{gathered}$$ The X is the time taken by the miners to reach a safe location. $$00\ E [X]& =E[E[X|Y]] \ &=E[X|Y=1]P{Y=1}+E[X|Y=2]P{Y=2} \ &+E [X|Y=3] P{Y=3} \ \text \E[X|Y=1]& \begin{aligned}=3, E[X|Y=2] = 5+E[X], E[X|Y=3] = 7+E[X]\end{aligned} I'm sorry, I'm sorry. Bring in for solver, 15 hours average.

Mean/Sq. of geometric distribution

$\begin{aligned}\text{if first successful, give }Y&♪ I'm not gonna let you go ♪ ${可知}E(X|Y=1)=1\text{,}E(X|Y=0)=E(1+X)=1+E(X)$ The double-spectrum formula. $$00\ E [X]& =E[E[X|Y]] \ &=E[X|Y=1]P{Y=1}+E[X|Y=0]P{Y=0} \ &=p+E(X+1)(1-p) \ &=p+E(X)+1 \end{aligned}$$ 解方程就可以得到均值 $E[X]=\frac{1}{p}$ 对于处理方差的问题 我们通过研究$E[X^{2}]$来研究它 $$\begin{aligned} E[X^{2}]& =E[E[X^2|Y]] \ &=E[X^2|Y=1]P{Y=1}+E[X^2|Y=0]P{Y=0} \ &=p+E(X+1)^2(1-p) \ &=p+E(X^2)+2E(X)+1 \ &=p+(1-p)E(X^2)+2\frac{1-p}p+(1-p) I'm sorry, I'm sorry. The equation will be able to get it.$E[X^{2}]=\frac{2-p}{p^{2}}$ The equation works, and the difference is made. Use $Var(X)=E[X^{2}]-E[X]^{2}$

Arguments relevant to solving the normal distribution of binary

$$\begin{aligned}f(x,y)&=\frac{1}{2\pi\sigma_x\sigma_y\sqrt{1-\rho^2}}\exp\Big(-\frac{1}{2(1-\rho^2)}\Big[\Big(\frac{x-\mu_x}{\sigma_x}\Big)^2\&-2\rho\frac{(x-\mu_x)(y-\mu_y)}{\sigma_x\sigma_y}+\Big(\frac{y-\mu_y}{\sigma_y}\Big)^2\Big]\Big).\end{aligned}$$ 我们需要证明他的相关系数是$\rho$ $$\mathrm{Corr}(X,Y)=\frac{\mathrm{Cov}(X,Y)}{\sigma_x\sigma_y}=\frac{\mathrm{E}(XY)-\mu_x\mu_y}{\sigma_x\sigma_y}$$ 求解相关系数的核心在于${E}(XY)$ 我们还是通过全期望公式的思想 先确定变量中的一个来简化原始问题 $$\begin{aligned} E(XY\mid Y=y)& =E(Xy\mid Y=y) \ &=yE(X\mid Y=y) \ &=y\left[\mu_x+\rho\frac{\sigma_x}{\sigma_y}(y-\mu_y)\right] \ &=\left.y\mu_x+\rho\frac{\sigma_x}{\sigma_y}(y^2-\mu_yy)\right. \end{aligned}$$ 条件密度函数也是正态分布 所以条件均值容易求解 借助全期望公式得 $$\begin{aligned} E(XY)& =E[E(XY\mid Y)] \ &=E[Y_{\mu_{x}}+\rho\frac{\sigma_{x}}{\sigma_{y}}(Y^{2}-\mu_{y}Y)] \ &=\mu_{x}E(Y)+\rho\frac{\sigma_{x}}{\sigma_{y}}E(Y^{2}-\mu_{y}Y) \ &=\mu_x\mu_y+\rho\frac{\sigma_x}{\sigma_y}\mathrm{Var}(Y) \ &♪ I'm gonna be ♪ I'm sorry, I'm sorry. That's how we're going to deal with the problem.

Full expectation formula reverses full probability formula

Satisfy by introducing indicative random variable X $$\left.X=\left(begin{array}ll1&\\text{A\text{occupying}&A/text{does not happen]$$ 我们容易知道 $E(X)=P(A)$ 再进行全期望公式的处理有$P(A)=E(X)=E(E(X|Y))$ 因此有 $$\left.P(A)=\left{begin{array}f Y(y) y(X|Y)P(Y)=sum yP(Y)\y(Y)\intE(X|Y)\f Y(y)dy=intP(A|Y)\f Y(y)dy\end{array}\right.\right.$ If we define events based on random variables, then this is the full probability formula, the manifestation of the partitionist ideology mentioned earlier.

A classic example.

$X~Y$ It's a stand-alone random variable. $$00\ P{X]<Y}& =\int P{X<Y|Y=y}f_Y(y)dy \ &=\int P{X<y|Y=y}f_Y(y)dy \ &=\int P{X<y}f_{Y}(y)dy \ &=int F X(y)f Y(y)dy I'm sorry, I'm sorry. So we can replace the complex accounting of the scores and quickly come to conclusions. A lot of similar issues like volume formulas can be dealt with like this. When you use this way, you have to figure out what it means to be in it. The former is$X$Bring your own separate distribution function$y$ And the latter is...$y$density function

Another interesting example.

You!$U_{1}~U_{2}...$It's an independent, even distribution sequence. They're all obeyed.$(0,1)$The flat distribution on it is = n: n \sum\limites k=>1}$ 求$E & $ We'll give you a more general picture.$N(x)$is the random number and the excess$x$Number of places You're the one who's gonna get you.$m(x)=E(N(x))$ Easy to get, according to the full-expected formula $$m(x)=E\big[N(x)\big]=\int_0^1E\big[N(x)\big|U_1=y\big]\mathrm{d}y.$$ $$E[N(x)\mid U_1=y]=\begin{cases}1,~~~~~~~~~~~~~~~~~~~~y>x;\1+m(x-y),y\leqslant x.\end{cases}$$ 所以 $$\begin{aligned} m\left(x\right)& =\int_0^x[1+m(x-y)]\mathrm{d}y+\int_x^1\mathrm{d}y \ &=1+\int_0^xm(x-y)\operatorname{d}y \ &=1+ \xm(u)\mathrm{d}u.\quad(\text{u=x-y) @aligned BAR $$ 两边求导得到 $$m'(x)=m(x), \\text{i.e.}quad\frac{m'(x)}{m(x)}=1.$$ 处理微分方程并且确定C后得到 $$m(x)=e^{x}$$

Conditional Difference

Definition of variance $Var(Y|X)=E\Big[(Y-E[Y|X])^2|X\Big]$ Statistical variance formula $Var[Y]=E[Var(Y|X)]+Var[E(Y|X)]$

The best way to deal with discrete columns in the whole probability, condition and condition segment is to write the distribution column, rather than using the formulas given earlier, which are used more in consecutive random variables and in those random variables that are not easily written in the distribution column, after all, the distribution is at the core of the discrete column and is the basis for studying all discrete random variables.

And the question of probability of conditions, you know, the probability formula is only a general treatment for continuity, and for the discrete distribution, we need to calculate the probability of conditions occurring in the known distribution column, and then we need to calculate the probability of events occurring, and then we can finally compare it, and the problem of differential conditions, and the problem we need to address, is whether the problem is not substantially different, or whether the formula is applied to the use of the formula (using the most basic equation, not the differential formula), and patience is the most necessary to deal with this type of problem.

Number of valid samples

Here we'll simply look at how many samples we need to sample if we want to achieve the desired precision, and here we'll just look at the mathematical expectations, the first-level, straight-and-right-hand problem, and we'll just leave it to the later stage to deal with the more complex questions. The small chapter on the number of active samples is an analysis of the validity of mathematical statistics, as is the technique of the reduction of the squares behind it.

Determination of the number of valid samples

Assumptions$X_1,X_2,\cdots,X_n$ It's a single sample of the same distribution. He's got the average.$\mu$Difference$\sigma^{2}$ We can estimate. $$E(\overline{X})=\mu,\quad\text{并且}Var(\overline{X})=E[(\overline{X}-E(\overline{X}))^2]=\frac{\sigma^2}n.$$ It's obvious. We know the estimates.$\overline{X}$It's a no-show.$\frac{\sigma^2}n.$ The smaller the estimates, the more effective they are, the smaller the average error in our estimates, the more important in modern data analysis. For sample variance$\sigma^{2}$ We use neutral estimates. $$S^2=\frac{1}{n-1}\sum_{i=1}^{n}(X_i-\overline{X})^2$$ With the means to measure deviations, it's easy to study the number of effective samples.

  1. Determine the appropriate small positive$d$Standard error as estimate
  2. At least 100 samples taken.
  3. I'll take a new sample from time to time.$\frac{S}{\sqrt{n}}\leq d$
  4. Estimated$\overline{X}$

The whole algorithm is designed to be very natural and easy to do.

Number of effective samples identified

Difference per calculation$S^{2}$And the way to calculate whether or not to satisfy the equation is to be calculated is to be very large, especially when the sample rises, and here is to give an iterative formula to reduce the need for the calculation. $$\left.\overline{X_{j+1}}=\overline{X_j}+\frac{X_{j+1}-\overline{X_j}}{j+1},S_{j+1}^2=(1-\frac1j)S_j^2+(j+1)(\overline{X_{j+1}}-\overline{X_j})^2.\right.$$ Use an iterative formula to avoid recalculating the sample size each time Bad Reduced consumption of calculated resources

For the sample variance as the desired function of the sample (e.g. distribution 01) We should calculate the sample averages in an iterative process to get the sampler by a function. Bad Direct calculation variance is larger than calculated resource consumption

Square-deflator technique

Monte Carlo, which is a large group of methods, not only does he include the method presented in Monte Carlo's score, but the whole solution to the probability problem based on random simulations is one of Monte Carlo's methods. We can sort of split the questions of Monte Carlo's approach into two main ones. Category

  • The problem itself is random, such as nuclear physics and molecular motion simulations.
  • The problem that needs to be solved can be transformed into some sort of distributional feature, like Monte Carlo's points. In the second category, we actually do a problem study of the construction statistics, and it's important to determine the validity of estimates, such as neutrality, that they assess whether our estimates are reasonable. On a neutral basis, the average error is equal to the difference between the difference and the technology for the reduction of the difference is the way in which the study of the method of the reduction of the difference in the final estimate can be tested to increase the validity of the estimate.

We can use the methods that we're going to use, and we can use a variety of methods that can help to reduce the differences.

Definition Rate of reduction of variance $$\frac{\mathrm{Var}(\hat{\theta})-\mathrm{Var}(\hat{\theta}_{\epsilon}\cdot)}{\mathrm{Var}(\hat{\theta})}$$

Comparison of validity of random drop points and sample averages

For a very standard issue of the exact score. $$\theta=\int_{a}^{b}f\left(x\right)\mathrm{d}x.$$ The random drop point estimate is That's a good idea.1=\hat{\theta}=M(b-a)\frac{n_0}n.$$ $nOther Organiser $ \\mathrm{Var} (hat(theta}){1})=\frac{M^{2}(b-a)^{2}}{n^{2}}\mathrm{Var}(n{0})=\frac{\theta}{n}\bigl[M(b-a)-\theta\bigr].$$ 类似的原理能得到样本均值法的估计和方差 $$\hat{\theta}{2}=\tilde{\theta}=\frac{1}{n}\sum{i=1}^{n}\frac{f(X_{i})}{g(X_{i})}=\frac{b-a}{n}\sum_{i=1}^{n}f(X_{i}).$$ $$\begin{aligned} \operatorname{Var}(\hat{\theta}{2})& =\text{Var}\biggl[\frac1n(b-a)\sum{i=1}^nf(x_i)\biggr] \ &=\frac1n\bigg[\left.(b-a)^2\int_a^bf^2\left(x\right)\frac1{b-a}\mathrm{d}x-\theta^2\right] \ &== sync, corrected by elderman == @elder man I'm sorry, I'm sorry. The difference is more likely to be found in the sample average, which means that the estimate is more effective. Is there some way to continue to improve effectiveness?

Important sampling method

Introduction of important sampling methods

For sample mean value method $$\theta=\int_{a}^{b}\frac{f(x)}{g(x)}g(x)\mathrm{d}x=E_{\kappa}\bigg[\frac{f(X)}{g(X)}\bigg].$$ Sample and estimated $$\tilde{\theta}=\frac1n\sum_{i=1}^n\frac{f(X_i)}{g(X_i)}.$$ The difference in the direct calculation is $$\mathrm{Var}(\hat{\theta})=\frac{1}{n}\bigg[E_{\kappa}\Big(\frac{f(X)}{g(X)}\Big)^{2}-\theta^{2}\Big].$$ This calculation tells us how the auxiliary sampling is distributed.$g(X)$and original distribution$f(X)$Satisfied$g(x)=\frac{f(x)}{\theta}$ We have the smallest difference.$\theta$It's unknown, of course it's impossible, but we can get them as close as possible. This is the idea of the important sampling method, which changes the flat sample that was used to make the estimates more effective, thereby increasing the validity of the estimates. Now we give a simple example of what we're guessing for. Consider the points$\theta=\int_{0}^{1}\mathrm{e}^{x}\mathrm{d}x.$ Try using two MC differences For sample mean value method $$00\ \mathrm{Var}& \left.=\left.\frac1n\right[\int_0^1\mathrm{e}^{2x}\mathrm{d}x-(\mathrm{e}-1)^2\right] \ &=\frac1n\biggl[\frac12(\mathrm{e}^2-1)-(\mathrm{e}-1)^2\biggr] \ &=\frac{0.242}n. \end{aligned}$$ 对于重要抽样法的改进 我们使用 原始函数的Taylor展开并且规范化的$\frac{2}{3}(1+x)=g(x)$ $$\begin{aligned} Var(\bar{\theta})& =\frac{1}{n}\biggl[\int_{0}^{1}\frac{f^{2}(x)}{g(x)}\mathrm{d}x-(\mathrm{e}-1)^{2}\biggr] \ &=\frac1n\biggl[\int_0^1\frac32\frac{\mathrm{e}^{2x}}{1+x}\mathrm{d}x-(\mathrm{e}-1)^2\biggr] \ &== sync, corrected by elderman == @elder man I'm sorry, I'm sorry. The key sampling method did help to reduce the variance.

Important sampling method and tilt density functions

Important sampling method

In general terms, for a density function$f(x)$Random variable$X$ For estimates $$\theta=E_{f}\bigl[h(X)\bigr]=\int_{a}^{b}h\left(x\right)f(x)\mathrm{d}x.$$ The key sampling method is to derive it from the sample average method and find new ones.$X$Distribution Functions$g(x)$ $$\theta=\int_{a}^{b}\frac{h\left(x\right)f\left(x\right)}{g\left(x\right)}g\left(x\right)\mathrm{d}x=E_{k}\bigg[\frac{h\left(X\right)f\left(X\right)}{g\left(X\right)}\bigg].$$ In actual simulations $$\hat{\theta}=\frac{1}{n}\sum_{i=1}^{n}\frac{h(X_{i})f(X_{i})}{g(X_{i})}$$ Just pick the right one.$g(x)$It's a way to reduce the difference.

Tilt density function

For the original distribution rectangular function $$M(t)=E_{f}\bigl[\mathrm{e}^{tX}\bigr]=\int\mathrm{e}^{tx}f\left(x\right)\mathrm{d}x$$ We're going to construct what's called the original distribution tilt density function. $$f_t(x)=\frac{\mathrm{e}^{tx}f(x)}{M(t)}$$ You know, the tilt density function is essentially a one-class function.$t$ How do you know that?$t$And, uh, let's get it closer to where we need to focus on the sample.

Below are some of the more specific distribution tilt density functions. If$f(x)$is the parameter as$\lambda$The index distribution$f_{t}$is the parameter as$\lambda-t$Index distribution If$f(x)$is the parameter as$p$The two distributions$f_{t}$is the parameter as$\frac{pe^{t}}{pe^{t}+1-p}$Distribution of two items If$f(x)$is the parameter as$(\mu,\sigma^{2})$Normal distribution$f_{t}$is the parameter as$(\mu+\sigma^{2}t,\sigma^{2})$Normal distribution It's a good calculation here, if you want rectangular.

Key sampling method and small probability event simulation

We'll give you an example of how we can deal with similar problems in the future. $$X{\sim}N(0,1),\text{ 欲通过模拟方法估计 }\theta{=}P(X{\geqslant}20).$$ We can only get a strange answer to the zero chance, because it's really too low, and probably, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know, you know$e^{-89}$So we're going to simulate the answer to the question. Actually, the original question is equal to the original question. $$\theta=E(I_{{X\geqslant20}})$$ Yeah, it's actually a question of studying expectations, just taking samples from the normal distribution, and then over 20 as one, and then the rest as zero, and then doing the desired operation on the vector. Now we're gonna use the important sampling method to correct this sample operation. The original normal distribution is$f(x)$ $h(x)=I_{{X\geqslant20}}$ $g(x)$is the tilt density function that is calculated Now there is. $$00\ &\theta =E_{f}[h(X)]=\int_{-\infty}^{\infty}h(x)f(x)\mathrm{d}x \ &=\int_{-\infty}^{\infty}\frac{h(x)f(x)}{g(x)}g(x)\mathrm{d}x \ &=\int_{-\infty}^{\infty}I_{(x\geqslant20)}\left{\frac{\dfrac{1}{\sqrt{2\pi}}\mathrm{e}^{-\frac{x^2}{2}}}{\dfrac{1}{\sqrt{2\pi}}\mathrm{e}^{-\frac{(x-\mu)^2}{2}}}\right}\sqrt{2\pi}\mathrm{e}^{-\frac{(x-\mu)^2}{2}}\mathrm{d}x \ &=\int_{-\infty}^{\infty}I_{(x\geqslant20)}\mathrm{e}^{-\mu x+\mu^{2}/2}\frac1{\sqrt{2\pi}}\mathrm{e}^{-\frac{(x-\mu)^{2}}2}\mathrm{d}x \ &=E_{{\mathcal{g}}}[I} (X\qslant20) }mathrm^ ^ \ + + + + + + + + + + + + + + + } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } + + \ \ \ } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + I'm sorry, I'm sorry. We just need to sample from the new tilt density function and then simulate the average. And if we go on board, we can find that with the use of important sampling, we can only use a small number of simulations to achieve the results that we could achieve with a very high number of simulations.

Scattered sampling method

We're here to highlight the stratification of the MC method of the points, and the other forms of the problem are translated into the problem. The stratification of sampling is also the method of using contribution rates to reduce the variance estimates, and we usually divide the entire area into parts to calculate his weight, and then allocate the number of samples to increase the efficiency of the sample using this method.

Introduction to the Core Approach

For the points$\theta=\int_{0}^{1}f(x)\mathrm{d}x$ We split up the blocks.$m$A small compartment, a tip.$a_{i}$ then $$\theta=\int_0^1f(x)\mathrm{d}x=\sum_{i=1}^m\int_{a_{i+1}}^{a_i}f(x)\mathrm{d}x=\sum_{i=1}^mI_i.$$ Remember$l_{i}=a_{i}-a_{i-1}$ It's possible to calculate using the sample average method.$I_{i}$ Then we can calculate the estimates we need.$\theta$ And there's $\tilde{\theta}{3}=\sum{i=1}^{in}\hat{I}I'm sorry. It's obvious. We know. $$\hat{E}I_i=I_i$$ $$\mathrm{Var}(\hat{\theta}{3})=\mathrm{Var}\Big{\sum_{i=1}^{m}\frac{l_{i}}{n_{i}}\sum_{j=1}^{n_{i}}f(X_{ij})\Big>=\sum_{i=1}^{m}\frac{l_{i}^{2}}{n_{i}}\sigma_{i}^{2}.$$ 其中 $$\sigma_i^2=\int_{a_{i-1}}^{a_i}\frac{f^2\left(x\right)}{l_i}\mathrm{d}x-\left(\frac{I_i}{l_i}\right)^2.$$

Core Theorem

Yes.$\sigma^{2},l_{i},n$When all are known, when the following distributions are made, $$\frac{n_i}n=\frac{l_i\sigma_i}{\sum_{j=1}^ml_j\sigma_j}$$ The estimated square difference is the smallest$\frac{1}{n}\left[\sum_{j=1}^{m}l_{j}\sigma_{j}\right]^{2}.$ Some additional certification process Based on the foregoing, $ \\mathrm{Var} (hat(theta}){3})=\sum{i=1}^{m}\frac{l_{i}^{2}}{n_{i}}\sigma_{i}^{2}=\frac{l_{1}^{2}}{n_{1}}\sigma_{1}^{2}+\frac{l_{2}^{2}}{n_{2}}\sigma_{2}^{2}+\cdots+\frac{l_{m-1}^{2}}{n_{m-1}}\sigma_{m-1}^{2}+\frac{l_{m}^{2}}{n-n_{1}-n_{2}-\cdots-n_{m-1}}\sigma_{m}^{2}.$$ 针对每一个$n_{i}$ 求偏导研究极小化问题都有 $$\frac{l_1\sigma_1}{n_1}=\frac{l_m\sigma_m}{n-n_1-n_2-\cdots-n_{m-1}}.$$ 根据等比性质有 $$=c{\l=n n 2\cdots}n}m}m}m}$m}m}$m}$m}{\}m}\}}}\m}{\\\\\\\\\\\\\\{\{\========$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ig$igigigigig$$$$$$$$$$$$$$$$}}$}}}}$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\\\\\\\\\ And that's when you get the difference to minimize it. Bringing back all the amounts will make the last tiny bit. Bad

For the issue of sampling, the implementation of the equation is the simplest and most common. The distribution of sampling numbers, even if proportionally based on the length of the area, will not produce any greater variance.

Summary

We need to start with a pre-sampling, calculate the variance data based on the results of the presampling, then make the required allocation of the sample ratio on the results of the presampling, and continue to use the average scale to calculate the estimates we need. We don't want to continue to expand the use of the method, but if we want to use a stratification, then we can turn the problem into a Monte-Carlo score problem. The expectation of a continuous function is a matter of points.

Pyramid Variable Method

I think I'm going to be able to get you out of here.

If we're right...$\theta=E[X]$I'm interested and there is.$X_{1},X_{2}$Same distribution and all equal values$\theta$ Then we can get it. $$\mathrm{Var}\Big(\frac{X_1+X_2}{2}\Big)=\frac{1}{4}\Big[\mathrm{Var}(X_1)+\mathrm{Var}(X_2)+2\mathrm{Cov}(X_1,X_2)\Big].$$ Just...$X_{1},X_{2}$Negative correlations can lead to lower differences, but he's still impartial. $$E\Big(\frac{X_{1}+X_{2}}{2}\Big)=\theta.$$ This is the core of our work on the even variable method.

Method of processing

Let's start with two principles we need to use. Theorem: For independent random variables$X_{1},X_{2}...X_{n}$Independently, for one dollar plus function$f,g$ For whatever.$x\ge y$ Yes. $$E[f(X)g(X)]\geqslant E[f(X)]E[g(X)].$$ Inference: If$h(x_{1},x_{2},\cdots,x_{n})$ It's a single-tone function of each of his variables, and it's a random set of numbers. - Yeah.$U_{1},U_{2}...U_{n}$ Yes. $$\mathrm{Cov}[h(U_1,U_2,\cdots,U_n),h(1-U_1,1-U_2,\cdots,1-U_n)]\leqslant0.$$

Now we can try to construct the pair of variables with this aphrodisiac. Assumptions$X_{1}=h(U_{1},U_{2}...U_{n})$ of which$U_{i}$So we build it.$X_{2}=h(1-U_{1},1-U_{2}...1-U_{n})$ It's easy to know.$U,1-U$Same distribution And...$\operatorname{Cov}(U,1-U)=-\frac{1}{12}.$ If$h$It's a single-tone function for each coordinates, then.$X_{1},X_{2}$ It's distributed and negative, but it's called pairing. The even variable method reduces the variance of the estimate and reduces the cost of taking random numbers twice in the front-score sample. The essence of the sample is the mean value method, but it's just improved on the sample. Of course, there's a price to this improvement. $[0,1]$Sampled in the compartments

Example

We'll use one example of how the even variable method is used to replicate this example. Estimating points using the pygmy variable method$\theta=\int_0^1\mathrm{e}^x\mathrm{d}x=\mathrm{e}-1.$ It's obvious. $h(x)=e^{x}$ It's a one-dollar monotonic function, and this space also meets our requirements for solving the equation. So for the estimate,$X_{1}$ We designed it as$e^{U_{}}$ Estimated$X_{2}$ Designed as $e^{1-U_{}}$ So this structure meets our requirements for using the veneer. So the final estimate is $$(\frac{e^{U}+e^{1-U}}{2})$$ We're pulling it manually.$U$ We get another random part of the population by way of an occasional one, and we're finally making up our estimates. For something like that.$(0,1)$This is how you do it. Only two conditions are used for the even variable.$(0,1)$ Untune by amplified Functions

In some other cases, we can transform it to meet the requirements of solving the problem with the pup variant. Calculate the following points $$\phi\left(x\right)=\int_{-\infty}^{x}\frac{1}{\sqrt{2\pi}}\mathrm{e}^{-t^{2}/2}\mathrm{d}t.$$ It's a matter of points between the infinite zones. It's obvious if $x<0$ 我们可以考虑求 $[0,-x]$ 上的积分 然后和$\frac barrel BAR and \carat scene scene scene scene scene scene scene scene scene scene scene scene scene scene scene scene scene scene scene scene scene scene scene scene scene scene scene scene scene scene scene scene scene scene scene sc sc sc sc sc sc sc sc sc sc sc scms s For $x>0$ 我们可以考虑求 $[0,x]$ 上的积分 然后加上${\cHFFFFFF}{\cH00FFFF} That's what the problem is. $$\Phi\left(x\right)=\int_{0}^{x}\frac{1}{\sqrt{2\pi}}\mathrm{e}^{-t^{2}/2}\mathrm{d}t.$$ And then we do it.$y=\frac{t}{x}$ And then we'll scale the blocks back.$[0,1]$ The problem is now to ask. $$\theta=\int_{0}^{1}xe^{-\left(xy\right)^{2}/2}dy.$$ It's obvious that this is the right place to satisfy.$y$Unanimous$[0,1]$The conditions in the compartments can be used using the Puppet Variable method.

Control Variable Method

Theory Introduction

We're dealing with this directly with the idea of expectations, and the MC score problem is directly translated into a desire to study, and the sample average method is fine.

In front. $\theta=E[h(X)]$ The estimate is...$\frac{1}{n}\sum\limits h(X_{i})$ Now we're going to construct a new distribution. $f(X)$ And...$\mu=E[f(X)]$ Now we're building it.$Y=h(X)+c[f(X)-\mu],$ It's easy to know. $E(Y)=\theta$ The research margin is in place. $$00\ \text{Var(Y)}& =\operatorname{Var}\langle h(X)+c[f(X)-\mu]\rangle \ &=\operatorname{Var}[h\left(X\right)]+c^2\operatorname{Var}[f\left(X\right)-\mu]+2c\operatorname{Cov}\langle h\left(X\right),f(X)-\mu\rangle \ &=\operatorname{Var}[h(X)\operatorname{}+c^2\operatorname{Var}[f(X)\operatorname{}+2c\operatorname{Cov}[h(X)\operatorname{}f(X)\operatorname{}]. \end{aligned}$$ 为了减少方差 我们继续化简 $$\begin{aligned} \text{Var(Y)}& =c^2\operatorname{Var}[f(X)]+2c\operatorname{Cov}[h(X),f(X)]+\operatorname{Var}[h(X)] \ &=\operatorname{Var}[f(X)]\Big|c+\frac{\operatorname{Cov}[h(X),f(X)\Big]}{\operatorname{Var}[f(X)\Big]}\Big|^2+\operatorname{Var}[h(X)\Big] \ &-\frac{\mathrm{Cov}^{2}\bigl[h\left(X\right),f\left(X\right)\bigr]}{\mathrm{Var}\bigl[f\left(X\right)\bigr]}. \end{aligned}$$ 因此我们已经找到了最后可以缩减方差的方法 $$c=c^=-\frac{\peratorname{Cov}\left[h(X), f\right]}{\pectorname{Var}\left[f(X)\right]}$$$ Now the problem has turned into this specific $c^How do we calculate it? It's obvious that we have to do a simulation of the difference and the difference between the squares here. $${\operatorname*{Cov}}\big[h(X),f(X)\big]=\frac{\sum\limits_{i=1}^n{\big[h(x_i)-\bar{h}\big][f(x_i)-\mu\big]}}{n-1},\\{\operatorname*{Var}}\big[f(X)\big]=\frac{\sum\limits_{i=1}^n\big[f(x_i)-u\big]^2}{n-1}.$$

That's a pretty clear description, and the range of issues that can be addressed is detailed.

Examples

Give it to me by controlling variables.$\theta=E[e^{(U+V)^{2}}]$ of which$U,V$It's independent.$U(0,1)$ Control variable selection as $f=(U+V)^{2}$ Here we usually use the method of increasing the number of random numbers to make simulations. We need to recalculate the average of the new random numbers generated.$\mu$ and Controls $c$ We'll use code to describe it.

Conditional Expectations Act

Theory

The conditional expectations are known. $$\operatorname{Var}(X)=E[\operatorname{Var}(X\mid Y)]+\operatorname{Var}[E(X\mid Y)],$$ So, because of the non-negative performance, $$\mathrm{Var}(X)\geqslant\mathrm{Var}[E(X\mid Y)].$$ So, the condition sample is more effective than the direct sample, because we know that. $$E[E(X\mid Y)]=EX=\theta.$$ The double expectation formula ensures that even if we add a sample of conditions (which also requires a set of expectations) it is a neutral estimate.

This conclusion is broader than that, so just construct one condition and deal with two layers of expectations by two layers of simulation.

And please note that the expectation method is special, and he needs us to do some theoretical research to use it; if there's something on the subject that's going to be done with the conditions, it's no different than a sample simulation that follows his conditions directly from the one we're doing.

Examples

Assumptions$Y$is the mean value as$1$The index distribution random variable in$Y=y$Conditions $X\sim N(y,4)$ Simulate $\theta=p{X>I'm sorry. The most direct way to simulate it is to... Mr.'s random count.$y$ Based on generated$y$Simulate Random Variables$X$ Then we'll see the number of criteria that meet the conditions.$I$ Last request$E(I)$ This is not our bargain. This is our deal! For deformation normal variables to facilitate analysis behind $$Z=\frac{X-y}2,$$ Theorizing expectations $$00\ [I\mid Y=y]& =P\langle X>1\mid Y=y\rangle \ &=P\left{Z>\frac{1-y}2\right} \ &== sync, corrected by elderman == @elder man I'm sorry, I'm sorry. And understand our first equation, and that's the same as the probability. Yeah.$y$ Take a sample and calculate the expectations. This is the procedure of the expectation that the equation will reduce the deviation. We know the conditions expect the two layers to be distributed, or the conditions expect that the theory will not be able to be extrapolated.

Another example. So, you can solve it with your expectations. $\theta=E[e^{XY}]$ Of which random variables $X,Y$ Obey. $b(n,p)$ We still need to set the expectations first. $E[e^{XY}|X=x]$ $$\begin{aligned} &E(e^{XY}|X=x)=E(e^{xY}) \ &=\sum_{y=0}^{\infty}e^{xy}\cdot C_{n}^{y}p^{y}\left(r-p\right)^{n-y} \ &=\sum^{}\left(e^{x}p\right)^{y}\left(1-p\right)^{n-y} \ &== sync, corrected by elderman == @elder man I'm sorry, I'm sorry. And then it was right.$y$I'm hoping we'll have to.

  • Title: Statistical Computing: Random Number Generation, Simulation, and Monte Carlo
  • Author: Hyacehila
  • Created at : 2023-09-12 10:43:25
  • Link: https://hyacehila.github.io//blog/2023/09/12/statistical-computing-notes/
  • License: This work is licensed under CC BY-NC-SA 4.0.
Comments