📄 logprior.m.txt
字号:
function [lpv,b] = logPrior(p,m,lic)
% [lpv,b] = logPrior(p,m,lic)
% [lpv,b] = logPrior(DR,m,lic)
% Calculate log of prior for state p, or matrix of resistances DR, given model m
% need to supply lic for cell-based prior
%
% Optionally returns b, a vector of booleans over nodes or cells that is true
% if the node/cell has different valued resistors on the node/cell.
% Colin Fox, 11 Jan 2003.
% cell-based prior added 28 Jan 2003
cell = 1; % 0=node based prior, 1=cell based prior
if isstruct(p)
DR = p.DR;
else
DR = p;
end
[nn,mm] = size(DR); % nn is the number of nodes
nr = length(m.Resistances); % number of allowable resistances
if cell==0
% node based prior
R = DR + DR'; % symmetric matrix of resistances
ni = zeros(nr,nn); % initialise number of each type
for it = 1:nr % loop over types
ni(it,:) = sum(R==m.Resistances(it)); % number of type cr at each node
end
else
% cell based prior
% cr = zeros(size(lic)); % resistors on each cell
% cr(:)=full(DR(lic(:))); % each row is resistors round cell
% cr = cr';
cr = DR(lic);
ni = zeros(nr,size(lic,2)); % initialize number of each type
for it = 1:nr % loop over types
ni(it,:) = sum(cr==m.Resistances(it)); % number of type it round each cell
end
end
dv = sum(ni).^2 - sum(ni.^2); % number of differences at each node or cell
sv = sum(ni.^2) - sum(ni); % number the same at each nodeor cell
if nargout > 1
b = dv ~= 0;
end
lpv = m.Theta*sum(sv); % sum is over nodes or cells
disp(lpv)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -