-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathprior_sqinvlogunif.m
69 lines (60 loc) · 1.73 KB
/
prior_sqinvlogunif.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
function p = prior_sqinvlogunif(varargin)
%PRIOR_SQINVLOGUNIF Uniform prior structure for the log of the square inverse of parameter
%
% Description
% P = PRIOR_SQINVLOGUNIF creates uniform prior structure for the
% log of the square inverse of the parameter.
%
% See also
% PRIOR_*
%
% Copyright (c) 2009 Jarno Vanhatalo
% Copyright (c) 2010 Jaakko Riihimäki
% Copyright (c) 2010,2012 Aki Vehtari
% This software is distributed under the GNU General Public
% License (version 3 or later); please refer to the file
% License.txt, included with the software, for details.
ip=inputParser;
ip.FunctionName = 'PRIOR_SQINVLOGUNIFORM';
ip.addOptional('p', [], @(x) isstruct(x) || isempty(x));
ip.parse(varargin{:});
p=ip.Results.p;
if isempty(p)
init=true;
p.type = 'SqInv-Log-Uniform';
else
if ~isfield(p,'type') && ~isequal(p.type,'SqInv-Log-Uniform')
error('First argument does not seem to be a valid prior structure')
end
init=false;
end
if init
% set functions
p.fh.pak = @prior_sqinvlogunif_pak;
p.fh.unpak = @prior_sqinvlogunif_unpak;
p.fh.lp = @prior_sqinvlogunif_lp;
p.fh.lpg = @prior_sqinvlogunif_lpg;
p.fh.recappend = @prior_sqinvlogunif_recappend;
end
end
function [w, s, h] = prior_sqinvlogunif_pak(p)
w=[];
s={};
h=[];
end
function [p, w] = prior_sqinvlogunif_unpak(p, w)
w = w;
p = p;
end
function lp = prior_sqinvlogunif_lp(x, p)
lJ = log(2./x); % log(|J|) of transformation
lp = sum(lJ);
end
function lpg = prior_sqinvlogunif_lpg(x, p)
lJg = -1./x; % gradient of log(|J|) of transformation
lpg = lJg;
end
function rec = prior_sqinvlogunif_recappend(rec, ri, p)
% The parameters are not sampled in any case.
rec = rec;
end