diff options
| author | jeanpouget-abadie <jean.pougetabadie@gmail.com> | 2015-11-23 13:50:01 -0500 |
|---|---|---|
| committer | jeanpouget-abadie <jean.pougetabadie@gmail.com> | 2015-11-23 13:50:01 -0500 |
| commit | 4383fbb4179e73e8b4c28eabd64199b3f7a16eee (patch) | |
| tree | 41ac39c33b33ff9b6f89b4ab800b7c50dab818a7 /simulation/vi.py | |
| parent | 65638ea7d886c25b8bf75e43a5ce46db2ebbaf53 (diff) | |
| download | cascades-4383fbb4179e73e8b4c28eabd64199b3f7a16eee.tar.gz | |
adding likelihood to theano implementation
Diffstat (limited to 'simulation/vi.py')
| -rw-r--r-- | simulation/vi.py | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/simulation/vi.py b/simulation/vi.py index aeccb69..1e45761 100644 --- a/simulation/vi.py +++ b/simulation/vi.py @@ -50,7 +50,7 @@ def kl(params1, params0): grad_kl = grad(kl) -def sgd(mu1, sig1, mu0, sig0, cascades, n_e=100, lr=lambda t: 1e-2, n_print=10): +def sgd(mu1, sig1, mu0, sig0, cascades, n_e=100, lr=lambda t: 1e-1, n_print=10): g_mu1, g_sig1 = grad_kl((mu1, sig1), (mu0, sig0)) for t in xrange(n_e): lrt = lr(t) # learning rate @@ -61,19 +61,19 @@ def sgd(mu1, sig1, mu0, sig0, cascades, n_e=100, lr=lambda t: 1e-2, n_print=10): sig1 = np.maximum(sig1 + lrt * g_sig1, 1e-3) res = np.sum(ll_full((mu1, sig1), x, s) for x, s in zip(*cascades))\ + kl((mu1, sig1), (mu0, sig0)) - if step % n_print == 0: - logging.info("Epoch:{}\tStep:{}\tLB:{}\t".format(t, step, res)) - print mu1[0:2, 0:2] - print sig1[0:2, 0:2] + #if step % n_print == 0: + logging.info("Epoch:{}\tStep:{}\tLB:{}\t".format(t, step, res)) + print mu1 + print sig1 if __name__ == '__main__': - #graph = np.array([[0, 0, 1], [0, 0, 0.5], [0, 0, 0]]) - graph = np.random.binomial(2, p=.2, size=(10, 10)) + graph = np.array([[0, 0, 1], [0, 0, 0.5], [0, 0, 0]]) + #graph = np.random.binomial(2, p=.2, size=(4, 4)) p = 0.5 graph = np.log(1. / (1 - p * graph)) - print(graph[0:2, 0:2]) - cascades = mn.build_cascade_list(mn.simulate_cascades(500, graph)) + print(graph) + cascades = mn.build_cascade_list(mn.simulate_cascades(100, graph)) mu0, sig0 = (1. + .2 * np.random.normal(size=graph.shape), 1 + .2 * np.random.normal(size=graph.shape)) mu1, sig1 = (1. + .2 * np.random.normal(size=graph.shape), |
