Random Systems

problems

(6.1)

(a) Work out the first three cumulants C1, C2, and C3.

(6.2)

(c) Write a uniform random number generator, and transform it by equation (6.78). Numerically evaluate the first three cumulants of its output.

In [158]:
import numpy as np
import time
import matplotlib.pyplot as plt
import math
In [159]:
# Linear Congruential Random Generator

prev = 0

a = 8121
b = 28311
c = 134456
 
def random_seed(x):
    global prev
    prev = (int(x)*a + b) % c

def random_gen():
    global prev
    prev = (a * prev + b) % c
    return prev / c

print(prev)
0
In [160]:
# Simulated LFSR

prev2 = ''
size = 32
taps = [0,1,21,31]

def random_seed2(size):
    global prev2
    curr_time = int(time.time()%1*(10**16) % (2**size))
    prev2 = format(curr_time, 'b').zfill(size)

def random_gen2():
    global prev2
    bit = 0
    for t in taps:
        bit = (bit + eval(prev2[t])) % 2
    prev2 = str(bit)+prev2[:-1]
    return int(prev2,2) / (2**size)

random_seed2(size)
print(prev2)
random_gen2()
print(prev2)
random_gen2()
print(prev2)
10001110101110010110011010100000
01000111010111001011001101010000
10100011101011100101100110101000
In [161]:
# 

N = 100

print(prev)
random_seed(round(time.time()%1*(10**6)))
print(prev)

x1 = np.array([random_gen2()*2*math.pi for i in range(N)])
x2 = np.array([random_gen2() for i in range(N)])
0
23500
In [162]:
plt.scatter(x1, x2)
plt.xlabel("x1")
plt.ylabel("x2")
plt.show()

concepts


1. properties of a random variable

  • near-certain probabiliy ( $1-\epsilon$ ) vs near-random uncertainty ( $ 0.5 + \epsilon $ )
  • it is not possible to predict the value of a random variable, but it is possible to predict the probability for seeing a given event in terms of the random variable.
    • realization: each instantiation of identical stochastic procedure will obey the same distribution laws.
  • discrete vs. continuous;
  • probability(|x-target value| < tolerance)
    $ \int_{a}^{b} p(x) dx $
  • support: values over which the integral of probability function is defined
  • expectation value: \begin{equation*} \begin{aligned} \langle f(x) \rangle & = \lim_{N\to\infty} \frac {1}{N} \sum_{i=1}^{N} f(x_i) \\ & = \int_{-\infty}^{\infty} f(x)\,p(x)\;dx \end{aligned} \end{equation*}
    • mean value: $ \bar{x} \equiv \langle x \rangle $
  • maximum likelihood value?
  • variance $ \sigma^2_x \equiv \langle (x-\bar{x})^2 \rangle = \langle x^2 \rangle - \langle x \rangle^2$: average value of the square
  • *standard deviation

2. inter-relationships among a collection of random variables

\begin{equation} p(x|y) = \frac {p(x,y)}{p(y)} \end{equation}
Bayes's rule: the joint probability of x,y is equal to the probability of x given y multiplied by probability of y

  • independent : $ \begin{aligned} p(x|y) &= p(x) \\ p(x,y) &= p(x)p(y) \end{aligned} $

3. stochastic processes: random systems that evolve in time

4. algorithms for generating random numbers

facts


procedures


In [ ]: