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

increase the number of burn-in steps #65

Merged
merged 8 commits into from
Aug 22, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion convoys/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ def fit(self, X, B, T, W=None, fix_k=None, fix_p=None):
)
result = {'map': res.x}

# TODO: should not use fixed k/p as search parameters
if fix_k: result['map'][0] = log(fix_k)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

multiple statements on one line (colon)

if fix_p: result['map'][1] = log(fix_p)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

multiple statements on one line (colon)


# Let's sample from the posterior to compute uncertainties
if self._ci:
dim, = res.x.shape
Expand All @@ -194,7 +198,7 @@ def fit(self, X, B, T, W=None, fix_k=None, fix_p=None):
mcmc_initial_noise = 1e-3
p0 = [result['map'] + mcmc_initial_noise * numpy.random.randn(dim)
for i in range(n_walkers)]
n_burnin = 20
n_burnin = 200
n_steps = numpy.ceil(1000. / n_walkers)
n_iterations = n_burnin + n_steps
sys.stdout.write('\n')
Expand All @@ -205,6 +209,8 @@ def fit(self, X, B, T, W=None, fix_k=None, fix_p=None):
sys.stdout.write('\n')
result['samples'] = sampler.chain[:, n_burnin:, :] \
.reshape((-1, dim)).T
if fix_k: result['samples'][0, :] = log(fix_k)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

multiple statements on one line (colon)

if fix_p: result['samples'][1, :] = log(fix_p)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

multiple statements on one line (colon)


self.params = {k: {
'k': exp(data[0]),
Expand Down
6 changes: 2 additions & 4 deletions test_convoys.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,15 @@ def test_weibull_regression_model(cs=[0.3, 0.5, 0.7],
for r in range(n)])
B, T = generate_censored_data(N, E, C)

model = convoys.regression.Weibull(ci=True)
model = convoys.regression.Weibull()
model.fit(X, B, T)

# Validate shape of results
x = numpy.ones((len(cs),))
assert model.cdf(x, float('inf')).shape == ()
assert model.cdf(x, float('inf'), ci=0.95).shape == (3,)
assert model.cdf(x, 1).shape == ()
assert model.cdf(x, 1, ci=True).shape == (3,)
assert model.cdf(x, [1, 2, 3, 4]).shape == (4,)
assert model.cdf(x, [1, 2, 3, 4], ci=True).shape == (4, 3)


# Check results
for r, c in enumerate(cs):
Expand Down