-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodeling-step2.R
70 lines (47 loc) · 1.72 KB
/
modeling-step2.R
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Try to fit an analytical distribution to the operator hists
#... kinda morphed to trying to get insight into why the
rm(list=ls())
load("~/Desktop/op2-hists/i=10,j=10,k=10,l=10.RData")
ls()
h2 = h
op2Bin = bin
op2Bin[1:10,]
load("~/Desktop/op3-hists/i=10,j=10,k=10,l=10.RData")
h3 = h
op3Bin = bin
ls()
load("~/Desktop/op6-hists/i=10,j=10,k=10,l=10.RData")
h6 = h
op6Bin = bin
ls()
# trying to fit a gamma to op2Bin$latency_ms
k=1
theta = 1/(k*nrow(op2Bin)) * sum(op2Bin$latency_ms)
par(mfrow=c(2,1))
gammaSamples = rgamma(10000, shape=1, scale=theta)
xmax = max(op2Bin$latency_ms, gammaSamples)
hist(op2Bin$latency_ms, breaks=25, xlim=c(0,xmax))
hist(gammaSamples, breaks=15, xlim=c(0,xmax))
# matches well, but how to set k?
# use initial value from wikipedia -- w/in 1.5% of correct value
s = log(1/(nrow(op2Bin)) * sum(op2Bin$latency_ms)) - 1/nrow(op2Bin) * sum(log(op2Bin$latency_ms))
k = (3 - s + sqrt((s-3)^2 + 24*s))/(12*s)
theta = 1/(k*nrow(op2Bin)) * sum(op2Bin$latency_ms)
par(mfrow=c(2,1))
gammaSamples = rgamma(10000, shape=k, scale=theta)
xmax = max(op2Bin$latency_ms, gammaSamples)
hist(op2Bin$latency_ms, breaks=25, xlim=c(0,xmax))
hist(gammaSamples, breaks=15, xlim=c(0,xmax))
# perfect!
# now try op3
opBin = op3Bin
s = log(1/(nrow(opBin)) * sum(opBin$latency_ms)) - 1/nrow(opBin) * sum(log(opBin$latency_ms))
k = (3 - s + sqrt((s-3)^2 + 24*s))/(12*s)
theta = 1/(k*nrow(opBin)) * sum(opBin$latency_ms)
par(mfrow=c(2,1))
gammaSamples = rgamma(10000, shape=k, scale=theta)
xmax = max(opBin$latency_ms, gammaSamples)
hist(opBin$latency_ms, breaks=25, xlim=c(0,xmax))
abline(v=median(opBin$latency_ms), col="green", lw=2)
hist(gammaSamples, breaks=25, xlim=c(0,xmax))
abline(v=median(gammaSamples), col="green", lw=2)