Skip to content

Commit f6095a5

Browse files
author
Frankie Patten-Elliott
committed
Changes for flexible no. of sweeps
1 parent ecc66de commit f6095a5

File tree

5 files changed

+16
-13
lines changed

5 files changed

+16
-13
lines changed

methods/classes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ def __init__(self, model, protocol, times, win, conc, param_dict):
5353
if model.split("-")[0] == 'sis':
5454
self.n_pulses = 10
5555
elif times[-1] > 15e3:
56-
self.n_pulses = 5
56+
#self.n_pulses = 5
57+
self.n_pulses = int(np.floor(250000/times[-1]))
5758
else:
5859
self.n_pulses = sweeps
5960
self._times = times

methods/funcs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def generate_data(herg_model, drug_vals, prot, sd, max_time, bounds, m_sel, conc
1313
herg_vals = []
1414

1515
if max_time != 15e3 and herg_model != '2024_Joey_sis_25C':
16-
swps = 5
16+
swps = int(np.floor(250000/max_time))
1717
else:
1818
swps = sweeps
1919

@@ -147,7 +147,7 @@ def model_outputs(model_pars, herg_model, prot, times, concs, alt_protocol = Non
147147
elif herg_model == 'kemp':
148148
herg_vals = []
149149
model_out = {}
150-
swps = 5 #when generating optimal protocol, we use 5 sweeps
150+
swps = int(np.floor(250000/(times[-1]+alt_times[-1])))
151151
win = (times >= wins[0]) & (times < wins[1])
152152
if alt_protocol is not None:
153153
win_alt = (alt_times >= wins_alt[0]) & (alt_times < wins_alt[1])
@@ -180,7 +180,7 @@ def model_outputs(model_pars, herg_model, prot, times, concs, alt_protocol = Non
180180
after = model.simulate(binding_params, times)[win]
181181
model_milnes = np.append(model_milnes, after/before)
182182
control = np.append(control, before)
183-
for i in range(swps-1):
183+
for i in range(swps*2-1):
184184
if (alt_protocol is not None) & ((i % 2) == 0):
185185
model.change_protocol(alt_protocol)
186186
after = model.simulate(binding_params, alt_times, reset=False)[win_alt]
@@ -196,4 +196,4 @@ def model_outputs(model_pars, herg_model, prot, times, concs, alt_protocol = Non
196196
except:
197197
model_out[m][conc] = np.ones(times.shape) * float('inf')
198198
save_control = np.ones(times.shape) * float('inf')
199-
return model_out, save_control
199+
return model_out, save_control, swps

src/fit_spline.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
parser.add_argument('-l', type=float, default=5, help='Smoothing parameter lambda')
1717
parser.add_argument('-s', type=str, default="[10000]", help="List of integers for the length of each voltage step e.g. '[1,2,3,4,5]'")
1818
parser.add_argument('-m', type=str, default='milnes', help='Milnes, opt, or real')
19+
parser.add_argument('-t', type=float, default=15e3, help='Max time')
1920
args = parser.parse_args()
2021

21-
def main(input, output, lambda_, t_steps, data):
22+
def main(input, output, lambda_, t_steps, data, max_t):
2223
df_all = pd.read_csv(f"{input}/synth_Y.csv")
2324
# Parameters
2425
if data == 'milnes':
@@ -28,7 +29,7 @@ def main(input, output, lambda_, t_steps, data):
2829
j = 0
2930
t_swp = t_steps[j]
3031
t_total = 0
31-
swps = sweeps*3
32+
swps = int(np.floor(250000/max_t))*6
3233
else:
3334
lens = [3340, 3330, 3340, 3330, 3330]
3435
t_total = 0
@@ -78,4 +79,4 @@ def main(input, output, lambda_, t_steps, data):
7879

7980
if __name__ == "__main__":
8081
t_steps = ast.literal_eval(args.s)
81-
main(args.i, args.o, float(args.l), t_steps, args.m)
82+
main(args.i, args.o, float(args.l), t_steps, args.m, args.t)

src/optimise_protocol.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ def __call__(self, p):
4141
self.v_st, self.t_st = funcs.get_steps(v_steps, t_steps, self.pars)
4242
prot = funcs.create_protocol(self.v_st, self.t_st)
4343
if alt_protocol is not None:
44-
model_out, cont = funcs.model_outputs(model_pars, herg, prot, times = np.arange(0, np.sum(self.t_st), 10), concs = concs,
44+
model_out, cont, swps = funcs.model_outputs(model_pars, herg, prot, times = np.arange(0, np.sum(self.t_st), 10), concs = concs,
4545
alt_protocol = prot_alt, alt_times = np.arange(0, np.sum(self.t_st_alt), 10), wins = [1e3, np.sum(self.t_st[1:4])],
4646
wins_alt = [1e3, np.sum(self.t_st_alt[1:4])])
4747
else:
48-
model_out, cont = funcs.model_outputs(model_pars, herg, prot, times = np.arange(0, np.sum(self.t_st), 10), concs = concs, wins = [1e3, np.sum(self.t_st[1:4])])
48+
model_out, cont, swps = funcs.model_outputs(model_pars, herg, prot, times = np.arange(0, np.sum(self.t_st), 10), concs = concs, wins = [1e3, np.sum(self.t_st[1:4])])
4949
### loop through models and concentrations to get traces
5050
all_traces = []
5151
for m in model_out:
@@ -66,6 +66,7 @@ def __call__(self, p):
6666
lhoods.append(-2*np.sum(np.log(top/bottom)))
6767
#out = -np.median(ssq)
6868
out = np.median(lhoods)
69+
print(swps)
6970
return out
7071

7172
def n_parameters(self):
@@ -126,7 +127,7 @@ def n_parameters(self):
126127

127128
opt.optimiser().set_population_size(CMAES_pop)
128129
opt.set_max_iterations(max_iter)
129-
opt.set_max_unchanged_iterations(iterations=100, threshold=1e-2)
130+
opt.set_max_unchanged_iterations(iterations=50, threshold=1)
130131
opt.set_parallel(-1)
131132

132133
try:
@@ -165,7 +166,7 @@ def main(model_nums, max_time, bounds, herg, output_folder):
165166
drug_fit_pars[m] = parlist
166167

167168
# perform optimisation
168-
p_out, cost = get_opt_prot(drug_fit_pars, herg, v_steps, t_steps, p0_1, CMAES_pop = 7, max_iter = 750, alt_protocol = p0_2)
169+
p_out, cost = get_opt_prot(drug_fit_pars, herg, v_steps, t_steps, p0_1, CMAES_pop = 7, max_iter = 500, alt_protocol = p0_2)
169170
print(f'Final objective cost: {cost}')
170171
print(f'Final optimised params: {p_out}')
171172

src/post_fit_plot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def main(model_nums, prot, max_time, bounds, herg, output_folder):
3535
if max_time == 15e3 and herg != '2024_Joey_sis_25C':
3636
swps = sweeps
3737
elif herg != '2024_Joey_sis_25C':
38-
swps = 5
38+
swps = int(np.floor(250000/max_time))
3939
else:
4040
swps = 10
4141

0 commit comments

Comments
 (0)