Skip to content

Commit 4b3c409

Browse files
committed
format DiscreteMarginals.h
1 parent dc79f49 commit 4b3c409

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

gtsam/discrete/DiscreteMarginals.h

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,26 @@
2020

2121
#pragma once
2222

23-
#include <gtsam/discrete/DiscreteFactorGraph.h>
24-
#include <gtsam/discrete/DiscreteBayesTree.h>
2523
#include <gtsam/base/Vector.h>
24+
#include <gtsam/discrete/DiscreteBayesTree.h>
25+
#include <gtsam/discrete/DiscreteFactorGraph.h>
2626

2727
namespace gtsam {
2828

29-
/**
30-
* A class for computing marginals of variables in a DiscreteFactorGraph
31-
* @ingroup discrete
32-
*/
29+
/**
30+
* A class for computing marginals of variables in a DiscreteFactorGraph
31+
* @ingroup discrete
32+
*/
3333
class DiscreteMarginals {
34+
protected:
35+
DiscreteBayesTree::shared_ptr bayesTree_;
3436

35-
protected:
36-
37-
DiscreteBayesTree::shared_ptr bayesTree_;
38-
39-
public:
40-
37+
public:
4138
DiscreteMarginals() {}
4239

4340
/** Construct a marginals class.
44-
* @param graph The factor graph defining the full joint distribution on all variables.
41+
* @param graph The factor graph defining the full joint
42+
* distribution on all variables.
4543
*/
4644
DiscreteMarginals(const DiscreteFactorGraph& graph) {
4745
bayesTree_ = graph.eliminateMultifrontal();
@@ -50,8 +48,8 @@ class DiscreteMarginals {
5048
/** Compute the marginal of a single variable */
5149
DiscreteFactor::shared_ptr operator()(Key variable) const {
5250
// Compute marginal
53-
DiscreteFactor::shared_ptr marginalFactor;
54-
marginalFactor = bayesTree_->marginalFactor(variable, &EliminateDiscrete);
51+
DiscreteFactor::shared_ptr marginalFactor =
52+
bayesTree_->marginalFactor(variable, &EliminateDiscrete);
5553
return marginalFactor;
5654
}
5755

@@ -61,19 +59,17 @@ class DiscreteMarginals {
6159
*/
6260
Vector marginalProbabilities(const DiscreteKey& key) const {
6361
// Compute marginal
64-
DiscreteFactor::shared_ptr marginalFactor;
65-
marginalFactor = bayesTree_->marginalFactor(key.first, &EliminateDiscrete);
62+
DiscreteFactor::shared_ptr marginalFactor = this->operator()(key.first);
6663

67-
//Create result
64+
// Create result
6865
Vector vResult(key.second);
69-
for (size_t state = 0; state < key.second ; ++ state) {
66+
for (size_t state = 0; state < key.second; ++state) {
7067
DiscreteValues values;
7168
values[key.first] = state;
7269
vResult(state) = (*marginalFactor)(values);
7370
}
7471
return vResult;
7572
}
76-
77-
};
73+
};
7874

7975
} /* namespace gtsam */

0 commit comments

Comments
 (0)