本文整理汇总了C++中state_type::feature_state方法的典型用法代码示例。如果您正苦于以下问题:C++ state_type::feature_state方法的具体用法?C++ state_type::feature_state怎么用?C++ state_type::feature_state使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类state_type
的用法示例。
在下文中一共展示了state_type::feature_state方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: operation_reduce
void operation_reduce(Parser& parser,
const feature_set_type& feats,
const Theta& theta,
const state_type& state,
const symbol_type& label)
{
const size_type offset1 = 0;
const size_type offset2 = theta.hidden_;
const state_type state_reduced = state.stack();
const state_type state_stack = state_reduced.stack();
state_type state_new = parser.state_allocator_.allocate();
state_new.step() = state.step() + 1;
state_new.next() = state.next();
state_new.unary() = state.unary();
state_new.operation() = operation_type::REDUCE;
state_new.label() = label;
state_new.head() = symbol_type::EPSILON;
state_new.span() = span_type(state_reduced.span().first_, state.span().last_);
state_new.stack() = state_stack;
state_new.derivation() = state;
state_new.reduced() = state_reduced;
state_new.feature_vector() = parser.feature_vector_allocator_.allocate();
state_new.feature_state() = feats.apply(state_new.operation(),
state_new.label(),
state.feature_state(),
state_reduced.feature_state(),
*state_new.feature_vector());
const size_type index_operation = theta.index_operation(state_new.operation());
const size_type offset_operation = index_operation * theta.hidden_;
const size_type offset_classification = theta.offset_classification(label);
const size_type offset_category = theta.offset_category(label);
state_new.layer(theta.hidden_) = (theta.Bre_.block(offset_category, 0, theta.hidden_, 1)
+ (theta.Wre_.block(offset_category, offset1, theta.hidden_, theta.hidden_)
* state.layer(theta.hidden_))
+ (theta.Wre_.block(offset_category, offset2, theta.hidden_, theta.hidden_)
* state_reduced.layer(theta.hidden_))
).array().unaryExpr(model_type::activation());
const double score = (theta.Wc_.block(offset_classification, offset_operation, 1, theta.hidden_) * state_new.layer(theta.hidden_)
+ theta.Bc_.block(offset_classification, index_operation, 1, 1))(0, 0);
state_new.score() = trance::dot_product(theta.Wfe_, *state_new.feature_vector()) + state.score() + score;
parser.agenda_[state_new.step()].push_back(state_new);
}
示例2: operation_idle
void operation_idle(Parser& parser,
const feature_set_type& feats,
const Theta& theta,
const state_type& state)
{
state_type state_new = parser.state_allocator_.allocate();
state_new.step() = state.step() + 1;
state_new.next() = state.next();
state_new.unary() = state.unary();
state_new.operation() = operation_type::IDLE;
state_new.label() = symbol_type::IDLE;
state_new.head() = symbol_type::EPSILON;
state_new.span() = state.span();
state_new.stack() = state.stack();
state_new.derivation() = state;
state_new.reduced() = state_type();
state_new.feature_vector() = parser.feature_vector_allocator_.allocate();
state_new.feature_state() = feats.apply(state_new.operation(),
state.feature_state(),
*state_new.feature_vector());
const size_type index_operation = theta.index_operation(state_new.operation());
const size_type offset_operation = index_operation * theta.hidden_;
const size_type offset_classification = theta.offset_classification(symbol_type::IDLE);
state_new.layer(theta.hidden_) = (theta.Bi_
+ theta.Wi_ * state.layer(theta.hidden_)
).array().unaryExpr(model_type::activation());
const double score = (theta.Wc_.block(offset_classification, offset_operation, 1, theta.hidden_) * state_new.layer(theta.hidden_)
+ theta.Bc_.block(offset_classification, index_operation, 1, 1))(0, 0);
state_new.score() = trance::dot_product(theta.Wfe_, *state_new.feature_vector()) + state.score() + score;
parser.agenda_[state_new.step()].push_back(state_new);
}