本文整理汇总了C++中CFactor::set_energy方法的典型用法代码示例。如果您正苦于以下问题:C++ CFactor::set_energy方法的具体用法?C++ CFactor::set_energy怎么用?C++ CFactor::set_energy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CFactor
的用法示例。
在下文中一共展示了CFactor::set_energy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loss_augmentation
void CFactorGraph::loss_augmentation(SGVector<int32_t> states_gt, SGVector<float64_t> loss)
{
if (loss.size() == 0)
{
loss.resize_vector(states_gt.size());
SGVector<float64_t>::fill_vector(loss.vector, loss.vlen, 1.0 / states_gt.size());
}
int32_t num_vars = states_gt.size();
ASSERT(num_vars == loss.size());
SGVector<int32_t> var_flags(num_vars);
var_flags.zero();
// augment loss to incorrect states in the first factor containing the variable
// since += L_i for each variable if it takes wrong state ever
// TODO: augment unary factors
for (int32_t fi = 0; fi < m_factors->get_num_elements(); ++fi)
{
CFactor* fac = dynamic_cast<CFactor*>(m_factors->get_element(fi));
SGVector<int32_t> vars = fac->get_variables();
for (int32_t vi = 0; vi < vars.size(); vi++)
{
int32_t vv = vars[vi];
ASSERT(vv < num_vars);
if (var_flags[vv])
continue;
SGVector<float64_t> energies = fac->get_energies();
for (int32_t ei = 0; ei < energies.size(); ei++)
{
CTableFactorType* ftype = fac->get_factor_type();
int32_t vstate = ftype->state_from_index(ei, vi);
SG_UNREF(ftype);
if (states_gt[vv] == vstate)
continue;
// -delta(y_n, y_i_n)
fac->set_energy(ei, energies[ei] - loss[vv]);
}
var_flags[vv] = 1;
}
SG_UNREF(fac);
}
// make sure all variables have been checked
int32_t min_var = SGVector<int32_t>::min(var_flags.vector, var_flags.vlen);
ASSERT(min_var == 1);
}