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

fix bug where some 2D arrays are not accepted instead lists of 1D arrays #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions pydream/Dream.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def __init__(self, model, variables=None, nseedchains=None, nCR=3, adapt_crossov
self.last_logp = None

#Set the number of seedchains to 10*dimensions to fit
if self.nseedchains == None:
if self.nseedchains is None:
self.nseedchains = self.total_var_dimension*10

#Set array of gamma values (decreasing step size with increasing level)
Expand Down Expand Up @@ -228,7 +228,7 @@ def astep(self, q0, T=1., last_loglike=None, last_logprior=None):

try:

if last_loglike != None:
if last_loglike is not None:
self.last_like = last_loglike
self.last_prior = last_logprior
self.last_logp = T*self.last_like + self.last_prior
Expand All @@ -254,7 +254,7 @@ def astep(self, q0, T=1., last_loglike=None, last_logprior=None):
else:
proposed_pts, snooker_logp_prop, z = self.generate_proposal_points(self.multitry, q0, CR, DEpair_choice, gamma_level, snooker=True)

if self.last_logp == None:
if self.last_logp is None:
self.last_prior, self.last_like = self.logp(q0)
self.last_logp = T*self.last_like + self.last_prior

Expand Down Expand Up @@ -424,11 +424,11 @@ def set_current_position_arr(self, ndimensions, q_new):
accepted point in parameter space
"""

if self.nchains == None:
if self.nchains is None:
current_positions = np.frombuffer(Dream_shared_vars.current_positions.get_obj())
self.nchains = len(current_positions)//ndimensions

if self.chain_n == None:
if self.chain_n is None:
with Dream_shared_vars.nchains.get_lock():
self.chain_n = Dream_shared_vars.nchains.value-1
Dream_shared_vars.nchains.value -= 1
Expand Down
11 changes: 6 additions & 5 deletions pydream/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def run_dream(parameters, likelihood, nchains=5, niterations=50000, start=None,
"""

if restart:
if start == None:
if start is None:
raise Exception('Restart run specified but no start positions given.')
if 'model_name' not in kwargs:
raise Exception('Restart run specified but no model name to load history and crossover value files from given.')
Expand All @@ -63,7 +63,8 @@ def run_dream(parameters, likelihood, nchains=5, niterations=50000, start=None,

else:

if type(start) is list:
if (type(start) is list
or isinstance(start, np.ndarray) and start.ndim == 2):
args = zip([step_instance]*nchains, [niterations]*nchains, start, [verbose]*nchains, [nverbose]*nchains)

else:
Expand Down Expand Up @@ -215,7 +216,7 @@ def _sample_dream_pt(nchains, niterations, step_instance, start, pool, verbose):
naccepts[i] += 1
naccepts100win[i] += 1
except TypeError:
#On first iteration without starting points this will fail because q0 == None
#On first iteration without starting points this will fail because q0 is None
pass

args = list(zip(dream_instances, qnews, T, loglikenews, logprinews))
Expand Down Expand Up @@ -280,10 +281,10 @@ def _setup_mp_dream_pool(nchains, niterations, step_instance, start_pt=None):
n = mp.Value('i', 0)
tf = mp.Value('c', b'F')

if step_instance.crossover_burnin == None:
if step_instance.crossover_burnin is None:
step_instance.crossover_burnin = int(np.floor(niterations/10))

if start_pt != None:
if start_pt is not None:
if step_instance.start_random:
print('Warning: start position provided but random_start set to True. Overrode random_start value and starting walk at provided start position.')
step_instance.start_random = False
Expand Down