本文整理汇总了C++中BayesNet::marginal_dist方法的典型用法代码示例。如果您正苦于以下问题:C++ BayesNet::marginal_dist方法的具体用法?C++ BayesNet::marginal_dist怎么用?C++ BayesNet::marginal_dist使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BayesNet
的用法示例。
在下文中一共展示了BayesNet::marginal_dist方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
void run(unsigned int size, unsigned int select) {
BayesNet<> bn;
map<vector<int>, map<int, double>> cpt;
map<int, double> dist;
map<vector<int>, map<int, double>> sinkCPT;
for (int i = 0; i < size; i++) {
if (i == select) {
dist.insert(make_pair(0, 0.0));
dist.insert(make_pair(1, 1.0));
cpt.insert(CondProb<>::CondCase(vector<int>(), dist));
bn.add_node(i, CondProb<>(cpt));
cpt.clear();
dist.insert(make_pair(0, 0.0));
dist.insert(make_pair(1, 1.0));
vector<int> parents(size, 0);
parents[i] = 1;
sinkCPT.insert(CondProb<>::CondCase(parents, dist));
} else {
dist.insert(make_pair(0, 1.0));
dist.insert(make_pair(1, 0.0));
cpt.insert(CondProb<>::CondCase(vector<int>(), dist));
bn.add_node(i, CondProb<>(cpt));
cpt.clear();
dist.insert(make_pair(0, 1.0));
dist.insert(make_pair(1, 0.0));
vector<int> parents(size, 0);
parents[i] = 1;
sinkCPT.insert(CondProb<>::CondCase(parents, dist));
}
cpt.clear();
dist.clear();
}
set<int> parents;
for (int i = 0; i < size; i++)
parents.insert(i);
bn.add_node(size, parents, CondProb<>(sinkCPT));
map<int, int> values;
for (int i = 0; i < size; i++)
values.insert(make_pair(0, 0));
values.insert(make_pair(select, 1));
map<std::map<int, int>, double> marginal_dist = bn.marginal_dist(values, 512, SampleStrategy::GIBBS);
assertEquals(marginal_dist[values], (double)1.0);
}
示例2: canMarginalizeNode
void canMarginalizeNode() {
BayesNet<> bn;
map<vector<int>, map<int, double>> cpt;
map<int, double> dist;
dist.insert(make_pair(0, 0.7));
dist.insert(make_pair(1, 0.3));
cpt.insert(CondProb<>::CondCase(vector<int>(), dist));
bn.add_node(0, CondProb<>(cpt));
map<int, double> marginal_dist = bn.marginal_dist(0, 512);
assertTrue(marginal_dist[0] > 0.65 && marginal_dist[0] < 0.75);
assertTrue(marginal_dist[1] > 0.25 && marginal_dist[1] < 0.35);
}
示例3: canMarginalizeNetwork
void canMarginalizeNetwork() {
BayesNet<> bn;
map<vector<int>, map<int, double>> cpt;
map<int, double> dist;
dist.insert(make_pair(0, 0.7));
dist.insert(make_pair(1, 0.3));
cpt.insert(CondProb<>::CondCase(vector<int>(), dist));
bn.add_node(0, CondProb<>(cpt));
map<int, int> values;
values.insert(make_pair(0, 0));
map<std::map<int, int>, double> marginal_dist = bn.marginal_dist(values, 512, SampleStrategy::GIBBS);
assertTrue(marginal_dist[values] > 0.65 && marginal_dist[values] < 0.75);
}