本文整理汇总了C++中Factor::get方法的典型用法代码示例。如果您正苦于以下问题:C++ Factor::get方法的具体用法?C++ Factor::get怎么用?C++ Factor::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Factor
的用法示例。
在下文中一共展示了Factor::get方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getMaxProbAssignments
void BruteForceOptMatching::getMaxProbAssignments(
const BP& ia, const FactorGraph& fg, const ConnectedFactorGraph& graph,
McDArray<McVec2i>& pairs) {
for (int i = 0; i < graph.variables.size(); i++) {
McDArray<int> possibleAssignments;
getAssignmentsForVariable(graph.variables[i], possibleAssignments);
Factor belief =
ia.belief(Var(graph.variables[i], possibleAssignments.size() + 1));
float maxVal = -1 * FLT_MAX;
int maxIdx = -1;
for (int j = 0; j < possibleAssignments.size() + 1; j++) {
if (belief.get(j) > maxVal) {
maxVal = belief.get(j);
maxIdx = j;
}
}
int indexOfAssignmentInVertexList =
mapVariableAssignmentToIndexInVertexList(graph.variables[i],
maxIdx);
McVec2i pair =
McVec2i(graph.variables[i], indexOfAssignmentInVertexList);
pairs.append(pair);
}
outputSingleFactorValues(graph);
// std::vector<std::size_t> maxes= ia.findMaximum();
// vector<std::size_t>::iterator it=maxes.begin();
}
示例2: checkAmbiguities
void BruteForceOptMatching::checkAmbiguities(const BP& ia,
const FactorGraph& fg,
const ConnectedFactorGraph& graph,
McDArray<int>& ambiguities) {
for (int h = 0; h < graph.variables.size(); h++) {
McDArray<int> possibleAssignments;
getAssignmentsForVariable(graph.variables[h], possibleAssignments);
Factor belief =
ia.belief(Var(graph.variables[h], possibleAssignments.size() + 1));
float maxProb = belief.max();
int countSame = 0;
for (int k = 0; k < possibleAssignments.size() + 1; k++) {
float curProb = belief.get(k);
if (fabs(curProb - maxProb) < 0.1)
countSame++;
}
/////
cout << "\n Belief for var " << graph.variables[h] << "\n";
for (int k = 0; k < possibleAssignments.size() + 1; k++) {
float curProb = belief.get(k);
cout << curProb << " ";
}
cout << "\n";
////
if (countSame > 1) {
// oh no! We found an ambiguos assignment!
ambiguities.append(graph.variables[h]);
// print it out:
cout << "Found an ambiguous assignemnt to variable "
<< graph.variables[h] << "\n";
for (int k = 0; k < possibleAssignments.size() + 1; k++) {
float curProb = belief.get(k);
cout << curProb << " ";
}
cout << "\n";
}
}
}
示例3: outputSingleFactorValues
void BruteForceOptMatching::outputSingleFactorValues(
const ConnectedFactorGraph& graph) {
// output factor values
for (int j = 0; j < graph.factors.size(); j++) {
Factor fac = graph.factors[j];
if (fac.vars().size() != 1)
continue;
cout << "singvals for var " << fac.vars().front().label() << " :\n";
for (int k = 0; k < fac.nrStates(); k++) {
cout << fac.get(k) << " ";
}
cout << "\n";
}
}
示例4: outputDoubleFactorValues
void BruteForceOptMatching::outputDoubleFactorValues(
const ConnectedFactorGraph& graph) {
// output factor values
for (int j = 0; j < graph.factors.size(); j++) {
Factor fac = graph.factors[j];
if (fac.vars().size() != 2)
continue;
cout << "\nPotentials for vars " << fac.vars().front().label() << " - "
<< fac.vars().back().label() << "\n";
for (int k = 0; k < fac.vars().front().states(); k++) {
for (int l = 0; l < fac.vars().front().states(); l++) {
cout << fac.get(k * fac.vars().front().states() + l) << " ";
}
cout << "\n";
}
}
}