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

Commit c2661a0

Browse files
author
Tanguy Damart
committed
Add feature computation functions to CellEvaluator, ObjectivesCalculator and Objectives
1 parent 6413222 commit c2661a0

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

bluepyopt/ephys/evaluators.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,34 +182,44 @@ def run_protocols(self, protocols, param_values):
182182

183183
return responses
184184

185-
def evaluate_with_dicts(self, param_dict=None):
185+
def evaluate_with_dicts(self, param_dict=None, target='scores'):
186186
"""Run evaluation with dict as input and output"""
187-
187+
188+
if target not in ['scores', 'values']:
189+
raise Exception(
190+
'CellEvaluator: target has to be "scores" or "values".')
191+
188192
if self.fitness_calculator is None:
189193
raise Exception(
190194
'CellEvaluator: need fitness_calculator to evaluate')
191195

192196
logger.debug('Evaluating %s', self.cell_model.name)
193-
197+
194198
responses = self.run_protocols(
195199
self.fitness_protocols.values(),
196200
param_dict)
197201

198-
return self.fitness_calculator.calculate_scores(responses)
202+
if target == 'scores':
203+
return self.fitness_calculator.calculate_scores(responses)
204+
205+
elif target == 'values':
206+
return self.fitness_calculator.calculate_values(responses)
199207

200-
def evaluate_with_lists(self, param_list=None):
208+
def evaluate_with_lists(self, param_list=None, target='scores'):
201209
"""Run evaluation with lists as input and outputs"""
202210

203211
param_dict = self.param_dict(param_list)
204212

205-
obj_dict = self.evaluate_with_dicts(param_dict=param_dict)
213+
obj_dict = self.evaluate_with_dicts(
214+
param_dict=param_dict, target=target
215+
)
206216

207217
return self.objective_list(obj_dict)
208218

209-
def evaluate(self, param_list=None):
219+
def evaluate(self, param_list=None, target='scores'):
210220
"""Run evaluation with lists as input and outputs"""
211221

212-
return self.evaluate_with_lists(param_list)
222+
return self.evaluate_with_lists(param_list, target=target)
213223

214224
def __str__(self):
215225

bluepyopt/ephys/objectives.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ def calculate_feature_scores(self, responses):
4747

4848
return scores
4949

50+
def calculate_feature_values(self, responses):
51+
"""Calculate the value of an individual features"""
52+
53+
values = []
54+
for feature in self.features:
55+
values.append(feature.calculate_feature(responses))
56+
57+
return values
58+
5059

5160
class SingletonObjective(EFeatureObjective):
5261

@@ -66,6 +75,11 @@ def calculate_score(self, responses):
6675
"""Objective score"""
6776

6877
return self.calculate_feature_scores(responses)[0]
78+
79+
def calculate_value(self, responses):
80+
"""Objective value"""
81+
82+
return self.calculate_feature_values(responses)[0]
6983

7084
def __str__(self):
7185
"""String representation"""

bluepyopt/ephys/objectivescalculators.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ def calculate_scores(self, responses):
4141
return {objective.name: objective.calculate_score(responses)
4242
for objective in self.objectives}
4343

44+
def calculate_values(self, responses):
45+
"""Calculator the value of each objective"""
46+
47+
return {objective.name: objective.calculate_value(responses)
48+
for objective in self.objectives}
49+
4450
def __str__(self):
4551
return 'objectives:\n %s' % '\n '.join(
4652
[str(obj) for obj in self.objectives]) \

0 commit comments

Comments
 (0)