Skip to content

Commit

Permalink
Make agc_weights work better across sample rate and n_fiber changes
Browse files Browse the repository at this point in the history
The agc_weights needed to be appropriately set up to do the right thing with different sample rates, and to allow different numbers of IHCs per channel.  The AGC feedback is still proportional to the number of fibers, healthy or not, so the agc_weights parameters might need adjustment if the healthy_n_fibers is changed.  The param n_fibers was renamed healthy_n_fibers, as that's what applied at design time, and as the n_fibers in the coeffs may change with model training (in the JAX version at least).
  • Loading branch information
dicklyon committed Sep 24, 2024
1 parent b79778a commit 0181d1e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
17 changes: 11 additions & 6 deletions matlab/CARFAC_Design.m
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,22 @@

if num_args < 6 % Default the SYN_params.
n_classes = 3; % Default. Modify params and redesign to change.
IHCs_per_channel = 10; % Maybe 20 would be better?
% Parameters could generally have columns if class-dependent.
CF_SYN_params = struct( ...
'do_syn', do_syn, ... % This may just turn it off completely.
'fs', fs, ...
'n_classes', n_classes, ...
'n_fibers', [50, 35, 25], ...
'healthy_n_fibers', [50, 35, 25] * IHCs_per_channel, ...
'spont_rates', [50, 6, 1], ...
'sat_rates', 200, ...
'sat_reservoir', 0.2, ...
'v_width', 0.02, ...
'tau_lpf', 0.000080, ...
'reservoir_tau', 0.020, ...
'agc_weights', [1.2, 1.2, 1.2]'); % column
'agc_weights', [1.2, 1.2, 1.2] / (22050*IHCs_per_channel)); % Tweaked.
% The weights 1.2 were picked before correctly account for sample rate
% and number of fibers. This way works for more different numbers.
end

% first figure out how many filter stages (PZFC/CARFAC channels):
Expand Down Expand Up @@ -619,19 +622,21 @@

spont_p = a2 .* w0 .* s0; % should match p0; check it; yes it does.

agc_weights = fs * SYN_params.agc_weights;
spont_sub = (SYN_params.healthy_n_fibers .* spont_p) * agc_weights';

% Copy stuff needed at run time into coeffs.
SYN_coeffs = struct( ...
'n_ch', n_ch, ...
'n_classes', n_classes, ...
'n_fibers', ones(n_ch,1) * SYN_params.n_fibers, ... % Synaptopathy comes in here.
'n_fibers', ones(n_ch,1) * SYN_params.healthy_n_fibers, ...
'v_widths', v_widths, ...
'v_halfs', offsets .* v_widths, ... % Same units as v_recep and v_widths.
'a1', a1, ... % Feedback gain
'a2', a2, ... % Output gain
'agc_weights', SYN_params.agc_weights, ... % For making a nap out to agc in.
'agc_weights', agc_weights, ... % For making a nap out to agc in.
'spont_p', spont_p, ... % used only to init the output LPF
'spont_sub', (SYN_params.n_fibers .* spont_p) * SYN_params.agc_weights, ...
'spont_sub', spont_sub, ...
'res_lpf_inits', q0, ...
'res_coeff', 1 - exp(-1/(SYN_params.reservoir_tau * fs)), ...
'lpf_coeff', 1 - exp(-1/(SYN_params.tau_lpf * fs)));

6 changes: 3 additions & 3 deletions matlab/CARFAC_SYN_Step.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
% associated with the CF channel, including reductions due to synaptopathy.

% Normalized offset position into neurotransmitter release sigmoid.
x = (v_recep - coeffs.v_halfs) ./ coeffs.v_widths ;
x = (v_recep - coeffs.v_halfs) ./ coeffs.v_widths;

s = 1 ./ (1 + exp(-x)); % Between 0 and 1; positive at rest.
q = state.reservoirs; % aka 1 - w, between 0 and 1; positive at rest.
Expand All @@ -27,5 +27,5 @@
% But it's relative to the healthy nominal spont, so could potentially go
% a bit negative in quiet is there was loss of high-spont or medium-spont units.
% The weight multiplication is an inner product, reducing n_classes
% columns to 1 column.
syn_out = (coeffs.n_fibers .* firing_probs) * coeffs.agc_weights - coeffs.spont_sub;
% columns to 1 column (first transpose the agc_weights row to a column).
syn_out = (coeffs.n_fibers .* firing_probs) * coeffs.agc_weights' - coeffs.spont_sub;
24 changes: 12 additions & 12 deletions matlab/CARFAC_Test.m
Original file line number Diff line number Diff line change
Expand Up @@ -336,21 +336,21 @@
switch test_freqs(k)
case 300
expected_results = [ ...
[0.582030, 101.529701];
[1.879711, 266.366280];
[3.399757, 461.743150];
[3.911907, 527.148854];
[3.915707, 511.042054];
[3.926793, 493.685648];
[1.055837, 184.180863];
[3.409906, 483.204136];
[6.167359, 837.629296];
[7.096430, 956.279101];
[7.103324, 927.060415];
[7.123434, 895.574871];
];
case 3000
expected_results = [ ...
[0.092435, 13.742136];
[0.342293, 40.817636];
[1.044103, 96.671170];
[1.952015, 148.463834];
[2.701081, 167.405953];
[3.071866, 153.483845];
[0.167683, 24.929044];
[0.620939, 74.045598];
[1.894064, 175.367201];
[3.541070, 269.322147];
[4.899921, 303.684269];
[5.572545, 278.428744];
];
otherwise
fprintf(1, 'No test_results for %f Hz in test_IHC.\n', ...
Expand Down

0 comments on commit 0181d1e

Please sign in to comment.