📄 multinom_logit.m
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -