本文整理汇总了C++中CDotFeatures::dense_dot方法的典型用法代码示例。如果您正苦于以下问题:C++ CDotFeatures::dense_dot方法的具体用法?C++ CDotFeatures::dense_dot怎么用?C++ CDotFeatures::dense_dot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDotFeatures
的用法示例。
在下文中一共展示了CDotFeatures::dense_dot方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: argmax
CResultSet* CMulticlassModel::argmax(
SGVector< float64_t > w,
int32_t feat_idx,
bool const training)
{
CDotFeatures* df = (CDotFeatures*) m_features;
int32_t feats_dim = df->get_dim_feature_space();
if ( training )
{
CMulticlassSOLabels* ml = (CMulticlassSOLabels*) m_labels;
m_num_classes = ml->get_num_classes();
}
else
{
REQUIRE(m_num_classes > 0, "The model needs to be trained before "
"using it for prediction\n");
}
int32_t dim = get_dim();
ASSERT(dim == w.vlen)
// Find the class that gives the maximum score
float64_t score = 0, ypred = 0;
float64_t max_score = -CMath::INFTY;
for ( int32_t c = 0 ; c < m_num_classes ; ++c )
{
score = df->dense_dot(feat_idx, w.vector+c*feats_dim, feats_dim);
if ( training )
score += delta_loss(feat_idx, c);
if ( score > max_score )
{
max_score = score;
ypred = c;
}
}
// Build the CResultSet object to return
CResultSet* ret = new CResultSet();
SG_REF(ret);
CRealNumber* y = new CRealNumber(ypred);
SG_REF(y);
ret->psi_pred = get_joint_feature_vector(feat_idx, y);
ret->score = max_score;
ret->argmax = y;
if ( training )
{
ret->delta = CStructuredModel::delta_loss(feat_idx, y);
ret->psi_truth = CStructuredModel::get_joint_feature_vector(
feat_idx, feat_idx);
ret->score -= SGVector< float64_t >::dot(w.vector,
ret->psi_truth.vector, dim);
}
return ret;
}