-
Notifications
You must be signed in to change notification settings - Fork 1
/
GLIF_4_Evaluator.py
109 lines (98 loc) · 4.77 KB
/
GLIF_4_Evaluator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/env python
import bluepyopt as bpop
from bluepyopt.parameters import Parameter
import numpy as np
import GLIF_4 as glif_model
import brian2 as b2
b2.prefs.codegen.target = 'cython'
class Evaluator(bpop.evaluators.Evaluator):
def __init__(self, input_current, dt, init_values, parameters, fitness, target_voltage):
self.input_current = input_current
self.dt = dt
self.init_values = init_values
self.parameters = parameters
self.fitness = fitness
self.target_voltage = target_voltage
super(Evaluator, self).__init__(
objectives=[x for x in fitness.keys()],
params=[
Parameter('El',
value = parameters['El']['value'],
bounds = parameters['El']['bounds'],
frozen = parameters['El']['frozen']),
Parameter('C',
value = parameters['C']['value'],
bounds = parameters['C']['bounds'],
frozen = parameters['C']['frozen']),
Parameter('G',
value = parameters['G']['value'],
bounds = parameters['G']['bounds'],
frozen = parameters['G']['frozen']),
Parameter('Th_inf',
value = parameters['Th_inf']['value'],
bounds = parameters['Th_inf']['bounds'],
frozen = parameters['Th_inf']['frozen']),
Parameter('t_ref',
value = parameters['t_ref']['value'],
bounds = parameters['t_ref']['bounds'],
frozen = parameters['t_ref']['frozen']),
Parameter('a_r',
value = parameters['a_r']['value'],
bounds = parameters['a_r']['bounds'],
frozen = parameters['a_r']['frozen']),
Parameter('b_r',
value = parameters['b_r']['value'],
bounds = parameters['b_r']['bounds'],
frozen = parameters['b_r']['frozen']),
Parameter('a_s',
value = parameters['a_s']['value'],
bounds = parameters['a_s']['bounds'],
frozen = parameters['a_s']['frozen']),
Parameter('b_s',
value = parameters['b_s']['value'],
bounds = parameters['b_s']['bounds'],
frozen = parameters['b_s']['frozen']),
Parameter('A_0',
value = parameters['A_0']['value'],
bounds = parameters['A_0']['bounds'],
frozen = parameters['A_0']['frozen']),
Parameter('k_0',
value = parameters['k_0']['value'],
bounds = parameters['k_0']['bounds'],
frozen = parameters['k_0']['frozen']),
Parameter('R_0',
value = parameters['R_0']['value'],
bounds = parameters['R_0']['bounds'],
frozen = parameters['R_0']['frozen']),
Parameter('A_1',
value = parameters['A_1']['value'],
bounds = parameters['A_1']['bounds'],
frozen = parameters['A_1']['frozen']),
Parameter('k_1',
value = parameters['k_1']['value'],
bounds = parameters['k_1']['bounds'],
frozen = parameters['k_1']['frozen']),
Parameter('R_1',
value = parameters['R_1']['value'],
bounds = parameters['R_1']['bounds'],
frozen = parameters['R_1']['frozen']),
]
)
def evaluate_with_dicts(self, param_dict):
b2.set_device('cpp_standalone')
# Simulate with parameter set
param_dict_units = glif_model.add_parameter_units(param_dict)
t, V, Th_s, I_0, I_1, = glif_model.run_brian_sim(
self.input_current * b2.amp,
self.dt * b2.second,
self.init_values,
param_dict_units)
#Evaluate fitness
fitness = {x: self.fitness[x](t, self.target_voltage, V) for x in self.fitness.keys()}
b2.device.delete(force = True)
b2.device.reinit()
return fitness
def evaluate_with_lists(self, param_list):
param_dict = glif_model.parameters_from_list(param_list)
fitness = self.evaluate_with_dicts(param_dict)
return np.array([fitness[x] for x in fitness.keys()])