-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathBeliefTypes.jl
More file actions
125 lines (104 loc) · 3.55 KB
/
BeliefTypes.jl
File metadata and controls
125 lines (104 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import DistributedFactorGraphs: getStateKind
"""
CliqStatus
Clique status message enumerated type with status.
"""
@enum CliqStatus NULL NO_INIT INITIALIZED UPSOLVED MARGINALIZED DOWNSOLVED UPRECYCLED ERROR_STATUS
# Used for UPWARD_DIFFERENTIAL, UPWARD_COMMON, DOWNWARD_COMMON marginalized types
abstract type MessagePassDirection end
struct UpwardPass <: MessagePassDirection end
struct DownwardPass <: MessagePassDirection end
abstract type MessageType end
struct NonparametricMessage <: MessageType end
struct ParametricMessage <: MessageType end
using DistributedFactorGraphs: PackedBelief
#TODO deprecate SamplableBelief
const SamplableBelief = Union{
<:Distributions.Distribution,
<:KDE.BallTreeDensity, # FIXME deprecate
<:AMP.ManifoldKernelDensity,
<:AliasingScalarSampler,
<:FluxModelsDistribution,
<:HeatmapGridDensity,
<:LevelSetGridNormal,
<:Mixture,
}
#Supported types for parametric
const ParametricTypes = Union{Normal, MvNormal}
"""
$TYPEDEF
INTERMEDIATE DATA STRUCTURE DURING REFACTORING.
Representation of the belief of a single variable.
Notes:
- we want to send the joint, this is just to resolve consolidation #459 first.
- Long term objective is single joint definition, likely called `LikelihoodMessage`.
"""
struct TreeBelief{T <: StateType, P, M <: MB.AbstractManifold}
val::Vector{P}
bw::Array{Float64, 2}
infoPerCoord::Vector{Float64}
# see DFG #603, variableType defines the domain and manifold as well as group operations for a variable in the factor graph
variableType::T
# TODO -- DEPRECATE
manifold::M # Tuple{Vararg{Symbol}} # NOTE added during #459 effort
# only populated during up as solvableDims for each variable in clique, #910
solvableDim::Float64
end
function TreeBelief(
p::ManifoldKernelDensity,
ipc::AbstractVector{<:Real} = [0.0;],
variableType::T = ContinuousScalar(),
manifold = getManifold(variableType),
solvableDim::Real = 0,
) where {T <: StateType}
return TreeBelief(getPoints(p), getBW(p), ipc, variableType, manifold, solvableDim)
end
function TreeBelief(
val::AbstractVector{P},
bw::Array{Float64, 2},
ipc::AbstractVector{<:Real} = [0.0;],
variableType::T = ContinuousScalar(),
manifold::M = getManifold(variableType),
solvableDim::Real = 0,
) where {P, T <: StateType, M <: MB.AbstractManifold}
return TreeBelief{T, P, M}(val, bw, ipc, variableType, manifold, solvableDim)
end
function TreeBelief(vnd::State, solvDim::Real = 0)
TreeBelief(DFG.getDensityKind(vnd), vnd, solvDim)
end
function TreeBelief(::DFG.GaussianDensityKind, vnd::State, solvDim::Real = 0)
return TreeBelief(
DFG.refMeans(vnd),
DFG.refCovariances(vnd)[1],
vnd.observability,
getStateKind(vnd),
getManifold(vnd),
solvDim,
)
end
function TreeBelief(::DFG.NonparametricDensityKind, vnd::State, solvDim::Real = 0)
return TreeBelief(
DFG.refPoints(vnd),
DFG.refBandwidth(vnd),
vnd.observability,
getStateKind(vnd),
getManifold(vnd),
solvDim,
)
end
function TreeBelief(vari::VariableCompute, solveKey::Symbol = :default; solvableDim::Real = 0)
return TreeBelief(getState(vari, solveKey), solvableDim)
end
#
DFG.getStateKind(tb::TreeBelief) = tb.variableType
DFG.getManifold(treeb::TreeBelief) = getManifold(treeb.variableType)
function compare(t1::TreeBelief, t2::TreeBelief)
TP = true
TP = TP && norm(t1.val - t2.val) < 1e-5
TP = TP && norm(t1.bw - t2.bw) < 1e-5
TP = TP && isapprox(t1.infoPerCoord, t2.infoPerCoord; atol = 1e-4)
TP = TP && t1.variableType == t2.variableType
TP = TP && abs(t1.solvableDim - t2.solvableDim) < 1e-5
return TP
end
#