Reverted variable name change to ease reviewing
parent
381087f48d
commit
26575921b0
|
@ -33,15 +33,15 @@ const DiscreteKey mode{M(0), 2};
|
|||
/**
|
||||
* Create a tiny two variable hybrid model which represents
|
||||
* the generative probability P(z,x,mode) = P(z|x,mode)P(x)P(mode).
|
||||
* numMeasurements is the number of measurements of the continuous variable x0.
|
||||
* num_measurements is the number of measurements of the continuous variable x0.
|
||||
* If manyModes is true, then we introduce one mode per measurement.
|
||||
*/
|
||||
inline HybridBayesNet createHybridBayesNet(int numMeasurements = 1,
|
||||
inline HybridBayesNet createHybridBayesNet(int num_measurements = 1,
|
||||
bool manyModes = false) {
|
||||
HybridBayesNet bayesNet;
|
||||
|
||||
// Create Gaussian mixture z_i = x0 + noise for each measurement.
|
||||
for (int i = 0; i < numMeasurements; i++) {
|
||||
for (int i = 0; i < num_measurements; i++) {
|
||||
const auto mode_i = manyModes ? DiscreteKey{M(i), 2} : mode;
|
||||
GaussianMixture gm({Z(i)}, {X(0)}, {mode_i},
|
||||
{GaussianConditional::sharedMeanAndStddev(
|
||||
|
@ -56,7 +56,7 @@ inline HybridBayesNet createHybridBayesNet(int numMeasurements = 1,
|
|||
GaussianConditional::sharedMeanAndStddev(X(0), Vector1(5.0), 0.5));
|
||||
|
||||
// Add prior on mode.
|
||||
const size_t nrModes = manyModes ? numMeasurements : 1;
|
||||
const size_t nrModes = manyModes ? num_measurements : 1;
|
||||
for (int i = 0; i < nrModes; i++) {
|
||||
bayesNet.emplaceDiscrete(DiscreteKey{M(i), 2}, "4/6");
|
||||
}
|
||||
|
@ -67,13 +67,13 @@ inline HybridBayesNet createHybridBayesNet(int numMeasurements = 1,
|
|||
* Create a tiny two variable hybrid factor graph which represents a discrete
|
||||
* mode and a continuous variable x0, given a number of measurements of the
|
||||
* continuous variable x0. If no measurements are given, they are sampled from
|
||||
* the generative Bayes net model HybridBayesNet::Example(numMeasurements)
|
||||
* the generative Bayes net model HybridBayesNet::Example(num_measurements)
|
||||
*/
|
||||
inline HybridGaussianFactorGraph createHybridGaussianFactorGraph(
|
||||
int numMeasurements = 1,
|
||||
int num_measurements = 1,
|
||||
boost::optional<VectorValues> measurements = boost::none,
|
||||
bool manyModes = false) {
|
||||
auto bayesNet = createHybridBayesNet(numMeasurements, manyModes);
|
||||
auto bayesNet = createHybridBayesNet(num_measurements, manyModes);
|
||||
if (measurements) {
|
||||
// Use the measurements to create a hybrid factor graph.
|
||||
return bayesNet.toFactorGraph(*measurements);
|
||||
|
|
|
@ -621,9 +621,9 @@ TEST(HybridGaussianFactorGraph, ErrorAndProbPrimeTree) {
|
|||
// assignment.
|
||||
TEST(HybridGaussianFactorGraph, assembleGraphTree) {
|
||||
using symbol_shorthand::Z;
|
||||
const int numMeasurements = 1;
|
||||
const int num_measurements = 1;
|
||||
auto fg = tiny::createHybridGaussianFactorGraph(
|
||||
numMeasurements, VectorValues{{Z(0), Vector1(5.0)}});
|
||||
num_measurements, VectorValues{{Z(0), Vector1(5.0)}});
|
||||
EXPECT_LONGS_EQUAL(3, fg.size());
|
||||
|
||||
// Assemble graph tree:
|
||||
|
@ -662,9 +662,9 @@ TEST(HybridGaussianFactorGraph, assembleGraphTree) {
|
|||
// Check that eliminating tiny net with 1 measurement yields correct result.
|
||||
TEST(HybridGaussianFactorGraph, EliminateTiny1) {
|
||||
using symbol_shorthand::Z;
|
||||
const int numMeasurements = 1;
|
||||
const int num_measurements = 1;
|
||||
auto fg = tiny::createHybridGaussianFactorGraph(
|
||||
numMeasurements, VectorValues{{Z(0), Vector1(5.0)}});
|
||||
num_measurements, VectorValues{{Z(0), Vector1(5.0)}});
|
||||
EXPECT_LONGS_EQUAL(3, fg.size());
|
||||
|
||||
// Create expected Bayes Net:
|
||||
|
@ -696,9 +696,9 @@ TEST(HybridGaussianFactorGraph, EliminateTiny1) {
|
|||
TEST(HybridGaussianFactorGraph, EliminateTiny2) {
|
||||
// Create factor graph with 2 measurements such that posterior mean = 5.0.
|
||||
using symbol_shorthand::Z;
|
||||
const int numMeasurements = 2;
|
||||
const int num_measurements = 2;
|
||||
auto fg = tiny::createHybridGaussianFactorGraph(
|
||||
numMeasurements,
|
||||
num_measurements,
|
||||
VectorValues{{Z(0), Vector1(4.0)}, {Z(1), Vector1(6.0)}});
|
||||
EXPECT_LONGS_EQUAL(4, fg.size());
|
||||
|
||||
|
@ -731,11 +731,11 @@ TEST(HybridGaussianFactorGraph, EliminateTiny2) {
|
|||
TEST(HybridGaussianFactorGraph, EliminateTiny22) {
|
||||
// Create factor graph with 2 measurements such that posterior mean = 5.0.
|
||||
using symbol_shorthand::Z;
|
||||
const int numMeasurements = 2;
|
||||
const int num_measurements = 2;
|
||||
const bool manyModes = true;
|
||||
|
||||
// Create Bayes net and convert to factor graph.
|
||||
auto bn = tiny::createHybridBayesNet(numMeasurements, manyModes);
|
||||
auto bn = tiny::createHybridBayesNet(num_measurements, manyModes);
|
||||
const VectorValues measurements{{Z(0), Vector1(4.0)}, {Z(1), Vector1(6.0)}};
|
||||
auto fg = bn.toFactorGraph(measurements);
|
||||
EXPECT_LONGS_EQUAL(5, fg.size());
|
||||
|
|
Loading…
Reference in New Issue