-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathplot-irl.py
More file actions
34 lines (27 loc) · 925 Bytes
/
plot-irl.py
File metadata and controls
34 lines (27 loc) · 925 Bytes
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
#!/usr/bin/env python
import numpy as np
import sys
from matplotlib import pyplot as pl
def rho(w, s1, ds1, s2, ds2):
return np.exp(w * np.exp(-(s1 + ds1) ** 2) + (1 - w) * np.exp(-(s2 + ds2) ** 2))
def partition(w, s1, s2):
ds = np.linspace(-10, 10, 100)
d = (ds[-1] - ds[0]) / len(ds)
return rho(w, s1, ds, s2, ds).sum() * d * d
def delta(x):
return np.concatenate([[0], x[1:] - x[:-1]])
weights = np.linspace(0, 1, 100)
logps = np.zeros_like(weights)
for filename in sys.argv[2:20]:
data = np.loadtxt(filename)
d = data[:, 1]
s = data[:, 2]
for i, w in enumerate(weights):
logps[i] += rho(w, d, delta(d), s, delta(s)).sum()
for _d, _s in zip(d, s):
logps[i] -= np.log(partition(w, _d, _s))
print sys.argv[1], logps.shape
pl.plot(weights, logps)
pl.xlabel('Follow module weight')
pl.ylabel('Log-probability')
pl.savefig('%s-weights.png' % sys.argv[1])