function bias = gaussian_bias(Nt,L)
% GAUSSIAN_BIAS Computes bias of gaussian entropy estimates
%
%   -----
%   USAGE
%   -----
%
%       bias = gaussian_bias(nt,L)
%
%   where NT is the number of trials used for the estimation of entropy and
%   L is the dimensionality of the response. NT can either be an integer
%   scalar or a column arra of integers: in this case the bias is computed
%   for each of the values in NT.
%
%   See also ENTROPY, INFORMATION

%   Copyright (C) 2009 Cesare Magri
%   Version: 1.0.0

% -------
% LICENSE
% -------
% This software is distributed free under the condition that:
%
% 1. it shall not be incorporated in software that is subsequently sold;
%
% 2. the authorship of the software shall be acknowledged and the following
%    article shall be properly cited in any publication that uses results
%    generated by the software:
%
%      Magri C, Whittingstall K, Singh V, Logothetis NK, Panzeri S: A
%      toolbox for the fast information analysis of multiple-site LFP, EEG
%      and spike train recordings. BMC Neuroscience 2009 10(1):81;
%
% 3.  this notice shall remain in place in each source file.

Nt = Nt-1;

NtMat = Nt(:, ones(L,1));

pvec = 0:L-1;

NtMat = NtMat - pvec(ones(length(Nt),1), :);

bias = sum(psi(NtMat./2), 2) - L.*log(Nt(:,1)./2);
bias = bias ./ (2*log(2));