Skip to content
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
18 changes: 10 additions & 8 deletions pydream/Dream.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ def estimate_crossover_probabilities(self, ndim, q0, q_new, CR):
cross_probs = Dream_shared_vars.cross_probs[0:self.nCR]

#Compute squared normalized jumping distance
m_loc = int(np.where(self.CR_values == CR)[0])
m_loc = int(np.flatnonzero(self.CR_values == CR).item())

Dream_shared_vars.ncr_updates[m_loc] += 1

Expand Down Expand Up @@ -520,7 +520,7 @@ def estimate_gamma_level_probs(self, ndim, q0, q_new, gamma_level):

gamma_level_probs = Dream_shared_vars.gamma_level_probs[0:self.ngamma]

gamma_loc = int(np.where(self.gamma_level_values == gamma_level)[0])
gamma_loc = int(np.flatnonzero(self.gamma_level_values == gamma_level).item())

Dream_shared_vars.ngamma_updates[gamma_loc] += 1

Expand All @@ -542,9 +542,10 @@ def estimate_gamma_level_probs(self, ndim, q0, q_new, gamma_level):
def set_snooker(self):
"""Choose to run a snooker update on a given iteration or not."""
if self.snooker != 0:
snooker_choice = np.where(np.random.multinomial(1, [self.snooker, 1-self.snooker])==1)

if snooker_choice[0] == 0:
snooker_choice = int(
np.random.multinomial(1, [self.snooker, 1-self.snooker]).argmax())

if snooker_choice == 0:
run_snooker = True
else:
run_snooker = False
Expand Down Expand Up @@ -612,12 +613,13 @@ def set_gamma(self, DEpairs, snooker_choice, gamma_level_choice, d_prime):
d_prime : int
number of parameter dimensions to be updated on this step."""

gamma_unity_choice = np.where(np.random.multinomial(1, [self.p_gamma_unity, 1-self.p_gamma_unity])==1)
gamma_unity_choice = int(
np.random.multinomial(1, [self.p_gamma_unity, 1-self.p_gamma_unity]).argmax())

if snooker_choice:
gamma = np.random.uniform(1.2, 2.2)

elif gamma_unity_choice[0] == 0:
elif gamma_unity_choice == 0:
gamma = 1.0

else:
Expand Down Expand Up @@ -905,7 +907,7 @@ def mt_choose_proposal_pt(self, log_priors, log_likes, proposed_pts, T):
#Calculate probabilities
sum_proposal_logps = np.sum(log_ps_sub)
logp_prob = log_ps_sub/sum_proposal_logps
best_logp_loc = int(np.squeeze(np.where(np.random.multinomial(1, logp_prob)==1)[0]))
best_logp_loc = int(np.random.multinomial(1, logp_prob).argmax())

#Randomly select one of the tested points with probability proportional to the probability density at the point
q_proposal = np.squeeze(proposed_pts[best_logp_loc])
Expand Down
12 changes: 6 additions & 6 deletions pydream/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ 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.')

if type(parameters) is not list:
if not isinstance(parameters, list):
parameters = [parameters]

model = Model(likelihood=likelihood, sampled_parameters=parameters)
Expand All @@ -71,7 +71,7 @@ def run_dream(parameters, likelihood, nchains=5, niterations=50000, start=None,

else:

if type(start) is list:
if isinstance(start, list):
args = zip([step_instance]*nchains, [niterations]*nchains, start, [verbose]*nchains, [nverbose]*nchains)

else:
Expand Down Expand Up @@ -137,7 +137,7 @@ def _sample_dream_pt(nchains, niterations, step_instance, start, pool, verbose):

step_instances = [step_instance]*nchains

if type(start) is list:
if isinstance(start, list):
args = list(zip(step_instances, start, T, [None]*nchains, [None]*nchains))
else:
args = list(zip(step_instances, [start]*nchains, T, [None]*nchains, [None]*nchains))
Expand Down Expand Up @@ -296,10 +296,10 @@ def _setup_mp_dream_pool(nchains, niterations, step_instance, start_pt=None, mp_
n = ctx.Value('i', 0)
tf = ctx.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
3 changes: 1 addition & 2 deletions pydream/parameters.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# -*- coding: utf-8 -*-

import numpy as np
import time

class SampledParam():
class SampledParam:
"""A SciPy-based parameter prior class.

Parameters
Expand Down