-
Notifications
You must be signed in to change notification settings - Fork 0
/
tapas_beta_obs_sim.m
49 lines (42 loc) · 1.36 KB
/
tapas_beta_obs_sim.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
function y = tapas_beta_obs_sim(r, infStates, p)
% Simulates observations from a Bernoulli distribution
%
% --------------------------------------------------------------------------------------------------
% Copyright (C) 2015 Christoph Mathys, TNU, UZH & ETHZ
%
% This file is part of the HGF toolbox, which is released under the terms of the GNU General Public
% Licence (GPL), version 3. You can redistribute it and/or modify it under the terms of the GPL
% (either version 3 or, at your option, any later version). For further details, see the file
% COPYING or <http://www.gnu.org/licenses/>.
% Inferred states
if strcmp(r.c_prc.model,'tapas_rw_binary')
mu = infStates(:,1,1); % Default: predictions (ie, mu1hat)
else
mu = infStates(:,1,1); % Default: predictions (ie, mu1hat)
if r.c_obs.predorpost == 2
mu = tapas_sgm(infStates(:,2,3), 1); % Alternative: posteriors (ie, sgm(mu2))
end
end
if strcmp(r.c_prc.model,'hgf_whichworld')
mu = tapas_sgm(infStates(:,2,1,3), 1);
end
if strcmp(r.c_prc.model,'ph_binary')
mu = infStates(:,2);
end
% Parameter nu-prime
nupr = p;
% Nu is nu-prime plus two (sometimes)
%nu = nupr+2;
nu = nupr;
% Calculate alpha and beta from mu and nu
al = mu.*nu;
be = nu - al;
% Initialize random number generator
if isnan(r.c_sim.seed)
rng('shuffle');
else
rng(r.c_sim.seed);
end
% Simulate
y = betarnd(al, be);
return;