-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_likelihood.m
32 lines (30 loc) · 1.69 KB
/
generate_likelihood.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
function [likelihood, out_r, TuningKernels] = generate_likelihood(LambdaVal, AmpVal, tiltPrefs, kappaVal, test_stim_index, tilts_rad, poiss)
%% Generate a likelihood function using von Mises tuning curves
% Inputs:
% LambdaVal: Scaling parameter that equates population gain and behavioral precision
% AmpVal: Max amplitude for the individual tuning curves
% tiltPrefs: A vector of the preferred tilt values for each neuron in radians
% kappaVal: Kappa value for the tuning curves (i.e., tuning curve width)
% test_stim_index: index of the stimulus tilt
% tilts_rad: tilts for building tuning curves
% poiss: simulate with poisson noise (or not)
tuning_fun = @(A,mu,x) A.*exp(-kappaVal)*exp(kappaVal*cos(x-mu)); % Inline Von mises function for generating tuning curves
for i = 1:length(tiltPrefs) % Define N tuning curves
temp_Tuning = tuning_fun(AmpVal, tiltPrefs(i), tilts_rad); %Generate tuning curve of the ith neuron
if poiss % Poisson noise?
unscaled_rMatrix(i,:) = poissrnd(round(temp_Tuning)); % Unscaled response vector
r_vec(i,:) = LambdaVal.*unscaled_rMatrix(i,:); % Response vector scaled by Lambda
else
unscaled_rMatrix(i,:) = temp_Tuning;
r_vec(i,:) = LambdaVal.*temp_Tuning;
end
TuningCurveStack(i,:) = temp_Tuning;
TuningKernels(i,:) = log(TuningCurveStack(i,:)); % Define kernels: log of the tuning curves
end
out_r = unscaled_rMatrix(:,test_stim_index);% Used for figures
if 0 == min(TuningCurveStack(:)) % Error check
'log of zero taken'
end
% p(r|s) ~ exp(hT(s) * r); the kernels h(s) are identical across input layers (for a given slant and distance), up to an additive constant
likelihood = exp(TuningKernels' * r_vec(:,test_stim_index));
end