Hierarchical Gaussian Filter (HGF) model of conditioned hallucinations task (Powers et al 2017)

 Download zip file 
Help downloading and running models
Accession:229278
This is an instantiation of the Hierarchical Gaussian Filter (HGF) model for use with the Conditioned Hallucinations Task.
Reference:
1 . Powers AR, Mathys C, Corlett PR (2017) Pavlovian conditioning-induced hallucinations result from overweighting of perceptual priors. Science 357:596-600 [PubMed]
Model Information (Click on a link to find other models with that property)
Model Type:
Brain Region(s)/Organism:
Cell Type(s):
Channel(s):
Gap Junctions:
Receptor(s):
Gene(s):
Transmitter(s):
Simulation Environment: MATLAB;
Model Concept(s): Hallucinations;
Implementer(s): Powers, Al [albert.powers at yale.edu]; Mathys, Chris H ;
/
HGF
analysis
hgfToolBox_condhalluc1.4
README
COPYING *
example_binary_input.txt
example_categorical_input.mat
example_usdchf.txt
Manual.pdf
tapas_autocorr.m
tapas_bayes_optimal.m
tapas_bayes_optimal_binary.m
tapas_bayes_optimal_binary_config.m
tapas_bayes_optimal_binary_transp.m
tapas_bayes_optimal_categorical.m
tapas_bayes_optimal_categorical_config.m
tapas_bayes_optimal_categorical_transp.m
tapas_bayes_optimal_config.m
tapas_bayes_optimal_transp.m
tapas_bayes_optimal_whatworld.m
tapas_bayes_optimal_whatworld_config.m
tapas_bayes_optimal_whatworld_transp.m
tapas_bayes_optimal_whichworld.m
tapas_bayes_optimal_whichworld_config.m
tapas_bayes_optimal_whichworld_transp.m
tapas_bayesian_parameter_average.m
tapas_beta_obs.m
tapas_beta_obs_config.m
tapas_beta_obs_namep.m
tapas_beta_obs_sim.m
tapas_beta_obs_transp.m
tapas_boltzmann.m
tapas_cdfgaussian_obs.m
tapas_cdfgaussian_obs_config.m
tapas_cdfgaussian_obs_transp.m
tapas_condhalluc_obs.m
tapas_condhalluc_obs_config.m
tapas_condhalluc_obs_namep.m
tapas_condhalluc_obs_sim.m
tapas_condhalluc_obs_transp.m
tapas_condhalluc_obs2.m
tapas_condhalluc_obs2_config.m
tapas_condhalluc_obs2_namep.m
tapas_condhalluc_obs2_sim.m
tapas_condhalluc_obs2_transp.m
tapas_Cov2Corr.m
tapas_datagen_categorical.m
tapas_fit_plotCorr.m
tapas_fit_plotResidualDiagnostics.m
tapas_fitModel.m
tapas_gaussian_obs.m
tapas_gaussian_obs_config.m
tapas_gaussian_obs_namep.m
tapas_gaussian_obs_sim.m
tapas_gaussian_obs_transp.m
tapas_hgf.m
tapas_hgf_ar1.m
tapas_hgf_ar1_binary.m
tapas_hgf_ar1_binary_config.m
tapas_hgf_ar1_binary_namep.m
tapas_hgf_ar1_binary_plotTraj.m
tapas_hgf_ar1_binary_transp.m
tapas_hgf_ar1_config.m
tapas_hgf_ar1_mab.m
tapas_hgf_ar1_mab_config.m
tapas_hgf_ar1_mab_plotTraj.m
tapas_hgf_ar1_mab_transp.m
tapas_hgf_ar1_namep.m
tapas_hgf_ar1_plotTraj.m
tapas_hgf_ar1_transp.m
tapas_hgf_binary.m
tapas_hgf_binary_condhalluc_plotTraj.m
tapas_hgf_binary_config.m
tapas_hgf_binary_config_startpoints.m
tapas_hgf_binary_mab.m
tapas_hgf_binary_mab_config.m
tapas_hgf_binary_mab_plotTraj.m
tapas_hgf_binary_mab_transp.m
tapas_hgf_binary_namep.m
tapas_hgf_binary_plotTraj.m
tapas_hgf_binary_pu.m
tapas_hgf_binary_pu_config.m
tapas_hgf_binary_pu_namep.m
tapas_hgf_binary_pu_tbt.m
tapas_hgf_binary_pu_tbt_config.m
tapas_hgf_binary_pu_tbt_namep.m
tapas_hgf_binary_pu_tbt_transp.m
tapas_hgf_binary_pu_transp.m
tapas_hgf_binary_transp.m
tapas_hgf_categorical.m
tapas_hgf_categorical_config.m
tapas_hgf_categorical_namep.m
tapas_hgf_categorical_norm.m
tapas_hgf_categorical_norm_config.m
tapas_hgf_categorical_norm_transp.m
tapas_hgf_categorical_plotTraj.m
tapas_hgf_categorical_transp.m
tapas_hgf_config.m
tapas_hgf_demo.m
tapas_hgf_demo_commands.m
tapas_hgf_jget.m
tapas_hgf_jget_config.m
tapas_hgf_jget_plotTraj.m
tapas_hgf_jget_transp.m
tapas_hgf_namep.m
tapas_hgf_plotTraj.m
tapas_hgf_transp.m
tapas_hgf_whatworld.m
tapas_hgf_whatworld_config.m
tapas_hgf_whatworld_namep.m
tapas_hgf_whatworld_plotTraj.m
tapas_hgf_whatworld_transp.m
tapas_hgf_whichworld.m
tapas_hgf_whichworld_config.m
tapas_hgf_whichworld_namep.m
tapas_hgf_whichworld_plotTraj.m
tapas_hgf_whichworld_transp.m
tapas_hhmm.m
tapas_hhmm_binary_displayResults.m
tapas_hhmm_config.m
tapas_hhmm_transp.m
tapas_hmm.m
tapas_hmm_binary_displayResults.m
tapas_hmm_config.m
tapas_hmm_transp.m
tapas_kf.m
tapas_kf_config.m
tapas_kf_namep.m
tapas_kf_plotTraj.m
tapas_kf_transp.m
tapas_logit.m
tapas_logrt_linear_binary.m
tapas_logrt_linear_binary_config.m
tapas_logrt_linear_binary_minimal.m
tapas_logrt_linear_binary_minimal_config.m
tapas_logrt_linear_binary_minimal_transp.m
tapas_logrt_linear_binary_namep.m
tapas_logrt_linear_binary_sim.m
tapas_logrt_linear_binary_transp.m
tapas_logrt_linear_whatworld.m
tapas_logrt_linear_whatworld_config.m
tapas_logrt_linear_whatworld_transp.m
tapas_ph_binary.m
tapas_ph_binary_config.m
tapas_ph_binary_namep.m
tapas_ph_binary_plotTraj.m
tapas_ph_binary_transp.m
tapas_quasinewton_optim.m
tapas_quasinewton_optim_config.m
tapas_riddersdiff.m
tapas_riddersdiff2.m
tapas_riddersdiffcross.m
tapas_riddersgradient.m
tapas_riddershessian.m
tapas_rs_belief.m
tapas_rs_belief_config.m
tapas_rs_precision.m
tapas_rs_precision_config.m
tapas_rs_precision_whatworld.m
tapas_rs_precision_whatworld_config.m
tapas_rs_surprise.m
tapas_rs_surprise_config.m
tapas_rs_transp.m
tapas_rs_whatworld_transp.m
tapas_rw_binary.m
tapas_rw_binary_config.m
tapas_rw_binary_dual.m
tapas_rw_binary_dual_config.m
tapas_rw_binary_dual_plotTraj.m
tapas_rw_binary_dual_transp.m
tapas_rw_binary_namep.m
tapas_rw_binary_plotTraj.m
tapas_rw_binary_transp.m
tapas_sgm.m
tapas_simModel.m
tapas_softmax.m
tapas_softmax_2beta.m
tapas_softmax_2beta_config.m
tapas_softmax_2beta_transp.m
tapas_softmax_binary.m
tapas_softmax_binary_config.m
tapas_softmax_binary_namep.m
tapas_softmax_binary_sim.m
tapas_softmax_binary_transp.m
tapas_softmax_config.m
tapas_softmax_namep.m
tapas_softmax_sim.m
tapas_softmax_transp.m
tapas_squared_pe.m
tapas_squared_pe_config.m
tapas_squared_pe_transp.m
tapas_sutton_k1_binary.m
tapas_sutton_k1_binary_config.m
tapas_sutton_k1_binary_plotTraj.m
tapas_sutton_k1_binary_transp.m
tapas_unitsq_sgm.m
tapas_unitsq_sgm_config.m
tapas_unitsq_sgm_mu3.m
tapas_unitsq_sgm_mu3_config.m
tapas_unitsq_sgm_mu3_transp.m
tapas_unitsq_sgm_namep.m
tapas_unitsq_sgm_sim.m
tapas_unitsq_sgm_transp.m
                            
%% This script contains a tutorial demo for the HGF toolbox
% --------------------------------------------------------------------------------------------------
% Copyright (C) 2014 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/>.

fprintf('\nFirst, we will load the example binary inputs provided in the\nfile example_binary_input.txt:\n')
input('\n(press ENTER)')

fprintf('\n>> u = load(''example_binary_input.txt'');\n')
u = load('example_binary_input.txt');
input('\n(press ENTER)')

fprintf('\nNow, we will find the Bayes optimal perceptual parameters for\nthis dataset under the binary HGF model:\n')
input('\n(press ENTER)')

fprintf('\n>> bopars = tapas_fitModel([], u, ''tapas_hgf_binary_config'', ''tapas_bayes_optimal_binary_config'', ''tapas_quasinewton_optim_config'');\n')
bopars = tapas_fitModel([], u, 'tapas_hgf_binary_config', 'tapas_bayes_optimal_binary_config', 'tapas_quasinewton_optim_config');
input('(press ENTER)')

fprintf('\n\nYou can now use the optimal parameters as prior means\nby adapting tapas_hgf_binary_config.m. See the manual or the\ncomments in the file itself for details on how to do that.\n')
input('\n(press ENTER)')

fprintf('\n\nNext, we simulate a non-optimal agent''s responses:\n')
input('\n(press ENTER)')

fprintf('\n>> sim = tapas_simModel(u, ''tapas_hgf_binary'', [NaN 0 1 NaN 1 1 NaN 0 0 NaN 1 NaN -2.5 -6], ''tapas_unitsq_sgm'', 5);\n')
sim = tapas_simModel(u, 'tapas_hgf_binary', [NaN 0 1 NaN 1 1 NaN 0 0 NaN 1 NaN -2.5 -6], 'tapas_unitsq_sgm', 5);
input('\n(press ENTER)')

fprintf('\nWe visualize the simulated trajectory:\n')
input('\n(press ENTER)')

fprintf('\n>> tapas_hgf_binary_plotTraj(sim)\n')
tapas_hgf_binary_plotTraj(sim)
input('\n(press ENTER)')

fprintf('\nThe general meaning of the arguments to tapas_simModel is\nexplained in the manual and in the file tapas_simModel.m.\nThe specific meaning of each argument in this example is\nexplained in the configuration files of the perceptual model\n(tapas_hgf_binary_config.m) and of the response model\n(tapas_unitsq_sgm_config.m).\n')
input('\n(press ENTER)')

fprintf('\nNow, let''s try to recover these parameters by fitting the\ncorresponding models to the simulated data:\n')
input('\n(press ENTER)')

fprintf('\n>> est = tapas_fitModel(sim.y, sim.u, ''tapas_hgf_binary_config'', ''tapas_unitsq_sgm_config'', ''tapas_quasinewton_optim_config'');\n')
est = tapas_fitModel(sim.y, sim.u, 'tapas_hgf_binary_config', 'tapas_unitsq_sgm_config', 'tapas_quasinewton_optim_config');
input('(press ENTER)')


fprintf('\nTo check how well the parameters could be identified,\nwe''ll take a look at their posterior correlation:\n')
input('\n(press ENTER)')

fprintf('\n>> tapas_fit_plotCorr(est)\n')
tapas_fit_plotCorr(est)
input('\n(press ENTER)')

fprintf('\nYou can find the posterior correlation and covariance\nin the structure returned by the estimation:\n')
input('\n(press ENTER)')

fprintf('\n>> disp(est.optim.Corr)\n\n')
disp(est.optim.Corr)
input('\n(press ENTER)')

fprintf('\n>> disp(est.optim.Sigma)\n\n')
disp(est.optim.Sigma)
input('\n(press ENTER)')

fprintf('\nThe posterior means of the estimated as well as the\nfixed parameters can be found in est.p_prc for the\nperceptual model and in est.p_obs for the observation\nmodel:\n')
input('\n(press ENTER)')

fprintf('\n>> disp(est.p_prc)\n\n')
disp(est.p_prc)
input('\n(press ENTER)')

fprintf('\n>> disp(est.p_obs)\n\n')
disp(est.p_obs)
input('\n(press ENTER)')

fprintf('\nParameters are contained in these structures separately\nby name (e.g., om for omega) as well as jointly as a vector\np in their native space and as a vector ptrans in their\ntransformed space (i.e., the space they are estimated in).\nFor details, see the manual.\n')
input('\n(press ENTER)')

fprintf('\nNow, let''s visualize the inferred belief trajectories\nimplied by the estimated parameters:\n')
input('\n(press ENTER)')

fprintf('\n>> tapas_hgf_binary_plotTraj(est)\n')
tapas_hgf_binary_plotTraj(est)
input('\n(press ENTER)')

fprintf('\nThese trajectories can be found in est.traj:\n')
input('\n(press ENTER)')

fprintf('\n>> disp(est.traj)\n\n')
disp(est.traj)
input('\n(press ENTER)')

fprintf('\nNext, let''s try to fit the same data using a different\nperceptual model:\n')
input('\n(press ENTER)')

fprintf('\n>> est1a = tapas_fitModel(sim.y, sim.u, ''tapas_rw_binary_config'', ''tapas_unitsq_sgm_config'', ''tapas_quasinewton_optim_config'');\n')
est1a = tapas_fitModel(sim.y, sim.u, 'tapas_rw_binary_config', 'tapas_unitsq_sgm_config', 'tapas_quasinewton_optim_config');
input('(press ENTER)')

fprintf('\n>> tapas_fit_plotCorr(est1a)\n')
tapas_fit_plotCorr(est1a)
input('\n(press ENTER)')

fprintf('\n>> tapas_rw_binary_plotTraj(est1a)\n')
tapas_rw_binary_plotTraj(est1a)
input('\n(press ENTER)')

fprintf('\nThe same procedure can be applied to continuous data.\nThe file example_usdchf.txt contains the value of the\nUS dollar in Swiss francs throughout much of 2010 and 2011.\n')
input('\n(press ENTER)')

fprintf('\n>> usdchf = load(''example_usdchf.txt'');\n')
usdchf = load('example_usdchf.txt');
input('\n(press ENTER)')

fprintf('\n>> bopars2 = tapas_fitModel([], usdchf, ''tapas_hgf_config'', ''tapas_bayes_optimal_config'', ''tapas_quasinewton_optim_config'');\n')
bopars2 = tapas_fitModel([], usdchf, 'tapas_hgf_config', 'tapas_bayes_optimal_config', 'tapas_quasinewton_optim_config');
input('\n(press ENTER)')

fprintf('\n>> tapas_fit_plotCorr(bopars2)\n')
tapas_fit_plotCorr(bopars2)
input('\n(press ENTER)')

fprintf('\n>> tapas_hgf_plotTraj(bopars2)\n')
tapas_hgf_plotTraj(bopars2)
input('\n(press ENTER)')

fprintf('\n>> sim2 = tapas_simModel(usdchf, ''tapas_hgf'', [1.04 1 0.0001 0.1 0 0 1 -13  -2 1e4], ''tapas_gaussian_obs'', 0.00002);\n')
sim2 = tapas_simModel(usdchf, 'tapas_hgf', [1.04 1 0.0001 0.1 0 0 1 -13  -2 1e4], 'tapas_gaussian_obs', 0.00002);
input('\n(press ENTER)')

fprintf('\n>> tapas_hgf_plotTraj(sim2)\n')
tapas_hgf_plotTraj(sim2)
input('\n(press ENTER)')

fprintf('\nBefore proceeding to recover the parameters we''ve\nput into the simulation, let''s look at a simulation\nthat uses three levels:\n')
input('\n(press ENTER)')

fprintf('\n>> sim2a = tapas_simModel(usdchf, ''tapas_hgf'', [1.04 1 1 0.0001 0.1 0.1 0 0 0 1 1 -13  -2 -2 1e4], ''tapas_gaussian_obs'', 0.00005);\n')
sim2a = tapas_simModel(usdchf, 'tapas_hgf', [1.04 1 1 0.0001 0.1 0.1 0 0 0 1 1 -13  -2 -2 1e4], 'tapas_gaussian_obs', 0.00005);
input('\n(press ENTER)')

fprintf('\n>> tapas_hgf_plotTraj(sim2a)\n')
tapas_hgf_plotTraj(sim2a)
input('\n(press ENTER)')

fprintf('\nAs a rule of thumb, adding levels makes sense as long\nas the topmost trajectory is not flat. When estimating\nmodels, the log-model evidence can be used as a criterion\nfor whether adding levels leads to an improvement.\n')
input('\n(press ENTER)')

fprintf('\nNow, let''s again try to recover the parameters\nthat went into our simulation:\n')
input('\n(press ENTER)')

fprintf('\n>> est2 = tapas_fitModel(sim2.y, usdchf, ''tapas_hgf_config'', ''tapas_gaussian_obs_config'', ''tapas_quasinewton_optim_config'');\n')
est2 = tapas_fitModel(sim2.y, usdchf, 'tapas_hgf_config', 'tapas_gaussian_obs_config', 'tapas_quasinewton_optim_config');
input('\n(press ENTER)')

fprintf('\n>> tapas_fit_plotCorr(est2)\n')
tapas_fit_plotCorr(est2)
input('\n(press ENTER)')

fprintf('\n>> tapas_hgf_plotTraj(est2)\n')
tapas_hgf_plotTraj(est2)
input('\n(press ENTER)')

fprintf('\nIt is often useful to average parameters from several estimations, for\ninstance to compare groups of subjects. This can be achieved by using\nthe function tapas_bayesian_parameter_average(...) which takes into\naccount the covariance structure between the parameters and weights\nindividual estimates according to their precision:\n')

fprintf('\n>> sim2b = tapas_simModel(usdchf, ''tapas_hgf'', [1.04 1 0.0001 0.1 0 0 1 -15  -2.5 1e4], ''tapas_gaussian_obs'', 0.00002);\n')
sim2b = tapas_simModel(usdchf, 'tapas_hgf', [1.04 1 0.0001 0.1 0 0 1 -15 -2.5 1e4], 'tapas_gaussian_obs', 0.00002);
input('\n(press ENTER)')

fprintf('\n>> tapas_hgf_plotTraj(sim2b)\n')
tapas_hgf_plotTraj(sim2b)
input('\n(press ENTER)')

fprintf('\n>> est2b = tapas_fitModel(sim2b.y, usdchf, ''tapas_hgf_config'', ''tapas_gaussian_obs_config'', ''tapas_quasinewton_optim_config'');\n')
est2b = tapas_fitModel(sim2b.y, usdchf, 'tapas_hgf_config', 'tapas_gaussian_obs_config', 'tapas_quasinewton_optim_config');
input('\n(press ENTER)')

fprintf('\n>> tapas_fit_plotCorr(est2b)\n')
tapas_fit_plotCorr(est2b)
input('\n(press ENTER)')

fprintf('\n>> tapas_hgf_plotTraj(est2b)\n')
tapas_hgf_plotTraj(est2b)
input('\n(press ENTER)')

fprintf('\n>> bpa = tapas_bayesian_parameter_average(est2, est2b);\n')
bpa = tapas_bayesian_parameter_average(est2, est2b);
input('\n(press ENTER)')

fprintf('\n>> tapas_fit_plotCorr(bpa)\n')
tapas_fit_plotCorr(bpa)
input('\n(press ENTER)')

fprintf('\n>> tapas_hgf_plotTraj(bpa)\n')
tapas_hgf_plotTraj(bpa)
input('\n(press ENTER)')

fprintf('\nNote that Bayesian parameter averaging only works for estimates that\nare based on the same priors and should only be used with care for\nestimates based on different inputs.\n')

input('\nEnd of demo - press ENTER to finish')


Loading data, please wait...