Variable Elimination in Hybrid Factor Graphs for Discrete-Continuous Inference & Estimation Varun Agrawal, Frank Dellaert Abstract Many hybrid problems in robotics involve both continuous and discrete components, and modeling them together for estimation tasks has been a long standing and difficult problem. Hybrid Factor Graphs give us a mathematical framework to model these types of problems, however existing approaches for solving them are based on approximations. In this work, we propose an efficient Hybrid Factor Graph framework alongwith a variable elimination algorithm to produce a hybrid Bayes network, which can then be used for exact Maximum A Posteriori estimation and marginalization over both sets of variables. Our approach first develops a novel hybrid Gaussian factor which can connect to both discrete and continuous variables, and a hybrid conditional which can represent multiple continuous hypotheses conditioned on the discrete variables. Using these representations, we derive the process of hybrid variable elimination under the Conditional Linear Gaussian scheme, giving us exact posteriors as hybrid Bayes network. To bound the number of discrete hypotheses, we use a tree-structured representation of the factors coupled with a simple pruning and probabilistic assignment scheme, which allows for tractable inference. We demonstrate the applicability of our framework on a SLAM dataset with ambiguous measurements, where discrete choices for the most likely measurement have to be made. Our demonstrated results showcase the accuracy, generality, and simplicity of our hybrid factor graph framework. I Introduction Robotics inherently has both discrete and continuous components to it, making it vital to be able to model both. Tasks such as Simultaneous Localization and Mapping (SLAM), grasping, Task and Motion Planning (TAMP), fault assessment [ 26 ] , and locomotion (amongst others) all involve some discrete components along with an optimization task over continuous variables. E.g . in SLAM, the continuous components are the positions of the robot and the landmarks, but the data association problem between features is a discrete estimation problem [ 18 , 14 ] . For manipulation, estimating the pose of the object to grasp, as well as identifying the discrete set of affordances and contacts on the object constitutes a hybrid estimation problem [ 29 , 16 , 44 ] . Additionally, being able to estimate discrete foot contact on the ground can significantly aid with continuous state estimation of humanoid and legged robots, boosting their use in real-world applications [ 4 ] . However, most approaches to these tasks either tackle the continuous and discrete components individually [ 6 , 9 , 45 , 30 ] , or they make use of approximations [ 36 , 40 , 15 , 14 ] . This usually leads to suboptimal performance since knowledge of one part can aid in the estimation of the other. In recent years, probabilistic methods to state estimation have been the de facto approach. Common techniques like Kalman filtering [ 37 ] have been analyzed from a Bayesian viewpoint, while Bayesian networks and factor graphs [ 23 , 13 ] have seen significant recent success. Consequently, recent hybrid estimation approaches leverage these methods [ 14 , 18 , 20 ] . Fig. 1 : An example of a hybrid factor graph for a state estimation problem with ambiguous motion models (blue factors) and measurement models (green factors). Here x represents the robot states, z represents the landmarks, and m and b (in square nodes) are sequences of discrete modes representing choices for the most likely motion and measurement model respectively. To tackle problems of a mixed discrete-continuous nature, we propose a general Hybrid Factor Graph framework alongwith a novel variable elimination algorithm for which results in exact posterior distributions (via a Hybrid Bayes Network) for hybrid inference and estimation. We rigorously define hybrid factor graphs, with design considerations to make them computationally efficient and easy to implement. We develop both Max-Product and Sum-Product as instances of the general variable elimination algorithm for Maximum A Posteriori (MAP) estimation and marginal computation respectively, which is both theoretically and experimentally verified. Furthermore, we derive the set of components to bridge the gap between modeling continuous and discrete components, and to optimize them computationally, allowing us to extend existing ideas and tools [ 32 ] to the hybrid case, while still being natural to postulate and solve. We next propose various means of handling potential exponential growth and managing data storage for large scale problems. By analyzing the complexity of hybrid inference, we show how hypothesis pruning and variable ordering proves vital to efficient performance on large scale problems. Finally, we experimentally validate our work on a 2D SLAM task with ambiguous measurements. We use the City10000 dataset [ 18 ] , which has multiple ambiguous odometry measurements. We show how we can naturally model this problem with our framework and optimize it. Overall, we can summarize our contributions as • A probabilistic factor graph based framework with novel hybrid factors for modeling both discrete and continuous variables jointly, and an algorithm for efficient variable elimination and MAP optimization. • Complexity analysis of our framework and approaches to constraint the exponential growth of hypotheses involved in hybrid inference. • Application to hybrid SLAM on the City10000 dataset with ambiguous odometry measurements. II Related Work II-A Discrete-Continuous Optimization Discrete-Continuous optimization has been an active area of research for many years. Most attempts at this kind of hybrid optimization fall into the realm of Mixed-Integer Programming (MIP) and Mixed-Integer Nonlinear Programming (MINLP) [ 22 ] . [ 17 ] detailed a new framework titled Generalized Disjunctive Programming (GDP), which is based on MIP, allowing for derivations of mixed-integer optimization problems with stronger continuous relaxations [ 46 , 42 ] . Evolutionary strategies have also been explored in hybrid spaces, such as Genetic Algorithms [ 35 ] and differential evolutionary algorithms [ 24 ] for handling hybrid optimization. II-B Hybrid Inference Probabilistic inference over hybrid graphical models has received significant interest. Lauritzen et al . [ 25 ] first developed exact inference over hybrid graphical models, defining the Conditional Linear Gaussian (CLG) as a class of models where discrete variables could not have continuous parents. [ 27 ] extended it by allowing discrete variables to have continuous parents, an approach we hope to adopt in future work. [ 31 ] proposed to use decision-tree structured conditional probability tables for efficient inference over large discrete and continuous domains. The influential work of [ 32 ] introduced Switching Kalman Filters [ 34 ] and Dynamic Bayes Networks [ 33 ] as unified approaches to modeling hybrid problems in a Bayesian framework, and algorithms for inferring desired posteriors. Various approaches to factor graph based hybrid inference have been proposed. [ 43 ] first defined the notion of a hybrid factor graph for biomedical data analysis, using an iterative message passing approach to optimize for the MAP. In contrast, our contribution is the development of both hybrid Bayes networks and hybrid factor graphs to follow the paradigm laid out by [ 11 ] , which goes from a generative Bayes network to a factor graph after conditioning on measurements, and then uses the elimination algorithm to transform the factor graph back to a Bayes network representing the now hybrid posterior. Furthermore, we show applications within the robotics field which generally have a different set of operational requirements (such as online, incremental, efficiency, etc.). [ 18 ] propose a multi-hypothesis extension to iSAM2 [ 21 ] , which only allows 3 types of hybrid relationships and requires the use of additional data structures for tracking the multiple hypotheses. Additionally, they do not support discrete probability relationships in their framework. [ 20 ] similarly uses a tree-based structure to model incremental smoothers, with each branch corresponding to a single discrete assignment. Our work generalizes and simplifies both these approaches by allowing for all types of hybrid relationships without the need for specific or dedicated data structures to track multiple hypotheses. [ 14 ] developed an alternating optimization scheme by fixing either the discrete or continuous variables while updating the other, which could cause the nonlinear optimization to be stuck in incorrect local minima due to inaccurate initial estimates. In contrast, we optimize both parts jointly, avoiding the issue of poor initial estimates. II-C Discrete-Continuous Estimation and Applications Hybrid estimation has been widely studied in the field of state estimation for discrete-continuous or switching systems. Its initial development was fueld by the need for tracking a variety of aircraft trajectories via Interacting Multiple Models and its variants [ 3 , 7 , 19 ] . Recent work has also focused on estimation in Switching Dynamical Systems, both linear [ 36 ] and nonlinear [ 15 ] . Hybrid estimation has also seen applications in other fields. In computer vision, it has been used for depth and plan normal estimation from images [ 28 ] , dense stereo matching [ 41 ] , Structure-from-Motion as discrete-continuous optimization [ 8 ] , optical flow [ 39 ] , and visual multi-target tracking [ 2 ] . These applications use approximate methods or optimize each component independently rather than jointly. Additionally, hybrid inference has also been explored in probabilistic programming languages [ 47 ] . III Hybrid Bayes Network For a hybrid problem, we wish to perform probabilistic inference on systems with both continuous and discrete variables. Specifically, we are given a hybrid joint probability distribution P(X,M,Z,Q) consisting of continuous states X , discrete modes M , and Z and Q are sets of measurements on continuous and discrete variables respectively. We wish to perform two tasks of interest to roboticists: 1. Compute the posterior distribution P(X,M|Z,Q) of the states X,M given the measurements Z,Q : P(X,M|Z,Q)\propto P(X,M,Z,Q) (1) 2. Infer the Maximum A Posteriori estimate of X and M X^{*},M^{*}=\arg\max_{X,M}P(X,M|Z,Q) (2) To do this, we can represent the joint probability distribution P(X,M,Z,Q) using a generative Hybrid Bayes Network [ 27 ] . A Hybrid Bayes Network (HBN) is a directed, acyclic graph whose nodes are conditional probability distributions over some subset of the variables X,M,Z,Q . P(X,M,Z,Q)=\prod_{A_{i}\in\{X,M,Z,Q\}}P(A_{i}|\Pi_{i}) (3) where \Pi_{i} are the parents of A_{i} . We consider the following types of conditionals in what follows below: • p(Z_{k}|X_{k},M_{k}) : A conditional of measurements Z_{k} over a subset of continuous X_{k} and discrete M_{k} variables. • p(X_{i}|M_{i}) : Probability distribution of a continuous variable subset X_{i} conditioned on a discrete subset M_{i} . • P(Q_{k}|M_{k}) : The conditional of measurements Q_{k} over the subset of discrete variables M_{k} . • P(M_{i}) : The prior probability over a discrete variable subset M_{i} . Following Lauritzen et al . [ 25 ] , we use the Conditional Linear Gaussian model and explicitly disallow distributions of discrete variables conditioned on continuous parents. Fig. 2 : An example Hybrid Bayes Network with 2 continuous latent variables x_{0},x_{1} , three observable measurements z_{0},z_{1},q_{0} , and 1 latent discrete variable m_{1} . This model represents a simple switching dynamical system. We illustrate this with a simple switching dynamical system [ 34 ] in figure 2 . Hybrid Bayes networks with evidence ( a.k.a . measurements) are computationally hard to perform inference with due to the larger state space [ 11 ] , which is why we introduce hybrid factor graphs in the next section. IV Hybrid Factor Graph To perform efficient inference, we follow the approach in Dellaert and Kaess [ 11 ] where we convert the hybrid Bayes network P(X,M,Z,Q) to a Hybrid Factor Graph \Phi(X,M;Z,Q) after conditioning on the measurements Z,Q [ 32 ] . A hybrid factor graph (HFG) is thus defined as a product of hybrid factors over X and M , Fig. 3 : A simple Hybrid Factor Graph with 2 continuous variables x_{0},x_{1} and 1 discrete variable m_{1} . In this example, the process model is a hybrid factor, and measurements and priors are encoded as factors. \Phi(X,M)=\prod_{\phi\in\Phi}\phi(X_{k},M_{k}) (4) where each factor \phi is a prior or a likelihood, defined on some subset of the variables X_{k},M_{k} . Concretely, we have the following factor types: \displaystyle\begin{split}&\phi^{\textrm{HL}}(X_{k},M_{k})=L(X_{k},M_{k};Z_{k})\propto p(Z_{k}|X_{k},M_{k})\\ &\phi^{\textrm{HP}}(X_{k},M_{k})\propto p(X_{k}|M_{k})\\ &\phi^{\textrm{L}}(X_{k})\propto p(Z_{k}|X_{k})\\ &\phi^{\textrm{P}}(X_{k})\propto p(X_{k})\\ &\phi^{\textrm{DL}}(M_{k})=L(M_{k};Q_{k})\propto P(Q_{k}|M_{k})\\ &\phi^{\textrm{DP}}(M_{k})\propto P(M_{k})\end{split} (5) where L(X_{k},M_{k};Z_{k}) is the likelihood of the continous X_{k} and discrete M_{k} variables given the evidence Z_{k} , and L(M_{k};Q_{k}) is the likelihood of the discrete variables M_{k} given evidence Q_{k} . A visual example of a hybrid factor graph which corresponds to the hybrid Bayes network in figure 2 with known measurements is shown in figure 3 . Full details of the factor types are provided in the supplementary. Going forward, we will use Z to refer to both continuous and discrete measurements for brevity. V Gaussian and Nonlinear Models In this section, we provide details of the hybrid factors and conditionals, both linear and nonlinear, which we later use for our experimental validation. We assume that each component of a hybrid linear factor/conditional, indexed by its discrete mode assignment, follows a Gaussian distribution. This lets us define the hybrid factor graph, hybrid Bayes network, and elimination algorithms in a concrete manner, and allows development of efficient computational tools for inference in robotics. We specify an assignment m of the subset of discrete variables M_{i}\subseteq M by m\circeq M_{i} . For computational efficiency, we store the components of a factor/conditional in a tree structure where each discrete variable corresponds to a level in the tree. Within each model, we can have multiple components depending on the number of discrete variables. A tree data structure allows us to access each component in O(\log M_{i}) time. The tree structure also allows for easier hypothesis pruning VII-A , since we can prune branches which are below a certain specified threshold. Fig. 4 : An example of the tree-structured hybrid conditional/factor representing P(X_{k}|M_{i}) where M_{i}=\{m_{0},m_{1}\} with cardinality 2 for each discrete variable. V-A Hybrid Conditional Each conditional in the hybrid Bayes network is represented as a Hybrid Gaussian Conditional which consists of two parts: a discrete probability distribution P(m) and a Gaussian conditional p(x|m,z) . P(x,m|z)=P(m)p(x|m,z) (6) We denote the probability p(x|m,z) as a Hybrid Gaussian Conditional Component which is defined as a set of Gaussian conditional densities indexed by m \displaystyle\begin{split}&p(x|m,z)=\bigg\{p^{m}(x|z);m\circeq M_{i}\bigg\}\\ &\int_{x}p^{m}(x|z)dx=1\end{split} (7) V-A 1 Hybrid Nonlinear Conditional In the nonlinear case, we define a hybrid conditional as a set of nonlinear Gaussian conditional densities, each of which is indexed by an assignment of the discrete variables m\circeq M_{i} . \displaystyle\begin{split}P(z|x,m)&=\{p^{m}(z|x);m\circeq M_{i}\}\\ p^{m}(z|x)&=\frac{1}{\sqrt{|2\pi\Sigma_{\textrm{z}}^{m}|}}\exp\Bigg(-\frac{1}{2}\|h_{m}(x)-z\|^{2}_{\Sigma_{\textrm{z}}^{m}}\Bigg)\end{split} (8) We similarly define conditionals for motion models and priors. V-A 2 Hybrid Linear Conditional For the linear case, the hybrid conditional is a set of linear Gaussian conditional densities, similarly indexed by an assignment of discrete variables m\circeq M_{i} . \displaystyle\begin{split}P(z|x,m)&=\{p^{m}(z|x);m\circeq M_{i}\}\\ p^{m}(z|x)&=\frac{1}{\sqrt{|2\pi\Sigma_{\textrm{Z}}^{m}|}}\exp\Bigg(-\frac{1}{2}\|H_{m}x-z\|^{2}_{\Sigma_{\textrm{Z}}^{m}}\Bigg)\end{split} (9) V-B Hybrid Factor In this section, we define the hybrid nonlinear factor and the hybrid Gaussian factor, both of which we can add to a HFG. Similar to Hybrid Conditionals, we store each of the underlying components in a tree structure indexed through the discrete variables. V-B 1 Hybrid Nonlinear Factor Many measurement and motion models we encounter in practice are nonlinear and thus we require a suitable factor model for nonlinear functions in a discrete-continuous scenario. We define a hybrid factor with a discrete mode dependent nonlinear function over its continuous variables h^{m}(x) as a Hybrid Nonlinear Factor \phi^{\textrm{HNF}} . Each component of the Hybrid Nonlinear Factor is a nonlinear factor proportional to a Gaussian density, which accounts for the normalizer as well. \displaystyle\begin{split}&\phi^{\textrm{HNF}}(x,M_{i})=\bigg\{\phi^{m}_{\textrm{hnf}}(x);m\circeq M_{i}\bigg\}\\ &\phi^{m}_{\textrm{hnf}}(x)\propto\frac{1}{\sqrt{|2\pi\Sigma^{m}|}}\exp\Bigg(-\frac{1}{2}\|h^{m}(x)-\mu^{m}\|^{2}_{\Sigma^{m}}\Bigg)\end{split} (10) Since the normalizer is potentially dependent on the discrete mode, we can include that within the factor definition. \phi^{m}_{\textrm{hnf}}(x)\propto\exp\bigg(-\frac{1}{2}\bigg[\|h^{m}(x)-z\|^{2}_{\Sigma^{m}}+2\log(\sqrt{|2\pi\Sigma^{m}|})\bigg]\bigg) (11) V-B 2 Hybrid Gaussian Factor In the case our underlying function is proportional to a linear Gaussian probability density function over the continuous variables, specified on a per discrete mode basis z=H^{m}x+\epsilon^{\textrm{L}} (12) where H^{m}\in\mathbb{R}^{\textrm{dim}(x)\times\textrm{dim}(x)},\epsilon^{\textrm{L}}\sim\mathcal{N}(0,\Sigma^{m}) , we can define a Hybrid Gaussian Factor (HGF). A HGF is thus a set of linear Gaussian factor components, each indexed by an assignment of the discrete variables. \displaystyle\begin{split}&\phi^{\textrm{HGF}}(x,M_{i})=\bigg\{\phi^{m}_{\textrm{hgf}}(x);m\circeq M_{i}\bigg\}\\ &\phi^{m}_{\textrm{hgf}}(x)\propto\frac{1}{\sqrt{|2\pi\Sigma^{m}|}}\exp\Bigg(-\frac{1}{2}\|H^{m}x-z\|^{2}_{\Sigma^{m}}\Bigg)\end{split} (13) Given our definitions of the hybrid factors, it becomes imperative to account for the discrete-mode dependent normalizer within the factor definition in a computationally feasible manner. When operating in the negative log-likelihood space, the factor takes the form, following which we can take its square root form [ 12 ] \displaystyle\begin{split}-\log&\phi^{m}_{\textrm{hgf}}(x)\propto\frac{1}{2}\|Hx-\mu^{m}\|^{2}_{\Sigma^{m}}+\log(\sqrt{|2\pi\Sigma^{m}|})\\ &\propto\frac{1}{2}\|(\Sigma^{m})^{-1/2}(Hx-\mu^{m})\|^{2}_{2}+\log(\sqrt{|2\pi\Sigma^{m}|})\\ &=\frac{1}{2}\bigg(\|A^{m}x-b^{m}\|^{2}_{2}+2\log(\sqrt{|2\pi\Sigma^{m}|})\bigg)\end{split} (14) where A^{m}=(\Sigma^{m})^{-1/2}H and b^{m}=(\Sigma^{m})^{-1/2}\mu^{m} . In practice, we store the factor and the constant value separately, which added together gives the original factor: \displaystyle-\log\phi^{m}_{\textrm{hgf}}(x) \displaystyle\propto\bigg\{\frac{1}{2}\|A^{m}x-b^{m}\|^{2}_{2},\log(\sqrt{|2\pi\Sigma^{m}|})\bigg\} (15) V-C Hybrid Nonlinear Factor Graph If our hybrid factor graph consists of nonlinear factors, including the Hybrid Nonlinear Factor defined above, we have a Hybrid Nonlinear Factor Graph \Phi^{\textrm{HN}} . \displaystyle\begin{split}\Phi^{\textrm{HN}}(X,M)&=\prod_{i}^{|\Phi^{\textrm{HN}}|}\phi^{\textrm{HNF}}(X_{i},M_{i})\phi^{\textrm{HP}}(X_{i},M_{i})\\ &\phi^{\textrm{L}}(X_{i})\phi^{\textrm{P}}(X_{i})\phi^{\textrm{DL}}(M_{i})\phi^{\textrm{DP}}(M_{i})\end{split} (16) Hybrid prior factors need not be nonlinear, and discrete factors don’t have a nonlinear form. We use X_{i} ( M_{i} ) to denote subset of X ( M ) involved in the i^{\text{th}} factor. V-D Hybrid Gaussian Factor Graph If the factors in a hybrid factor graph consist of only linear factors, namely Hybrid Gaussian Factors , Linear Gaussian & Prior Factors and/or Discrete Factors , we denote this as a Hybrid Gaussian Factor Graph \Phi^{\textrm{HG}} . \displaystyle\begin{split}\Phi^{\textrm{HG}}(X,M)&=\prod_{i}^{|\Phi^{\textrm{HG}}|}\phi^{\textrm{HGF}}(X_{i},M_{i})\phi^{\textrm{HP}}(X_{i},M_{i})\\ &\phi^{\textrm{L}}(X_{i})\phi^{\textrm{P}}(X_{i})\phi^{\textrm{DL}}(M_{i})\phi^{\textrm{DP}}(M_{i})\end{split} (17) V-E Conditional As A Factor In many cases, we would like to directly add a hybrid Gaussian conditional P(x|\mathcal{X},\mathcal{M}) to our hybrid factor graph. Thus, we would need to model the conditional appropriately, since the normalizer for the conditional is potentially dependent on the discrete variables \mathcal{M} . We have defined our Hybrid Gaussian Conditional as P(x|y,m)=\frac{1}{\sqrt{|2\pi\Sigma^{m}|}}\exp\bigg(-\frac{1}{2}\|Rx+Sy-d\|^{2}_{\Sigma^{m}}\bigg) (18) where y\subseteq\mathcal{X} and m\subseteq\mathcal{M} . Since the normalizer is dependent on m , we have to account for it as well \displaystyle\begin{split}&P(x|y,m)=\frac{1}{\sqrt{|2\pi\Sigma^{m}|}}\exp\Big(-\frac{1}{2}\|Rx+Sy-d\|^{2}_{\Sigma^{m}}\Big)\\ &=\exp\Big(-\frac{1}{2}\log(|2\pi\Sigma^{m}|)\Big)\exp\Big(-\frac{1}{2}\|Rx+Sy-d\|^{2}_{\Sigma^{m}}\Big)\end{split} (19) We define C as C=\frac{1}{2}\log(|2\pi\Sigma^{m}|)-\min_{\tilde{m}}{\frac{1}{2}\log(|2\pi\Sigma^{\tilde{m}}|)} (20) such that C is positive so the first exponential term always evaluates to less than or equal to 1. Now, we can define the corresponding factor for the conditional as \displaystyle\begin{split}&P(x|y,m)\propto\phi(x,y,m)\\ &=\exp\bigg(-C\bigg)\exp\bigg(-\frac{1}{2}\|Rx+Sy-d\|^{2}_{\Sigma^{m}}\bigg)\end{split} (21) Thus, C is the negative-log normalization constant of the probability density function. In the case of discrete factors, this constant is 0 , but in the hybrid case it depends on the covariances of the individual Gaussian densities. VI Hybrid Elimination A key contribution of this work is a general variable elimination algorithm to convert a hybrid factor graph to a hybrid Bayes network representing the desired posterior distribution. While a factor graph allows us to condition our joint distribution on observed measurements, making for ease of modeling, a hybrid Bayes network lets us perform various computational operations such as MAP estimation, sampling, and marginalization. Thus being able to efficiently convert a hybrid factor graph to a valid hybrid Bayes network is vital to good performance in robotics applications. In this section, we derive the Sum-Product and Max-Product algorithms for variable elimination over the hybrid domain. To perform variable elimination, we need to provide an ordering of the variables, which is how the elimination algorithm proceeds from one variable to the next. In the case of Hybrid Factor Graphs, we use a strong ordering [ 32 , B.3.6] , where we order all the continuous variables followed by all the discrete variables. This gives a resulting hybrid Bayes network under the Conditional Linear Gaussian scheme, where discrete nodes cannot have continuous parents [ 25 , 27 ] . The ordering in-between only continuous or discrete variables, however, can be application specific. We describe general variable elimination algorithms which allow us to do this “exactly” and efficiently. In particular, we show how to handle the continuous-discrete boundary which arises due to our strong ordering, allowing for a general and consistent algorithm in both cases. Fig. 5 : The hybrid Bayes network resulting from our variable elimination algorithm applied to the factor graph in figure 3 . VI-A Sum-Product Algorithm We first consider the problem of obtaining the posterior distribution P(X,M|Z) over the continuous X and discrete M variables. To do this, we apply the Sum-Product algorithm on the HFG which performs variable elimination to convert the hybrid factor graph back to a hybrid Bayes network over only the latent variables X,M , giving us our desired posterior. Given our variable ordering, we eliminate each variable a_{j}\in\{X,M\} in turn, to obtain a conditional on that variable, and a factor \phi(\mathcal{S}_{j}) on its separator \mathcal{S}_{j}=(\mathcal{C}_{j},\mathcal{M}_{j}) . Here, \mathcal{C}_{j} and \mathcal{M}_{j} correspond to the continuous and discrete separators respectively. Starting with a continuous variable x_{j}\in X due to our strong ordering, we collect all the factors associated with the current variable to eliminate, and form a product factor: \psi(x_{j},\mathcal{S}_{j})=\prod_{\phi_{i}\in\Phi}\phi_{i}(x_{j},\mathcal{S}_{j}) (22) We factorize the product factor into a conditional distribution p(x_{j}|\mathcal{S}_{j}) and the separator factor \tau(\mathcal{S}_{j}) as \displaystyle\begin{split}&\tau(\mathcal{S}_{j})=\int_{x_{j}}\psi(x_{j},\mathcal{S}_{j})\\ &p(x_{j}|\mathcal{S}_{j})=\psi(x_{j},\mathcal{S}_{j})/\tau(\mathcal{S}_{j})\end{split} (23) In the case \mathcal{S}_{j}=\mathcal{C}_{j} , we have continuous elimination [ 11 ] . For hybrid factors where \mathcal{S}_{j}=(\mathcal{C}_{j},\mathcal{M}_{j}) , we perform continuous elimination for every indexed discrete mode. After we eliminate all the continuous variables, we will be at the continuous-discrete boundary , which requires special care. Here, while the conditional p(x_{j}|\mathcal{M}_{j}) is obtained as before, the separator factor \tau(\mathcal{M}_{j}) is only over discrete variables, and is thus a discrete factor. At this point, we are left with only discrete factors due to our strong ordering. We can now compute the many conditional distributions P(m_{j}|\mathcal{M}_{j}) and separator factors \tau(\mathcal{M}_{j}) as \displaystyle\begin{split}&\tau(\mathcal{M}_{j})=\sum_{m_{j}}\psi(m_{j},\mathcal{M}_{j})\\ &P(m_{j}|\mathcal{M}_{j})=\psi(m_{j},\mathcal{M}_{j})/\tau(\mathcal{M}_{j})\end{split} (24) This sequence of operations applied to each variable results in a set of conditionals, the product of which represents the hybrid Bayes network P(X,M) . VI-B Max-Product Algorithm Now we consider the problem of estimating the MAP of the variables X,M . To do so, we perform Max-Product over the hybrid factor graph, resulting in a series of functions which we can query to get the MAP value for each variable. Given a strong variable ordering, we eliminate each variable a_{j}\in\{X,M\} to obtain a function g on that variable and a separator factor on the separator variables \mathcal{S}_{j}=(C_{j},M_{j}) , where C_{j} and M_{j} are the continuous and discrete separators respectively. Similar to Sum-Product and starting with variable x_{j}\in X , we first collect all the factors connected to it and form the product factor \psi(x_{j},\mathcal{S}_{j})=\prod_{\phi_{i}\in\Phi}\phi_{i}(x_{j},\mathcal{S}_{j}) (25) We now factorize the product factor into a function which gives use the maximum value of x_{j} given the separator values g_{j}(\mathcal{S}_{j}) and the separator factor \tau(\mathcal{S}_{j}) as \displaystyle\begin{split}&g_{j}(\mathcal{S}_{j})=\arg\max_{x_{j}}\psi(x_{j},\mathcal{S}_{j})\\ &\tau(\mathcal{S}_{j})=\max_{x_{j}}\psi(x_{j},\mathcal{S}_{j})\end{split} (26) Once we reach the continuous-discrete boundary after eliminating all continuous variables, we take extra care to obtain the separator factor as a discrete factor: \displaystyle\begin{split}&g_{j}(\mathcal{M}_{j})=\arg\max_{x_{j}}\psi(x_{j},\mathcal{M}_{j})\\ &\tau(\mathcal{M}_{j})=\max_{x_{j}}\psi(x_{j},\mathcal{M}_{j})\end{split} (27) We can now continue with elimination as before, this time on discrete variables. Our final result g_{N}()g_{N-1}(m_{j})\dots g_{1}(\mathcal{S}_{1}) is a set of functions which when evaluated, gives us the MAP values for both continuous X and discrete M variables. VII Complexity Analysis & Management It is imperative we analyze the complexity of our proposed elimination algorithm because in the general case, the Discrete Bayes Network formed after elimination has an exponential number of hypotheses [ 32 ] . While continuous variable elimination is quadratic in its cost, discrete elimination is exponential. Consider eliminating a discrete variable m_{j} with cardinality K . The separator \mathcal{M}_{j} is dependent on the elimination ordering, since a poor ordering can introduce fill-in, leading to a high tree-width ( a.k.a . “dense” clique connectivity) of the graph. A tree-width of W for the separator \mathcal{M}_{j} gives us a cost of O(K^{W+1}) on average. In the worst case, the cost of discrete elimination can be O(K^{M}) , with M being the total number of discrete variables in the graph. This exponential cost is thus the primary reason for intractability when performing hybrid inference. VII-A Hypothesis Pruning To make inference tractable, we adopt hypothesis pruning, a simple yet effective scheme to keep the number of hypotheses manageable. Given a pruning number P , the idea is to evaluate the discrete probabilities, which are available thanks to our strong ordering, and set all probabilities outside the top P probabilities to 0 . Concretely, after a time interval during which we add a new discrete variable m_{j} , after we perform elimination of all the new variables added and we get a distribution over discrete variables P(D) , we set all the probabilities beyond the top P to 0 . This reduces the complexity of discrete elimination from O(K^{W+1}) to O(PK) where K is the cardinality of m_{j} added during the current elimination step. Since P\ll K^{D} , we can achieve real-time performance by suitably selecting a value for P . VII-B Dead Mode Removal Another approach to reducing the number of discrete hypotheses is evaluating whether a discrete mode is a certain assignment with high probability. Given a threshold value \delta_{\text{DMR}} , we compute the marginal probabilities of each discrete mode and if the probability for a specific value is greater than this threshold \delta_{\text{DMR}} , we consider that mode to be “dead”, since its entropy is sufficiently low. We then remove that mode from our optimization and reduce the hybrid factors and conditionals to now have a fixed assignment for that mode. P(X_{i}|M_{i}\setminus m)=\underset{m=i}{\text{choose}}P(X_{i}|M_{i});P(m=i)>\delta_{\text{DMR}} (28) where “choose” selects the underlying component corresponding to the discrete index m=i . VIII Experimental Results VIII-A City10000 Dataset We showcase our framework on the City10000 dataset from Hsiao et al . [ 18 ] , a 2D SLAM problem with ambiguous odometry measurements added at random and uncertain loop closures, upto 2000 timesteps. The ambiguities can be modeled using factor types #1 and #3 in [ 18 ] . ((a)) 2000 timesteps. ((b)) 5000 timesteps. ((c)) Estimates on the full dataset. ((d)) Using vanilla iSAM2. ((e)) Estimates from MH-iSAM2. ((f)) DC-SAM estimates. Fig. 6 : Hybrid Factor Graphs applied to the City10000 dataset. With 10 hypotheses retained at each update, our framework is able to handle ambiguous odometry measurements as well as switching modes for loop closures. In panel (d), iSAM2 is applied to the same dataset with randomly selected measurements and loop closures, seeing multiple failure modes. Our framework outperforms MH-iSAM2, while DC-SAM falls into a local minima and fails to recover. To use hybrid factor graphs for estimation on this dataset, we provide a hybrid motion model factor, and a hybrid switching factor for loop closures. The motion model factor accepts multiple measurements, with the discrete mode selecting which measurement to use. \phi(X_{k},X_{k+1},M_{k})=\{\phi_{m}(X_{k},X_{k+1};\mu_{m},\Sigma);m\in|M_{k}|\} The switching factor has a binary mode where L_{k}=1 indicates a loop and L_{k}=0 is not a loop. We achieve this by using a noise model with a tight covariance (same as the motion model) for L_{k}=1 and a loose covariance of \Sigma_{0}=10.0 for non-loops L_{k}=0 . \phi(X_{k},X_{j},L_{k})=\{\phi_{l}(X_{k},X_{j};\mu,\Sigma_{l});l\in|L_{k}|\} As baselines, we compare our framework against iSAM2 [ 21 ] , MH-iSAM2 [ 18 ] , and DC-SAM [ 14 ] . iSAM2 only supports continuous variables so we select one of the multiple ambiguous odometry measurements at random and provide true loop closures, whereas MH-iSAM2 and DC-SAM are hybrid frameworks capable of both discrete and continuous estimation. The subplots in figure 6 show the best hybrid estimate over time for the City10000 dataset from [ 18 ] . In this experiment, we ran hybrid elimination after every third hybrid factor, regardless of the number of continuous pose constraints in between. We take care to only re-eliminate the part of the graph affected by the new factors, a la iSAM [ 21 ] . After every 10th hybrid elimination we restrict all non-linear factors according to the fixed values obtained by dead mode removal, and then re-linearize, followed by a full batch elimination. This is fast because there are typically only few discrete variables left after our pruning/DMR strategy. Not all hypotheses are pruned however: at k=2000 (panel (a)) it is clear that the continuous trajectory corresponding to the discrete MPE is incorrect. In panel (d), we see that our framework was able to recover from the early mistake to a much better hybrid estimate. In contrast, MH-iSAM2 displays minor errors which are never resolved, and DC-SAM falls into a local minima which it does not recover from yielding poor results. VIII-B Runtime Comparisons Fig. 7 : Plot showing time per solver update step. Our elimination scheme is slower than continuous-only iSAM2, but is more efficient than MH-iSAM2 [ 18 ] . We also compare runtimes between our framework, with pruning and dead mode removal (DMR) \delta_{\text{DMR}}=0.8 , MH-iSAM2, and iSAM2 in figure 7 . Our approach is faster than MH-iSAM2 with similar results, and provides far better estimates than iSAM2. IX Conclusion In this work, we have presented a rigorous derivation of Hybrid Factor Graphs which extends Hybrid Bayes Networks to perform inference in general discrete-continuous problems. We have shown our formulation allows for exact inference using variable elimination via the Sum-Product and Max-Product algorithms. Furthermore, we propose two schemes, Pruning and Dead Mode Removal, to curb the exponential growth of discrete hypotheses, allowing for efficient performance. Our experimental results demonstrate the applicability of our approach to different robotics problems. Importantly, a contact estimator for legged robots devised upon our framework is capable of detecting discrete contact events using only kinematic information, thus being vastly more simple compared to other approaches. Given the generality of our approach, we hope to further extend it to incorporate various accuracy, robustness, and efficiency improvements which have been proposed over the years towards factor graph based smoothing problems. We hope this will lead to widespread applicability and adoption of our work. Appendix A Hybrid Bayes Network to a Hybrid Factor Graph A-A Hybrid Bayes Network Decomposition A Hybrid Bayes Network (HBN) represents the joint probability distribution over continuous states X , discrete modes M and measurements over both Z as P(X,M,Z) We can use the probability chain rule to decompose the joint probability of the HBN into a set of measurement conditionals and a distribution over the latent variables P(X,M,Z)=P(Z|X,M)P(X,M) Additionally, we can decompose the distribution over X and M in a similar fashion to give us a conditional of the continuous variables dependent on the discrete variables and a prior on the discrete variables. P(X,M,Z)=P(Z|X,M)P(X|M)P(M) A-B Converting a Hybrid Bayes Network to a Hybrid Factor Graph We defined a hybrid Bayes network with the form P(X,M,Z)=P(Z|X,M)P(X|M)P(M) In order to compute the posterior, the Hybrid Bayes Network can be factorized as \displaystyle\begin{split}P(X,M,Z)&=P(Z|X,M)P(X,M)\\ &=P(Z_{X},Z_{M}|X,M)P(X,M)\end{split} The desired posterior is proportional to the factorized form of the HBN. To see this, we apply Bayes’ Law to the posterior probability which yields \displaystyle\begin{split}P(X,M|Z_{X},Z_{M})&=\frac{P(Z_{X},Z_{M}|X,M)P(X,M)}{P(Z_{X},Z_{M})}\\ &\propto P(Z_{X},Z_{M}|X,M)P(X,M)\end{split} We can further simplify this by applying the chain rule to P(X,M) \displaystyle P(X,M|Z_{X},Z_{M})\propto P(Z_{X},Z_{M}|X,M)P(X|M)P(M) Furthermore, by applying the chain rule on Z_{X} and Z_{M} , we get P(Z_{X},Z_{M}|M,X)=P(Z_{X}|M,X,Z_{M})P(Z_{M}|X,M) (29) Since continuous measurements are independent of discrete measurements given the continuous variables and discrete modes, and discrete measurements are independent of continuous variables (since there is no relationship between them), we can take advantage of the conditional independence to simplify 29 to P(Z_{X},Z_{M}|M,X)=P(Z_{X}|M,X)P(Z_{M}|M) (30) which we then substitute to give us the following expression: P(X,M|Z_{X},Z_{M})\propto P(Z_{X}|X,M)P(Z_{M}|M)P(M)P(X|M) (31) Since we are given the measurement instantiations, we use likelihoods which are proportional to probabilities, as they capture the effect of the latent variables X,M on the observed measurements Z , and are denoted as L(X,M;Z)\propto P(Z|X,M) (32) Normally, we can drop constants when leveraging this proportionality, however in the hybrid scenario, parts of the constants can potentially be dependent on M , necessitating their involvement in the likelihood and subsequent factor definitions. The corresponding likelihoods thus become \displaystyle L(X,M;Z_{X})\propto P(Z_{X}|X,M) \displaystyle L(M;Z_{M})\propto P(Z_{M}|M) Using the above likelihoods, we can rewrite 31 as P(X,M|Z_{X},Z_{M})\propto L(X,M;Z_{X})L(M;Z_{M})P(M)P(X|M) Thus we have a factored form of our desired posterior, which has an equivalence to a Hybrid Factor Graph . A-C Discrete Assignment We define each assignment m of the subset \mathcal{M}\subseteq M discrete variables by the notation m\circeq\mathcal{M} . For example, if we have \mathcal{M}=\{m_{1},m_{2}\} as the subset of discrete variables with m_{1},m_{2}\in\{0,1\} , we can define an assignment m\circeq\mathcal{M} as one of the following cases m=\begin{cases}\{0,0\}\text{ where }m_{1}=0,m_{2}=0\\ \{0,1\}\text{ where }m_{1}=0,m_{2}=1\\ \{1,0\}\text{ where }m_{1}=1,m_{2}=0\\ \{1,1\}\text{ where }m_{1}=1,m_{2}=1\\ \end{cases} A-D Converting a Probability Density to a Factor We now describe how to convert a hybrid probability density to a hybrid likelihood, which in turn can be used in our factor definition. Assuming the errors of our general measurement model follow a Gaussian distribution \mathcal{N}(0,\Sigma^{m}) , the probability density function (PDF) can be written as \displaystyle\begin{split}&p(z|x,\mathcal{M})=\bigg\{p^{m}(z|x);m\circeq\mathcal{M}\ \bigg\}\\ &p^{m}(z|x)=\frac{1}{\sqrt{|2\pi\Sigma^{m}|}}\exp\Bigg(-\frac{1}{2}\|z-h^{m}(x)\|^{2}_{\Sigma^{m}}\Bigg)\end{split} where z is an instantiation of Z , x is a vector instantiation of X , m is a specific assignment of the discrete modes \mathcal{M}\subseteq M , and the density is potentially dependent on the discrete mode assignment m via h^{m} and covariance \Sigma^{m} . In a robotics setting, we observe a measurement z from a sensor, and this gives the likelihood function as \displaystyle\begin{split}L(x,\mathcal{M};z)&=\bigg\{l^{m}(x;z);m\circeq\mathcal{M}\bigg\}\\ l^{m}(x;z)&\propto\frac{1}{\sqrt{|2\pi\Sigma^{m}|}}\exp\Bigg(-\frac{1}{2}\|h^{m}(x)-z\|^{2}_{\Sigma^{m}}\Bigg)\end{split} Previously, we could drop the normalizer in the Gaussian density function since it was a constant. However, in the hybrid case, the covariance \Sigma^{m} is potentially dependent on the discrete mode assignment m , necessitating the inclusion of the Gaussian normalizer within the likelihood function definition. We use the above likelihood for our factor definitions, thus getting the corresponding hybrid factor \displaystyle\begin{split}\phi(x)=\bigg\{l^{m}(x;z);m\circeq\mathcal{M}\bigg\}\\ \end{split} Similar factors can be defined for other relationships, such as motion models. For computational efficiency, we store the factor components as a tree where each level corresponds to a discrete variable involved in the factor. Thus, each factor component corresponds to a leaf in the tree for a particular discrete assignment. Appendix B Factor Types From the factorized form of the hybrid Bayes network, L(X,M;Z_{X}) and P(X|M) correspond to hybrid measurement factors and hybrid prior factors respectively, and L(M;Z_{M}) and P(M) are the measurement factors and the set of priors respectively on the discrete modes. \displaystyle\begin{split}&\phi^{\textrm{HL}}(X,M)=L(X,M;Z_{X})\propto P(Z_{X}|X,M)\\ &\phi^{\textrm{HP}}(X,M)\propto P(X|M)\\ &\phi^{\textrm{DL}}(M)=L(M;Z_{M})\propto P(Z_{M}|M)\\ &\phi^{\textrm{DP}}(M)\propto P(M)\end{split} A hybrid factor graph consists of many (potentially hundreds) of factors. Each factor falls under one of the aforementioned types of factors and collectively are denoted as a product. For instance, L(X,M;Z_{X}) is a product of hybrid factors given as \phi^{\textrm{HL}}(X,M)=\prod_{i}^{n}\phi(x_{i},Pa(x_{i});\mathcal{Z}_{i})\propto L(X,M;Z_{X}) where n is the number of continuous variables, and Pa(x) represents the set of continuous and discrete variables which are parents of x i.e . x has a dependency on them. \phi^{\textrm{HP}}(X,M) is the product of all the mode-dependent priors on the n continuous variables \phi^{\textrm{HP}}(X,M)=\prod_{i}^{n}\phi(x_{i},Pa(x_{i}))\propto P(X|M) Hybrid factors as described above consist of sub-factors, each corresponding to a mode assignment for m_{i} , e.g . \phi^{\textrm{HL}}(x_{j},m_{i})=\{\phi^{m}(x_{j});m\circeq m_{i}\} In a similar vein, L(M;Z_{M}) is the product of factors on d discrete variables and their respective parents, given measurements on those variables. \phi^{\textrm{DL}}(M)=\prod_{i}^{d}\phi(m_{i},Pa(m_{i});\mathcal{Z}_{i})\propto L(M;Z_{M}) and \phi^{\textrm{DP}}(M) is the product of discrete priors \phi^{\textrm{DP}}(M)=\prod_{i}^{d}\phi(m_{i},Pa(m_{i}))\propto P(M) Appendix C Hybrid Conditional Definitions C-A Hybrid Gaussian Conditional A Hybrid Gaussian Conditional in a hybrid Bayes network consists of two parts: a discrete probability distribution P(m) and a Gaussian conditional conditioned on the corresponding discrete variable p(x|m,z) . P(x,m|z)=P(m)p(x|m,z) We denote the probability p(x|m,z) as a Hybrid Gaussian Conditional Component which is defined as a set of Gaussian conditional densities indexed by m \displaystyle\begin{split}&p(x|m,z)=\bigg\{p^{m}(x|z);m\circeq M\bigg\}\\ &\int_{x}p^{m}(x|z)dx=1\end{split} C-B Nonlinear If a sensor model has different operational modalities, each being a nonlinear measurement function, we can capture the different measurements z\in\mathbb{R}^{d} based on the underlying state x\in\mathbb{R}^{n} via a discrete switching variable m\in\mathbb{Z} . For example, a sensor with 2 modalities can be specified as z=\begin{cases}h_{0}(x)+\epsilon_{0}&\mbox{if }m=0\\ h_{1}(x)+\epsilon_{1}&\mbox{if }m=1\end{cases} where \epsilon_{0}\sim\mathcal{N}(0,\Sigma_{\textrm{Z}}^{0}),\epsilon_{1}\sim\mathcal{N}(0,\Sigma_{\textrm{Z}}^{1}) are noise values assumed to be sampled from two different zero-mean Gaussian distributions. The above defined hybrid measurement model can be specified as a set of nonlinear Gaussian conditional densities, each of which is indexed by an assignment of the discrete variables m\circeq\mathcal{M} . \displaystyle\begin{split}P(z|x,m)&=\{p^{m}(z|x);m\circeq\mathcal{M}\}\\ p^{m}(z|x)&=\frac{1}{\sqrt{|2\pi\Sigma_{\textrm{Z}}^{m}|}}\exp\Bigg(-\frac{1}{2}\|h_{m}(x)-z\|^{2}_{\Sigma_{\textrm{Z}}^{m}}\Bigg)\end{split} We can similarly define a nonlinear motion model. A binary version can be specified as x_{t+1}=\begin{cases}f_{0}(x_{t})+\epsilon_{0}&\text{if }m=0\\ f_{1}(x_{t})+\epsilon_{1}&\text{if }m=1\end{cases} with the hybrid density \displaystyle\begin{split}P(x_{t+1}|x_{t},m)&=\{p^{m}(x_{t+1}|x_{t});m\circeq\mathcal{M}\}\\ p^{m}(x_{t+1}|x_{t})&=\frac{1}{\sqrt{|2\pi\Sigma_{\textrm{M}}^{m}|}}\exp\Bigg(-\frac{1}{2}\|f_{m}(x_{t})-x_{t+1}\|^{2}_{\Sigma_{\textrm{M}}^{m}}\Bigg)\end{split} and a nonlinear prior with mean \mu_{m}\in\mathbb{R}^{n} , potentially dependent on the discrete mode m \displaystyle\begin{split}P(x|m)&=\{p^{m}(x);m\circeq\mathcal{M}\}\\ p^{m}(x)&=\frac{1}{\sqrt{|2\pi\Sigma_{\textrm{P}}^{m}|}}\exp\Bigg(-\frac{1}{2}\|x-\mu_{m}\|^{2}_{\Sigma_{\textrm{P}}^{m}}\Bigg)\end{split} (33) In this case, since the means and covariances are potentially dependent on the discrete mode m , it is imperative to take care not to ignore the normalization constants, as is usually done in the continuous or discrete cases. C-C Linear In the linear case, each conditional in the hybrid Bayes network is represented as a set of linear Gaussian conditional densities. Similar to the nonlinear case, we have a (binary) linear measurement model z=\begin{cases}H_{0}x+\epsilon_{0}&\text{if }m=0\\ H_{1}x+\epsilon_{1}&\text{if }m=1\end{cases} given H_{m}\in\mathbb{R}^{\textrm{dim}(z)\times\textrm{dim}(x)},\epsilon_{0}\sim\mathcal{N}(0,\Sigma_{\textrm{Z}}^{0}),\epsilon_{1}\sim\mathcal{N}(0,\Sigma_{\textrm{Z}}^{1}) , giving the Gaussian densities as \displaystyle\begin{split}P(z|x,m)&=\{p^{m}(z|x);m\circeq\mathcal{M}\}\\ p^{m}(z|x)&=\frac{1}{\sqrt{|2\pi\Sigma_{\textrm{Z}}^{m}|}}\exp\Bigg(-\frac{1}{2}\|H_{m}x-z\|^{2}_{\Sigma_{\textrm{Z}}^{m}}\Bigg)\end{split} The motion model with a binary mode can be defined as x_{t+1}=\begin{cases}F_{0}x_{t}+\epsilon_{0}&\mbox{if }m=0\\ F_{1}x_{t}+\epsilon_{1}&\mbox{if }m=1\end{cases} with F_{m}\in\mathbb{R}^{\textrm{dim}(x_{t})\times\textrm{dim}(x_{t})},\epsilon_{0}\sim\mathcal{N}(0,\Sigma_{\textrm{M}}^{0}),\epsilon_{1}\sim\mathcal{N}(0,\Sigma_{\textrm{M}}^{1}) , and the linear densities defined as \displaystyle\begin{split}&P(x_{t+1}|x_{t},m)=\{p^{m}(x_{t+1}|x_{t});m\circeq\mathcal{M}\}\\ &p^{m}(x_{t+1}|x_{t})=\frac{1}{\sqrt{|2\pi\Sigma_{\textrm{M}}^{m}|}}\exp\Bigg(-\frac{1}{2}\|F_{m}x_{t}-x_{t+1}\|^{2}_{\Sigma_{\textrm{M}}^{m}}\Bigg)\end{split} and the hybrid prior density is the same as the nonlinear version viz . 33 . Appendix D Hybrid Factor Definitions D-A Hybrid Nonlinear Factor We define a Hybrid Nonlinear Factor as a set of functions each of which is proportional to a Gaussian density over an underlying nonlinear function. \displaystyle\begin{split}&\phi^{\textrm{HNF}}(x,\mathcal{M})=\bigg\{\phi^{m}_{\textrm{hnf}}(x);m\circeq\mathcal{M}\bigg\}\\ &\phi^{m}_{\textrm{hnf}}(x)\propto\frac{1}{\sqrt{|2\pi\Sigma^{m}|}}\exp\Bigg(-\frac{1}{2}\|h^{m}(x)-\mu^{m}\|^{2}_{\Sigma^{m}}\Bigg)\end{split} A hybrid nonlinear factor can have as its components either a nonlinear measurement model \phi^{m}_{\textrm{hnf}}(x)=\phi^{m}_{h}(x)\propto\frac{1}{\sqrt{|2\pi\Sigma^{m}|}}\exp\Bigg(-\frac{1}{2}\|h^{m}(x)-z\|^{2}_{\Sigma^{m}}\Bigg) or a nonlinear motion model \displaystyle\begin{split}\phi^{m}_{\textrm{hnf}}(x_{t},x_{t+1})&\propto\phi^{m}_{f}(x_{t},x_{t+1})\\ &=\frac{1}{\sqrt{|2\pi\Sigma^{m}|}}\exp\Bigg(-\frac{1}{2}\|f^{m}(x_{t})-x_{t+1}\|^{2}_{\Sigma^{m}}\Bigg)\end{split} both of which have the same general form. We can simplify the hybrid nonlinear factor definition to a general exponential form \displaystyle\begin{split}\phi^{m}_{\textrm{hnf}}(x)&\propto\frac{1}{\sqrt{|2\pi\Sigma^{m}|}}\exp\Bigg(-\frac{1}{2}\|h^{m}(x)-\mu^{m}\|^{2}_{\Sigma^{m}}\Bigg)\\ &=\exp\Bigg(-\frac{1}{2}\|h^{m}(x)-z\|^{2}_{\Sigma^{m}}+\log(\frac{1}{\sqrt{|2\pi\Sigma^{m}|}})\Bigg)\\ &=\exp\Bigg(-\frac{1}{2}\|h^{m}(x)-z\|^{2}_{\Sigma^{m}}-\log(\sqrt{|2\pi\Sigma^{m}|})\Bigg)\\ &=\exp\Bigg(-\frac{1}{2}\bigg(\|h^{m}(x)-z\|^{2}_{\Sigma^{m}}+2\log(\sqrt{|2\pi\Sigma^{m}|})\bigg)\Bigg)\end{split} D-B Hybrid Gaussian Factor A hybrid factor in which each component is proportional to a Gaussian probability density function over the continuous variables, but with a linear function specified on a per discrete mode basis z=H^{m}x+\epsilon^{\textrm{L}} where H^{m}\in\mathbb{R}^{\textrm{dim}(x)\times\textrm{dim}(x)},\epsilon^{\textrm{L}}\sim\mathcal{N}(0,\Sigma^{m}) , is defined as a Hybrid Gaussian Factor. \displaystyle\begin{split}&\phi^{\textrm{HGF}}(x,\mathcal{M})=\bigg\{\phi^{m}_{\textrm{hgf}}(x);m\circeq\mathcal{M}\bigg\}\\ &\phi^{m}_{\textrm{hgf}}(x)\propto\frac{1}{\sqrt{|2\pi\Sigma^{m}|}}\exp\Bigg(-\frac{1}{2}\|H^{m}x-z\|^{2}_{\Sigma^{m}}\Bigg)\end{split} If we linearize a nonlinear function at an initial estimate x^{0} h(x)=h(x^{0}+\Delta)\approx h(x^{0})+\Delta where H the Jacobian matrix of h at x^{0} and \Delta=x-x^{0} is the difference between the initial estimate and the true value a.k.a . the state update vector , we get a similar factor definition \displaystyle\begin{split}&\phi^{\textrm{HGF}}(x,\mathcal{M})=\bigg\{\phi^{m}_{\textrm{hgf}}(x);m\circeq\mathcal{M}\bigg\}\\ &\phi^{m}_{\textrm{hgf}}(x)\propto\frac{1}{\sqrt{|2\pi\Sigma^{m}|}}\exp\Bigg(-\frac{1}{2}\|H^{m}\Delta-(z-h(x^{0}))\|^{2}_{\Sigma^{m}}\Bigg)\\ &=\frac{1}{\sqrt{|2\pi\Sigma^{m}|}}\exp\Bigg(-\frac{1}{2}\|H^{m}\Delta-\tilde{z}^{m}\|^{2}_{\Sigma^{m}}\Bigg)\end{split} where \tilde{z}=z-h(x^{0}) . For a discrete mode-dependent motion model between two continuous variables x_{t},x_{t+1} x_{t+1}=F^{m}x_{t}+\epsilon^{\textrm{L}} we can define the hybrid Gaussian factor as \displaystyle\begin{split}&\phi^{\textrm{HGF}}(x,\mathcal{M})=\bigg\{\phi^{m}_{\textrm{hgf}}(x);m\circeq\mathcal{M}\bigg\}\\ &\phi^{m}_{\textrm{hgf}}(x)\propto\frac{1}{\sqrt{|2\pi\Sigma^{m}|}}\exp\Bigg(-\frac{1}{2}\|F^{m}x_{t}-x_{t+1}\|^{2}_{\Sigma^{m}}\Bigg)\end{split} Finally, a hybrid prior factor with mode-dependent means \mu^{m}\in\mathbb{R}^{\textrm{dim}(x)} is defined as \displaystyle\begin{split}&\phi^{\textrm{HGF}}(x,\mathcal{M})=\bigg\{\phi^{m}_{\textrm{hgf}}(x);m\circeq\mathcal{M}\bigg\}\\ &\phi^{m}_{\textrm{hgf}}(x)\propto\frac{1}{\sqrt{|2\pi\Sigma^{m}|}}\exp\Bigg(-\frac{1}{2}\|x-\mu^{m}\|^{2}_{\Sigma^{m}}\Bigg)\end{split} Based on the above definitions, we can derive a general form for the hybrid Gaussian factor components \displaystyle\begin{split}\phi^{m}_{\textrm{hgf}}(x)&\propto\frac{1}{\sqrt{|2\pi\Sigma^{m}|}}\exp\Bigg(-\frac{1}{2}\|Hx-\mu^{m}\|^{2}_{\Sigma^{m}}\Bigg)\\ &=\exp\Bigg(-\frac{1}{2}\|Hx-\mu^{m}\|^{2}_{\Sigma^{m}}-\log(\sqrt{|2\pi\Sigma^{m}|})\Bigg)\end{split} Appendix E Notes about Conditional as a Factor A few things to note here. The first is that the factor is actually two factors, one on the error and the other on the normalizer. The one on the error is inserted as a regular factor, but the factor on the normalizer is added to the appropriate leaf when we create the hybrid factor tree structure. This is added to the factor on the error at the corresponding discrete assignment. The second is that based on our definition of C , if the normalizer is independent of m , C will evaluate to 0 , leading to the factor on the normalizer to equate to 1 and effectively vanish from our computations. This is a useful property as it allows us to generalize to both cases where \Sigma is dependent on and independent of the discrete separator. Thus for each conditional added to the hybrid factor graph, we have at most two factors we need to add. In the case that the normalizer is not dependent on the discrete separator, it simplifies to a single factor definition. Appendix F General Elimination Algorithm We first develop a high-level intuition of the various steps involved in the elimination process. The account below is geared towards the Sum-Product algorithm but a similar scheme is involved in the Max-Product algorithm. Subsequently, we provide details (mathematical and computational) about each step in the supplementary material. We begin by eliminating the continuous variables X first \displaystyle\begin{split}P(X|M,&Z_{X})\phi(M;Z_{X})=\\ &\textrm{ELIMINATE}(L(X,M;Z_{X})\phi(X,M),X)\end{split} with \phi(M;Z_{X}) being a factor on the separator discrete modes. In the case of the continuous-discrete boundary, it is not clear how to perform the elimination and obtain \phi(M;Z_{X}) , thus during the derivation of elimination we show how it yields a discrete factor . Inserting the result of the continuous elimination back into the original probability expansion gives us \displaystyle\begin{split}P(X,M|&Z_{X},Z_{M})\propto\\ &P(X|M,Z_{X})\phi(M;Z_{X})L(M;Z_{M})P(M)\end{split} (34) The first term, P(X|M,Z_{X}) , corresponds to a Hybrid Bayes Network (HBN) which is the state probability given the discrete mode sequence, and is exactly the continuous state estimation problem [ 1 ] . Like in continuous state estimation, if we want the MAP estimate of the continuous variables, we can optimize the HBN to get them as a function of the discrete mode sequence. \displaystyle X^{*}(M)=\arg\max_{X}P(X|M,Z_{X}) (35) Fig. 8 : The hybrid factor graph after all continuous variables have been eliminated. This results in a partial hybrid Bayes net and a Discrete Factor Graph since the factors are only connected to discrete variables now. We now turn our attention to the remaining terms in 34 \phi(M;Z_{X})L(M;Z_{M})P(M) In this case they, form a Discrete Factor Graph with measurements factors and priors on the discrete modes respectively. We can eliminate this discrete factor graph in a manner similar to continuous elimination, giving us a Discrete Bayes Network which represents P(M|Z_{M},Z_{X})=P(M|Z) . P(M|Z_{M},Z_{X})=\textrm{ELIMINATE}(\phi(M;Z_{X})L(M;Z_{M})P(M),M) In the case of Max-Product , we instead optimize the discrete factor graph to compute the Most Probable Explanation (MPE) [ 5 ] directly. Given the MPE, we can plug that into 35 to retrieve the optimal continuous state sequence. Fig. 9 : A full hybrid Bayes net after both the continuous and discrete variables have been eliminated. Appendix G Sum-Product for Hybrid Factor Graphs The Sum-Product algorithm is used to convert a Hybrid Factor Graph to a Hybrid Bayes Network . Here, we provide detailed derivations for each of the various variable combinations. G-A Continuous-Only The case where we wish to eliminate a continuous variable that has a separator consisting of only continuous variables \mathcal{C}_{j} . Following the Sum-Product algorithm, we get the conditional Gaussian density function p(x_{j}|\mathcal{C}_{j}) and the separator factor \tau(\mathcal{C}_{j}) . \displaystyle\begin{split}p(x_{j}|\mathcal{C}_{j})=&\frac{1}{q(\mu_{x_{j}}(\mathcal{C}_{j}))\sqrt{|2\pi\Sigma|}}\\ &\exp\Bigg(-\frac{1}{2}\|R_{j}x_{j}+T_{j}\mathcal{C}_{j}-d_{j}\|_{2}^{2}\Bigg)\\ \tau(\mathcal{C}_{j})=&\exp\Bigg(-\frac{1}{2}\|A_{\tau}\mathcal{C}_{j}-b_{\tau}\|_{2}^{2}\Bigg)\\ &q(\mu_{x_{j}}(\mathcal{C}_{j}))\sqrt{|2\pi\Sigma|}\end{split} Furthermore, in continuous-only estimation, the terms q(\mu_{x_{j}}(\mathcal{C}_{j}))=1 and \sqrt{|2\pi\Sigma|} behave like scaling constant. Since \Sigma is independent of x_{j} or \mathcal{C}_{j} , we can drop the corrective normalizer term \sqrt{|2\pi\Sigma|} on the \tau factor without affecting the final result. This simplifies the elimination step results to \displaystyle p(x_{j}|\mathcal{C}_{j})=\frac{1}{\sqrt{|2\pi\Sigma|}}\exp\Bigg(-\frac{1}{2}\|R_{j}x_{j}+T_{j}\mathcal{C}_{j}-d_{j}\|_{2}^{2}\Bigg) \displaystyle\tau(\mathcal{C}_{j})=\exp\Bigg(-\frac{1}{2}\|A_{\tau}\mathcal{C}_{j}-b_{\tau}\|_{2}^{2}\Bigg) Computationally, we can take advantage of the fact that we compute \log{\frac{1}{\sqrt{|2\pi\Sigma|}}} for p(x_{j}|\mathcal{C}_{j}) , and we can reuse this term for \tau(\mathcal{C}_{j}) . \displaystyle\begin{split}&\tau(\mathcal{C}_{j})=\sqrt{|2\pi\Sigma|}\exp\Bigg(-\frac{1}{2}\|A_{\tau}\mathcal{C}_{j}-b_{\tau}\|_{2}^{2}\Bigg)\\ &=\exp\Bigg(-\frac{1}{2}\|A_{\tau}\mathcal{C}_{j}-b_{\tau}\|_{2}^{2}+\log{(\sqrt{|2\pi\Sigma|})}\Bigg)\\ &=\exp\Bigg(-\frac{1}{2}\|A_{\tau}\mathcal{C}_{j}-b_{\tau}\|_{2}^{2}-\log{\frac{1}{\sqrt{|2\pi\Sigma|}}}\Bigg)\\ &=\exp\Bigg(-\frac{1}{2}\bigg[\|A_{\tau}\mathcal{C}_{j}-b_{\tau}\|_{2}^{2}+2\log\frac{1}{\sqrt{|2\pi\Sigma|}}\bigg]\Bigg)\end{split} where \Sigma^{-1}=R^{\mathchoice{\raisebox{0.0pt}{$\displaystyle\intercal$}}{\raisebox{0.0pt}{$\textstyle\intercal$}}{\raisebox{0.0pt}{$\scriptstyle\intercal$}}{\raisebox{0.0pt}{$\scriptscriptstyle\intercal$}}}R . G-B Hybrid The subgraph involving the variable to eliminate has both continuous and discrete variables, e.g . \Phi(\mathcal{X}_{j},\mathcal{M}_{j}) . The separator \mathcal{S}_{j}=(\mathcal{C}_{j},\mathcal{M}_{j}) in this case consists of both continuous \mathcal{C}_{j} and discrete \mathcal{M}_{j} variables. We can compute the product factor, this time including the discrete variables \mathcal{M}_{j} connected to the current variable x_{j} , and the continuous separator as \mathcal{C}_{j} . The product is formed via factors corresponding to the same discrete assignment m\in\mathcal{M}_{j} . \displaystyle\begin{split}\psi^{m}(x_{j},\mathcal{C}_{j})&=\prod_{\phi_{i}\in\Phi}\phi^{m}_{i}(\mathcal{X}_{j})\\ &=\prod_{\phi_{i}\in\Phi}\exp\Bigg(-\frac{1}{2}\|A_{j}^{m}\begin{bmatrix}x_{j}\\ \mathcal{C}_{j}\end{bmatrix}-b_{j}^{m}\|_{2}^{2}\Bigg)\end{split} with the complete product factor involving all discrete indices being \psi(x_{j},\mathcal{S}_{j})=\bigg\{\psi^{m}(x_{j},\mathcal{C}_{j});m\circeq\mathcal{M}_{j}\bigg\} We can factorize the product factor corresponding to each discrete assignment \displaystyle\begin{split}\psi^{m}(x_{j},\mathcal{C}_{j})=&\exp\Bigg(-\frac{1}{2}\|R_{j}^{m}x_{j}+T_{j}^{m}\mathcal{C}_{j}-d_{j}^{m}\|_{2}^{2}\Bigg)\\ &\exp\Bigg(-\frac{1}{2}\|A_{\tau}^{m}\mathcal{C}_{j}-b_{\tau}^{m}\|_{2}^{2}\Bigg)\end{split} where we can denote \displaystyle q^{m}(x_{j}|\mathcal{C}_{j},\mathcal{M}_{j})=\exp\Bigg(-\frac{1}{2}\|R_{j}^{m}x_{j}+T_{j}^{m}\mathcal{C}_{j}-d_{j}^{m}\|_{2}^{2}\Bigg) After elimination, we get the conditional p(x_{j}|\mathcal{C}_{j},\mathcal{M}_{j}) and a hybrid factor \tau(\mathcal{C}_{j},\mathcal{M}_{j}) , both as a set of functions on the continuous separator variables \mathcal{C}_{j} , indexed by the discrete separator variables \mathcal{M}_{j} . Each component of \tau(\mathcal{C}_{j},\mathcal{M}_{j}) and p(x_{j}|\mathcal{C}_{j},\mathcal{M}_{j}) indexed by m\circeq\mathcal{M}_{j} is given by \displaystyle\begin{split}\tau^{m}(\mathcal{C}_{j})&=\int_{x_{j}}\psi^{m}(x_{j},\mathcal{C}_{j})dx_{j}\\ &=\exp\Bigg(-\frac{1}{2}\|A_{\tau}^{m}\mathcal{C}_{j}-b_{\tau}^{m}\|^{2}\Bigg)\sqrt{|2\pi\Sigma^{m}|}\\ &=\exp\Bigg(-\frac{1}{2}\|A_{\tau}^{m}\mathcal{C}_{j}-b_{\tau}^{m}\|^{2}\Bigg)\bigg(\frac{1}{\sqrt{|2\pi\Sigma^{m}|}}\bigg)^{-1}\\ &=\exp\Bigg(-\frac{1}{2}\|A_{\tau}^{m}\mathcal{C}_{j}-b_{\tau}^{m}\|^{2}+\log(\frac{1}{\sqrt{|2\pi\Sigma^{m}|}})^{-1}\Bigg)\\ &=\exp\Bigg(-\bigg[\frac{1}{2}\|A_{\tau}^{m}\mathcal{C}_{j}-b_{\tau}^{m}\|^{2}-\log(\frac{1}{\sqrt{|2\pi\Sigma^{m}|}})^{-1}\bigg]\Bigg)\\ &=\exp\Bigg(-\bigg[\frac{1}{2}\|A_{\tau}^{m}\mathcal{C}_{j}-b_{\tau}^{m}\|^{2}+\log(\frac{1}{\sqrt{|2\pi\Sigma^{m}|}})\bigg]\Bigg)\end{split} \displaystyle\begin{split}p^{m}(x_{j}|\mathcal{C}_{j})&=\frac{q^{m}(x_{j}|\mathcal{C}_{j})}{q(\mu_{x_{j}}(\mathcal{C}_{j}))\sqrt{|2\pi\Sigma^{m}|}}\\ &=\frac{1}{\sqrt{|2\pi\Sigma^{m}|}}\exp\Bigg(-\frac{1}{2}\|R_{j}^{m}x_{j}+T_{j}^{m}\mathcal{C}_{j}-d_{j}^{m}\|_{2}^{2}\Bigg)\end{split} where \Sigma^{m}=((R^{m})^{\mathchoice{\raisebox{0.0pt}{$\displaystyle\intercal$}}{\raisebox{0.0pt}{$\textstyle\intercal$}}{\raisebox{0.0pt}{$\scriptstyle\intercal$}}{\raisebox{0.0pt}{$\scriptscriptstyle\intercal$}}}R^{m})^{-1} and q(\mu_{x_{j}}(\mathcal{C}_{j}))=1 for each mode m . Here, since each continuous distribution indexed by the discrete mode m had its own mean \mu^{m} and covariance \Sigma^{m} , we keep track of the normalizer values within the factor definition, as detailed in V-B and A-D . Each of these functions is a multivariate gaussian, so the \tau(\mathcal{C}_{j},\mathcal{M}_{j}) factor is represented computationally as a Hybrid Gaussian Factor . Similarly, the conditional p^{m}(x_{j}|\mathcal{C}_{j}) inserted in the hybrid Bayes net as a Hybrid Gaussian Conditional Component . G-C Continuous-Discrete Boundary This is the case where we eliminate the final continuous variable in the hybrid factor \phi(x_{n},M) , where x_{n} is the last continuous variable and \mathcal{M}_{n} is the set of discrete variables. To perform elimination, we first form the product factor as \displaystyle\begin{split}\psi(x_{n},\mathcal{M}_{n})=\bigg\{\psi^{m}(x_{n});m\circeq\mathcal{M}_{n}\bigg\}\\ \psi^{m}(x_{n})=\exp\Bigg(-\frac{1}{2}\|A^{m}x_{n}-b^{m}\|^{2}_{2}\Bigg)\end{split} where m\circeq\mathcal{M}_{n} is a specific mode assignment. We can once again represent the hybrid factor in its factored form as \psi^{m}(x_{n})=\exp\Bigg(-\frac{1}{2}\|R^{m}_{n}x_{n}-d^{m}_{n}\|^{2}_{2}\Bigg)\exp\Bigg(-\frac{1}{2}\|b_{\tau}^{m}\|^{2}_{2}\Bigg) The first term represents a conditional without any continuous parents (due to the lack of a continuous separator \mathcal{C}_{j} ), and a second term which represents the leftover residual after continuous elimination. As shown in the continous-only case, we get the probability density on x_{n} \displaystyle\begin{split}&p(x_{n}|\mathcal{M}_{n})=\bigg\{p^{m}(x_{n});m\circeq\mathcal{M}_{n}\bigg\}\\ &p^{m}(x_{n})=\frac{1}{\sqrt{|2\pi\Sigma|}}\exp\Bigg(-\frac{1}{2}\|R^{m}_{n}x_{n}-d^{m}_{n}\|^{2}_{2}\Bigg)\end{split} and we can compute the separator factor component \tau^{m}() for each discrete assignment \displaystyle\begin{split}\tau^{m}()&=\int_{x_{n}}\psi^{m}(x_{n})dx_{n}\\ &=\int_{x_{n}}\exp\Bigg(-\frac{1}{2}\|R^{m}_{n}x_{n}-d^{m}_{n}\|^{2}_{2}\Bigg)\exp\Bigg(-\frac{1}{2}\|b_{\tau}^{m}\|^{2}_{2}\Bigg)dx_{n}\\ &=\exp\Bigg(-\frac{1}{2}\|b_{\tau}^{m}\|^{2}_{2}\Bigg)\int_{x_{n}}\exp\Bigg(-\frac{1}{2}\|R^{m}_{n}x_{n}-d^{m}_{n}\|^{2}_{2}\Bigg)dx_{n}\\ &=\exp\Bigg(-\frac{1}{2}\|b_{\tau}^{m}\|^{2}_{2}\Bigg)\sqrt{|2\pi\Sigma^{m}|}\end{split} After eliminating all the continuous variables, we are left with a factor of the residual b^{m}_{\tau} which is independent of any continuous variables X . Computing its exponential gives us a fully discrete factor , yielding a Discrete Factor Graph . We can incorporate the \sqrt{|2\pi\Sigma^{m}|} term into the discrete factor for computational convenience. \displaystyle\begin{split}\tau^{m}()&=\exp\Bigg(-\frac{1}{2}\|b^{m}\|^{2}_{2}\Bigg)\sqrt{|2\pi\Sigma^{m}|}\\ &=\exp\Bigg(-\frac{1}{2}\|b^{m}\|^{2}_{2}\Bigg)\bigg(\frac{1}{\sqrt{|2\pi\Sigma^{m}|}}\bigg)^{-1}\\ &=\exp\Bigg(-\frac{1}{2}\|b^{m}\|^{2}_{2}-\log(\frac{1}{\sqrt{|2\pi\Sigma^{m}|}})\Bigg)\end{split} G-D Discrete-Only In this case, all the involved factors are over discrete variables \Phi(M) . We can apply the Sum-Product algorithm to the remaining Discrete Factor Graph \Phi(M) to obtain the Discrete Bayes Network P(M) . P(m_{j}|\mathcal{M}_{j})\tau_{\text{sum}}(\mathcal{M}_{j})=\textrm{ELIMINATE}(\Phi(M),m_{j}) Computationally, we represent P(m_{j}|\mathcal{M}_{j}) as a Discrete Conditional , and the separator factor \tau_{\text{sum}}(\mathcal{M}_{j}) as a Discrete Factor . Appendix H Max-Product for Hybrid Factor Graphs In this section, we detail Maximum A Posteriori estimation via the Max-Product algorithm for different factor combinations, which is another variable elimination algorithm. H-A Continuous-Only In this case we wish to eliminate a continuous variable that has a separator \mathcal{C}_{j} consisting of only continuous variables ( e.g . a continuous-only factor graph). \displaystyle\begin{split}g_{j}(\mathcal{C}_{j})&=\arg\max_{x_{j}}\bigg(\exp\Bigg(-\frac{1}{2}\|R_{j}x_{j}+T_{j}\mathcal{C}_{j}-d_{j}\|_{2}^{2}\Bigg)\bigg)\\ &=R_{j}^{-1}(d_{j}-T_{j}\mathcal{C}_{j})\\ \tau(\mathcal{C}_{j})&=\max_{x_{j}}\psi(x_{j},\mathcal{C}_{j})\\ &=\exp\Bigg(-\frac{1}{2}\|A_{\tau}\mathcal{C}_{j}-b_{\tau}\|_{2}^{2}\Bigg)\end{split} H-B Hybrid The subgraph involving the variable to eliminate has both continuous and discrete variables, e.g . \Phi(\mathcal{X}_{j},\mathcal{M}_{j}) . Similar to the Sum-Product algorithm, elimination is performed using steps similar to the Continuous-Only case, with extra care taken for each continuous function corresponding to a discrete mode. g_{j}(\mathcal{C}_{j},\mathcal{M}_{j})\tau(\mathcal{C}_{j},\mathcal{M}_{j})=\textrm{ELIMINATE}(\Phi(\mathcal{X}_{j},\mathcal{M}_{j}),x_{j}) Firstly, we compute the product factor including the discrete variables \mathcal{M}_{j} connected to the current variable x_{j} . The product is formed via factors corresponding to the same discrete assignment m\circeq\mathcal{M}_{j} . \displaystyle\begin{split}\psi^{m}(x_{j},\mathcal{C}_{j})=&\prod_{\phi_{i}\in\Phi}\phi^{m}_{i}(\mathcal{X}_{j})\\ =&\prod_{\phi_{i}\in\Phi}\exp\Bigg(-\frac{1}{2}\|A_{j}^{m}\begin{bmatrix}x_{j}\\ \mathcal{C}_{j}\end{bmatrix}-b_{j}^{m}\|_{2}^{2}\Bigg)\end{split} We can factorize the product factor per each discrete assignment m \displaystyle\begin{split}\psi^{m}(x_{j},\mathcal{C}_{j})=\exp\Bigg(-\frac{1}{2}\|R_{j}^{m}x_{j}+T_{j}^{m}\mathcal{C}_{j}-d_{j}^{m}\|_{2}^{2}\Bigg)\\ \exp\Bigg(-\frac{1}{2}\|A_{\tau}^{m}\mathcal{C}_{j}-b_{\tau}^{m}\|_{2}^{2}\Bigg)\end{split} giving us \displaystyle q^{m}_{j}(\mathcal{C}_{j})=\exp\Bigg(-\frac{1}{2}\|R_{j}^{m}x_{j}+T_{j}^{m}\mathcal{C}_{j}-d_{j}^{m}\|_{2}^{2}\Bigg) \displaystyle\psi^{m}(\mathcal{C}_{j})=\exp\Bigg(-\frac{1}{2}\|A_{\tau}^{m}\mathcal{C}_{j}-b_{\tau}^{m}\|_{2}^{2}\Bigg) After elimination, we get a hybrid function p_{j}(\mathcal{C}_{j},\mathcal{M}_{j}) and a hybrid factor \tau(\mathcal{C}_{j},\mathcal{M}_{j}) , both which represent a set indexed by the separator discrete variables m\circeq\mathcal{M}_{j} , where each entry is a function of the continuous variables in the separator. \displaystyle\begin{split}&g_{j}(\mathcal{C}_{j},\mathcal{M}_{j})=\bigg\{g^{m}_{j}(\mathcal{C}_{j});m\circeq\mathcal{M}_{j}\bigg\}\\ &g^{m}_{j}(\mathcal{C}_{j})=\arg\max_{x_{j}}\psi^{m}(x_{j},\mathcal{C}_{j})=(R^{m}_{j})^{-1}(d^{m}_{j}-T^{m}_{j}\mathcal{C}_{j})\end{split} \displaystyle\begin{split}&\tau(\mathcal{C}_{j},\mathcal{M}_{j})=\bigg\{\tau^{m}_{j}(\mathcal{C}_{j});m\circeq\mathcal{M}_{j}\bigg\}\\ &\tau^{m}(\mathcal{C}_{j})=\max_{x_{j}}\psi^{m}(x_{j},\mathcal{C}_{j})=\exp\Bigg(-\frac{1}{2}\|A_{\tau}^{m}\mathcal{C}_{j}-b_{\tau}^{m}\|^{2}_{2}\Bigg)\end{split} Each of the functions within \tau(\mathcal{C}_{j},\mathcal{M}_{j}) indexed by m\circeq\mathcal{M}_{j} follows the form of a multivariate gaussian, this factor can also be represented computationally as a Hybrid Gaussian Factor . Similarly, the function g_{j}(\mathcal{C}_{j},\mathcal{M}_{j}) can be represented as a Hybrid Gaussian Conditional , even though semantically it is not. H-C Continuous-Discrete Boundary This is the case where we eliminate the final continuous variable x_{n} in the hybrid factor \phi(x_{n},\mathcal{M}_{n}) , where \mathcal{M}_{n} is the set of discrete variables involved in the factors. We form the product factor \displaystyle\begin{split}\psi(x_{n},\mathcal{M}_{n})=\bigg\{\psi^{m}(x_{n});m\circeq\mathcal{M}_{n}\bigg\}\\ \psi^{m}(x_{n})=\exp\Bigg(-\frac{1}{2}\|A^{m}x_{n}-b^{m}\|^{2}_{2}\Bigg)\end{split} where m\circeq\mathcal{M}_{n} is a specific mode assignment, just like in the Sum-Product case ( G-C ). We can represent the hybrid product factor in its factored form as \psi^{m}(x_{n})=\exp\Bigg(-\frac{1}{2}\|R^{m}_{n}x_{n}-d^{m}_{n}\|^{2}_{2}\Bigg)\exp\Bigg(-\frac{1}{2}\|b_{\tau}^{m}\|^{2}_{2}\Bigg) with the first term representing a function without any continuous variables as dependent (shown by the lack of an \mathcal{C}_{j} term), and a second term which represents the leftover residual after continuous elimination. As shown in the continous-only case, we get the function on x_{n} as \displaystyle\begin{split}&g_{n}(\mathcal{M}_{n})=\bigg\{g^{m}_{n}();m\circeq\mathcal{M}_{n}\bigg\}\\ &g^{m}_{n}()=\arg\max_{x_{n}}\bigg(\exp\Bigg(-\frac{1}{2}\|R^{m}_{n}x_{n}-d^{m}_{n}\|^{2}_{2}\Bigg)\bigg)=(R^{m}_{n})^{-1}d^{m}_{n}\end{split} and we can similarly compute the separator factor \tau(\mathcal{M}_{n}) \displaystyle\begin{split}&\tau(\mathcal{M}_{n})=\bigg\{\tau^{m}();m\circeq\mathcal{M}_{n}\bigg\}\\ &\tau^{m}()=\max_{x_{n}}\psi^{m}(x_{n})\\ &=\max_{x_{n}}\bigg(\exp\Bigg(-\frac{1}{2}\|R^{m}_{n}x_{n}-d^{m}_{n}\|^{2}_{2}\Bigg)\exp\Bigg(-\frac{1}{2}\|b_{\tau}^{m}\|^{2}_{2}\Bigg)\bigg)\\ &=\exp\Bigg(-\frac{1}{2}\|b_{\tau}^{m}\|^{2}_{2}\Bigg)\max_{x_{n}}\bigg(\exp\Bigg(-\frac{1}{2}\|R^{m}_{n}x_{n}-d^{m}_{n}\|^{2}_{2}\Bigg)\bigg)\\ &=\exp\Bigg(-\frac{1}{2}\|b_{\tau}^{m}\|^{2}_{2}\Bigg)\end{split} Since the factor \tau(\mathcal{M}_{n}) is only on discrete variables, it forms a discrete factor which consequently leaves us with a Discrete Factor Graph . H-D Discrete-Only In this case, all the involved factors are over discrete variables \Phi(M) . As such, we can apply the Discrete Max-Product algorithm to compute the Most Probable Explanation or MPE [ 10 ] . For each variable m_{j} to eliminate, we collect the factors \Phi(m_{j},\mathcal{M}_{j}) connected to the variable and its separators \mathcal{M}_{j} , and eliminate it via the Max-Product operations. Here g_{j} represents the conditional optimal value for m_{j} . \displaystyle g_{j}(\mathcal{M}_{j})=\arg\max_{m_{j}}\Phi(m_{j},\mathcal{M}_{j}) \displaystyle\tau_{\text{max}}(\mathcal{M}_{j})=\max_{m_{j}}\Phi(m_{j},\mathcal{M}_{j}) Computationally, we can represent g(\mathcal{M}_{j}) as a Discrete Conditional a.k.a . a lookup table based on \mathcal{M}_{j} , and the separator factor \tau_{\text{sum}}(\mathcal{M}_{j}) as a Discrete Factor , since even though they have different semantic meanings, they possess similar forms.