-
Notifications
You must be signed in to change notification settings - Fork 2
/
dogsummate.m
103 lines (93 loc) · 2.34 KB
/
dogsummate.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
function [y,f,space]=dogsummate(x,xdata,data,ROG,rectify)
% This generates a summation curve (y) using a DOG equation
% compatible with the optimisation toolbox.
%
% y=summate1(x,xdata)
%
% x= the set of parameters for the DOG model
%
% x(1) = centre amplitude
% x(2) = centre size
% x(3) = surround amplitude
% x(4) = surround size
% x(5) = DC level
% x(6) = Shift Parameter
% x(7) = Center offset
%
% xdata = the x-axis values of the summation curve to model
%
% it will output a tuning curve from the model parameters
if nargin < 2
xdata=0:0.5:9;
end
if nargin < 3
data=[];
end
if nargin < 4
ROG=0;
end
if nargin < 5
rectify = 0;
end
if length(x)==4
x(5)=0;
x(6)=0;
end
if length(x)==5
x(6)=0;
end
if length(x)==6
x(7)=0;
end
a=find(x==0);
x(a)=0.0000000000001;
for i=1:length(xdata)
if xdata(i)==0
sc(i)=x(5)+0;
else
%------------old code
%space=-xdata(i):xdata(i)/80:xdata(i); % generate the 'stimulus'
%f=(x(1)*exp(-space.^2/x(2)^2))-(x(3)*exp(-space.^2/x(4)^2)); % do the DOG!
%sc(i)=trapz(space,f)+x(5); % integrate area under the curve
%--------------------
%------------current code
% space=(-xdata(i)/2):(xdata(i)/2)/(80-1):(xdata(i)/2); % generate the 'stimulus'
% switch ROG
% case 0
% f=(x(1)*exp(-((2*space)/x(2)).^2))-(x(3)*exp(-((2*space)/x(4)).^2));
% case 1
% f=(x(1)*exp(-((2*space)/x(2)).^2))./(x(3)*exp(-((2*space)/x(4)).^2));
% end
%-------------------------
space=(-xdata(i)/2):(xdata(i)/2)/(80-1):(xdata(i)/2); % generate the 'stimulus'
space = space + x(7);
switch ROG
case 0
f=(x(1)*exp(-((2*space)/x(2)).^2))-(x(3)*exp(-((2*space)/x(4)).^2));
case 1
f=(x(1)*exp(-((2*space)/x(2)).^2))./(x(3)*exp(-((2*space)/x(4)).^2));
end
sc(i)=x(5)+trapz(space,f);
end
end
if x(6)>0.0000000000001 %this does the rectification for small diameter non-linearity
[m,i]=minim(xdata,x(6));
if m>0
sc(1:i)=x(5);
end
end
if rectify == 1
sc(sc<0) = 0;
end
if ~isempty(data)
y=sum((data-sc).^2); %percentage
else
y=sc;
end
if x(5)<0 %this is to stop the nlinfit, which has no upper or lower bounds to not select negative spontaneous levels.by making the fit really bad
if ~isempty(data)
y=y*1e6;
else
y=y/1e6;
end
end