Home > wafo > markov > tr_x2p.m

tr_x2p

PURPOSE ^

Transforms a vector X to a transition matrix P.

SYNOPSIS ^

P = tr_x2p(X,trans)

DESCRIPTION ^

  TR_X2P  Transforms a vector X to a transition matrix P.
 
  CALL: P = tr_x2p(X,trans)
 
  P     = transition matrix.           [rxr]
  
  X     = Vector of length n=r*(r-1).  [nx1]
  trans = 0: No transformation. (default)
          1: inverse log-odds-transformation.
               x = 1/(exp(-y)+1)
 
  See also tr_p2x

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

001 function P = tr_x2p(X,trans)
002 % TR_X2P  Transforms a vector X to a transition matrix P.
003 %
004 % CALL: P = tr_x2p(X,trans)
005 %
006 % P     = transition matrix.           [rxr]
007 % 
008 % X     = Vector of length n=r*(r-1).  [nx1]
009 % trans = 0: No transformation. (default)
010 %         1: inverse log-odds-transformation.
011 %              x = 1/(exp(-y)+1)
012 %
013 % See also tr_p2x
014 
015 if nargin<2, trans=[]; end
016 if isempty(trans), trans=0; end
017 
018 r=(1+sqrt(1+4*length(X)))/2;
019 
020 switch trans
021 
022 case 0  % No transformation
023 
024 case 1  % inverse-log-odds-transformation
025 
026   X = invlogOdds(X);
027 
028 otherwise
029 
030   error(['Transformation ' num2str(trans) ' not defined.']);
031 
032 end % switch
033 
034 E= eye(r);
035 EE = E(:);
036 IE = find(EE==0);
037 Y = zeros(r*r,1);
038 Y(IE) = X;
039 P = reshape(Y,r,r)';
040 for i = 1:r
041   P(i,i) = 1-sum(P(i,:));
042 end
043 
044 %
045 % inverse of log-odds
046 %
047 
048 function x=invlogOdds(y)
049 
050 x=1./(exp(-y)+1);
051 
052

Mathematical Statistics
Centre for Mathematical Sciences
Lund University with Lund Institute of Technology

Comments or corrections to the WAFO group


Generated on Thu 06-Oct-2005 02:21:16 for WAFO by m2html © 2003