Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit 214ccf0

Browse files
author
Tanguy Damart
committed
Rebase CMA on master
1 parent 887f60c commit 214ccf0

File tree

15 files changed

+65
-115
lines changed

15 files changed

+65
-115
lines changed

bluepyopt/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import bluepyopt.stoppingCriteria
3434
import bluepyopt.deapext.optimisations
3535
import bluepyopt.deapext.optimisationsCMA
36-
import bluepyopt.deapext.hype
3736

3837
# Add some backward compatibility for the time when DEAPoptimisation not in
3938
# deapext yet

bluepyopt/deapext/CMA_SO.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ def update(self, population):
135135
(
136136
numpy.linalg.norm(self.ps)
137137
/ sqrt(1.0 - (1.0 - self.cs) **
138-
(2.0 * (self.update_count + 1.0)))
138+
(2.0 * (self.update_count + 1.0)))
139139
/ self.chiN
140140
< (1.4 + 2.0 / (self.dim + 1.0))
141141
)
142-
)
142+
) # noqa
143143

144144
self.update_count += 1
145145

bluepyopt/deapext/algorithms.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,7 @@ def eaAlphaMuPlusLambdaCheckpoint(
112112
terminator (multiprocessing.Event): exit loop when is set.
113113
Not taken into account if None.
114114
"""
115-
<<<<<<< HEAD
116115

117-
=======
118-
119-
>>>>>>> 7e9c3ea (Added rules)
120116
if cp_filename:
121117
cp_filename_tmp = cp_filename + '.tmp'
122118

@@ -147,13 +143,11 @@ def eaAlphaMuPlusLambdaCheckpoint(
147143
history = deap.tools.History()
148144

149145
invalid_count = _evaluate_invalid_fitness(toolbox, population)
150-
146+
151147
utils.update_history_and_hof(halloffame, history, population)
152-
utils.record_stats(stats,
153-
logbook,
154-
start_gen,
155-
population,
156-
invalid_count)
148+
utils.record_stats(
149+
stats, logbook, start_gen, population, invalid_count
150+
)
157151

158152
stopping_criteria = [MaxNGen(ngen)]
159153

bluepyopt/deapext/optimisations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,14 @@ def setup_deap(self):
160160

161161
# Number of parameters
162162
IND_SIZE = len(self.evaluator.params)
163-
164163
if IND_SIZE == 0:
165164
raise Exception(
166165
"Length of evaluator.params is zero. At least one "
167-
"non-fix parameter is neededto run an optimization."
166+
"non-fix parameter is needed to run an optimization."
168167
)
169168

170169
# Bounds for the parameters
170+
171171
LOWER = []
172172
UPPER = []
173173

bluepyopt/deapext/optimisationsCMA.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import pickle
2525
import random
2626
import functools
27+
import shutil
28+
import os
2729

2830
import deap.tools
2931

@@ -91,11 +93,9 @@ def __init__(
9193
self.hof = hof
9294
if self.hof is None:
9395
self.hof = deap.tools.HallOfFame(10)
94-
95-
if offspring_size < 2:
96-
raise Exception("offspring_size has to be at least 2.")
96+
9797
self.offspring_size = offspring_size
98-
98+
9999
self.fitness_reduce = fitness_reduce
100100
self.centroids = centroids
101101
self.sigma = sigma
@@ -251,6 +251,9 @@ def run(
251251
Not taken into account if None.
252252
"""
253253

254+
if cp_filename:
255+
cp_filename_tmp = cp_filename + '.tmp'
256+
254257
stats = self.get_stats()
255258

256259
if continue_cp:
@@ -345,8 +348,10 @@ def run(
345348
np_rndstate=numpy.random.get_state(),
346349
CMA_es=CMA_es,
347350
)
348-
pickle.dump(cp, open(cp_filename, "wb"))
349-
logger.debug("Wrote checkpoint to %s", cp_filename)
351+
pickle.dump(cp, open(cp_filename_tmp, "wb"))
352+
if os.path.isfile(cp_filename_tmp):
353+
shutil.copy(cp_filename_tmp, cp_filename)
354+
logger.debug('Wrote checkpoint to %s', cp_filename)
350355

351356
CMA_es.map_function = temp_mf
352357

bluepyopt/deapext/stoppingCriteria.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""StoppingCriteria class"""
22

33
"""
4-
Copyright (c) 2016-2020, EPFL/Blue Brain Project
4+
Copyright (c) 2016-2021, EPFL/Blue Brain Project
55
66
This file is part of BluePyOpt <https://github.com/BlueBrain/BluePyOpt>
77

bluepyopt/ephys/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
from . import recordings # NOQA
3838
from . import objectivescalculators # NOQA
3939
from . import stimuli # NOQA
40-
from . import rules # NOQA
4140

4241
# TODO create all the necessary abstract methods
4342
# TODO check inheritance structure

bluepyopt/ephys/evaluators.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,13 @@ def objective_dict(self, objective_array):
116116
def objective_list(self, objective_dict):
117117
"""Convert objective_dict in objective_list"""
118118
objective_list = []
119+
<<<<<<< HEAD
119120
objective_names = [objective.name for objective in self.fitness_calculator.objectives]
120121

122+
=======
123+
objective_names = [objective.name
124+
for objective in self.fitness_calculator.objectives]
125+
>>>>>>> 923c7e5 (Rebase CMA on master)
121126
for objective_name in objective_names:
122127
objective_list.append(objective_dict[objective_name])
123128

bluepyopt/ephys/objectives.py

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -127,52 +127,3 @@ def calculate_score(self, responses):
127127
score += weight * feature_score
128128

129129
return score
130-
131-
132-
class RuleObjective(bluepyopt.objectives.Objective):
133-
134-
"""Multi rules objective"""
135-
136-
def __init__(self, name, rules=None):
137-
"""Constructor
138-
Args:
139-
name (str): name of this object
140-
rules (list): rule used in the Objective
141-
"""
142-
143-
super(RuleObjective, self).__init__(name)
144-
self.name = name
145-
self.rules = rules
146-
147-
def calculate_scores(self, cell_model):
148-
"""Calculate the scores for the individual rules"""
149-
150-
scores = []
151-
for rule in self.rules:
152-
scores.append(rule.calculate_score(cell_model))
153-
154-
return scores
155-
156-
157-
class SingletonRuleObjective(RuleObjective):
158-
159-
"""Single rule objective"""
160-
161-
def __init__(self, name, rule):
162-
"""Constructor
163-
Args:
164-
name (str): name of this object
165-
rule (EFeature): single rule inside this objective
166-
"""
167-
168-
super(SingletonRuleObjective, self).__init__(name, [rule])
169-
170-
def calculate_score(self, cell_model):
171-
"""Objective score"""
172-
173-
return self.calculate_scores(cell_model)[0]
174-
175-
def __str__(self):
176-
"""String representation"""
177-
178-
return '( %s )' % self.rule[0]

bluepyopt/ephys/objectivescalculators.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2020
"""
2121

22+
<<<<<<< HEAD
2223
from . import objectives
24+
=======
25+
>>>>>>> 923c7e5 (Rebase CMA on master)
2326

2427
class ObjectivesCalculator(object):
2528

@@ -36,8 +39,9 @@ def __init__(
3639

3740
self.objectives = objectives
3841

39-
def calculate_scores(self, responses, cell_model=None, param_dict=None):
42+
def calculate_scores(self, responses):
4043
"""Calculator the score for every objective"""
44+
<<<<<<< HEAD
4145

4246
scores = {}
4347

@@ -58,6 +62,11 @@ def calculate_scores(self, responses, cell_model=None, param_dict=None):
5862
cell_model.unfreeze(param_dict.keys())
5963

6064
return scores
65+
=======
66+
67+
return {objective.name: objective.calculate_score(responses)
68+
for objective in self.objectives}
69+
>>>>>>> 923c7e5 (Rebase CMA on master)
6170

6271
def calculate_values(self, responses):
6372
"""Calculator the value of each objective"""
@@ -66,7 +75,10 @@ def calculate_values(self, responses):
6675
for objective in self.objectives}
6776

6877
def __str__(self):
78+
<<<<<<< HEAD
6979

80+
=======
81+
>>>>>>> 923c7e5 (Rebase CMA on master)
7082
return 'objectives:\n %s' % '\n '.join(
7183
[str(obj) for obj in self.objectives]) \
7284
if self.objectives is not None else 'objectives:\n'

0 commit comments

Comments
 (0)