| 1 |
function of = a0asfun(x,s,nobs,nvar,a0indx) |
| 2 |
% General program to setup A0 matrix with asymmetric prior (as) and compute the posterior |
| 3 |
% function of = a0asfun(x,s,nobs,nvar,a0indx) -- negative logPosterior |
| 4 |
% Note: columns correspond to equations |
| 5 |
% x (parameter vector), |
| 6 |
% s (diag(S1,...,Sm)): note, as in "a0lhfun", already divided by "nobs" |
| 7 |
% nobs (no of obs), |
| 8 |
% nvar (no of variables), |
| 9 |
% a0indx (matrix indicating the free parameters in A0, and each column in A0 corresponds |
| 10 |
% to an equation) |
| 11 |
% |
| 12 |
% |
| 13 |
% Copyright (C) 1997-2012 Tao Zha |
| 14 |
% |
| 15 |
% This free software: you can redistribute it and/or modify |
| 16 |
% it under the terms of the GNU General Public License as published by |
| 17 |
% the Free Software Foundation, either version 3 of the License, or |
| 18 |
% (at your option) any later version. |
| 19 |
% |
| 20 |
% It is distributed in the hope that it will be useful, |
| 21 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 |
% GNU General Public License for more details. |
| 24 |
% |
| 25 |
% If you did not received a copy of the GNU General Public License |
| 26 |
% with this software, see <http://www.gnu.org/licenses/>. |
| 27 |
% |
| 28 |
|
| 29 |
a0 = zeros(nvar); |
| 30 |
a0(a0indx) = x; |
| 31 |
% Note: each column in a0 corresponds to an equation!! |
| 32 |
% |
| 33 |
%%ada = chol(a0'*a0); |
| 34 |
%%ada = log(abs(diag(ada))); |
| 35 |
%%ada = sum(ada); |
| 36 |
% ** TZ, 10/15/96, the above two lines can be improved by the following three lines |
| 37 |
[a0l,a0u] = lu(a0); |
| 38 |
%ada=diag(abs(a0u)); |
| 39 |
%ada=sum(log(ada)); |
| 40 |
ada = sum(log(abs(diag(a0u)))); |
| 41 |
|
| 42 |
% |
| 43 |
%tra = sum(i=1:m){a0(:,i)'*Si*a0(:,i)} |
| 44 |
tra = 0.0; |
| 45 |
for i=1:nvar |
| 46 |
tra = tra + a0(:,i)'*s{i}*a0(:,i); |
| 47 |
end |
| 48 |
|
| 49 |
of = -nobs*ada + nobs*.5*tra; |