• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ context_type类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中context_type的典型用法代码示例。如果您正苦于以下问题:C++ context_type类的具体用法?C++ context_type怎么用?C++ context_type使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了context_type类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: operator

			SPROUT_CONSTEXPR result_type operator()(
				Expr const& expr,
				context_type const& ctx
				) const
			{
				return sprout::weed::eval(sprout::tuples::get<0>(expr.args()), ctx).success()
					? result_type(true, ctx.begin(), attribute_type(), ctx)
					: result_type(false, ctx.begin(), attribute_type(), ctx)
					;
			}
开发者ID:LoliGothick,项目名称:Sprout,代码行数:10,代码来源:address_of.hpp


示例2: operator

			SPROUT_CONSTEXPR result_type operator()(
				Expr const& expr,
				context_type const& ctx
				) const
			{
				return call(
					sprout::tuples::get<0>(expr.args())
						.template operator()(ctx.begin(), ctx.end(), ctx),
					ctx
					);
			}
开发者ID:darkfall,项目名称:Sprout,代码行数:11,代码来源:parser.hpp


示例3: dispatch

 virtual void dispatch(context_type ctx,
                       const std::string & path,
                       std::string::const_iterator segment_begin,
                       std::string::const_iterator segment_end)
 {
     ctx.write_response(response_);
 }
开发者ID:jamal-fuma,项目名称:http,代码行数:7,代码来源:static_file.hpp


示例4: call

			SPROUT_CONSTEXPR typename std::enable_if<
				(sizeof...(Attrs) + 2 < limit::value),
				result_type
			>::type call(
				expr_type const& expr,
				context_type const& ctx,
				sprout::weed::limited::category limited_category,
				Result const& res,
				Head const& head,
				Attrs const&... attrs
				) const
			{
				return res.success()
					? call(
						expr,
						res.ctx(),
						limited_category,
						sprout::weed::eval(expr, res.ctx()),
						head,
						attrs...,
						res.attr()
						)
					: result_type(
						true,
						ctx.begin(),
						sprout::weed::attr_cnv::times<limit::value, attr_type>(head, attrs...),
						ctx
						)
					;
			}
开发者ID:kundor,项目名称:Sprout,代码行数:30,代码来源:dereference.hpp


示例5: call_1

			SPROUT_CONSTEXPR result_type call_1(
				expr1_type const& expr1,
				expr2_type const& expr2,
				context_type const& ctx,
				sprout::weed::limited::category limited_category,
				Result const& res,
				Attrs const&... attrs
				) const
			{
				return res.success()
					? call(
						expr1,
						expr2,
						res.ctx(),
						limited_category,
						sprout::weed::eval(expr1, res.ctx()),
						attrs...
						)
					: result_type(
						true,
						ctx.begin(),
						sprout::weed::attr_cnv::modulus<limit::value, attr_type>(attrs...),
						ctx
						)
					;
			}
开发者ID:filthy-faith,项目名称:Sprout,代码行数:26,代码来源:modulus.hpp


示例6: call_1

			SPROUT_CONSTEXPR result_type call_1(
				typename Expr::args_type const& args,
				context_type const& ctx,
				Result1 const& res
				) const
			{
				return res.success() && !sprout::weed::eval(sprout::tuples::get<1>(args), ctx).success()
					? res
					: result_type(false, ctx.begin(), attribute_type(), ctx)
					;
			}
开发者ID:Fadis,项目名称:Sprout,代码行数:11,代码来源:minus.hpp


示例7: call_inf

			SPROUT_CONSTEXPR result_type call_inf(
				expr_type const& expr,
				context_type const& ctx,
				Result const& res
				) const
			{
				return res.success()
					? call_inf(expr, res.ctx(), sprout::weed::eval(expr, res.ctx()))
					: result_type(true, ctx.begin(), attribute_type(), ctx)
					;
			}
开发者ID:kundor,项目名称:Sprout,代码行数:11,代码来源:dereference.hpp


示例8: dispatch

 virtual void dispatch(context_type ctx,
                       const std::string & path,
                       std::string::const_iterator segment_begin,
                       std::string::const_iterator segment_end)
 {
     boost::shared_ptr<response_type> response(boost::make_shared<response_type>());
     response->headers.at<headers::content_type>() = type_;
     boost::interprocess::file_mapping mapping((path_ + std::string(segment_end, path.end())).c_str(), boost::interprocess::read_only);
     response->body = boost::make_shared<boost::interprocess::mapped_region>(mapping, boost::interprocess::read_only);
     ctx.write_response(response);
 }
开发者ID:jamal-fuma,项目名称:http,代码行数:11,代码来源:static_directory.hpp


示例9: eval

/**
 * Evaluates a context, return the conditional probability p(y|x).
 *
 * This method calculates the conditional probability p(y|x) for given x and y.
 *
 * @param context A list of pair<string, double> indicates names of 
 *        the contextual predicates and their values which are to be
 *        evaluated together.
 * @param outcome The outcome label for which the conditional probability is
 *        calculated.
 * @return The conditional probability of p(outcome|context).
 * \sa eval_all()
 */
double MaxentModel::eval(const context_type& context,
                const outcome_type& outcome) const{

    size_t oid = m_outcome_map->id(outcome);

    if (oid == m_outcome_map->null_id) {
        cerr << "[MaxentModel::eval()] unknown outcome id:" << oid << endl;
        return 0.0;
    }

    static vector<double> probs;
    if (probs.size() != m_outcome_map->size())
        probs.resize(m_outcome_map->size());
        fill(probs.begin(), probs.end(), 0.0);

    size_t pid;
    for (size_t i = 0; i < context.size(); ++i) {
        pid = m_pred_map->id(context[i].first);
        if (pid != m_pred_map->null_id) {
            std::vector<pair<size_t, size_t> >& param = (*m_params)[pid];
            float fval = context[i].second;
            for(size_t j = 0;j < param.size(); ++j)
                probs[param[j].first] += m_theta[param[j].second] * fval;
        } else {
            //#warning how to deal with unseen predicts?
            //m_debug.debug(0,"Predict id %d not found.",i);
        }
    }


    /* For the rationale behind subtracting max_prob from the log-probabilities
       see maxentmodel.cpp:maxent::MaxentModel::eval_all*/

    // Find the maximum log-prob
    double max_prob = numeric_limits<double>::min();
    for (size_t i = 0; i < probs.size(); ++i) {
        max_prob = max(max_prob, probs[i]);
    }

    double sum = 0.0;
    for (size_t i = 0; i < probs.size(); ++i) {
        // Subtract the maximum log-prob from the others to get them in
        // the (-inf,0] range.
        probs[i] = exp(probs[i] - max_prob);
        sum += probs[i];
    }

    for (size_t i = 0; i < probs.size(); ++i) {
        probs[i] /= sum;
    }

    return probs[oid];
}
开发者ID:pyongjoo,项目名称:maxent,代码行数:66,代码来源:maxentmodel.cpp


示例10: renderScene

void WglViewBase::renderScene(context_type &context, camera_type &camera)
{
#ifdef _DEBUG
	{
		// error-checking routine of OpenGL
		const GLenum glErrorCode = glGetError();
		if (GL_NO_ERROR != glErrorCode)
			std::cerr << "OpenGL error at " << __LINE__ << " in " << __FILE__ << ": " << gluErrorString(glErrorCode) << std::endl;
	}
#endif

	GLint oldMatrixMode = 0;
	glGetIntegerv(GL_MATRIX_MODE, &oldMatrixMode);
	if (oldMatrixMode != GL_MODELVIEW) glMatrixMode(GL_MODELVIEW);

	{
		glPushMatrix();
			//
			glLoadIdentity();
			camera.lookAt();

			//
			glPushMatrix();
				doPrepareRendering(context, camera);
			glPopMatrix();

			glPushMatrix();
				doRenderStockScene(context, camera);
			glPopMatrix();

			doRenderScene(context, camera);
		glPopMatrix();
	}

	glFlush();

	// swap buffers
	context.swapBuffer();

	if (oldMatrixMode != GL_MODELVIEW) glMatrixMode(oldMatrixMode);

#ifdef _DEBUG
	{
		// error-checking routine of OpenGL
		const GLenum glErrorCode = glGetError();
		if (GL_NO_ERROR != glErrorCode)
			std::cerr << "OpenGL error at " << __LINE__ << " in " << __FILE__ << ": " << gluErrorString(glErrorCode) << std::endl;
	}
#endif
}
开发者ID:sangwook236,项目名称:sangwook-library,代码行数:50,代码来源:WglViewBase.cpp


示例11: call

			SPROUT_CONSTEXPR typename std::enable_if<
				Infinity,
				result_type
			>::type call(
				expr1_type const& expr1,
				expr2_type const& expr2,
				context_type const& ctx,
				Result const& res
				) const
			{
				return res.success()
					? call_inf_1(expr1, expr2, res.ctx(), sprout::weed::eval(expr2, res.ctx()))
					: result_type(false, ctx.begin(), attribute_type(), ctx)
					;
			}
开发者ID:filthy-faith,项目名称:Sprout,代码行数:15,代码来源:modulus.hpp


示例12: call_2

			SPROUT_CONSTEXPR result_type call_2(
				typename Expr::args_type const&,
				context_type const& ctx,
				Result2 const& res
				) const
			{
				return res.success()
					? result_type(
						true,
						res.current(),
						sprout::weed::attr_cnv::bitwise_or<attr1_type, attr2_type>(res.attr()),
						context_type(ctx, res.current())
						)
					: result_type(false, ctx.begin(), attribute_type(), ctx)
					;
			}
开发者ID:Fadis,项目名称:Sprout,代码行数:16,代码来源:bitwise_or.hpp


示例13: call_2

			SPROUT_CONSTEXPR result_type call_2(
				typename Expr::args_type const&,
				context_type const& ctx,
				Attr1 const& attr,
				Result2 const& res
				) const
			{
				return res.success()
					? result_type(
						true,
						res.current(),
						sprout::weed::attr_cnv::shift_left(attr, res.attr()),
						context_type(ctx, res.current())
						)
					: result_type(false, ctx.begin(), attribute_type(), ctx)
					;
			}
开发者ID:kundor,项目名称:Sprout,代码行数:17,代码来源:shift_left.hpp


示例14: eval_all

/**
 * Evaluates a context, return the conditional distribution of the context.
 *
 * This method calculates the conditional probability p(y|x) for each possible
 * outcome tag y.
 *
 * @param context A list of pair<string, double> indicates the contextual
 *                predicates and their values (must be >= 0) which are to be
 *                evaluated together.
 * @param outcomes An array of the outcomes paired with it's probability
 *        predicted by the model (the conditional distribution).
 * @param sort_result Whether or not the returned outcome array is sorted
 *                    (larger probability first). Default is true.
 *
 * TODO:  need optimized for large number of outcomes
 *
 * \sa eval()
 */
void MaxentModel::eval_all(const context_type& context,
        std::vector<pair<outcome_type, double> >& outcomes,
        bool sort_result) const {
    assert(m_params);

    //static vector<double> probs; //REMIND remove static here
    vector<double> probs;
    if (probs.size() != m_outcome_map->size())
        probs.resize(m_outcome_map->size());
    fill(probs.begin(), probs.end(), 0.0);

    size_t pid;
    for (size_t i = 0; i < context.size(); ++i) {
        pid = m_pred_map->id(context[i].first);
        if (pid != m_pred_map->null_id) {
            std::vector<pair<size_t, size_t> >& param = (*m_params)[pid];
            float fval = context[i].second;
            for(size_t j = 0;j < param.size(); ++j)
                probs[param[j].first] += m_theta[param[j].second] * fval;
        } else {
            //#warning how to deal with unseen predicts?
            //m_debug.debug(0,"Predict id %d not found.",i);
        }
    }

    double sum = 0.0;
    for (size_t i = 0; i < probs.size(); ++i) {
        probs[i] = exp(probs[i]);
        sum += probs[i];
    }

    for (size_t i = 0; i < probs.size(); ++i) {
        probs[i] /= sum;
    }

    outcomes.resize(m_outcome_map->size());
    for (size_t i = 0;i < outcomes.size(); ++i) {
        outcomes[i].first = (*m_outcome_map)[i];
        outcomes[i].second = probs[i];
    }


    if (sort_result)
        sort(outcomes.begin(),outcomes.end(), cmp_outcome());
}
开发者ID:izenecloud,项目名称:icma,代码行数:63,代码来源:maxentmodel.cpp


示例15: call_1

			SPROUT_CONSTEXPR result_type call_1(
				typename Expr::args_type const& args,
				context_type const& ctx,
				Result1 const& res
				) const
			{
				return res.success()
					? result_type(
						true,
						res.current(),
						sprout::weed::attr_cnv::mem_ptr(
							res.attr(), sprout::tuples::get<0>(sprout::tuples::get<1>(args).args())
							),
						context_type(ctx, res.current())
						)
					: result_type(false, ctx.begin(), attribute_type(), ctx)
					;
			}
开发者ID:kundor,项目名称:Sprout,代码行数:18,代码来源:mem_ptr.hpp


示例16: eval

/**
 * Evaluates a context, return the conditional probability p(y|x).
 *
 * This method calculates the conditional probability p(y|x) for given x and y.
 *
 * @param context A list of pair<string, double> indicates names of 
 *        the contextual predicates and their values which are to be
 *        evaluated together.
 * @param outcome The outcome label for which the conditional probability is
 *        calculated.
 * @return The conditional probability of p(outcome|context).
 * \sa eval_all()
 */
double MaxentModel::eval(const context_type& context,
                const outcome_type& outcome) const{

    size_t oid = m_outcome_map->id(outcome);

    if (oid == m_outcome_map->null_id) {
        //cerr << "[MaxentModel::eval()] unknown outcome id:" << oid << endl;
        return 0.0;
    }

    static vector<double> probs;
    if (probs.size() != m_outcome_map->size())
        probs.resize(m_outcome_map->size());
        fill(probs.begin(), probs.end(), 0.0);

    size_t pid;
    for (size_t i = 0; i < context.size(); ++i) {
        pid = m_pred_map->id(context[i].first);
        if (pid != m_pred_map->null_id) {
            std::vector<pair<size_t, size_t> >& param = (*m_params)[pid];
            float fval = context[i].second;
            for(size_t j = 0;j < param.size(); ++j)
                probs[param[j].first] += m_theta[param[j].second] * fval;
        } else {
            //#warning how to deal with unseen predicts?
            //m_debug.debug(0,"Predict id %d not found.",i);
        }
    }

    double sum = 0.0;
    for (size_t i = 0; i < probs.size(); ++i) {
        probs[i] = exp(probs[i]);
        if (!finite(probs[i]))
            probs[i] = numeric_limits<double>::max();// DBL_MAX;
        sum += probs[i];
    }
    for (size_t i = 0; i < probs.size(); ++i) {
        probs[i] /= sum;
    }

    return probs[oid];
}
开发者ID:izenecloud,项目名称:icma,代码行数:55,代码来源:maxentmodel.cpp


示例17: call

			SPROUT_CONSTEXPR result_type call(
				Arg const& arg,
				context_type const& ctx
				) const
			{
				return sprout::distance(ctx.begin(), ctx.end()) >= sprout::size(arg)
					&& sprout::equal(sprout::begin(arg), sprout::end(arg), ctx.begin())
					? result_type(
						true,
						sprout::next(ctx.begin(), sprout::size(arg)),
						attribute_type(),
						context_type(ctx, sprout::next(ctx.begin(), sprout::size(arg)))
						)
					: result_type(false, ctx.begin(), attribute_type(), ctx)
					;
			}
开发者ID:LoliGothick,项目名称:Sprout,代码行数:16,代码来源:string.hpp


示例18: operator

			SPROUT_CONSTEXPR result_type operator()(
				Expr const& expr,
				context_type const& ctx
				) const
			{
				typedef typename std::iterator_traits<Iterator>::value_type elem_type;
				return ctx.begin() != ctx.end()
					&& *ctx.begin() == elem_type(sprout::tuples::get<0>(expr.args()))
					? result_type(
						true,
						sprout::next(ctx.begin()),
						attribute_type(),
						context_type(ctx, sprout::next(ctx.begin()))
						)
					: result_type(false, ctx.begin(), attribute_type(), ctx)
					;
			}
开发者ID:darkfall,项目名称:Sprout,代码行数:17,代码来源:char_type.hpp


示例19: eval_all

/**
 * Evaluates a context, return the conditional distribution of the context.
 *
 * This method calculates the conditional probability p(y|x) for each possible
 * outcome tag y.
 *
 * @param context A list of pair<string, double> indicates the contextual
 *                predicates and their values (must be >= 0) which are to be
 *                evaluated together.
 * @param outcomes An array of the outcomes paired with it's probability
 *        predicted by the model (the conditional distribution).
 * @param sort_result Whether or not the returned outcome array is sorted
 *                    (larger probability first). Default is true.
 *
 * TODO:  need optimized for large number of outcomes
 *
 * \sa eval()
 */
void MaxentModel::eval_all(const context_type& context,
        std::vector<pair<outcome_type, double> >& outcomes,
        bool sort_result) const {
    assert(m_params);

    //TODO:static?
    static vector<double> probs;
    if (probs.size() != m_outcome_map->size())
        probs.resize(m_outcome_map->size());
    fill(probs.begin(), probs.end(), 0.0);

    size_t pid;
    for (size_t i = 0; i < context.size(); ++i) {
        pid = m_pred_map->id(context[i].first);
        if (pid != m_pred_map->null_id) {
            std::vector<pair<size_t, size_t> >& param = (*m_params)[pid];
            float fval = context[i].second;
            for(size_t j = 0;j < param.size(); ++j)
                probs[param[j].first] += m_theta[param[j].second] * fval;
        } else {
            //#warning how to deal with unseen predicts?
            //m_debug.debug(0,"Predict id %d not found.",i);
        }
    }


    /* We will need to exponentiate the log-probabilites in probs. These
       log-probabilites can however be quite large and exponentiating them
       can render them infinite. At some places in the library, there is
       an effort to fight this by reducing the infinite value down to
       DBL_MAX, which isn't okay either, because we can have two such
       large probabilites and when we try to find their sum for normalization,
       we overflow again. Trying to normalize these large probabilities
       would also make them NaN, which is a fatal error in this domain.
       Also, by clipping all large values to DBL_MAX, we can lose a lot of
       information when more than 1 log-prob with very distinct values
       crosses over the maximum exponent.

       The proposed solution is to subtract some value from the log-probs
       to put them in the (-inf,O] range, so that exponentiation won't
       cause an overflow. The log-probabilities aren't so large that we
       would have to fear an underflow. If an underflow would occur, the
       exponentiation would make the probability 0 (exp(-inf) == 0) and we can
       show that this is correct. Because one of the log-probabilites now
       equals 0, we know that after exponentiation their sum is >= 1. This
       means that the true normalized probabilites will be even smaller. As
       the logarithm of the smallest positive double is pretty much finite
       (about -700 on my machine), we know that our probability is vastly
       smaller and 0 is about the best way to represent it.
       
       In this way, it could be possible that a significant difference between
       two highly improbable outcomes might be lost (the chance is however
       very small because we would have to have a sum of features * parameters
       equal to negative infinity). This is however much more tolerable than a
       loss of significant difference between two highly likely outcomes. */

    // Find the maximum log-prob
    double max_prob = numeric_limits<double>::min();
    for (size_t i = 0; i < probs.size(); ++i) {
        max_prob = max(max_prob, probs[i]);
    }

    double sum = 0.0;
    for (size_t i = 0; i < probs.size(); ++i) {
        // Subtract the maximum log-prob from the others to get them in
        // the (-inf,0] range.
        probs[i] = exp(probs[i] - max_prob);
        sum += probs[i];
    }

    for (size_t i = 0; i < probs.size(); ++i) {
        probs[i] /= sum;
    }

    outcomes.resize(m_outcome_map->size());
    for (size_t i = 0;i < outcomes.size(); ++i) {
        outcomes[i].first = (*m_outcome_map)[i];
        outcomes[i].second = probs[i];
    }


    if (sort_result)
//.........这里部分代码省略.........
开发者ID:pyongjoo,项目名称:maxent,代码行数:101,代码来源:maxentmodel.cpp



注:本文中的context_type类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ cpp_int_backend类代码示例发布时间:2022-05-31
下一篇:
C++ context_t类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap