summaryrefslogtreecommitdiffstats
path: root/Wrappers/Matlab/studentst.m
diff options
context:
space:
mode:
authorEdoardo Pasca <edo.paskino@gmail.com>2017-11-10 14:03:37 +0000
committerEdoardo Pasca <edo.paskino@gmail.com>2018-01-19 14:26:06 +0000
commitd8da92d590fcab561b9e65ee57851e2e402f0cd4 (patch)
tree8ff25f41a7ea4a690235fe92f79c807615f0aef2 /Wrappers/Matlab/studentst.m
parent2b11ca3f30580b814971fcad39110e0751161acb (diff)
downloadregularization-d8da92d590fcab561b9e65ee57851e2e402f0cd4.tar.gz
regularization-d8da92d590fcab561b9e65ee57851e2e402f0cd4.tar.bz2
regularization-d8da92d590fcab561b9e65ee57851e2e402f0cd4.tar.xz
regularization-d8da92d590fcab561b9e65ee57851e2e402f0cd4.zip
code refactoring step1
Diffstat (limited to 'Wrappers/Matlab/studentst.m')
-rw-r--r--Wrappers/Matlab/studentst.m47
1 files changed, 47 insertions, 0 deletions
diff --git a/Wrappers/Matlab/studentst.m b/Wrappers/Matlab/studentst.m
new file mode 100644
index 0000000..99fed1e
--- /dev/null
+++ b/Wrappers/Matlab/studentst.m
@@ -0,0 +1,47 @@
+function [f,g,h,s,k] = studentst(r,k,s)
+% Students T penalty with 'auto-tuning'
+%
+% use:
+% [f,g,h,{k,{s}}] = studentst(r) - automatically fits s and k
+% [f,g,h,{k,{s}}] = studentst(r,k) - automatically fits s
+% [f,g,h,{k,{s}}] = studentst(r,k,s) - use given s and k
+%
+% input:
+% r - residual as column vector
+% s - scale (optional)
+% k - degrees of freedom (optional)
+%
+% output:
+% f - misfit (scalar)
+% g - gradient (column vector)
+% h - positive approximation of the Hessian (column vector, Hessian is a diagonal matrix)
+% s,k - scale and degrees of freedom
+%
+% Tristan van Leeuwen, 2012.
+% tleeuwen@eos.ubc.ca
+
+% fit both s and k
+if nargin == 1
+ opts = optimset('maxFunEvals',1e2);
+ tmp = fminsearch(@(x)st(r,x(1),x(2)),[1;2],opts);
+ s = tmp(1);
+ k = tmp(2);
+end
+
+
+if nargin == 2
+ opts = optimset('maxFunEvals',1e2);
+ tmp = fminsearch(@(x)st(r,x,k),[1],opts);
+ s = tmp(1);
+end
+
+% evaulate penalty
+[f,g,h] = st(r,s,k);
+
+
+function [f,g,h] = st(r,s,k)
+n = length(r);
+c = -n*(gammaln((k+1)/2) - gammaln(k/2) - .5*log(pi*s*k));
+f = c + .5*(k+1)*sum(log(1 + conj(r).*r/(s*k)));
+g = (k+1)*r./(s*k + conj(r).*r);
+h = (k+1)./(s*k + conj(r).*r);