Commit 81e55595 authored by dlinzner-bcs's avatar dlinzner-bcs
Browse files

Bug fixing

parent 102f362c
function [T,M] = CTBN_cond_stat_star_sparse_reg_DIMS(node,i,t,dt,MU,RHO)
%CALCULATE COND STATISTICS OF CTBN
mu=MU{i};
rho=RHO{i};
D=node(i).D;
%%%get effective rate
ps=node(i).allPosStatesOfParents;
Q_i=node(i).R_gm;
sp=size(ps);
T=zeros(sp(1),D);
M=zeros(sp(1),D,D);
if (isempty(node(i).parents)==0)
%%%%averaging
sp=size(ps);
for mn=1:sp(1)
T_i=0;
M_i=0;
pa=ones(t,1);
ki=1;
for k=node(i).parents
mu_p=MU{k};
pa=pa.*mu_p(1:t,ps(mn,ki));
ki=ki+1;
end
for d=1:D
T_i(d)=trapz(linspace(0,dt*t,t),mu(1:t,d).*pa);
for d_=1:D
if (d~=d_)
M_i(d,d_)=trapz(linspace(0,dt*t,t),pa.*mu(1:t,d).*rho(1:t,d_)./rho(1:t,d)).*Q_i{mn}(d,d_);
end
end
end
T(mn,:)=T_i(:);
M(mn,:,:)=M_i(:,:);
end
else
for d=1:D
T_i(d)=trapz(linspace(0,dt*t,t),mu(1:t,d));
for d_=1:D
if (d~=d_)
M_i(d,d_)=trapz(linspace(0,dt*t,t),mu(1:t,d).*(rho(1:t,d_)./rho(1:t,d))).*Q_i{1}(d,d_);
end
end
end
T(1,:,:)=T_i;
M(1,:,:)=M_i;
end
end
......@@ -25,7 +25,6 @@ for i=1:length(node)
for l=node(i).subsets{k}
ind=[ind,find(node(i).parents==l)];
end
%states=de2bi(0:(2^length(ind))-1)+1;
states=node_states(node,node(i).subsets{k});
ss=size(states);
M_k=zeros(ss(1),D,D);
......
......@@ -16,6 +16,7 @@ for k=1:length(TZ)
end
parfor k=1:length(TZ)
try
[mu,rho,~] = P_CVMCTBN_STAR_POST_REG_DIMS(node,dt,Mmax,t0,Z{k},TZ{k},thresh);
MU{k}=mu{Mmax};
RHO{k}=rho{Mmax-1};
......
function [F] = marg_llh_sparse_reg_noexpln_single_DIMS(node,i,lam)
%UNTITLED3 Summary of this function goes here
% Detailed explanation goes here
F=0;
E=0;
D=node(i).D;
subsets=node(i).subsets;
for k=1:length(subsets)
states=node_states(node,subsets{k});
if isempty(states)==0
sp=size(states);
for u=1:sp(1)
for d=1:D
beta_bar=squeeze(node(i).pi(k)*node(i).dwell_k{k}(u,d)+node(i).beta_k{k}(u,d));
for d_=1:D
if(d~=d_)
alpha_bar=squeeze(node(i).pi(k)*node(i).trans_k{k}(u,d,d_)+node(i).alpha_k{k}(u,d,d_));
E = E-(alpha_bar).*log(beta_bar)+gammaln(alpha_bar);
end
end
end
end
else
u=1;
for d=1:D
beta_bar=squeeze(node(i).pi(k)*node(i).dwell_k{k}(u,d)+node(i).beta_k{k}(u,d));
for d_=1:D
if(d~=d_)
alpha_bar=squeeze(node(i).pi(k)*node(i).trans_k{k}(u,d,d_)+node(i).alpha_k{k}(u,d,d_));
E = E-(alpha_bar).*log(beta_bar)+gammaln(alpha_bar);
end
end
end
end
end
P=lam*sum(log(node(i).pi));
F=F+E+P;
end
......@@ -41,9 +41,5 @@ if nargout > 1 % gradient required
end
end
%grad[i] -= alpha_bar dwell / beta_bar
%grad[i] -= log( beta_bar) M_Sum
%grad[i] += SpecialFunctions.digamma(alpha_bar) M_Sum
end
......@@ -39,48 +39,42 @@ end
%creating conditional rate matrixes
for w=1:numbOfV
for d=1:length(states)
for d_=1:length(states)
r=(1/2)*(1+tanh((d-d_)*temp*0));
% wUp=(1/2)*(1-tanh(abs(d-d_)*temp*sumOfParSt));
%cellOfCRM{v}=rand*[-wDown, wDown; wUp, -wUp];
%cellOfCRM{v}=tau*[-wDown, wDown; wUp, -wUp];
D=node(w).D;
for d=1:D
for d_=1:D
x=((d-d_)-mean(node(w).Omega))/mean(node(w).Omega);
r=(1/2)*(1+tanh(x*temp*0));
cellOfCRM{1}(d,d_)=tau*r;
%cellOfCRM{v}=tau*[-wUp, wUp; wDown, -wDown];
end
cellOfCRM{1}(d,d)=0;
cellOfCRM{1}(d,d)=-sum(cellOfCRM{1}(d,:));
end
for v=1:length(node(w).allPosStatesOfParents)
if length(node(w).parents)>0
for u=1:length(node(w).parents)
% if node(w).allPosStatesOfParents(v,u)==2
% node(w).allPosStatesOfParents(v,u)=-1;
% end
sumOfParSt=sum(node(w).allPosStatesOfParents(v,:));
sumOfParSt=(sum(node(w).allPosStatesOfParents(v,:)-mean(node(w).allPosStatesOfParents,1)));
end
else
sumOfParSt=0;
end
for d=1:length(states)
for d_=1:length(states)
r=(1/2)*(1+tanh((d-d_)*temp*sumOfParSt));
% wUp=(1/2)*(1-tanh(abs(d-d_)*temp*sumOfParSt));
%cellOfCRM{v}=rand*[-wDown, wDown; wUp, -wUp];
%cellOfCRM{v}=tau*[-wDown, wDown; wUp, -wUp];
cellOfCRM{v}(d,d_)=tau*r;
%cellOfCRM{v}=tau*[-wUp, wUp; wDown, -wDown];
CIM=zeros(D);
for d=1:D
for d_=1:D
if d_~=d
x=(d_-mean(node(w).Omega));
r=(1/2)*(1+tanh(x*temp*sumOfParSt));
CIM(d,d_)=tau*r;
end
end
cellOfCRM{v}(d,d)=-sum(cellOfCRM{v}(d,:));
end
CIM(d,d)=-sum(CIM(d,:));
end
cellOfCRM{v}=CIM;
end
node(w).cellOfCondRM=cellOfCRM;
clear cellOfCRM;
end
for i=1:numbOfV
node(i).children=[];
end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment