Skip to content

Commit

Permalink
Merge pull request translationalneuromodeling#155 from translationaln…
Browse files Browse the repository at this point in the history
…euromodeling/development

Release v5.1.2
  • Loading branch information
inezpereira authored Sep 2, 2021
2 parents dd3378f + 78a0193 commit feab34f
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 11 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Changelog
TAPAS toolbox

## [5.1.1] 2021-06-22
## [5.1.2] 2021-09-06

### Fixed
- TOOLS: Fixed a bug in the computation of WAIC (function [tapas_waic.m](tools/tapas_waic.m)). Added new function to compute log-exp_sum (function [tapas_logsumexp.m](tools/tapas_logsumexp.m)).

## [5.1.1] 2021-06-22

### Fixed
- Added references to TAPAS paper (in collection and toolboxes)
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![TAPAS Logo](misc/TapasLogo.png?raw=true "TAPAS Logo")

*Version 5.1.1*
*Version 5.1.2*

T A P A S - Translational Algorithms for Psychiatry-Advancing Science.
========================================================================
Expand All @@ -15,9 +15,10 @@ DESCRIPTION
-----------

TAPAS is a collection of algorithms and software tools developed by the
Translational Neuromodeling Unit (TNU, Zurich) and collaborators. The goal of
these tools is to support clinical neuromodeling, particularly computational
psychiatry, computational neurology, and computational psychosomatics.
Translational Neuromodeling Unit (TNU, Zurich) and collaborators. These
tools are intended to support the development of computational assays
(Translational Neuromodeling) and their clinical application in
Computational Psychiatry, Neurology and Psychosomatics.

Currently, TAPAS includes the following packages:

Expand Down
1 change: 1 addition & 0 deletions misc/log_tapas.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
5.1.2 https://www.tapas.tnu-zurich.com/examples_v5.0.0.zip 24c1248d3054f025b853b5ab7ce08a1a
5.1.1 https://www.tapas.tnu-zurich.com/examples_v5.0.0.zip 24c1248d3054f025b853b5ab7ce08a1a
5.1.0 https://www.tapas.tnu-zurich.com/examples_v5.0.0.zip 24c1248d3054f025b853b5ab7ce08a1a
5.0.0 https://www.tapas.tnu-zurich.com/examples_v5.0.0.zip 24c1248d3054f025b853b5ab7ce08a1a
Expand Down
42 changes: 42 additions & 0 deletions tools/tapas_logsumexp.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
function [y_sum,y_mean] = tapas_logsumexp(x)


%% -------------------------------------------------------------------------------------------
% [y_sum,y_mean] = tapas_logsumexp(x) takes the values in x, exponates
% them, then takes the sum over the column, and finally applies the natural logarithm.
% The calculation uses the "log-sum-exp" trick: See e.g. http://gregorygundersen.com/blog/2020/02/09/log-sum-exp/
% The function also returns the log-mean-exp.
%---------------------------------------------------------------------------------------------
% INPUT:
% x - A column vector or matrix of values. All computations are
% made along the direction of a column.
%
% Optional:
%
%--------------------------------------------------------------------------------------------
% OUTPUT:
% y_sum - The log-sum-exp of all columns of x.
% y_mean - The log-mean-exp of all columns of x.
%
% Author: Jakob Heinzle, TNU, UZH & ETHZ - April, 2021
%
% REVISION LOG:
%
% Jakob Heinzle, 2021/04/16: new function
%
%%

sz = size(x);

if numel(sz)~=2
error('Input x needs to be a matrix of 2 dimensions');
end

max_x = max(x); %compute maximum of each column
y_sum = max_x + log(sum(exp(x-ones(sz(1),1)*max_x)));

if nargout==2
y_mean = y_sum-log(sz(1)); % compute mean if necessary.
end

return;
20 changes: 14 additions & 6 deletions tools/tapas_waic.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [waic, accuracy] = tapas_waic(llh)
function [waic, lppd] = tapas_waic(llh)
%% Computes the Watanabe-Akaike Information criterion
%
% Input
Expand All @@ -7,10 +7,10 @@
% the number of samples.
%
% Output
% waic -- The Watanaba AIC usin the methods in [1].
% accuracy -- The expected log likelihood of the model.
% waic -- The Watanabe AIC usin the methods in [1].
% lppd -- The log pointwise predictive density of the model.
%
% The WAIC can be computed as the accuracy - penalization, where the
% The WAIC can be computed as the lppd - penalization, where the
% penalization is the sum of the variance of the log likelihood, i.e., the
% gradient of the Free energy.
%
Expand All @@ -21,13 +21,21 @@
% aponteeduardo@gmail.com
% copyright (C) 2019
%
% REVISION LOG:
%
% Jakob Heinzle, 2021/04/16: changed computation of accuracy to be exactly log
% pointwise predictive density as in Gelman et al.
%
%%

s = size(llh,2);

% Estimator of the accuracy
accuracy = sum(mean(llh, 2));
lppd = sum(tapas_logsumexp(llh')-log(s));

% Estimator of the variance
penalization = sum(var(llh, [], 2));

waic = accuracy - penalization;
waic = lppd - penalization;

end

0 comments on commit feab34f

Please sign in to comment.