Skip to content

Commit

Permalink
Merge branch 'development' into 'master'
Browse files Browse the repository at this point in the history
Development

See merge request !18
  • Loading branch information
tnutapas committed Aug 17, 2017
2 parents 6a6942c + 8bf866e commit d43b3ed
Show file tree
Hide file tree
Showing 52 changed files with 3,272 additions and 505 deletions.
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Changelog
TAPAS toolbox



## [2.7.3] 2017-08-17

## Added
- Added condhalluc_obs and condhalluc_obs2 models.

## Changed
- Introduced kappa1 in all binary HGF models.

## [2.7.2] 2017-08-17
## Added
- New PhysIO CHANGELOG.md specific file.

## Changed
- Specified in PhysIO/CHANGELOG.md.

## [2.7.1] 2017-08-17

### Added
- Added a CHANGELOG.md file

### Changed
- Now the README.txt file is in markdown format.
- The documentation is integrated with the wiki in github.
4 changes: 4 additions & 0 deletions HGF/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ hgf_demo.pdf.

## Release notes

### v5.1
- Added condhalluc_obs and condhalluc_obs2 models
- Introduced kappa1 in all binary HGF models

### v5.0
- Ported interactive demo to Matlab LiveScript
- Various additional small improvements
Expand Down
2 changes: 1 addition & 1 deletion HGF/hgf_demo.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
%%
sim = tapas_simModel(u,...
'tapas_hgf_binary',...
[NaN 0 1 NaN 1 1 NaN 0 0 NaN 1 NaN -2.5 -6],...
[NaN 0 1 NaN 1 1 NaN 0 0 1 1 NaN -2.5 -6],...
'tapas_unitsq_sgm',...
5);
%%
Expand Down
Binary file modified HGF/hgf_demo.mlx
Binary file not shown.
49 changes: 49 additions & 0 deletions HGF/tapas_condhalluc_obs.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
function [logp, yhat, res] = tapas_condhalluc_obs(r, infStates, ptrans)
% Calculates the log-probability of response y=1 under the unit-square sigmoid model
%
% --------------------------------------------------------------------------------------------------
% Copyright (C) 2015-2016 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/>.

% Transform beta to its native space
be = exp(ptrans(1));

% Initialize returned log-probabilities as NaNs so that NaN is
% returned for all irregualar trials
n = size(infStates,1);
logp = NaN(n,1);
yhat = NaN(n,1);
res = NaN(n,1);

% Check input format
if size(r.u,2) ~= 2
error('tapas:hgf:CondHalluc:InputsIncompatible', 'Inputs incompatible with condhalluc_obs observation model. See tapas_condhalluc_obs_config.m.')
end

% Get true-positive rate corresponding to stimuli
tp = r.u(:,2);

% Weed irregular trials out
mu1hat = infStates(:,1,1);
mu1hat(r.irr) = [];
y = r.y(:,1);
y(r.irr) = [];
tp(r.irr) = [];

% Calculate belief x using Bayes' theorem
x = tp.*mu1hat./(tp.*mu1hat + (1-mu1hat).^2);

% Belief is mu1hat in trials where there is no tone
x(find(tp==0)) = mu1hat(find(tp==0));

% Calculate log-probabilities for non-irregular trials
reg = ~ismember(1:n,r.irr);
logp(reg) = -log(1+exp(-be.*(2.*x-1).*(2.*y-1)));
yhat(reg) = x;
res(reg) = (y-x)./sqrt(x.*(1-x));

return;
48 changes: 48 additions & 0 deletions HGF/tapas_condhalluc_obs2.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
function [logp, yhat, res] = tapas_condhalluc_obs2(r, infStates, ptrans)
% Calculates the log-probability of response y=1 under the unit-square sigmoid model
%
% --------------------------------------------------------------------------------------------------
% Copyright (C) 2016 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/>.

% Transform alpha and beta to their native spaces
be = exp(ptrans(1));
nu = exp(ptrans(2));

% Initialize returned log-probabilities as NaNs so that NaN is
% returned for all irregualar trials
n = size(infStates,1);
logp = NaN(n,1);
yhat = NaN(n,1);
res = NaN(n,1);

% Check input format
if size(r.u,2) ~= 2
error('tapas:hgf:CondHalluc:InputsIncompatible', 'Inputs incompatible with condhalluc_obs observation model. See tapas_condhalluc_obs_config.m.')
end

% Get true-positive rate corresponding to stimuli
tp = r.u(:,2);

% Weed irregular trials out
mu1hat = infStates(:,1,1);
mu1hat(r.irr) = [];
y = r.y(:,1);
y(r.irr) = [];
tp(r.irr) = [];

% Update belief using precision-weighted prediction error
% with nu the generalized precision
x = mu1hat + 1/(1 + nu)*(tp - mu1hat);

% Calculate log-probabilities for non-irregular trials
reg = ~ismember(1:n,r.irr);
logp(reg) = -log(1+exp(-be.*(2.*x-1).*(2.*y-1)));
yhat(reg) = x;
res(reg) = (y-x)./sqrt(x.*(1-x));

return;
55 changes: 55 additions & 0 deletions HGF/tapas_condhalluc_obs2_config.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
function c = tapas_condhalluc_obs2_config
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Contains the configuration for the response model used to analyze data from conditioned
% hallucination paradigm by Powers & Corlett
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% The rationale for this model is as follows:
%
% TO BE DESCRIBED...
%
% --------------------------------------------------------------------------------------------------
% Copyright (C) 2016 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/>.

% Config structure
c = struct;

% Model name
c.model = 'tapas_condhalluc_obs2';

% Sufficient statistics of Gaussian parameter priors

% Beta
c.logbemu = log(48);
c.logbesa = 1;

% Nu
c.lognumu = log(1);
c.lognusa = 1;

% Gather prior settings in vectors
c.priormus = [
c.logbemu,...
c.lognumu,...
];

c.priorsas = [
c.logbesa,...
c.lognusa,...
];

% Model filehandle
c.obs_fun = @tapas_condhalluc_obs2;

% Handle to function that transforms observation parameters to their native space
% from the space they are estimated in
c.transp_obs_fun = @tapas_condhalluc_obs2_transp;

return;
15 changes: 15 additions & 0 deletions HGF/tapas_condhalluc_obs2_namep.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function pstruct = tapas_condhalluc_obs2_namep(pvec)
% --------------------------------------------------------------------------------------------------
% Copyright (C) 2016 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/>.

pstruct = struct;

pstruct.be = pvec(1);
pstruct.nu = pvec(2);

return;
35 changes: 35 additions & 0 deletions HGF/tapas_condhalluc_obs2_sim.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
function y = tapas_condhalluc_obs2_sim(r, infStates, p)
% Simulates responses according to the condhalluc_obs model
%
% --------------------------------------------------------------------------------------------------
% Copyright (C) 2016 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/>.

% Get parameters
be = p(1);
nu = p(2);

% Prediction trajectory
mu1hat = infStates(:,1,1);

% Get true-positive rate corresponding to stimuli
tp = r.u(:,2);

% Update belief using precision-weighted prediction error
% with nu the generalized precision
x = mu1hat + 1/(1 + nu)*(tp - mu1hat);

% Apply the logistic sigmoid to the inferred beliefs
prob = tapas_sgm(be.*(2.*x-1),1);

% Initialize random number generator
rng('shuffle');

% Simulate
y = binornd(1, prob);

return;
19 changes: 19 additions & 0 deletions HGF/tapas_condhalluc_obs2_transp.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function [pvec, pstruct] = tapas_condhalluc_obs2_transp(r, ptrans)
% --------------------------------------------------------------------------------------------------
% Copyright (C) 2016 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/>.

pvec = NaN(1,length(ptrans));
pstruct = struct;

pvec(1) = exp(ptrans(1)); % be
pstruct.be = pvec(1);

pvec(2) = exp(ptrans(2)); % nu
pstruct.nu = pvec(2);

return;
94 changes: 94 additions & 0 deletions HGF/tapas_condhalluc_obs_config.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
function c = tapas_condhalluc_obs_config
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Contains the configuration for the response model used to analyze data from conditioned
% hallucination paradigm by Powers & Corlett
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% The rationale for this model is as follows:
%
% We apply decision noise (i.e., a logistic sigmoid, see below) to the probability that the subject
% says “yes” on a given trial:
%
% p( yes | belief ) = sigmoid( belief ),
%
% where belief = p( tone | percept, light ),
%
% and where in turn “percept” is the subjective experience of hearing (or not hearing) a tone, while
% “tone” is the objective presentation of a tone, and “light” is the presentation of a light.
%
% In trial where there is a tone, we may use Bayes’ theorem to get the belief:
%
% belief = p( tone | percept, light ) = p( percept | tone )*p( tone | light ) / (p( percept |
% tone )*p( tone | light ) + p( percept | no tone )*p( no tone | light ))
%
% Unpacking the various ingredients, we have
%
% - p( percept | tone ) is given by experimental design: the true positive rate of the tone
% presented without light at each trial - 1/4, 1/2, or 3/4
%
% - p( tone | light ) is the prior from learning using the HGF: mu1hat
%
% - p( percept | no tone ) is the false positive rate, which we can take to be 1 - mu1hat
%
% - p( no tone | light ) is the other half of the prior: 1 - mu1hat
%
% In trials where there is no tone, the belief is mu1hat.
%
% The logistic sigmoid is
%
% f(x) = 1/(1+exp(-beta*(v1-v0))),
%
% where v1 and v0 are the values of options 1 and 0, respectively, and beta > 0 is a parameter that
% determines the slope of the sigmoid. Beta is sometimes referred to as the (inverse) decision
% temperature. In the formulation above, it represents the probability of choosing option 1.
% Reversing the roles of v1 and v0 yields the probability of choosing option 0.
%
% Beta can be interpreted as inverse decision noise. To have a shrinkage prior on this, choose a
% high value. It is estimated log-space since it has a natural lower bound at zero. In general, v1
% and v0 can be any real numbers.
%
% This observation model expects the first column of the input matrix to contain the outcomes
% (corresponding in this case to the choices of the subject): 1 or 0 for each trial. The SECOND
% COLUMN of the input matrix is expected to contain the true-positive rate of the stimulus for
% each trial. The response matrix only contains one column consisting of the choices of the
% subject. This means that it will be identical to the first column of the input matrix.
%
% --------------------------------------------------------------------------------------------------
% 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/>.

% Config structure
c = struct;

% Model name
c.model = 'tapas_condhalluc_obs';

% Sufficient statistics of Gaussian parameter priors

% Beta
c.logbemu = log(48);
c.logbesa = 1;

% Gather prior settings in vectors
c.priormus = [
c.logbemu,...
];

c.priorsas = [
c.logbesa,...
];

% Model filehandle
c.obs_fun = @tapas_condhalluc_obs;

% Handle to function that transforms observation parameters to their native space
% from the space they are estimated in
c.transp_obs_fun = @tapas_condhalluc_obs_transp;

return;
14 changes: 14 additions & 0 deletions HGF/tapas_condhalluc_obs_namep.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function pstruct = tapas_condhalluc_obs_namep(pvec)
% --------------------------------------------------------------------------------------------------
% Copyright (C) 2016 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/>.

pstruct = struct;

pstruct.be = pvec(1);

return;
Loading

0 comments on commit d43b3ed

Please sign in to comment.