Debugged the thinTree. Now works with tree indexing starting at 1 at the root. TODO : make it work with index 0 on a leaf.
parent
0357559827
commit
8d85d679cd
|
@ -17,7 +17,11 @@
|
|||
% * @author Jean-Guillaume Durand
|
||||
% */
|
||||
|
||||
%% Clean the workspace
|
||||
clc, clear all, close all;
|
||||
|
||||
%% Run the tests
|
||||
import gtsam.*
|
||||
bayesNet = thinTreeBayesNet(3,2);
|
||||
[bayesNet tree] = thinTreeBayesNet(4,2);
|
||||
EQUALITY('7 = bayesNet.size', 7, bayesNet.size);
|
||||
bayesNet.saveGraph('thinTreeBayesNet.dot');
|
|
@ -49,12 +49,17 @@ classdef thinTree
|
|||
% Function to return the ID's of a node's parents
|
||||
function ids = getParents(obj, nodeID)
|
||||
% Initialisation
|
||||
ids = zeros(1,obj.w);
|
||||
node = nodeID;
|
||||
% Loop on w, the number of parents associated to one node
|
||||
for i=1:obj.w
|
||||
ids(i) = floor(node/2);
|
||||
node = floor(node/2);
|
||||
depthOfNode = obj.getNodeDepth(nodeID);
|
||||
if depthOfNode == 1
|
||||
ids = 1;
|
||||
else
|
||||
ids = zeros(1,min(obj.w, depthOfNode-1));
|
||||
% Loop on w, the number of parents associated to one node
|
||||
for i=1:min(obj.w, depthOfNode-1)
|
||||
ids(i) = floor(node/2);
|
||||
node = floor(node/2);
|
||||
end
|
||||
end
|
||||
% Return
|
||||
return
|
||||
|
@ -74,5 +79,10 @@ classdef thinTree
|
|||
function output = getNumberOfElements(obj)
|
||||
output = 2^obj.depth - 1;
|
||||
end
|
||||
|
||||
% Returns the depth of a node
|
||||
function output = getNodeDepth(obj, nodeID)
|
||||
output = ceil(log(nodeID+1)/log(2));
|
||||
end
|
||||
end % Methods
|
||||
end % Class
|
|
@ -1,7 +1,7 @@
|
|||
function [bayesNet, tree] = thinTreeBayesNet(d,w)
|
||||
import gtsam.*
|
||||
bayesNet = GaussianBayesNet;
|
||||
tree = thinTree(3,2);
|
||||
tree = thinTree(d,w);
|
||||
|
||||
% Filling the tree
|
||||
|
||||
|
@ -10,24 +10,30 @@ gc = gtsam.GaussianConditional(1, 5*rand(1), 5*rand(1), 3*rand(1));
|
|||
% Getting it into the GaussianBayesNet
|
||||
bayesNet.push_front(gc);
|
||||
|
||||
for i=1:2^tree.getNumberOfElements()
|
||||
for i=1:tree.getNumberOfElements()
|
||||
% Getting the parents of that node
|
||||
parents = tree.getParents(i);
|
||||
% Create and link the corresponding GaussianConditionals
|
||||
if tree.getW == 1
|
||||
if tree.getW == 1 || tree.getNodeDepth(i) <= 2
|
||||
% Creation of the GaussianConditional
|
||||
gc = gtsam.GaussianConditional(parents(1), 5*rand(1), 5*rand(1));
|
||||
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);
|
||||
% Getting it in the thinTree
|
||||
t = tree.addContent({gc,parents}, i);
|
||||
elseif tree.getW == 2
|
||||
% Creation of the GaussianConditional
|
||||
gc = gtsam.GaussianConditional(parents(2), 5*rand(1), 5*rand(1), parents(1), 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
|
||||
t = tree.addContent({gc,parents}, i);
|
||||
tree = tree.addContent({gc,parents}, i);
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue