Fixed thin tree indexing, and conditionals

release/4.3a0
Frank Dellaert 2012-09-15 02:54:42 +00:00
parent a9cae46b10
commit ea6655beba
2 changed files with 24 additions and 36 deletions

View File

@ -10,18 +10,15 @@
% * -------------------------------------------------------------------------- */ % * -------------------------------------------------------------------------- */
% %
% /** % /**
% * @file testThinTree.cpp % * @file testThinTreeBayesNet.cpp
% * @brief Test of binary tree % * @brief Test of binary tree
% * @date Sep 13, 2012 % * @date Sep 13, 2012
% * @author Frank Dellaert % * @author Frank Dellaert
% * @author Jean-Guillaume Durand % * @author Jean-Guillaume Durand
% */ % */
%% Clean the workspace
clc, clear all, close all;
%% Run the tests %% Run the tests
import gtsam.* import gtsam.*
[bayesNet tree] = thinTreeBayesNet(4,2); [bayesNet tree] = thinTreeBayesNet(4,2);
EQUALITY('7 = bayesNet.size', 7, bayesNet.size); EQUALITY('7 = bayesNet.size', 7, bayesNet.size);
bayesNet.saveGraph('thinTreeBayesNet.dot'); gtsam.plotBayesNet(bayesNet);

View File

@ -1,39 +1,30 @@
function [bayesNet, tree] = thinTreeBayesNet(d,w) function [bayesNet, tree] = thinTreeBayesNet(depth,width)
% thinTreeBayesNet
import gtsam.* import gtsam.*
bayesNet = GaussianBayesNet; bayesNet = GaussianBayesNet;
tree = thinTree(d,w); tree = thinTree(depth,width);
% Filling the tree % Add root to the Bayes net
% Creation of the root
gc = gtsam.GaussianConditional(1, 5*rand(1), 5*rand(1), 3*rand(1)); gc = gtsam.GaussianConditional(1, 5*rand(1), 5*rand(1), 3*rand(1));
% Getting it into the GaussianBayesNet
bayesNet.push_front(gc); bayesNet.push_front(gc);
for i=1:tree.getNumberOfElements() n=tree.getNumberOfElements();
for i=2:n
% Getting the parents of that node % Getting the parents of that node
parents = tree.getParents(i); i
parents = tree.getParents(i)
di = tree.getNodeDepth(i)
% Create and link the corresponding GaussianConditionals % Create and link the corresponding GaussianConditionals
if tree.getW == 1 || tree.getNodeDepth(i) <= 2 if tree.getW == 1 || di == 2
% Creation of the GaussianConditional % Creation of single-parent GaussianConditional
gc = gtsam.GaussianConditional(parents(1), 5*rand(1), 5*rand(1), i, 5*rand(1), 5*rand(1)); gc = gtsam.GaussianConditional(n-i, 5*rand(1), 5*rand(1), n-parents(1), 5*rand(1), 5*rand(1));
% Getting it into the GaussianBayesNet elseif tree.getW == 2 || di == 3
bayesNet.push_front(gc); % GaussianConditionalj associated with the second parent
% Getting it in the thinTree gc = gtsam.GaussianConditional(n-i, 5*rand(1), 5*rand(1), n-parents(1), 5*rand(1), n-parents(2), 5*rand(1), 5*rand(1));
tree = tree.addContent({gc,parents}, i);
elseif tree.getW == 2 && tree.getNodeDepth(i) > 2
% Creation of the GaussianConditional associated with the first
% parent
gc = gtsam.GaussianConditional(parents(1), 5*rand(1), 5*rand(1), i, 5*rand(1), 5*rand(1));
% Getting it into the GaussianBayesNet
bayesNet.push_front(gc);
% Creation of the GaussianConditionalj associated with the second
% parent
gc = gtsam.GaussianConditional(parents(2), 5*rand(1), 5*rand(1), i, 5*rand(1), 5*rand(1));
% Getting it into the GaussianBayesNet
bayesNet.push_front(gc);
% Getting it in the thinTree
tree = tree.addContent({gc,parents}, i);
end end
% Add conditional to the Bayes net
bayesNet.push_front(gc);
end end
end end