(a) Work out the first three cumulants C1, C2, and C3.
(c) Write a uniform random number generator, and transform it by equation (6.78). Numerically evaluate the first three cumulants of its output.
import numpy as np
import time
import matplotlib.pyplot as plt
import math
# 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)
# 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)
#
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)])
plt.scatter(x1, x2)
plt.xlabel("x1")
plt.ylabel("x2")
plt.show()
\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