-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathinvert_VBAtoolbox.m
48 lines (37 loc) · 1.62 KB
/
invert_VBAtoolbox.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
function [posterior, logEvidence] = invert_VBAtoolbox(data, prior)
% Bayesian logistic regression using the VBA toolbox (variational laplace)
% -------------------------------------------------------------------------
% This script is a minimal demo showing how to run the inference only given
% the specification of the model prediction, letting the toolbox do the all
% the work.
% -------------------------------------------------------------------------
%% =========================================================================
% Model definition
% =========================================================================
% Note that in the toolbox, parameters of static models are called "phi"
% mapping between input and response
function [gx] = g_logistic(~,param,input,~)
gx = VBA_sigmoid(param * input);
end
% number of parameters
dim.n_phi = 1;
% indicate we are fitting binary data
options.sources.type = 1;
%% =========================================================================
% Inference
% =========================================================================
% specify the prior
options.priors.muPhi = prior.mu;
options.priors.SigmaPhi = prior.sigma;
options.tolFun = 1e-4;
options.GNtolFun = 1e-4;
% call the inversion routine
[post, out] = VBA_NLStateSpaceModel (data.y, data.x, [], @g_logistic, dim, options);
%% =========================================================================
% Wrapping up
% =========================================================================
% rename for consitency with the other demos
posterior.mu = post.muPhi;
posterior.sigma = post.SigmaPhi;
logEvidence = out.F;
end