Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

summary method of elfi.methods.results.Sample object throws NoneType error in Python interactive mode #223

Closed
p-robot opened this issue Aug 8, 2017 · 2 comments

Comments

@p-robot
Copy link

p-robot commented Aug 8, 2017

Summary:

As per the title, calling the summary method of elfi.methods.results.Sample object throws NoneType error in Python interactive mode

Description:

This is following the MA(2) model in the ELFI documentation.

Reproducible Steps:

import numpy as np
import scipy.stats

seed = 20170530
np.random.seed(seed)

def MA2(t1, t2, n_obs=100, batch_size=1, random_state=None):
    # Make inputs 2d arrays for numpy broadcasting with w
    t1 = np.asanyarray(t1).reshape((-1, 1))
    t2 = np.asanyarray(t2).reshape((-1, 1))
    random_state = random_state or np.random

    w = random_state.randn(batch_size, n_obs+2)  # i.i.d. sequence ~ N(0,1)
    x = w[:, 2:] + t1*w[:, 1:-1] + t2*w[:, :-2]
    return x

t1_true = 0.6; t2_true = 0.2
y_obs = MA2(t1_true, t2_true)


import elfi

t1 = elfi.Prior(scipy.stats.uniform, 0, 2)
t2 = elfi.Prior('uniform', 0, 2)

Y = elfi.Simulator(MA2, t1, t2, observed=y_obs)

def autocov(x, lag=1):
    C = np.mean(x[:,lag:] * x[:,:-lag], axis=1)
    return C

S1 = elfi.Summary(autocov, Y); S2 = elfi.Summary(autocov, Y, 2)

d = elfi.Distance('euclidean', S1, S2)
rej = elfi.Rejection(d, batch_size=10000, seed=seed)

result = rej.sample(1000, quantile=0.01)
result.summary()

Current Output:

In [2]: result.summary()
Method: Rejection
Number of posterior samples: 1000
Number of simulations: 100000
Threshold: 0.123
Posterior means: t1: 0.552, t2: 0.272

TypeError                                 Traceback (most recent call last)
<ipython-input-2-c942b82acb49> in <module>()
> 1 result.summary()

TypeError: 'NoneType' object is not callable

ELFI Version:

0.6.0

Python Version:

3.6.1

Operating System:

MacOSX 10.12.5

@p-robot p-robot changed the title summary method of elfi.methods.results.Sample object throws NoneType error in Python interactive mode summary method of elfi.methods.results.Sample object throws NoneType error in Python interactive mode Aug 8, 2017
@vuolleko
Copy link
Member

vuolleko commented Aug 9, 2017

The automatic name inspection does not work in interactive Python shell, so you have to name the nodes manually:

t1 = elfi.Prior(scipy.stats.uniform, 0, 2, name='t1')
t2 = elfi.Prior('uniform', 0, 2, name='t2')
Y = elfi.Simulator(MA2, t1, t2, observed=y_obs, name='Y')

and so on.

Also, please update to ELFI 0.6.1, which gives a warning in this scenario.

@p-robot
Copy link
Author

p-robot commented Aug 9, 2017

Excellent. I upgraded via github and now no error is thrown. Thanks very much!

@p-robot p-robot closed this as completed Aug 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants