11# Clique types
22
3- # #==============================================================================
4- # # BayesTreeNodeData
5- # #==============================================================================
3+
4+
5+ # this is a developmental type, will be standardized after conclusion of #1010
6+ # TODO resolve type instability
7+ const MsgRelativeType = Vector{NamedTuple{(:variables , :likelihood ), Tuple{Vector{Symbol},DFG. AbstractRelative}}}
8+
9+ const MsgPriorType = Dict{Symbol, MsgPrior{<: ManifoldKernelDensity }}
10+
11+
12+ """
13+ $TYPEDEF
14+
15+ Internal development types used during consolidation. Stores relative and prior information making up a joint likelihood
16+ message passed upward on the Bayes tree.
17+ """
18+ mutable struct _MsgJointLikelihood
19+ relatives:: IIF.MsgRelativeType
20+ priors:: IIF.MsgPriorType
21+ end
22+
23+
24+ """
25+ $(TYPEDEF)
26+ Belief message for message passing on the tree. This should be considered an incomplete joint probility.
27+
28+ Notes:
29+ - belief -> Dictionary of [`TreeBelief`](@ref)
30+ - variableOrder -> Ordered variable id list of the seperators in cliqueLikelihood
31+ - cliqueLikelihood -> marginal distribution (<: `SamplableBelief`) over clique seperators.
32+ - Older names include: productFactor, Fnew, MsgPrior, LikelihoodMessage
33+
34+ DevNotes:
35+ - Used by both nonparametric and parametric.
36+ - Objective for parametric case: `MvNormal(μ=[:x0;:x2;:l5], Σ=[+ * *; * + *; * * +])`.
37+ - Part of the consolidation effort, see #459.
38+ - Better conditioning for joint structure in the works using deconvolution, see #579, #635.
39+ - TODO confirm why <: Singleton.
40+
41+ $(TYPEDFIELDS)
42+ """
43+ mutable struct LikelihoodMessage{T <: MessageType } <: AbstractPrior
44+ sender:: NamedTuple{(:id,:step),Tuple{Int,Int}}
45+ status:: CliqStatus
46+ belief:: Dict{Symbol, TreeBelief} # will eventually be deprecated
47+ variableOrder:: Vector{Symbol}
48+ cliqueLikelihood:: Union{Nothing,SamplableBelief} # TODO drop the Union
49+ msgType:: T
50+ hasPriors:: Bool
51+ # this is different from belief[].inferdim, as the total available infer dims remaining during down msgs -- see #910
52+ childSolvDims:: Dict{Int, Float64}
53+ # calc differential factors for joint in the child clique
54+ jointmsg:: _MsgJointLikelihood
55+ # diffJoints::Vector{NamedTuple{(:variables, :likelihood), Tuple{Vector{Symbol},DFG.AbstractRelative}}}
56+ end
657
758
859"""
2677MessageBuffer () = MessageBuffer (Dict {Int, LikelihoodMessage} (), nothing , nothing , nothing )
2778
2879
80+ # #==============================================================================
81+ # # BayesTreeNodeData
82+ # #==============================================================================
83+
84+
2985"""
3086$(TYPEDEF)
3187
65121
66122
67123
68- function BayesTreeNodeData (;status:: CliqStatus = NULL,
69- frontalIDs= Symbol[],
70- separatorIDs= Symbol[],
71- inmsgIDs= Symbol[],
72- potIDs= Symbol[],
73- potentials= Symbol[],
74- partialpotential= Bool[],
75- dwnPotentials= Symbol[],
76- dwnPartialPotential= Bool[],
77- cliqAssocMat= Array {Bool} (undef, 0 ,0 ),
78- cliqMsgMat= Array {Bool} (undef, 0 ,0 ),
79- directvarIDs= Int[],
80- directFrtlMsgIDs= Int[],
81- msgskipIDs= Int[],
82- itervarIDs= Int[],
83- directPriorMsgIDs= Int[],
84- debug= nothing ,
85- debugDwn= nothing ,
86- allmarginalized= false ,
87- initialized= :NULL ,
88- upsolved= false ,
89- downsolved= false ,
90- isCliqReused= false ,
91- messages = MessageBuffer ()
92- )
93- btnd = BayesTreeNodeData (status,
94- frontalIDs,
95- separatorIDs,
96- inmsgIDs,
97- potIDs,
98- potentials,
99- partialpotential,
100- dwnPotentials,
101- dwnPartialPotential,
102- cliqAssocMat,
103- cliqMsgMat,
104- directvarIDs,
105- directFrtlMsgIDs,
106- msgskipIDs,
107- itervarIDs,
108- directPriorMsgIDs,
109- debug,
110- debugDwn,
111- allmarginalized,
112- initialized,
113- upsolved,
114- downsolved,
115- isCliqReused,
116- messages )
117- #
118- return btnd
119- end
120- #
121-
122-
123- function compare ( c1:: BayesTreeNodeData ,
124- c2:: BayesTreeNodeData ;
125- skip:: Vector{Symbol} = [] )
126- #
127- TP = true
128-
129- TP = TP && c1. frontalIDs == c2. frontalIDs
130- TP = TP && c1. separatorIDs == c2. separatorIDs
131- TP = TP && c1. inmsgIDs == c2. inmsgIDs
132- TP = TP && c1. potIDs == c2. potIDs
133- TP = TP && c1. potentials == c2. potentials
134- TP = TP && c1. partialpotential == c2. partialpotential
135- TP = TP && c1. dwnPotentials == c2. dwnPotentials
136- TP = TP && c1. dwnPartialPotential == c2. dwnPartialPotential
137- TP = TP && c1. cliqAssocMat == c2. cliqAssocMat
138- TP = TP && c1. cliqMsgMat == c2. cliqMsgMat
139- TP = TP && c1. directvarIDs == c2. directvarIDs
140- TP = TP && c1. directFrtlMsgIDs == c2. directFrtlMsgIDs
141- TP = TP && c1. msgskipIDs == c2. msgskipIDs
142- TP = TP && c1. itervarIDs == c2. itervarIDs
143- TP = TP && c1. directPriorMsgIDs == c2. directPriorMsgIDs
144- TP = TP && c1. debug == c2. debug
145- TP = TP && c1. debugDwn == c2. debugDwn
146- TP = TP && c1. allmarginalized == c2. allmarginalized
147- TP = TP && c1. initialized == c2. initialized
148- TP = TP && c1. upsolved == c2. upsolved
149- TP = TP && c1. downsolved == c2. downsolved
150- TP = TP && c1. isCliqReused == c2. isCliqReused
151-
152- return TP
153- end
154-
155-
156124# # Packed types for serialization
157125
158126
@@ -175,61 +143,13 @@ mutable struct PackedBayesTreeNodeData
175143end
176144
177145
178-
179- function convert (:: Type{PackedBayesTreeNodeData} , btnd:: BayesTreeNodeData )
180- return PackedBayesTreeNodeData (
181- btnd. frontalIDs,
182- btnd. separatorIDs,
183- btnd. inmsgIDs,
184- btnd. potIDs,
185- btnd. potentials,
186- btnd. partialpotential,
187- btnd. dwnPotentials,
188- btnd. dwnPartialPotential,
189- btnd. cliqAssocMat,
190- btnd. cliqMsgMat,
191- btnd. directvarIDs,
192- btnd. directFrtlMsgIDs,
193- btnd. msgskipIDs,
194- btnd. itervarIDs,
195- btnd. directPriorMsgIDs )
196- end
197-
198-
199- function convert (:: Type{BayesTreeNodeData} , pbtnd:: PackedBayesTreeNodeData )
200- btnd = BayesTreeNodeData ()
201- btnd. frontalIDs = pbtnd. frontalIDs
202- btnd. separatorIDs = pbtnd. separatorIDs
203- btnd. inmsgIDs = pbtnd. inmsgIDs
204- btnd. potIDs = pbtnd. potIDs
205- btnd. potentials = pbtnd. potentials
206- btnd. partialpotential = pbtnd. partialpotential
207- btnd. dwnPotentials = pbtnd. dwnPotentials
208- btnd. dwnPartialPotential = pbtnd. dwnPartialPotential
209- btnd. cliqAssocMat = pbtnd. cliqAssocMat
210- btnd. cliqMsgMat = pbtnd. cliqMsgMat
211- btnd. directvarIDs = pbtnd. directvarIDs
212- btnd. directFrtlMsgIDs = pbtnd. directFrtlMsgIDs
213- btnd. msgskipIDs = pbtnd. msgskipIDs
214- btnd. itervarIDs = pbtnd. itervarIDs
215- btnd. directPriorMsgIDs = pbtnd. directPriorMsgIDs
216- return btnd
217- end
218-
146+ # # Full Clique Types
219147
220148
221- # #==============================================================================
222- # # Cliques
223- # # TreeClique
224- # #==============================================================================
225149struct CliqueId{T}
226150 value:: T
227151end
228152
229- Base. getindex (cId:: CliqueId ) = cId. value
230- Base. show (io:: IO , :: MIME"text/plain" , x:: CliqueId ) = print (io, x. value)
231- Base. show (io:: IO , x:: CliqueId ) = print (io, x. value)
232-
233153"""
234154 $(TYPEDEF)
235155Structure to store clique data
@@ -246,34 +166,5 @@ mutable struct TreeClique
246166 # solveInProgress #on a clique level a "solve in progress" might be very handy
247167end
248168
249- getId (c:: TreeClique ) = c. id
250-
251- function Base. getproperty (x:: TreeClique ,f:: Symbol )
252- if f == :index
253- Base. depwarn (" `TreeCliqe` field `index` is deprecated, use `id`" , :getproperty )
254- f = :id
255- end
256- getfield (x,f)
257- end
258-
259- function Base. setproperty! (x:: TreeClique , f:: Symbol , val)
260- if f == :index
261- Base. depwarn (" `TreeCliqe` field `index` is deprecated, use `id`" , :setproperty! )
262- f = :id
263- end
264- return setfield! (x, f, convert (fieldtype (typeof (x), f), val))
265- end
266-
267- TreeClique (i:: Int ) = TreeClique (CliqueId (i), BayesTreeNodeData (), Dict {String,Any} ())
268- TreeClique (id:: CliqueId ) = TreeClique (id, BayesTreeNodeData (), Dict {String,Any} ())
269-
270-
271- DFG. getLabel (cliq:: TreeClique ) = cliq. attributes[" label" ]
272- function setLabel! (cliq:: TreeClique , lbl:: String )
273- cliq. attributes[" label" ] = lbl
274- lbl
275- end
276-
277-
278169
279- # # end Cliques
170+ #
0 commit comments