forked from aludnam/MATLAB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gradloglikGaPExpWfix.m
59 lines (50 loc) · 2.12 KB
/
gradloglikGaPExpWfix.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
function gf=gradloglikGaPExp(x, varargin)
% f=loglikGaP(x, varargin)
% complete log likellihood of the GaP model
% Vxt = varargin{1}; %data
% sigpsf = varargin{2}; %std deviation of the PSF gaussian approx
% alpha = varargin{3}; %parameters of the Gamma prior on the blinking
% beta = varargin{4}; %parameters of the Gamma prior on the blinking
% peval = varargin{5}; %parameters
% x(1:end-2*peval.ncomp) is Hkt
Vxt = varargin{1}; %data
sigpsf = varargin{2}; %std deviation of the PSF gaussian approx
alpha = varargin{3}; %parameters of the Gamma prior on the blinking
beta = varargin{4}; %parameters of the Gamma prior on the blinking
peval = varargin{5}; %parameters
[Hkt_r, cx, cy, Wxk] = loglikGaPreadparamWfix(x,varargin);
Hkt=exp(Hkt_r); %nonnegativity constrains
[Wxkbg,Hktbg]=addbg(Wxk, Hkt, peval.bg);
P=Wxkbg*Hktbg; %current approximation
%linear grasdient shifted by cx
xxvc = lineargrad([peval.nx, peval.ny, peval.ncomp], cx, 'xx');
yyvc = lineargrad([peval.nx, peval.ny, peval.ncomp], cy, 'yy');
% dW/dcx:
Wxtcx=1/sigpsf^2*xxvc.*Wxk;
% dW/dcy:
Wxtcy=1/sigpsf^2*yyvc.*Wxk;
% d(log(L))/dHkt:
% gfHkt=(alpha-1)*1./Hkt - 1/beta*Hkt + Wxk'*(Vxt./P)-1;
% gfHkt= -(alpha-1)./Hkt - 1/beta;%Hkt.*(Wxk'*(Vxt./P)-1)-(alpha-1)./Hkt - 1/beta; %without background (->not Wxkgb) and d(log(L)/dcx)
gfHkt= Hkt.*(Wxk'*(Vxt./P)-1)-(alpha-1)./Hkt; %- 1/beta; %without background (->not Wxkgb) and d(log(L)/dcx)
% d(log(L))/dcx:
%gfcx=diag(Wxtcx'*(Vxt./P-ones(peval.nx*peval.ny, peval.nt))*Hkt');
% d(log(L))/dcy:
%gfcy=diag(Wxtcy'*(Vxt./P-ones(peval.nx*peval.ny, peval.nt))*Hkt');
gf = [reshape(gfHkt,1,peval.nt*peval.ncomp)];
% gf = [reshape(gfHkt,1,peval.nt*peval.ncomp)];
% gf = [gfcx', gfcy'];
gf=-gf; %conjugate gradient is minimizing!
end
function xxvc = lineargrad(sizevec, cx, dir)
switch dir
case 'xx'
xxp=double(xx(sizevec, 'corner')); %linear function - pixels
case 'yy'
xxp=double(yy(sizevec, 'corner')); %linear function - pixels
otherwise
error('Wrong dir')
end
xxv=reshape(xxp,sizevec(1)*sizevec(2),sizevec(3)); %linear function - vector
xxvc=xxv-repmat(cx,sizevec(1)*sizevec(2),1);
end