{'fraction_non_alphanumeric': 0.034419643549612994, 'fraction_numerical': 0.009942763188509207, 'mean_word_length': 4.772226698898738, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Learned Factor Graphs for Inference from Stationary Time Sequences

The design of methods for inference from time sequences has traditionally relied on statistical models that describe the relation between a latent desired sequence and the observed one. A broad family of model-based algorithms have been derived to carry out inference at controllable complexity using recursive computations over the factor graph representing the underlying distribution. An alternative model-agnostic approach utilizes machine learning (ML) methods. Here we propose a framework that combines model-based algorithms and data-driven ML tools for stationary time sequences. In the proposed approach, neural networks are developed to separately learn specific components of a factor graph describing the distribution of the time sequence, rather than the complete inference task. By exploiting stationary properties of this distribution, the resulting approach can be applied to sequences of varying temporal duration. Learned factor graph can be realized using compact neural networks that are trainable using small training sets, or alternatively, be used to improve upon existing deep inference systems. We present an inference algorithm based on learned stationary factor graphs, which learns to implement the sum-product scheme from labeled data, and can be applied to sequences of different lengths. Our experimental results demonstrate the ability of the proposed learned factor graphs to learn to carry out accurate inference from small training sets for sleep stage detection using the Sleep-EDF dataset, as well as for symbol detection in digital communications with unknown channels.


I. INTRODUCTION
A multitude of practical problems involve inference from time sequences. The need to accurately estimate a hidden time series from a measured signal is frequently encountered in signal processing, communications, control, finance, and various other fields. Traditional algorithms, such as those based on the maximum a-posteriori probability (MAP) rule, are model-based, namely, they carry out inference based on complete knowledge of the underlying statistical model relating the desired time series and the observed one. The joint distribution of a large family of time sequences encountered in practice can be factorized, which facilitates inference at reduced complexity by representing their distribution as a Forney-style factor graph [2], [3], referred to henceforth as a factor graph for brevity. In factor graphs, variables are represented as edges connected to function nodes forming a graphical representation of joint distribution measures. When Parts of this work were presented in the IEEE International Symposium on Information Theory (ISIT) 2020 [1]. This work was supported in part by the Israeli Innovation Authority through the 5G-WIN consortium, the Benoziyo Endowment Fund for the Advancement of Science, QuantERA this graph is cycle-free, it can be used to evaluate marginal distributions in an efficient manner, i.e., with complexity that only grows linearly with the number of variables. As a result, many important model-based algorithms, such as the Viterbi algorithm [4], the sum-product (SP) method [5] also known as belief propagation (BP) [6], the BCJR detector [7], the Baum-Welch scheme for estimating the parameters of hidden Markov models (HMMs) [8], and the Kalman filter [9,Ch. 7], all process time sequences via recursive computations over a factor graph [10].
Often in practice, the underlying statistical model relating the observations and the desired time series is highly complex or poorly understood. In such cases, model-based algorithms, which are typically sensitive to inaccurate knowledge of the underlying statistics, cannot be reliably applied, and modelagnostic data-driven schemes are preferable. Consequently, recent years have witnessed extensive interest in the application of machine learning (ML), and particularly of deep neural networks (DNNs), for time sequence inference, with various architectures proposed to exploit the presence of temporal correlation [11]- [13]. However, training these deep architectures typically requires a massive amount of labeled data, which may not always be available. Furthermore, applying inference using highly parameterized DNNs may not be feasible on devices with limited hardware capabilities.
The individual challenges of model-based signal processing and model-agnostic ML has given rise to various hybrid systems combining ML and model-based algorithms [14]. Such hybrid model-based/data-driven attempt to benefit from the best of both worlds. These include the usage of DNNs to learn a possibly analytically intractable regularization in compressed sensing applications [15], [16], as well as the use of deep denoisers in regularized optimization via plug-andplay networks [17], [18]. A systematic strategy to combine model-based algorithms and ML is based on deep unfolding or unrolling [19]- [22]. Deep unfolding sets the layers of a DNN in light of the iterations of some iterative optimization algorithm, while using the resulting unfolded network for the complete inference task. Deep unfolding typically requires knowledge of the underlying model, up to perhaps some unknown parameters, in order to unfold the optimization method. Unfolding commonly results in a highly parameterized DNN utilized for the complete inference task, whose architecture is inspired by a model-based algorithm.
In this work, we propose an alternative strategy that combines model-based signal processing algorithms based on factor graph computations with data-driven ML tools. Here, instead of using DNNs for inference, they are utilized to learn only the function nodes of the factor graph, which in turn is used for inference via conventional factor graph methods, such as the SP algorithm. This approach builds upon the fact that the statistical behavior of time sequences can often be approximated using stationary factorizable distributions, which allows incorporating domain knowledge in the structure of the graph while learning its nodes from data. This results in a hybrid model-based/data-driven inference scheme that only requires prior knowledge of the factorization of the underlying distribution. This is in contrast to deep unfolding where the distribution in parametric form is typically required. Moreover, the hybrid scheme can also incorporate additional domain knowledge in its learned nodes. As opposed to previous works that used highly-parameterized deep architectures to represent messages along a factor graph, and trained the overall system in an end-to-end manner [23]- [30], our strategy learns the function nodes separately from the task, exploiting stationarity by reusing a DNN for multiple function nodes. Consequently, this approach can use relatively compact networks that are trained with small training sets and employed on hardwarelimited devices, as well as to improve upon existing DNN architectures by utilizing them for learning the factor graph instead of for inference. Furthermore, the same learned factor graph may be used for sequences of varying length, as well as combined with multiple inference algorithms.
In particular, we present a data-driven inference scheme based on learned factor graphs that learns to implement the SP method over factor graphs of stationary Markovian time sequences from labeled data. While the SP scheme requires accurate knowledge of the underlying statistical model, its data-driven implementation allows this algorithm to be utilized in scenarios involving time sequences with complex and possibly analytically intractable distributions. We detail how such hybrid model-based/data-driven inference is derived from the SP algorithm by learning the underlying factor graph. We also show that, by assuming stationarity, the complete factor graph can be learned using a single relatively compact neural network. We discuss how ViterbiNet, proposed in [31] for realtime data-driven symbol detection in digital communications, can be obtained as a special case of our framework, and in fact be implemented using the same learned factor graph as that used for SP-based inference. We then discuss how the ability to learn factor graphs of stationary distributions from small training sets may be exploited to facilitate adaptation to blockwise statistical variations when some future indication on the inference correctness is available, as in, e.g., coded communications setups.
We evaluate the usage of learned factor graphs for sleep pattern prediction as well as in a digital communications setup with unknown channel settings. For sleep pattern prediction, we use the Sleep-EDF dataset [32], and show how using a neural predictor as a learned node in the SP method improves the accuracy by 4% compared with using it for inference. We also demonstrate how this facilitates the usage of compact networks trainable with small data sets, enabling training using only part of the data of a single patient, while achieving accurate inference on its remaining data. For the communications setup, we demonstrate that inference over learned factor graphs is capable of approaching the performance of the MAP detector, which requires full knowledge of the underlying statistical model, while achieving improved robust-ness to model uncertainty compared with the conventional SP algorithm. Furthermore, we demonstrate that by utilizing compact networks that are trainable with small training sets, learned factor graphs can be tuned to accurately track temporal variations in the statistical model via online training.
The rest of this paper is organized as follows: In Section II, we detail the problem of inference over stationary time sequences, and briefly review model-based factor graph methods. Section III details the proposed framework for inference over learned factor graphs by deriving it from the SP algorithm applied to Markovian signals. Experimental results are presented in Section IV. Finally, Section V provides concluding remarks.
Throughout the paper, we use upper-case letters for random variables (RVs), e.g. X. Boldface lower-case letters denote vectors, e.g., x is a deterministic vector, and X is a random vector; the ith element of x is written as x i . The probability measure of an RV X evaluated at x is denoted P X (x), while N (·, ·) represents the Gaussian distribution. We use caligraphic letters for sets, e.g., X , where |X | is the cardinality of a finite set X , while R denotes the set of real numbers. Finally, for a sequence {x i } and integers II. SYSTEM MODEL In this section, we present the system model for which we propose the concept of data-driven factor graphs in Section III. We begin by formulating the considered time series inference problem in Subsection II-A. We then discuss the modelbased approach for the problem at hand in Subsection II-B, after which we briefly review conventional model-based factor graph methods in Subsection II-C.

A. Problem Formulation
We consider the problem of recovering a desired time series {S i } taking values in a set S from an observed sequence {Y i } taking values in a set Y. The subscript i denotes the time index. The joint distribution of {S i } and {Y i } obeys an lthorder Markovian stationary model, for some integer l ≥ 1, representing the memory of the sequences. Consequently, when the initial state S 0 −l is given, the joint distribution of Y t and S t satisfies for any fixed sequence length t > 0. The joint distribution in (2) is a special case of an lth order Markov model, where given S i i−l , the observed sequence Y i does not depend on the past observations Y i−1 i−l . In principle, the lth order Markov model in (2) can be expressed as an order-one Markov model by replacing S i with the multivariate However, since we focus on the recovery of the sample S i from Y t (rather than the stacking of l samples S i i−l+1 ), we keep the above formulation without limiting our attention to the case where l = 1.
In general, the above statistical relationship can change over time. Here, we assume that the marginal distribution of the desired sequence {S i } remains static over time, i.e., P Si|S i−1 i−l (·) does not depend on i. We allow the conditional probability density function (PDF) in (2) to evolve over time in the following manners: • Stationary sequence -the conditional PDF in (2) remains invariant over time, i.e., P Yi|Si (·) does not depend on the time index i. • Blockwise stationary -the conditional PDF P Yi|Si (·) changes every t b time instances. The stationarity assumption implies that within a given block of t b time instances, (2) represents the joint distribution as the product of the same function with different arguments.
The statistical relationship in (2) accurately represents a broad range of problems encountered in practice, including inference from bio-medical signals [33], [34] as well as symbol detection in digital communications [35,Ch. 3]. The common aspect of these problems is the presence of temporal correlation, implying that information regarding a state variable S i is contained not only in its corresponding observation Y i , but also in its preceding and subsequent measurements.
Our goal is to design a system that learns to reliably infer a block of desired variables S t from its corresponding observations Y t for arbitrary blocklength t. The system learns its inference mapping using a data set comprised of a sequence of n t labeled samples denoted {s k , y k } nt k=1 , as well as prior knowledge that the joint distribution obeys the factorization in (2). Nonetheless, it is emphasized that distribution functions in (2), e.g., P Yi|S i i−l , are unknown and may not be analytically tractable. The presence of data as well as partial domain knowledge motivates the design of hybrid model-based/datadriven schemes.

B. Model-Based Inference
When the joint distribution of S t and Y t is a-priori known and can be computed, the inference rule that minimizes the symbol error probability for each time instance is the MAP detector,ŝ for each i ∈ {1, . . . , t} T . This rule can be efficiently evaluated for finite-memory distributions using the SP algorithm [5]. An alternative common inference rule is the maximum likelihood sequence detector, given bŷ Unlike (3), the maximum likelihood sequence detector (4) has no optimality guarantee in general. However, similarly to (3), the inference rule in (4) is amenable to efficient iterative computation. In particular, for sequences obeying the structure (2), the detector (4) can be computed efficiently using the Viterbi algorithm [4], [36]. Viterbi detection allows real-time inference, i.e., it operates in a sequential manner and uses the partial vector y i+l−1 , instead of the complete observations y t , when recovering S i .
Both the SP method and the Viterbi scheme are modelbased algorithms that employ recursive computations over the underlying factor graph encapsulating the joint distribution of S t and Y t . Consequently, to design a system capable of learning from data how to carry out such inference, we first review factor graph methods in the following subsection.

C. Factor Graphs Methods
In the following we provide a brief introduction to factor graphs. We then review the SP algorithm for computing marginal distributions as a representative method for efficient inference over factor graphs [5].
A Forney-style factor graph, referred to henceforth as factor graph, is a graphical representation of the factorization of a function of several variables [10], commonly a joint distribution measure. Its main advantage over alternative graphical models of joint distributions, such as Bayesian (belief) networks [37] and junction graphs [38], stems from its suitability to hierarchical models and its resulting simple formulation of the SP message passing algorithm [3]. To present the concept of factor graphs and their usage, consider a t×1 random vector X ∈ X t where X is a finite set, i.e., the entries of X, denoted {X i }, are discrete RVs. The joint distribution of X, P X (x), is factorizable if it can be represented as the product of m functions {f k (·)} m k=1 , i.e., there exist some partition variables . , x t }, which are not subsets of one another, such that In order to represent (5) as a factor graph, the functions {f k (·)} m k=1 should be set such that each variable x i appears in no more than two partitions 1 {V k } m k=1 . Subject to this assumption, the distribution P X (x) can be described as a factor graph with m nodes, which are the functions {f k (·)} m k=1 , while the variables {x i } t i=1 represent edges or half-edges. In the sequel we focus on partitions in which the resulting graphical representation is cycle-free.
A major motivation for representing joint distributions via factor graphs is that they allow some statistical computations to be carried out with reduced complexity. One of the most common methods to exploit factorization via factor graphs for reduced complexity inference is the SP algorithm, that evaluates a marginal distribution from a factor graph representation of a joint probability measure [5]. To formulate the SP method, consider for simplicity a factorized distribution in which the ordering of the partitions {V i } corresponds to the order of the variables {x i }, e.g., Furthermore, as noted above, assume that the factor graph does not contain cycles. 2 In this case, the marginal distribution of an RV X i whose corresponding variable appears in the partitions V j and V j+1 can be computed from the joint distribution P X via The factorization of the joint distribution implies that the marginal distribution, whose computation typically requires summation over |X | t−1 variables, can now be evaluated as the product of two terms, − → µ Xi (x i ) and ← − µ Xi (x i ). These terms may be viewed as messages propagating forward and backward along the factor graph, e.g., − → µ Xi (x i ) represents a forward message conveyed to edge x i . In particular, these messages can be computed recursively.
where the last equality follows from the fact that x i−τ here is the variable with the largest index in V j−1 . The computation of message terms in a recursive manner over a graphical model, as done in (7), is referred to as message passing. In particular, the method of computing marginals in (6) using message passing over factor graphs is referred to as the SP algorithm [5].
III. INFERENCE VIA LEARNED FACTOR GRAPHS In this section we present our proposed system for MLbased inference applied to stationary time sequences. We begin by reviewing the application of the SP method to stationary signals in Subsection III-A. We next introduce the hybrid model-based/data-driven implementation of the SP algorithm in Subsection III-B through the concept of learned factor graphs, which is followed by a discussion of this proposed method in Subsection III-C. Then, in Subsection III-D we show how the learned factor graph can be used to carry out Viterbi detection, detailing how the architecture proposed in [31] for receiver design in digital communications can be obtained as a special case of a learned factor graph. Finally, we present training of learned factor graphs in the presence of blockwise stationary distributions based on some future correctness indication in Subsection III-E.

A. SP Inference for Stationary Markovian Time Sequences
The SP algorithm computes the MAP rule in (3) for the signal model detailed in Section II by recursive message passing. To formulate this application of the SP scheme, define the vector variable s i s i i−l+1 ∈ S l (similarly, the random vector S i S i i−l+1 ∈ S l ). We can now represent the factorizable joint distribution P Y t ,S t (·) (2) as the factor graph Consequently, for the considered Markovian model, the par- Due to the stationarity of the model, it holds that the mapping f i (·) does not depend on the index i, and since s i is an element of the vector s i , we can write the function nodes as In the special case where it holds that P Yi|Si,Si−1 (y i |s i , s i−1 ) = P Yi|Si, (y i |s i ) in (8), the statistical model and the corresponding factor graph coincides with that of a hidden Markov model. Note that when s i is a shifted version of s i−1 , (8) coincides with P Yi|S i i−l y i |s i i−l P Si|Si−1 s i |s i−1 i−l , otherwise it equals zero. The fact that the distribution is stationary implies that the function node mapping f (·) is invariant to the time index i. Using its factor graph representation, one can compute the joint distribution of S t and Y t by recursive message passing along its factor graph. In particular, where for i = 1, . . . , k, the forward messages satisfy Similarly, for i = k + 1, . . . , t − 1, the backward messages are This message passing is illustrated in Fig. 2. The ability to compute the joint distribution in (9) via message passing leads to computation of the MAP detector in (3) with complexity that grows linearly with t; without this message passing the computation grows exponentially with the block size. This reduction in complexity is achieved by noting that the MAP estimate satisfieŝ for each i ∈ T , where the summands can be computed recursively. When t is large, the messages may tend to zero. Hence, the messages are commonly scaled [3], e.g., for some scale factor that does not depend on s, and thus does not affect the MAP rule. This instantiation of the SP algorithm is summarized in Algorithm 1 below.

B. Learned Factor Graphs
Here, we propose a hybrid model-based/data-driven implementation of the SP scheme in Algorithm 1, which learns to implement MAP detection of stationary Markovian time sequences from labeled data. Our framework builds upon the fact that in order to implement Algorithm 1, one must be able to specify the factor graph representing the underlying distribution. In particular, the stationarity assumption implies that the complete factor graph is encapsulated in the single function f (·) (8) regardless of the block size t. The Markovian nature of the signals implies that the structure of the graph is known to be of the form detailed in the previous subsection and illustrated in Fig. 2, regardless of the actual values of its function nodes. Building upon this insight, we utilize DNNs to learn the mapping carried out at the function node separately from the inference task. By doing so, one can train a system to learn an underlying factor graph, which can then be utilized for inference using conventional factor graph methods, such as the SP algorithm. The resulting learned stationary factor graph is then used to recover {S i } by message passing, as illustrated in Fig. 3.
In order to learn a stationary factor graph from samples, one must only learn its function node, which boils down to learning P Yi|S i i−l (·) and P Si|S i−1 i−l (·) by (8). Specifically, for stationary sequences, only a single function node must be learned, as the mapping f (·) does not depend on the time index i. This implies that one can utilize a single learned mapping, denotedf (·), to carry out SP-based inference over an arbitrary blocklength t, as illustrated in Fig. 3. When {S i } take values in a finite set, i.e., S is finite, the transition probability can be learned via a histogram, as we do in our numerical study. For learning the distribution P Yi|S i i−l (·) we consider two architectures, based on classification and density estimation networks, respectively.
1) Function Nodes as Classification Networks: Since y i is given and may take continuous values while the desired variables take discrete values, a natural approach to evaluate A parametric estimate of P S i i−l |Yi (s|y i ), denotedP θ (s|y i ), is obtained for each s ∈ S l+1 by training classification networks with softmax output layers to minimize the cross entropy loss.
In general, the marginal PDF of Y i can be estimated from the training data using mixture density estimation via, e.g., expectation maximization [40,Ch. 2], or any other finite mixture model fitting method. However, while the joint distribution in (2) depends on the marginal PDF of Y i , the MAP rule is invariant of it. This follows since P Yi (y i ) does not depend on the variable s, and thus (12) can be written aŝ Consequently, one can use a surrogate factor graph in which the function nodes are computed as f (yi,si],si−1) instead of using (8) without altering the predictions of the SP algorithm. The surrogate function nodes, which differ from (8) yet yield the same inference rule, are equivalently computed by setting P Yi (y i ) ≡ 1 in (13). The resulting structure in which the parametric estimates are combined into a learned function nodef (·), scaled by some constant γ i = 1 P Y i (yi) , is illustrated in the upper part of Fig. 4.
2) Function Nodes as Conditional Density Networks: An additional strategy is to directly estimate the conditional P Yi|S i i−l (y i |s) from data. This can be achieved using conditional density estimation networks [41], [42] that are specifically designed to learn such PDFs. Alternatively, normalizing flow networks [43] can be used; these architectures which are typically used in the context of generative models, are capable of explicitly learning complex densities [44]. For example, mixture density networks [41] model the conditional PDF P Yi|S i i−l (y i |s) as a mixture of K Gaussians, and train a DNN to learn a parametric estimate of its mixing parameters, mean values, and covariances, denoted w k,θ (s), µ k,θ (s) and Σ k,θ (s), respectively, by maximizing the likelihood of as illustrated in the lower part of Fig. 4. Both of the above architectures can be used for learning the conditional distribution P Yi|S i i−l (·) utilized by the learned stationary factor graph. To provide guidelines for choosing between these architectures, we note that when Y is high-dimensional, directly learning the conditional density is difficult and likely to be inaccurate. In such cases, the classification-based architecture, which avoids the need to explicitly learn the density by accounting for the invariance of Algorithm 1 to message scaling, may be preferable. When the state cardinality |S| l+1 is large, conditional density networks are expected to be more reliable. However, the SP algorithm, which computes the messages for each possible state, becomes computationally infeasible when |S| l+1 grows, making the application of the SP algorithm over learned factor graphs nonsuitable for such setups. Consequently, in our numerical study we use the classification network architecture for learning the function nodes.

C. Using Learned Factor Graphs for Inference
The proposed approach of inference over learned factor graphs has several key advantages: First, as learning a single function node is expected to be a simpler task compared with learning the overall inference method for recovering S t from Y t , this approach uses relatively compact DNNs, which can be learned from a relatively small set of labeled data. Furthermore, the learned function node describes the factor graph for different values of t, implying that the same architecture can be used for inference from sequences with different lengths. When the learned function node is an accurate estimate of the true one, message passing over it effectively implements the MAP detection rule (3), and thus approaches the minimal probability of error for each time instance.
Learned factor graphs rely on prior knowledge of the graph structure, which directly follows from the Markovian and stationarity assumptions. As such, it incorporates this limited level of domain knowledge in the structure of the factor graph, but does not impose any assumptions on the function nodes. These properties allow the representation of complex and possibly analytically intractable joint distributions as learned factor graphs, as long as they obey the Markovian stationary structure. The mapping of the function nodes is learned in a model-invariant manner from labeled data comprised of realizations of the observed sequence along with the corresponding realizations of the hidden state. In practice, the latter can be obtained from measurements or based on human annotations, as in the numerical study detailed in Subsection IV-A. If additional domain knowledge is present, it can be incorporated via imposing some parametric model on the function nodes {f (·)}, which follows from our understanding of the behavior of the setup at hand. Moreover, partial domain knowledge can be exploited to facilitate unsupervised training of the learned modules, thus relieving the dependence on known realizations of the state sequence, as recently proposed for DNN-aided tracking based in [45]. The operation of the proposed learned SP inference is invariant of whether its DNN-based function nodes were trained in a supervised or in an unsupervised manner. Nonetheless, we leave the study of unsupervised training of the learned function nodes for future investigation.
The proposed strategy significantly simplifies inference for scenarios represented by cycle-free factor graphs, such as the considered Markovian setup, compared with previously proposed DNNs whose structure imitates the message passing operation trained end-to-end, such as factor graph neural networks [27], [30]. In particular, this approach enables the usage of compact DNNs which can be trained using small data sets and achieve improved performance over factor graph neural networks for cycle-free factor graphs, as numerically demonstrated in Section IV. Furthermore, the learned factor graph can be applied to stationary time sequences of different lengths, without having to change its architecture and train anew, as well as be utilized with different message passing mechanisms, as we show in Subsection III-D. For blockwise stationary sequences, one only needs to learn a different function node for each block, as discussed in Subsection III-E. Factor graph neural networks are expected to be advantageous for scenarios characterized by loopy factor graphs, i.e., setups not obeying the system model detailed in Subsection II-A, where SP inference does not coincide with the MAP rule, and thus training end-to-end with sufficient data can lead to an improved inference rule.
The proposed approach of inference over learned factor graphs bears some similarity to previous works on the optimization of information bounds for communication channels with memory [46], [47]. In particular, the channel model considered in [46] specializes to the stationary Markovian setup of (2) under the additional constraint that the observations take values in a finite set. The main similarity to our work follows from the optimization over an auxiliary observations model, which [46] uses for formulating tight bounds on the information rates. Here, we use DNNs to capture the subtleties of this model from data such that the data-driven model can be integrated into factor graph based inference. Despite the similarity in the model and the approach, our work is somewhat different from these prior works on information rate bounds in the considered task as well as the usage of deep learning tools combined with principled model-based algorithms.
The proposed approach for using learned factor graphs trains the function nodes separately from the inference algorithm which utilizes the factor graph. Consequently, the factor graph learned can be processed using various message passing algorithms other than the SP scheme, e.g., the max-product method [3] and the Viterbi algorithm [4]. In particular, in the following subsection we show that the function nodes of learned factor graphs assuming equiprobable {S i } produce the same learned quantities as that used by ViterbiNet, proposed in [31] for symbol detection in finite-memory communication channels. Furthermore, the rationale of inference over learned factor graphs can be combined with alternative factor graph structures and message passing mechanisms, such as those used for joint channel estimation and iterative detection in [48]- [51]. Finally, we expect the same design to be applicable when training in an end-to-end manner, i.e., by backpropating through the message passing algorithm, as was done in [52] for image segmentation problems. We leave these extensions for future research.

D. Application as the Viterbi Algorithm
SP inference over learned factor graphs detailed in Subsection III-B is based on the ability to learn a parametric estimate of the function node mapping for factor graphs of stationary time sequences. However, once the factor graph is learned from data, it can also be used by factor graph inference algorithms other than the SP method. One such alternative designed for Markovian observations is the Viterbi scheme [4], originally proposed for decoding convolutional channel codes in digital communications. While the Viterbi algorithm can be applied with both forward and backward recursions over the underlying factor graph, we focus here on its implementation with a single forward recursive computation, following the description of the Viterbi scheme in [53,Ch. 3.4] and [35,Ch. 8.3].
1) The Viterbi Algorithm: The Viterbi detector aims at recovering the maximum likelihood sequence estimator in (4) viaŝ t y t = arg min where in (16) we use the abbreviated term S i defined in Subsection III-A, i.e., S i = S i i−l+1 . The optimization problem (16) can be solved recursively using dynamic programming, by iteratively updating a path cost c i (s) for each state s ∈ S l . The resulting scheme, known as the Viterbi algorithm, is given below as Algorithm 2.

Algorithm 2: The Viterbi Algorithm [4]
Init: Fix an initial path p 0 (s) = ∅ and path cost c 0 (s) = 0, for each s ∈ S l . 1 for i = 1, 2, . . . , t do 2 For each s ∈ S l , compute previous state with shortest path, denoted u s , via u s = arg min 3

Update cost and path via
and p i (s) = p i−1 (u s ) , u s ; 4 end Output:ŝ t = p t (s * ) where s * = arg min s c t (s).
Algorithm 2 outputs its estimate of the complete unknown sequence, i.e.,ŝ t , at time instance t. However, its output can also be approximated in real-time, since all paths at time i + l, {p i+l (s)} s∈S l typically include the same states corresponding to time instances not larger then i [36], [54]. Consequently, the output of Algorithm 2 can be approached by estimatinĝ s i when processing y i+l , and thus produce its estimates with a constant delay of l time instances. It is emphasized though that while this implementation typically comes at a negligible performance loss compared to Algorithm 2, it is no longer guaranteed to recover the maximum likelihood sequence estimator.
2) Viterbi Detection over Learned Factor Graphs: To see that the learned factor graph detailed in Subsection III-B can also be applied for Viterbi detection, we focus on the case where the conditional distribution of S i given S i−1 is uniform, as is commonly the case in digital communications systems for which Algorithm 2 was originally derived. In such cases the shortest path equation (17) can be written as where f i (·) is defined in (8).
Similarly, the cost update equation (18) can be replaced with without affecting the resulting inference rule. Furthermore, scaling the function nodes f i (·) by some γ i that is independent of the state does not affect the Viterbi algorithm due to the arg min statements in Algorithm 2. This implies that the same learned factor graph proposed in Subsection III-B for SP inference, which trains parametric estimates of f i (·), can be utilized to also carry out Viterbi detection in a data-driven manner. In fact, carrying out the Viterbi algorithm (rather than the SP method) over the learned factor graphs coincides with ViterbiNet, proposed in [31] for symbol detection in finite-memory communications. The application of the modelbased SP algorithm in such scenarios, i.e., symbol detection in finite-memory channels, specializes to the BCJR algorithm [7]. Thus SP inference over learned factor graphs of the joint input-output distribution of finite memory communications implements BCJR detection from data.
3) Discussion: Learned factor graphs can thus be applied, once trained, to carry out multiple inference algorithms, including the SP scheme (as proposed in Subsection III-B) as well as the Viterbi algorithm (via ViterbiNet). Furthermore, while Algorithm 2 considers the combination of learned factor graphs with Viterbi detection to produce hard decisions, where the output is the vectorŝ t ∈ S t , similar computations can be used to output soft decisions by utilizing the soft-output Viterbi algorithm over the learned factor factor graph. Once the factor graph encapsulating the underlying distribution is learned, one can decide which inference algorithm to apply to a learned factor graph. The preference of one method over the other is invariant of the learned factor graph, and follows from the differences between model-based message passing schemes, e.g., the differences between the SP algorithm and the Viterbi algorithm. The main advantages of Algorithm 2 over Algorithm 1, and thus of using a learned factor graph as part of ViterbiNet over SP inference, are its reduced complexity and the fact that it can be approached using a real-time operation. In particular, while the complexity of both algorithms grows linearly with the block size t, the Viterbi scheme as detailed in Algorithm 2 computes only a forward recursion and can thus provide its estimations in real time within a given delay from each incoming observation, while the SP scheme implements both forward and backward recursions, and can thus infer only once the complete block is observed. One can also implement the SP method using only the forward messages, and thus share the real-time operation and reduced complexity of Algorithm 2, at the cost of reduced accuracy and deviation from the MAP rule.
The main advantage of Algorithm 1 over Algorithm 2, i.e., of using the learned factor graphs for SP inference with forward and backward recursions rather than as part of the ViterbiNet system, stems from the fact that it implements the MAP rule (3), which minimizes the symbol error probability. The maximum likelihood sequence detector (4) computed by the Viterbi algorithm, requires the states to be equiprobable in order to be able to approach the performance of the MAP rule. In digital communications, where the Viterbi algorithm originates, the states correspond to transmitted symbols, which are commonly equiprobable, and thus the Viterbi detector is far more popular and widely used compared with the SP scheme.
However, in many other problems involving inference from time sequences, such as sleep pattern detection considered in Subsection IV-A, the states do not obey a uniform distribution, making the combination of learned factor graphs with SP inference the more attractive and natural data-driven method for such tasks.

E. Application for Blockwise-Stationary Statistical Variations
In the previous subsections we discussed how one can learn to infer from time sequences by using DNNs for estimating the function nodes in factor graphs with known structures, rather than using these networks for the complete end-to-end inference task. As a result, inference over learned factor graphs can be carried out using relatively compact networks which are trainable with a small number of training samples, as we also numerically demonstrate in our experimental study detailed in Section IV. This property of learned factor graphs facilitates their operation in the presence of blockwise stationary distributions.
As detailed in Subsection II-A, under a blockwise stationary distribution, the conditional PDF P Yi|Si (·), which is the mapping produced by a neural network in learned factor graphs, changes every t b time instances. Such scenarios correspond to, e.g., communication over block-fading channels. In general, one can tackle these time variations by joint learning [55], [56], i.e., training the function nodes using labeled data corresponding to a broad set of expected distributions. However, this approach requires a large data set, and the resulting mapping may be inaccurate for each of the observed P Yi|Si (·). Alternatively, one can train in advance a different network for each statistical block via ensemble models [57]. Such a strategy is feasible when one has prior access to training data corresponding to each statistical relationship as well as knowledge regarding the order in which these statistical models are observed during inference. An additional approach involves the usage of meta-learning tools as in [58], [59] for tuning the architecture and training hyperparameters of the data-driven function node architecture such that it can be rapidly re-trained to accurately represent a given family of expected distributions.
Finally, when some future indication on the inference correctness is available, the ability to train data-driven function nodes individually using a small number of labeled samples can be exploited to track temporal variations in the underlying statistics, without requiring prior knowledge of these variations. This is achieved by using the future indication to retrain the network in a self-supervised manner. For example, in a digital communications setup, the desired S t represents the transmitted symbols, while the observed Y t is the output of the channel used for recovering these symbols. Such communications are typically protected using error correction coding, implying that even when some of the symbols are inaccurately estimated, the conveyed message is still recoverable, as long as the number of errors does not exceed the code distance [35,Ch. 8]. In such cases, the recovered message can be reencoded, generating the postulated transmitted symbols, which in turn can be used along with corresponding observations for re-training the learned parameters, as proposed in [31], [60], [61]. When this network can be effectively adapted using a small training set of the order of a communication codeword, the resulting data-driven digital communication receiver is capable of tracking the variations of the underlying statistical model, thereby avoiding errors caused by these variations. We numerically demonstrate the gains of this approach for adapting learned factor graphs to track blockwise variations in the context of digital communications in our experimental study described in Subsection IV-B.

IV. EXPERIMENTAL RESULTS
We next numerically evaluate inference over learned factor graphs in an experimental study. First, we consider the problem of sleep pattern detection, using the PhysioNet Sleep-EDF Expanded database [32]. Then, we focus on symbol detection in communication over finite-memory channels, using simulated data of common channel models. We conclude the section with an evaluation of the computational complexity associated with inference via learned factor graphs. Throughout this section, we use the classification network architecture (upper part of Fig. 4), trained with the Adam optimizer [62] to minimize the cross-entropy loss for learning the function nodes. 3 The state transition probability is estimated from the training data provided in each experiment via a histogram, i.e., for n t labeled training samples {s k , y k } nt k=1 , it is computed aŝ where 1(·) is the indicator function. We utilize relatively compact networks which require only several minutes to train on a standard CPU. The specific architectures used for each setup are detailed in the description of the corresponding scenarios below.

A. Sleep Pattern Detection
Here, we consider the problem of sleep pattern detection from EEG signals. We use the PhysioNet Sleep-EDF Expanded database [32], which consists of 197 whole-night PolySomnoGraphic sleep recordings, containing EEG, EOG, chin EMG, and event markers. Similar to many prior works in this area [63]- [65], we use 20 patients from one of the two studies in this dataset that investigates the age effect in healthy subjects, known as the Sleep Cassette (SC) dataset. We focus on using a single EEG channel recording (the EEG channel Fpz-Cz) to classify five stages of sleep: awake (AWA), REM, and non-REM sleep stages (N1-N3), i.e., |S| = 5. In particular, every 30 seconds of recording (i.e., 3000 EEG samples at 100 Hz), which is called an epoch, is labeled by human experts. For some of our experiments, we apply the feature extraction method proposed in [34] to extract 150 features in each epoch, used as the observation Y i .
The task here is to identify the sleep states from the observed EEG signal. The common strategy is to train highlyparameterized DNNs to predict S i from Y i , based on convolutional layers [63], [65] or bidirectional recurrent neural networks (RNNs) [64]. Our goal here is to show that by using the 3 The source code used in this section is available online in the following link: https://github.com/nirshlezinger1/LearnedFactorGraphs

Method
Accuracy CNN-BLSTM [63] 82.0% BLSTM-SVM [64] 82.5% 5 FC (direct) 79.2% 5 FC (learned factor graph) 82.8% 34 ResNet (direct) 82.3% 34 ResNet (learned factor graph) 84.2% compact networks associated with learned factor graphs, one can achieve comparable performance to previously proposed deep detectors. These compact networks can be trained using smaller data sets and are simpler to implement compared with previously proposed DNNs. We also show that the learned factor graph framework can be used to improve upon existing architectures, using their predictors for learning the function nodes instead of for directly recovering the desired {S i }.
We learn the factor graph assuming that the sleep states follow a first-order Markov chain model, i.e., l = 1, and the joint distribution of states and measurements is stationary. In particular, we utilize a five layer fully-connected (FC) network (referred to as 5 FC) consisting of: 150 × 1200 FC layer with sigmoid activation; 1200 × 600, 600 × 300, and 300 × 150 FC layers with ReLU activations; and 150 × 5 FC layer with softmax output layer. An illustration of this network is depicted in Fig. 5. Here we use the 150 features extracted from EEG signals at each epoch as the network input. We also use a 34 layer residual network (referred to as 34 ResNet) proposed in [65], where the network input is the raw EEG signals during each epoch. For both of these networks, we compare the accuracy of the trained network directly applied for sleep pattern detection with that achieved when used as learned function nodes for SP inference.
First, we apply leave-one-out (LOO) cross-validation, where the data from one patient is left out for evaluation, while the data from the 19 other patients is used for training the models. The average accuracy of the algorithms for each patient is shown in Fig. 6a, while the confusion matrices achieved using learned factor graphs when using the 5 FC network and with 34 ResNet are shown in Figs. 7a-7b, respectively. Here, the 5 FC network is trained with an initial learning rate of 0.001 over 50 epochs with a mini-batch size of 60 samples. Directly applying 5 FC achieves an average accuracy of 79.2%, while using it to learn the factor graph in SP inference achieves an improvement of 3.6%, resulting in an accuracy of 82.8%. Similarly, the 34 ResNet achieves an accuracy of 82.3% while applying it to learn the factor graph achieves an average improvement of about 2%, resulting in an accuracy of 84.2%. As summarized by Table I, when using either the 5 FC   network or the 34 ResNet classifier to learn the factor graph, our algorithm outperforms the state-of-the-art deep learning algorithms applied to this dataset [63], [64].
We also observe in Fig. 6a that for some patients, such as patient 12, the samples appear to obey a considerably different statistical model from that of the remaining patients. This degrades the classification accuracy of the compact network, which in turn leads to an inaccurate estimate of the function nodes, resulting in accuracy below 75%. This motivates us to evaluate learned factor graphs when trained and tested using samples from the same patient, exploiting the compact networks of then learned factor graphs, which facilitates training from small data sets. We thus compute the accuracy when, for each patient, the networks are trained using its first 1000 samples and tested using the remaining samples, except for patient 14 for which less than 1000 samples are available.
The average accuracy for each patient is depicted in Fig. 6b, and the confusion matrix achieved by learned factor graphs using the 5 FC network for learning the function nodes is shown in Fig. 7c. Here, directly applying the 5 FC network as a classifier achieves an accuracy of 76%, as the DNN is trained using only 1000 samples, using it to form a learned factor graph improves the accuracy to 81%. 34 ResNet achieves only 60% accuracy due to its inability to properly train its highly parameterized network using small datasets. Building upon the ability of the relatively compact network to adapt with few samples, learned factor graphs achieve improved accuracy when applied to patients whose measurements obey a unique statistical model. For example, the SP method over the learned factor graph achieves an accuracy of 92% when applied to patient 12, improving by over 8% compared with using the network as predictor, and by 25%, compared with its performance when trained over the remaining 19 patients in Fig. 6a. These results demonstrate the potential of combining neural networks for learning the function nodes rather than to carry out the complete classification tasks, as well as the advantages of this approach in allowing the usage of compact networks, which can be trained with small training sets, for accurate inference from time sequences with non-synthetic data.

B. Symbol Detection in Digital Communications
Next, we apply learned factor graphs for detection in a finite-memory communication setup. We use simulated data based on common channel models, which allows us to compare the performance of the SP method over learned factor graphs with that of the model-based SP algorithm, as well as to that of existing deep detectors. Here, a transmitter sends a sequence of symbols S i ∈ S, i ∈ T , and a receiver uses the channel output Y i ∈ R to recover the symbols. Each Y i is affected only by the last l transmitted symbols, where l is the memory length.
We consider two channels with memory length l = 4: A Gaussian channel and a Poisson channel. Let h(γ) ∈ R l be a vector whose entries obey an exponentially decaying profile h τ (γ) e −γ(τ −1) for γ > 0 and τ ∈ {1, . . . , l}. For the Gaussian channel, the symbols take values in the set S = {−1, 1}, representing a binary phase shift keying constellation, and the channel output is generated via where ρ > 0 represents the signal-to-noise ratio (SNR). For the Poisson channel, the channel input represents on-off keying, i.e., S = {0, 1}, and the channel output Y i obeys where P(·) is the Poisson distribution. Namely, for each realization S t = s t , the channel output for every time instance is generated independently, where the output at corresponding to the ith time instance is generated from a Poisson distribution with parameter which equals √ ρ· l τ =1 h τ (γ)s i−τ +1 +1 [66]. We implement the classification network with three FC layers: 1 × 100, 100 × 50, and 50 × 16 layers, using sigmoid and ReLU activation functions, respectively. The network is trained using 5000 samples, which is the order of a typical preamble sequence in wireless networks [   here. The DNN architecture is depicted in Fig. 8.
For each channel, we compute the symbol error rate (SER) achieved using learned factor graphs for different values of the SNR ρ, and the DNN-aided function node is trained anew for each value of ρ. For every SNR, the SER values are averaged over 20 different channel vectors h(γ), obtained by letting γ vary in the range [0. 1,2]. For comparison, we evaluate the SER of the model-based SP algorithm, as well as that of the data-driven sliding bidirectional RNN (SBRNN) deep detector proposed in [66] and the factor graph neural network of [27], for which we use the same architecture as that utilized in the numerical study in [27,Sec. 4.1]. We consider two cases: The first is perfect channel state information (CSI), in which the SP method knows the exact h(γ), while the data-driven systems are trained using data consisting of samples generated with the same h(γ) used for the test data. The second setup considered, referred to as CSI uncertainty, considers the scenario in which the SP algorithm is implemented using an estimate of h(γ) corrupted by Gaussian noise with variance which equals 10% and 8% of the magnitude of the channel tap for the Gaussian and Poisson channels, respectively. Using the considered setup for CSI uncertainty represents the operation of the modelbased SP algorithm in scenarios where the underlying model is not accurately known, in a manner that is invariant of how this uncertainty is obtained. For the DNN-aided systems, the training data is generated with the noisy h(γ), allowing us to study resiliency to inaccurate training. In all cases, the information symbols are uniformly randomized in an i.i.d. fashion from S, and the test samples are generated from their corresponding channel with the true vector h(γ).
The SER values, averaged over 50000 Monte Carlo sim-   Fig. 9: Symbol detection accuracy of the SP algorithm over learned factor graphs compared the data-driven SBRNN detector [66] and the purely model-based SP method.
ulations, are depicted in Figs. 9a-9b for the Gaussian and Poisson channels, respectively. We observe in Figs. 9a-9b that the SER achieved using learned factor graphs approaches that of the SP algorithm from which it originates, while the latter requires accurate prior knowledge of the underlying distribution. In the presence of CSI uncertainty, carrying out SP inference over a learned factor graph significantly outperforms applying it over the inaccurate model-based factor graphs. When the function nodes are trained with a variety of different channels, learned factor graphs achieve relatively good SER when inferring under each of the channels for which it is trained, while the performance of the conventional SP method is significantly degraded due to imperfect CSI. We also observe that the SBRNN receiver, shown in [66] to approach the performance of the MAP rule when sufficient training is provided, is outperformed by SP inference over learned factor graphs here due to the small training set. A similar observation is noted for the factor graph neural network of [27], whose SER performance is within a notable gap from by the proposed approach of learned factor graphs for the considered scenario. These results demonstrate the ability of learned factor graphs to enable accurate implementation of the SP method while requiring small training sets and improving robustness to uncertainty. Next, we consider blockwise stationary channels, showing how the approach discussed in Subsection III-E can exploit coded communications for channel tracking. Here, transmission consists of multiple codewords of length t b = 2040, each representing 1784 bits encoded using a Reed-Solomon (RS) [255, 223] channel code, and protected with a cyclic redundency check (CRC) for error detection. We simulate the Gaussian and Poisson channels in (22)-(23), respectively. To simulate block-wise temporal variations, we let the entries of h(γ) vary between codewords. As in [31], for the jth codeword, we use h τ (γ) e −γ(τ −1) · 0.8 + 0.2 cos 2π·j pτ for each τ ∈ {1, . . . , l}, with a fixed exponential decay parameter γ = 0.2, and with p = [51,39,33,21] T , representing blockwise periodic variations in the channel coefficients.
Before the first block is transmitted, a factor graph representing a stationary distribution is learned using 5000 training samples taken using the initial channel coefficients. In order to track channel variations via online training, we use successful decoding to re-train the function nodes in a decision-directed manner [31], [60]. In particular, each recovered blockŜ t b is decoded to its corresponding 1784 bits using an RS decoder, and validated using a CRC check. If the CRC check passes, the bits are re-encoded using an RS encoder into a postulated symbol blockS t b , which is used along with its corresponding observed Y t b to retrain the learned function node using 50 epochs with an initial learning rate of 0.002.
In addition to evaluating learned factor graphs with online training, we also compute the coded bit error rate (BER) when the function node is trained only once using the 5000 training samples representing the initial channel, referred to as initial training, as well as when trained once using 5000 training samples corresponding to the channels observed at blocks j ∈ 3 · {1, . . . , 10}, referred to as joint training. The coded BER   of SP inference over learned factor graphs is compared with that of the SP detector with full instantaneous CSI as well as to that with knowledge of only the initial channel conditions. The coded BER results, averaged over 200 consecutive blocks, are depicted in Figs. 10a-10b for the Gaussian and Poisson channels, respectively.
Observing Figs. 10a-10b, we note that for both channels, as the SNR increases, learned factor graphs with online training approaches the performance of the model-based SP detector with instantaneous CSI, which implements MAP detection here. The latter require accurate knowledge of the complete input-output statistical relationship for each block. For low SNRs, the performance of SP inference over the online-trained factor graph is only slightly improved compared with training only using the initial channel. This can be explained by noting that for high SNR values, the number of symbol detection errors does not grow above the code distance as the channel changes between block, and thus the proposed online training scheme is capable of generating reliable labels. The onlinetrained factor graphs can accurately track the channel, allowing inference with optimal-approaching performance. However, for low SNR values, the RS decoder frequently fails to correctly decode the bits, and the online training methods does not frequently update its neural network, thus achieving only a minor improvement over using only the initial training data set. The ability to track channel variations in a decision-directed manner can be potentially improved by utilizing syndrome decoders, as proposed in [60]. We leave this study for future work.
We also observe in Figs. 10a-10b that the (offline) joint training approach allows inference over learned factor graphs to achieve improved BER performance compared with using only initial training. This follows since the resulting decoder is capable of operating in a broader range of different channel conditions. Still, joint training is notably outperformed by the SP detector with instantaneous CSI, whose BER performance is approached only when using online training at high SNRs.
The results reported in Figs. 10a-10b indicate that in order to reliably cope with non-stationary conditions, learned factor graphs designed for stationary setups should be combined with additional mechanisms for tracking the statistical variations, such as the online training mechanism discussed in Subsection III-E. Nonetheless, one can also design learned factor graphs to cope with non-stationarity by learning different function nodes for different time instances, at the cost of requiring larger datasets for training and possible limitations on the duration of the time sequences. We leave this extension of learned factor graphs for future study.

C. Inference Computational Complexity
We conclude this section by comparing the computational complexity of inference over learned factor graphs with that of end-to-end deep learning models. Specifically, we focus on the symbol detection setup detailed in Subsection IV-B and consider the SBRNN algorithm as the end-to-end deep learning model, as this architecture is shown to achieve the best performance among the end-to-end deep learning models evaluated in Figs. 9a-9b.
Recall that t is the length of the sequence, S is the symbol set, and l is the memory length of the channel. Let N f be the computational complexity of the learned factor node in the factor graph, i.e., the number of operations required to map a single observation y i and state vector s i−1 into an estimate of the function node {f (y i , s i , s i−1 )} si∈S . For instance, using the classification DNN architecture illustrated in Fig. 4(a), this operation involves passing the value y i through a fully-connected DNN, which using the DNN in Fig. 8 is comprised of approximately 6 · 10 3 multiplications, and computing |S| transition estimates from s i using a lookup table. Once the messages are computed for each state and for each time instance i, i.e., |S| l · t times, inference is carried out by computing the forward and backward messages via (10)- (11), resulting in an overall computational burden of the order of O(N f · |S| l · t). For comparison, letting N r be the computational complexity of the RNN block corresponding to one time-step in the SBRNN architecture, the computational complexity of the SBRNN is on the order of O(N r · l · t). Generally, we expect N r N f ; For example, in the scenario reported in Subsection IV-B computing the function nodes is done using N f ≈ 6 · 10 3 multiplications, while the SBRNN architecture requires N r ≈ 1.3 · 10 5 multiplications per time instance. Therefore, for the symbol detection scenario, SP over learned factor graphs does not only train with less data compared with the SBRNN system, but also infers at reduced computational complexity.
When the state cardinality |S| l+1 is large, SP inference, and thus also its application over learned factor graphs, may be computationally prohibitive. In these regimes, one can still utilize learned factor graphs for inference at controllable computational burden by utilizing alternative inference methods based on, e.g., state reduction [68]. This indicates that it is possible to have learned factor graphs that are efficient both in terms of sample efficiency during training, and in terms of computational complexity during inference. Nonetheless, we leave the detailed study of the combination of learned factor graphs with such reduced complexity inference methods for future work.
V. CONCLUSIONS In this work we proposed a framework for inference from stationary time sequences via learned factor graphs, combining the model-based SP algorithm with data-driven ML tools. By exploiting domain knowledge of a stationary and Markovian characteristics, encountered in many applications in signal processing and communications, the factor graph encapsulating the underlying distribution can be learned separately from the overall inference task. This results in a hybrid modelbased/data-driven system based on compact neural networks which can be trained with relatively small training sets. The resulting algorithm carries out inference over the learned factor graph in a manner which is not restricted to a specific number of input samples. The integration of DNNs for learning the function nodes combined with domain knowledge which determines the structure of the graph results in a system which learns from data to carry out MAP-approaching detection in complex setups. Furthermore, a learned factor graph can be used with different message passing based inference algorithms, other than the SP method. Our numerical evaluations demonstrate the ability of learned factor graphs to facilitate accurate inference and improve upon existing classifiers for sleep pattern detection and symbol recovery. We also show that its ability to train with small training sets enables personalized learning as well as tracking of blockwise temporal variations in the statistical model, which are both extremely challenging to carry out using conventional highly-parameterized DNNs.