diff --git a/Documentation.pdf b/Documentation.pdf index e0b17a02..3b5ed2bc 100644 Binary files a/Documentation.pdf and b/Documentation.pdf differ diff --git a/docs/config_keys.rst b/docs/config_keys.rst index ae8dd26b..70e45d5d 100644 --- a/docs/config_keys.rst +++ b/docs/config_keys.rst @@ -539,9 +539,9 @@ The following options are only available with ``fit_type = de``, and serve to ma * ``social = 1.7`` **particle_weight** - Inertia weight of particle. A value less than 1 can be thought of as friction that contiuously decelerates the particle. + Inertia weight of particle. A value less than 1 can be thought of as friction that contniuously decelerates the particle. - Default: 1 + Default: 0.7 Example: * ``particle_weight = 0.9`` diff --git a/pybnf/algorithms.py b/pybnf/algorithms.py index e664a432..0d598296 100644 --- a/pybnf/algorithms.py +++ b/pybnf/algorithms.py @@ -922,8 +922,10 @@ def start_run(self): for i in range(len(new_params_list)): p = new_params_list[i] p.name = 'iter0p%i' % i - # Todo: Smart way to initialize velocity? - new_velocity = {v.name: np.random.uniform(-1, 1) for v in self.variables} + + # As suggested by Engelbrecht 2012, set all initial velocities to 0 + new_velocity = dict({v.name: 0. for v in self.variables}) + self.swarm.append([p, new_velocity]) self.pset_map[p] = len(self.swarm)-1 # Index of the newly added PSet. @@ -987,10 +989,13 @@ def got_result(self, res): # If so, update based on reflection protocol and set velocity to 0 new_vars = [] for v in self.swarm[p][0]: - new_val = v.value + self.swarm[p][1][v.name] + new_vars.append(v.add(self.swarm[p][1][v.name])) + if v.log_space: + new_val = 10.**(np.log10(v.value) + self.swarm[p][1][v.name]) + else: + new_val = v.value + self.swarm[p][1][v.name] if new_val < v.lower_bound or v.upper_bound < new_val: self.swarm[p][1][v.name] = 0.0 - new_vars.append(v.add(self.swarm[p][1][v.name])) new_pset = PSet(new_vars) self.swarm[p][0] = new_pset diff --git a/pybnf/config.py b/pybnf/config.py index 05411fda..3165ba62 100644 --- a/pybnf/config.py +++ b/pybnf/config.py @@ -128,7 +128,7 @@ def default_config(): 'mutation_rate': 0.5, 'mutation_factor': 0.5, 'islands': 1, 'migrate_every': 20, 'num_to_migrate': 3, 'stop_tolerance': 0.002, 'de_strategy': 'rand1', - 'particle_weight': 1.0, 'adaptive_n_max': 30, 'adaptive_n_stop': np.inf, 'adaptive_abs_tol': 0.0, + 'particle_weight': 0.7, 'adaptive_n_max': 30, 'adaptive_n_stop': np.inf, 'adaptive_abs_tol': 0.0, 'adaptive_rel_tol': 0.0, 'cognitive': 1.5, 'social': 1.5, 'v_stop': 0., 'local_min_limit': 5, diff --git a/pybnf/pset.py b/pybnf/pset.py index 23d1632f..15f3c2a0 100644 --- a/pybnf/pset.py +++ b/pybnf/pset.py @@ -974,8 +974,11 @@ def _reflect(self, new): while True: if num_reflections >= 1000: - logger.error("Error in parameter reflection. Too many reflections: Init = %s, add = %s, parameter = %s" % (cur, add, self.name)) - raise PybnfError("Too many reflections for parameter %s. Current value = %s, adding value %s" % (self.name, cur, add)) + logger.error("Error in parameter reflection. Too many reflections: Init = %s, add = %s, parameter =" + " %s. Set parameter to a random value" % (cur, add, self.name)) + # Return a random value. Not ideal, but better than crashing the whole run. + rand = np.random.uniform(lb, ub) + return 10.**rand if self.log_space else rand num_reflections += 1 if cur + add > ub: