0
$\begingroup$

I need a simple way of generating a list of random numbers from a Gaussian distribution (with mean $\mu$ and standard deviation $\sigma$), which must satisfy the following (squared exponential) autocorrelation function:

$$R=\exp\left(-\left(\frac{d}{l_r}\right)^2\right)$$

where $d$ is the distance between two points and $l_r$ is the correlation length.

As a practical example, I want to assign a random material strength along the length of a metal specimen at a number of consecutive points ($x_1$, $x_2$, $x_3$, ...), where these points are $d=1$ apart. For $\mu=100$, $\sigma=10$, and $l_r=5$, I would need to generate a list of random numbers that satisfies the above condition (e.g. 96, 101, 87, 102, 111, 90, 80, 105, ...).

I understand that the values of two neighbouring points are highly correlated, and for two remote points the values are essentially independent.

Is there a straightforward way to do this using a simple VBA code, for example?

  • 0
    I see that $d$ is the lag but what is $l_r$, exactly? I am not familiar with the term "correlation length."2017-02-20
  • 0
    In the context of material properties (as per the example), the correlation length represents the typical length scale on which the deviations from the mean stop being similar.2017-02-20

1 Answers 1

1

My understanding of your question is that you are trying to generate two random variables $Y_{1}$ and $Y_{2}$ such that $(Y_{1},Y_{2})$ has bivariate normal distribution with mean $(\mu_{1},\mu_{2})$ and variance-covariance matrix $\left[\begin{array}{cc}\sigma_{1}^{2}&\rho\sigma_{1}\sigma_{2}\\\rho\sigma_{1}\sigma_{2}&\sigma_{2}^{2}\end{array}\right]$. (This is one of your pairs. Well, for $\mu_{1}=\mu_{2}=\mu$ and $\sigma_{1}=\sigma_{2}=\sigma$.)

To do this, you can use property of bivariate normal (see the part with "To derive the bivariate normal probability function"), where for $X_{1}$ and $X_{2}$ such that $(X_{1},X_{2})$ has bivariate normal with mean $(0,0)$ and variance-covariance matrix equal to $\left[\begin{array}{cc}1&0\\0&1\end{array}\right]$, $$\begin{aligned}Y_{1}=\mu_{1}+\sigma_{11}X_{1}+\sigma_{12}X_{2}\\Y_{2}=\mu_{2}+\sigma_{21}X_{1}+\sigma_{22}X_{2}\end{aligned}$$ has bivariate normal distribution with mean $(\mu_{1},\mu_{2})$ and variance-covariance matrix $\left[\begin{array}{cc}\sigma_{1}^{2}&\rho\sigma_{1}\sigma_{2}\\\rho\sigma_{1}\sigma_{2}&\sigma_{2}^{2}\end{array}\right]$, where $$\begin{aligned}\sigma_{1}^{2}&=\sigma_{11}^{2}+\sigma_{12}^{2}\\\sigma_{2}^{2}&=\sigma_{21}^{2}+\sigma_{22}^{2}\\\rho&=\frac{\sigma_{11}\sigma_{21}+\sigma_{12}\sigma_{22}}{\sigma_{1}\sigma_{2}}\end{aligned}$$

Generating standard multivariate normal in excel is done via

=NORMINV(RAND(); 0;1)
You need to set $\mu_{1}=\mu_{2}=100$. To get your $\sigma=10$ for both variables and $\rho=R$, you need to solve system of $3$ equations above in $4$ unknowns $\sigma_{11}$, $\sigma_{21}$, $\sigma_{21}$ and $\sigma_{22}$. Asking Mathametica to do so (and then confirming the solution)
eq1 := 100 == s11^2 + s12^2;
eq2 := 100 == s21^2 + s22^2;
eq3 := R == (s11*s21 + s12*s22)/Sqrt[s11^2 + s12^2]/
    Sqrt[s21^2 + s22^2];
eq4 := s22 == 1;
eq := {eq1, eq2, eq3, eq4};
s = FullSimplify[Solve[eq, {s11, s12, s21, s22}]];
Simplify[eq /. s[[2]] /. R -> 1/2]
s[[2]]
gives $$\begin{aligned} s_{11}&=\sqrt{1 + 98 R^2 - 6\sqrt {11}\sqrt {R^2 - R^4}}\\ s_{12}&=\sqrt{99 - 98 R^2 + 6\sqrt {11}\sqrt {R^2 - R^4}}\\ s_{21}&=-\frac{3s_ {11}s_ {12}(33-66R^2+98\sqrt{11}\sqrt{R^2-R^4})} {99+10000R^2(R^2-1)}\\ s_{22}&=1\\ \end{aligned}$$

  • 0
    Thanks for your answer - it is a big help. Could you clarify a few things? First, where does the variance-covariance matrix [0 1;0 1] come from? Should this be [1 0;0 1]? Second, with the system of 4 equations, where does s22 = 1 come from? Finally, do you have an suggestion for how I could generate a list of random numbers?2017-02-20
  • 0
    @AngusMurray Matrix: yes, typo, corrected. Equations: you have 3 equations and 4 unknowns. Hence you can (hoping it will work and it does) normalize one variable to $1$. Generating list: Use the code for Excel. Say you generate $X_{1}$, $X_{2}$ and $X_{3}$. The first pair , $X_{1}$ and $X_{2}$, gives you $Y_{1}$ and $Y_{2}$ according to the equations above. Then $X_{2}$ and $X_{3}$ gives you $Y_{1}'$ and $Y_{2}'$. $Y_{1}$ and $Y_{2}$ should have correlation $R$. Likewise for $Y_{1}'$ with $Y_{2}'$. Across the two pairs, the correlation should be lower.2017-02-20
  • 0
    Again, thanks for taking the time to explain this, I'm understanding about 90% of it. One thing I'm still unsure about is how we can justify assuming s22 = 1 or some other value. My approach so far has been to generate a random X1 and X2, assume a starting value of Y1 - and then use the relation Y1 = mu + s11*X1 + s12*X2 as the 4th equation. Then it is possible to determine all values of s11, s12, s21, s22 and then to solve Y2. This would the repeat for consecutive points.2017-02-21
  • 0
    I have two queries about this approach: first, solving the four equations simultaneously gives 4 combinations of different s11, s12, s21, s22. I'm unsure of which to use. In some cases these values are negative (is this permitted?). Secondly, these values sometimes take on complex values, which I'm sure is meaningless. Any tips?2017-02-21
  • 0
    .@AngusMurray I know about the multiple possibly complex solutions. I would take any real solution that gives you what you want.2017-02-21