| 
									
										
										
										
											2012-09-15 10:54:42 +08:00
										 |  |  | function [bayesNet, tree] = thinTreeBayesNet(depth,width)
 | 
					
						
							|  |  |  | % thinTreeBayesNet | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-15 06:14:37 +08:00
										 |  |  | import gtsam.* | 
					
						
							|  |  |  | bayesNet = GaussianBayesNet; | 
					
						
							| 
									
										
										
										
											2012-09-15 10:54:42 +08:00
										 |  |  | tree = thinTree(depth,width); | 
					
						
							| 
									
										
										
										
											2012-09-15 06:14:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-15 10:54:42 +08:00
										 |  |  | % Add root to the Bayes net | 
					
						
							| 
									
										
										
										
											2021-03-11 04:58:12 +08:00
										 |  |  | model = noiseModel.Isotropic.Sigma(1, 3*rand(1)); | 
					
						
							|  |  |  | gc = gtsam.GaussianConditional(1, 5*rand(1), 5*rand(1), model); | 
					
						
							|  |  |  | bayesNet.push_back(gc); | 
					
						
							| 
									
										
										
										
											2012-09-15 06:14:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-15 10:54:42 +08:00
										 |  |  | n=tree.getNumberOfElements(); | 
					
						
							|  |  |  | for i=2:n | 
					
						
							|  |  |  |   % Getting the parents of that node | 
					
						
							| 
									
										
										
										
											2012-09-15 10:56:19 +08:00
										 |  |  |   parents = tree.getParents(i); | 
					
						
							|  |  |  |   di = tree.getNodeDepth(i); | 
					
						
							| 
									
										
										
										
											2012-09-15 10:54:42 +08:00
										 |  |  |   % Create and link the corresponding GaussianConditionals | 
					
						
							|  |  |  |   if tree.getW == 1 || di == 2 | 
					
						
							|  |  |  |     % Creation of single-parent GaussianConditional | 
					
						
							| 
									
										
										
										
											2021-03-11 04:58:12 +08:00
										 |  |  |     model = noiseModel.Isotropic.Sigma(1, 5*rand(1)); | 
					
						
							|  |  |  |     gc = gtsam.GaussianConditional(n-i, 5*rand(1), 5*rand(1), n-parents(1), 5*rand(1), model); | 
					
						
							| 
									
										
										
										
											2012-09-15 10:54:42 +08:00
										 |  |  |   elseif tree.getW == 2 || di == 3 | 
					
						
							|  |  |  |     % GaussianConditionalj associated with the second parent | 
					
						
							| 
									
										
										
										
											2021-03-11 04:58:12 +08:00
										 |  |  |     model = noiseModel.Isotropic.Sigma(1, 5*rand(1)); | 
					
						
							|  |  |  |     gc = gtsam.GaussianConditional(n-i, 5*rand(1), 5*rand(1), n-parents(1), 5*rand(1), n-parents(2), 5*rand(1), model); | 
					
						
							| 
									
										
										
										
											2012-09-15 10:54:42 +08:00
										 |  |  |   end | 
					
						
							|  |  |  |   % Add conditional to the Bayes net | 
					
						
							| 
									
										
										
										
											2021-03-11 04:58:12 +08:00
										 |  |  |   bayesNet.push_back(gc); | 
					
						
							| 
									
										
										
										
											2012-09-15 06:14:37 +08:00
										 |  |  | end | 
					
						
							| 
									
										
										
										
											2012-09-15 10:54:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-15 06:14:37 +08:00
										 |  |  | end |