-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandomVariable
More file actions
41 lines (32 loc) · 1.66 KB
/
randomVariable
File metadata and controls
41 lines (32 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# imports that correspond to later sections of the code and project
from numpy.random import seed, uniform,randint, exponential
import argparse
import math
import hashlib, binascii
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
from collections import Counter
from scipy.stats import binom
from scipy.stats import poisson
import random
class RandVar:
#will use a uniform random genrator and returns a random value that is distributed according
# to an exponential distribution with mean of T = 1/$\lambda$
# you pass in the lambda (arrival rate)
def exp(sample,lam):
#sample = np.random.uniform(0,1)
x = (-math.log(1-sample))/lam
return x
# test for sanity
num_trials = 1000
uni = sorted([random.random() for x in range(num_trials)])
expi = [RandVar.exp(x, 4) for x in uni]
theo = [x*.001 for x in range(num_trials)]
theox = [RandVar.exp(x,4)for x in theo ]
plt.xlabel("Exponential distribution variable")
plt.ylabel("Uniform random variable")
plt.plot(expi,uni)
plt.plot(theox,theo, 'w--')
plt.show()