multinom_logit.m

来自「The BNL toolbox is a set of Matlab funct」· M 代码 · 共 23 行

M
23
字号
function y=multinom_logit(x,baselinecategory)
%every column of x is prob vector of size k, y is multinomial logit of length k-1
%if only one prob vector, use row vector!
if nargin==1 
     baselinecategory=1;
end


if isvector(x)
     if (size(x,2)==1), error('sum of rows =1, input should be row vector! ');,return,end;
end

d=ndims(x);
siz=size(x);
a=sum(x,d);
if any(a(:)<.999) || any(a(:)>1.001), error('one of the x is not a probability vector, sum(x)~=1');,return,end;
y=reshape(x,[prod(siz(1:d-1)) siz(d)]);
v=y(:,baselinecategory);
y(:,baselinecategory)=[];
y=log(y./repmat(v(:,baselinecategory),1,size(y,2)));
y=reshape(y,[siz(1:d-1) siz(d)-1]);

 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?