-
Notifications
You must be signed in to change notification settings - Fork 6
/
obj_fun_v.m
38 lines (33 loc) · 1.41 KB
/
obj_fun_v.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
function [E, g, loga_hat, loga_error] = obj_fun_v(X,loga,m,p)
sz = size(loga,2);
v = reshape(X,m.K,sz);
[loga_error, loga_hat] = calc_loga_error(loga,v,m,p);
% Compute Energy Terms
loga_noise_cost = .5*p.ampmodel.loga_noise_factor*sum(loga_error(:).^2);
switch p.ampmodel.prior
case 'laplace'
v_cost = sum(S_laplace(v(:),p.ampmodel.v_laplace_beta));
case 'cauchy'
v_cost = sum(S_cauchy(v(:),p.ampmodel.v_cauchy_beta,p.ampmodel.v_cauchy_sigma));
case 'slow_laplace'
v_cost = sum(S_laplace(v(:),p.ampmodel.v_laplace_beta)) + .5*p.ampmodel.v_lambda_S*sum(sum(Slow(v)));
case 'slow_cauchy'
v_cost = sum(S_cauchy(v(:),p.ampmodel.v_cauchy_beta,p.ampmodel.v_cauchy_sigma)) + .5*p.ampmodel.v_lambda_S*sum(sum(Slow(v)));
end
E= loga_noise_cost + v_cost;
E = double(E);
if nargout>1
dv = - p.ampmodel.loga_noise_factor*(m.B'*loga_error);
switch p.ampmodel.prior
case 'laplace'
dv = dv + dS_laplace(v,p.ampmodel.v_laplace_beta);
case 'cauchy'
dv = dv + dS_cauchy(v,p.ampmodel.v_cauchy_beta,p.ampmodel.v_cauchy_sigma);
case 'slow_laplace'
dv = dv + dS_laplace(v,p.ampmodel.v_laplace_beta) + p.ampmodel.v_lambda_S*Slowp(v);
case 'slow_cauchy'
dv = dv + dS_cauchy(v,p.ampmodel.v_cauchy_beta,p.ampmodel.v_cauchy_sigma) + p.ampmodel.v_lambda_S*Slowp(v);
end
%dw(:,1) = 0;
g = reshape(dv,numel(dv),1);
end