-
Notifications
You must be signed in to change notification settings - Fork 8
/
get_params.m
281 lines (227 loc) · 7.53 KB
/
get_params.m
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
function params = get_params(base_params)
% GET_PARAMS Build and return a struct of parameters for PSC detection
% based on values set in this function.
% params = GET_PARAMS(base_params_path) returns a struct with fields
% defining the parameters for PSC detection. The input base_params_path
% should either be a struct called with a subset of the fields below
% or an emptry array. If it's the former the loaded struct's
% values will override any default parameters set below. Note that the
% loaded params struct does not need to contain all of the fields below.
% Only the ones that you want to override. If base_params_path is an
% empty array then only the defaults below are used.
% Please inspect the code/comments in this function for information on
% the different parameters.
% load a params struct from a file to start with
if ~isempty(base_params)
params = base_params;
% or create a new struct
else
params = struct();
end
% do we need to put the source into the path for MATLAB?
if ~isfield(params,'do_addpath')
params.do_addpath = 0; % generally we use this when we also are using the cluster
end
% if so, what is the source path?
if ~isfield(params,'source_path')
params.source_path = '/vega/stats/users/bms2156/psc-detection';
end
% use MATLAB's parfor across traces?
if ~isfield(params,'par')
params.par = 0;
end
% only run initialization algorithm (usually Wiener Filter)
if ~isfield(params,'init_only')
params.init_only = 0;
end
%% use an rng seed
% seed the rng?
if ~isfield(params,'rand')
params.rand = 1;
end
% pick a seed
if ~isfield(params,'seed')
params.seed = 12341;
end
%% data params
% time in seconds per sample
if ~isfield(params,'dt')
params.dt = 1/20000;
end
% direction/sign of events: upward is 1 (e.g. ipscs, ca imaging), downard is -1
% (e.g. epscs)
if ~isfield(params,'event_sign')
params.event_sign = -1;
end
%% inference params
% event amplitude bounds - a_min needs to be less than a_max, but a_min
% does not have to be greater than or equal to 0. That is,
% you can simultaneously detect upward and downward events.
if ~isfield(params,'a_max')
params.a_max = Inf;
end
if ~isfield(params,'a_min')
params.a_min = 5;
end
% baseline bounds - i.e. the holding current
if ~isfield(params,'b_min')
params.b_min = -200;
end
if ~isfield(params,'b_max')
params.b_max = 200;
end
% min and max for "rise time" in seconds
if ~isfield(params,'tau1_min')
params.tau1_min = 0.0002500;
end
if ~isfield(params,'tau1_max')
params.tau1_max = 1e-3;
end
% min and max for "decay time" in seconds
if ~isfield(params,'tau2_min')
params.tau2_min = .0025;
end
if ~isfield(params,'tau2_max')
params.tau2_max = .0075;
end
% how long to make kernel in samples
if ~isfield(params,'event_samples')
params.event_samples = 6*params.tau2_max/params.dt;
end
% poisson rate in events/sample
if ~isfield(params,'p_event')
params.p_event = 1e-6;
end
% ar noise model parameters
% p, the number of timesteps for filter
if ~isfield(params,'p')
params.p = 2; % how many time steps to regress on
end
% mean for MVN prior on phi - we find that the ar parameters are - to some extent -
% headstage dependent for voltage clamp recordings
if ~isfield(params,'phi_0')
params.phi_0 = [1.0, -0.30]';
end
% inverse covariance/precision matrix for MVN prior on phi
if ~isfield(params,'Phi_0')
params.Phi_0 = 10*eye(params.p); %inverse covariance
end
% prior parameters for inverse gamma on sigma_sq
if ~isfield(params,'nu_0')
params.nu_0 = 0;
end
if ~isfield(params,'sig2_0')
params.sig2_0 = .1;
end
% initial value for variance for white noise input to filter
if ~isfield(params,'noise_var_init')
params.noise_var_init = 3.5;
end
% it can be useful to estimate the noise from a small amount of data and
% then take it as known for further analysis within that recordings - or
% possibly even more generally across recordings. if the noise model is
% known, then enter it here.
if ~isfield(params, 'noise_known')
params.noise_known = 0;
if params.noise_known
params.phi_known = [1.000000000000000 1.0 -.30];
params.noise_var_known = 3.5;
end
end
% select an subset of each trace, in samples, e.g., 1:1000,
% to use for noise estimateion. this can be useful when there are sections
% of the trace with a high-rate of events due to some stimulus
if ~isfield(params,'noise_est_subset')
params.noise_est_subset = [];
end
%% sampling params
% how long to run the sampler
if ~isfield(params,'num_sweeps')
params.num_sweeps = 2000;
end
% nubmer of burn in sweeps to run
if ~isfield(params,'burn_in_sweeps')
params.burn_in_sweeps = 0;
end
% sampling event times proposal variance in seconds
if ~isfield(params,'time_proposal_var')
params.time_proposal_var = 7.5e-04;
end
% rise time proposal variance in seconds
if ~isfield(params,'tau1_prop_std')
params.tau1_prop_std = 2/20000;
end
% fall time proposal variance in seconds
if ~isfield(params,'tau2_prop_std')
params.tau2_prop_std = 20/20000;
end
% amplitude proposal variance in pA or trace units
if ~isfield(params,'amp_prop_std')
params.amp_prop_std = 3;
end
% baseline proposal variance in pA or trace units
if ~isfield(params,'baseline_prop_std')
params.baseline_prop_std = 2;
end
% for each parameter we run an inner loop and collect extra samples - this
% can help balance the amount of samples we run for different parameters.
% only the last sample for each parameter is kept such that there this is
% still only one sample per sweep
% number of add/drop subsweeps per sweep
if ~isfield(params,'add_drop_sweeps')
params.add_drop_sweeps = 10;
end
% number of event time subsweeps per sweep
if ~isfield(params,'time_sweeps')
params.event_time_sweeps = 5;
end
% number of amplitude subsweeps per sweep
if ~isfield(params,'amp_sweeps')
params.amp_sweeps = 5;
end
% number of baseline/holding current subsweeps per sweep
if ~isfield(params,'baseline_sweeps')
params.baseline_sweeps = 1;
end
% number of rise time subsweeps per sweep
if ~isfield(params,'tau1_sweeps')
params.tau1_sweeps = 1;
end
% number of fall time subsweeps per sweep
if ~isfield(params,'tau2_sweeps')
params.tau2_sweeps = 1;
end
% number of samples for window around new event time to guide amplitude
% initialization - essentially the max or min within that window
if ~isfield(params,'a_init_window')
params.a_init_window = 50;
end
% do not detect events within this many seconds of another event
if ~isfield(params,'exclusion_bound')
params.exclusion_bound = 10/20000;
end
%% initialization method - best choice is usually a wiener filter
if ~isfield(params,'init_method')
% ipsc template file
% params.init_method.template_file = 'data/ipsc-template.mat';
% ipsc
params.init_method.template_file = 'data/epsc-template.mat';
% noise parameters for Wiener Filter
params.init_method.ar_noise_params.sigma_sq = 3.0;
params.init_method.ar_noise_params.phi = [1.000000000000000, 1.0, -0.20];
% threshold output of filter
params.init_method.theshold = 2.0; % in std devs of filtered trace
params.init_method.min_interval = 20; % in samples
end
%% paths for data
if ~isfield(params,'traces_filename')
params.traces_filename = ...
['data/sample_data.mat'];
end
if ~isfield(params,'savepath')
params.savepath = '';
end
% use the four digit identifier to run different versions of inference on
% the same data. if the name is already taken, the algorithm will abort
params.savename = [params.traces_filename(1:end-4) '-0001.mat'];
params.full_save_string = [params.savename];