From 4774c34159306208bada7db2c47b78b3c8252ac4 Mon Sep 17 00:00:00 2001 From: loqueelvientoajuarez Date: Fri, 29 Nov 2019 12:38:32 -0300 Subject: [PATCH 1/2] fix bug where some 2D arrays are not accepted instead lists of 1D arrays --- pydream/Dream.py | 10 +++++----- pydream/core.py | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pydream/Dream.py b/pydream/Dream.py index 00daffc..ec8d494 100644 --- a/pydream/Dream.py +++ b/pydream/Dream.py @@ -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) @@ -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 @@ -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 @@ -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 diff --git a/pydream/core.py b/pydream/core.py index 87fa663..50757f9 100644 --- a/pydream/core.py +++ b/pydream/core.py @@ -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.') @@ -215,7 +215,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)) @@ -280,10 +280,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 From 43b65b7055bdc9b487d37f48b2bd89996c3bdb74 Mon Sep 17 00:00:00 2001 From: loqueelvientoajuarez Date: Fri, 29 Nov 2019 15:21:21 -0300 Subject: [PATCH 2/2] start may be a 2D array instead of an array list --- pydream/core.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pydream/core.py b/pydream/core.py index 50757f9..66e4463 100644 --- a/pydream/core.py +++ b/pydream/core.py @@ -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: