コード例 #1
0
ファイル: meta_objects.hpp プロジェクト: Manokha/firestarter
	static void call_op(
		void(*operation_ptr)(void),
		some& value,
		some& context,
		std::false_type
	)
	{
		if(operation_ptr)
		{
			assert(!value.empty());
			typedef void(*operation_type)(T&, some&);
			operation_type operation = operation_type(operation_ptr);
			operation(some_cast<T>(value), context);
		}
	}
コード例 #2
0
ファイル: model1.hpp プロジェクト: tarowatanabe/trance
      void operation_unary(Parser& parser,
			   const feature_set_type& feats,
			   const Theta& theta,
			   const state_type& state,
			   const symbol_type& label)
      {
	state_type state_new = parser.state_allocator_.allocate();

	state_new.step()  = state.step() + 1;
	state_new.next()  = state.next();
	state_new.unary() = state.unary() + 1;
      
	state_new.operation() = operation_type(operation_type::UNARY, state.operation().closure() + 1);
	state_new.label()     = label;
	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_new.label(),
						 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(label);
	const size_type offset_category       = theta.offset_category(label);
      
	state_new.layer(theta.hidden_) = (theta.Bu_.block(offset_category, 0, theta.hidden_, 1)
					  + (theta.Wu_.block(offset_category, 0, theta.hidden_, theta.hidden_)
					     * 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);
      }