当前位置: 首页>>代码示例>>C++>>正文


C++ VecType类代码示例

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


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

示例1: FeedForward

  /**
   * Ordinary feed forward pass of a neural network, evaluating the function
   * f(x) by propagating the activity forward through f.
   *
   * @param inputActivation Input data used for evaluating the specified
   * activity function.
   * @param outputActivation Datatype to store the resulting output activation.
   */
  void FeedForward(const VecType& inputActivation, VecType& outputActivation)
  {
    if (inGate.n_cols < seqLen)
    {
      inGate = arma::zeros<MatType>(layerSize, seqLen);
      inGateAct = arma::zeros<MatType>(layerSize, seqLen);
      inGateError = arma::zeros<MatType>(layerSize, seqLen);
      outGate = arma::zeros<MatType>(layerSize, seqLen);
      outGateAct = arma::zeros<MatType>(layerSize, seqLen);
      outGateError = arma::zeros<MatType>(layerSize, seqLen);
      forgetGate = arma::zeros<MatType>(layerSize, seqLen);
      forgetGateAct = arma::zeros<MatType>(layerSize, seqLen);
      forgetGateError = arma::zeros<MatType>(layerSize, seqLen);
      state = arma::zeros<MatType>(layerSize, seqLen);
      stateError = arma::zeros<MatType>(layerSize, seqLen);
      cellAct = arma::zeros<MatType>(layerSize, seqLen);
    }

    // Split up the inputactivation into the 3 parts (inGate, forgetGate,
    // outGate).
    inGate.col(offset) = inputActivation.subvec(0, layerSize - 1);
    forgetGate.col(offset) = inputActivation.subvec(
        layerSize, (layerSize * 2) - 1);
    outGate.col(offset) = inputActivation.subvec(
        layerSize * 3, (layerSize * 4) - 1);

    if (peepholes && offset > 0)
    {
      inGate.col(offset) += inGatePeepholeWeights % state.col(offset - 1);
      forgetGate.col(offset) += forgetGatePeepholeWeights %
          state.col(offset - 1);
    }

    VecType inGateActivation = inGateAct.unsafe_col(offset);
    GateActivationFunction::fn(inGate.unsafe_col(offset), inGateActivation);

    VecType forgetGateActivation = forgetGateAct.unsafe_col(offset);
    GateActivationFunction::fn(forgetGate.unsafe_col(offset),
        forgetGateActivation);

    VecType cellActivation = cellAct.unsafe_col(offset);
    StateActivationFunction::fn(inputActivation.subvec(layerSize * 2,
        (layerSize * 3) - 1), cellActivation);

    state.col(offset) = inGateAct.col(offset) % cellActivation;

    if (offset > 0)
      state.col(offset) += forgetGateAct.col(offset) % state.col(offset - 1);

    if (peepholes)
      outGate.col(offset) += outGatePeepholeWeights % state.col(offset);

    VecType outGateActivation = outGateAct.unsafe_col(offset);
    GateActivationFunction::fn(outGate.unsafe_col(offset), outGateActivation);

    OutputActivationFunction::fn(state.unsafe_col(offset), outputActivation);
    outputActivation = outGateAct.col(offset) % outputActivation;

    offset = (offset + 1) % seqLen;
  }
开发者ID:riveridea,项目名称:mlpack,代码行数:68,代码来源:lstm_layer.hpp

示例2: operator

 void operator()(VecType x, VecType& y) {
   // y = x;
   // printf("Calling Preconditioners::LocalInnerSolver\n");
   std::fill(y.begin(),y.end(),typename VecType::value_type(0.));
   GMRES(plan, y, x, options, M, context);
   context.reset();
 }
开发者ID:LEONOB2014,项目名称:fmm-bem-relaxed,代码行数:7,代码来源:BlockDiagonalPC_Stokes.hpp

示例3: vec_exp_tanh_float

always_inline VecType vec_exp_tanh_float(VecType const & arg)
{
    typedef typename VecType::int_vec int_vec;

    /* Express e**x = e**g 2**n
     *   = e**g e**( n loge(2) )
     *   = e**( g + n loge(2) )
     */

    // black magic
    VecType x = arg;
    VecType z = round(VecType(1.44269504088896341f) * x);
    int_vec n = z.truncate_to_int();
    x -= z*VecType(0.693359375f);
    x -= z*VecType(-2.12194440e-4f);

    /* Theoretical peak relative error in [-0.5, +0.5] is 3.5e-8. */
    VecType p = 1.f +
        x * (1.00000035762786865234375f +
        x * (0.4999996721744537353515625f +
        x * (0.16665561497211456298828125f +
        x * (4.167006909847259521484375e-2f +
        x * (8.420792408287525177001953125e-3f +
        x * 1.386119984090328216552734375e-3f)))));

    /* multiply by power of 2 */
    VecType approx = ldexp_float(p, n);

    return approx;
}
开发者ID:mrotondo,项目名称:poopworm,代码行数:30,代码来源:vec_math.hpp

示例4:

hduPlane<T>::hduPlane(const VecType &pt1,
                   const VecType &pt2,
                   const VecType &p3)
{
    const VecType v1 = pt2 - pt1;
    const VecType v2 = p3 - pt1;
    
    m_normal = v1.crossProduct(v2);
    m_normal.normalize();
    
    m_d = -(m_normal.dotProduct(pt1));
}
开发者ID:gzmk,项目名称:phantom_code,代码行数:12,代码来源:hduPlane.cpp

示例5: dimCheck

  /** Dimensionality check during initialization */
  bool dimCheck(){

    if( Sx_.rows() != Sx_.cols() ){
      std::cerr << "Error: MatType must be a square matrix \n";
      return false;
    }
    if( Sx_.rows() != x_.size() ){
      std::cerr << "Error: VecType and MatType dimension mismatch \n";
      return false;
    }
    nDim_ = x_.size();
    return true;
  }
开发者ID:bigjun,项目名称:RFS-SLAM,代码行数:14,代码来源:RandomVec.hpp

示例6: entry_or_zero

 inline typename VecType::value_type entry_or_zero(const VecType &v, unsigned i)
 {
   if (i >= v.size())
     return 0;
   else
     return v[i];
 }
开发者ID:gimac,项目名称:pyrticle,代码行数:7,代码来源:tools.hpp

示例7: outputClass

 /*
  * Calculate the output class using the specified input activation.
  *
  * @param inputActivations Input data used to calculate the output class.
  * @param output Output class of the input activation.
  */
 void outputClass(const VecType& inputActivations, VecType& output)
 {
   output = arma::zeros<VecType>(inputActivations.n_elem);
   arma::uword maxIndex;
   inputActivations.max(maxIndex);
   output(maxIndex) = 1;
 }
开发者ID:PhenixI,项目名称:mlpack,代码行数:13,代码来源:one_hot_layer.hpp

示例8: vec_sin_float

always_inline VecType vec_sin_float(VecType const & arg)
{
    typedef typename VecType::int_vec int_vec;

    const typename VecType::float_type four_over_pi = 1.27323954473516268615107010698011489627567716592367;

    VecType sign = arg & VecType::gen_sign_mask();
    VecType abs_arg = arg & VecType::gen_abs_mask();

    VecType y = abs_arg * four_over_pi;

    int_vec j = y.truncate_to_int();

    /* cephes: j=(j+1) & (~1) */
    j = (j + int_vec(1)) & int_vec(~1);
    y = j.convert_to_float();

    /* sign based on quadrant */
    VecType swap_sign_bit = slli(j & int_vec(4), 29);
    sign = sign ^ swap_sign_bit;

    /* polynomial mask */
    VecType poly_mask = VecType (mask_eq(j & int_vec(2), int_vec(0)));

    /* black magic */
    static float DP1 = 0.78515625;
    static float DP2 = 2.4187564849853515625e-4;
    static float DP3 = 3.77489497744594108e-8;
    VecType base = ((abs_arg - y * DP1) - y * DP2) - y * DP3;

    /* [0..pi/4] */
    VecType z = base * base;
    VecType p1 = ((  2.443315711809948E-005 * z
        - 1.388731625493765E-003) * z
        + 4.166664568298827E-002) * z * z
        -0.5f * z + 1.0
        ;

    /* [pi/4..pi/2] */
    VecType p2 = ((-1.9515295891E-4 * z
         + 8.3321608736E-3) * z
         - 1.6666654611E-1) * z * base + base;

    VecType approximation =  select(p1, p2, poly_mask);

    return approximation ^ sign;
}
开发者ID:mrotondo,项目名称:poopworm,代码行数:47,代码来源:vec_math.hpp

示例9: VecType

//==========================
//	NW	N			N	NE
//	  \	|			|  /
//		a-----------b
//	  /	|			|  \
//	SW	S			S	SE
//==========================
int Stick::extrudeLines(const PathType& path, float width)
{
	if (path.size() < 2)
	{
		return EXTRUDE_FAIL;
	}
	
	int pointSize = path.size();
	int lineSize = pointSize - 1;

	_indexList.resize( lineSize*IDEX_FACTOR );

	for (int idx=0; idx < lineSize; idx++)
	{
		const VecType& a = path[idx];
		const VecType& b = path[idx+1];

		VecType e = (b-a);
		e.normalize();
		e *= width;

		VecType N = VecType(-e.y(), e.x(), 0);
		VecType S = -N;
		VecType NE = N + e;
		VecType NW = N - e;

		VecType SW = -NE;
		VecType SE = -NW;

		_vertexList.push_back( Vertex(a + SW) );
		_vertexList.push_back( Vertex(a + NW) );
		_vertexList.push_back( Vertex(a + S) );
		_vertexList.push_back( Vertex(a + N) );

		_vertexList.push_back( Vertex(b + S) );
		_vertexList.push_back( Vertex(b + N) );
		_vertexList.push_back( Vertex(b + SE) );
		_vertexList.push_back( Vertex(b + NE) );
	}

	_generateTriangleTexCoord();
	_generateTriangesIndices();

	return EXTRUDE_SUCCESS;	
}
开发者ID:dizuo,项目名称:xrender,代码行数:52,代码来源:stick.cpp

示例10: perform

	inline typename boost::disable_if_c<VecType::has_compare_bitmask, VecType >::type
	perform(VecType arg) const
	{
		typedef VecType vec;

		vec result;
		for (int i = 0; i != result.size; ++i)
			result.set(i, sc_scurve(arg.get(i)));
		return result;
	}
开发者ID:HuaxingXu,项目名称:supercollider,代码行数:10,代码来源:UnaryOpUGens.cpp

示例11: vec_exp_float

always_inline VecType vec_exp_float(VecType const & arg)
{
    typedef typename VecType::int_vec int_vec;

    /* Express e**x = e**g 2**n
     *   = e**g e**( n loge(2) )
     *   = e**( g + n loge(2) )
     */

    // black magic
    VecType x = arg;
    VecType z = round(VecType(1.44269504088896341f) * x);
    int_vec n = z.truncate_to_int();
    x -= z*VecType(0.693359375f);
    x -= z*VecType(-2.12194440e-4f);

    /* Theoretical peak relative error in [-0.5, +0.5] is 3.5e-8. */
    VecType p = VecType(VecType::gen_one()) +
        x * (1.00000035762786865234375f +
        x * (0.4999996721744537353515625f +
        x * (0.16665561497211456298828125f +
        x * (4.167006909847259521484375e-2f +
        x * (8.420792408287525177001953125e-3f +
        x * 1.386119984090328216552734375e-3f)))));

    /* multiply by power of 2 */
    VecType approx = ldexp_float(p, n);

    /* handle min/max boundaries */
    const VecType maxlogf(88.72283905206835f);
//    const VecType minlogf(-103.278929903431851103f);
	const VecType minlogf = -maxlogf;
    const VecType max_float(std::numeric_limits<float>::max());
    const VecType zero = VecType::gen_zero();

    VecType too_large = mask_gt(arg, maxlogf);
    VecType too_small = mask_lt(arg, minlogf);

    VecType ret = select(approx, max_float, too_large);
    ret = select(ret, zero, too_small);

    return ret;
}
开发者ID:ELVIS-Project,项目名称:VISIntervalSonifier,代码行数:43,代码来源:vec_math.hpp

示例12: compare_float_mask

void compare_float_mask(VecType const & v, unsigned int mask)
{
   for (int i = 0; i != v.size; ++i) {
        union {
            float f;
            unsigned int i;
        } x;
        x.f = v.get(i);
        BOOST_REQUIRE_EQUAL( x.i, mask);
    }
}
开发者ID:mrotondo,项目名称:poopworm,代码行数:11,代码来源:vec_test.cpp

示例13: vec_tan_float

always_inline VecType vec_tan_float(VecType const & arg)
{
    typedef typename VecType::int_vec int_vec;
    const typename VecType::float_type four_over_pi = 1.27323954473516268615107010698011489627567716592367;

    VecType sign = arg & VecType::gen_sign_mask();
    VecType abs_arg = arg & VecType::gen_abs_mask();

    VecType y = abs_arg * four_over_pi;
    int_vec j = y.truncate_to_int();

    /* cephes: j=(j+1) & (~1) */
    j = (j + int_vec(1)) & int_vec(~1);
    y = j.convert_to_float();

    /* approximation mask */
    VecType poly_mask = VecType (mask_eq(j & int_vec(2), int_vec(0)));

    /* black magic */
    static float DP1 = 0.78515625;
    static float DP2 = 2.4187564849853515625e-4;
    static float DP3 = 3.77489497744594108e-8;
    VecType base = ((abs_arg - y * DP1) - y * DP2) - y * DP3;

    VecType x = base; VecType x2 = x*x;

    // sollya: fpminimax(tan(x), [|3,5,7,9,11,13|], [|24...|], [-pi/4,pi/4], x);
    VecType approx =
        x + x * x2 * (0.3333315551280975341796875 + x2 * (0.1333882510662078857421875 + x2 * (5.3409568965435028076171875e-2 + x2 * (2.443529665470123291015625e-2 + x2 * (3.1127030961215496063232421875e-3 + x2 * 9.3892104923725128173828125e-3)))));

    //VecType recip = -reciprocal(approx);
    VecType recip = -1.0 / approx;

    VecType approximation = select(recip, approx, poly_mask);

    return approximation ^ sign;
}
开发者ID:mrotondo,项目名称:poopworm,代码行数:37,代码来源:vec_math.hpp

示例14: result

  PartialVolumeAnalysisClusteringCalculator::ClusterResultType
      PartialVolumeAnalysisClusteringCalculator::CalculateCurves(ParamsType params, VecType xVals) const
  {

    int arraysz = xVals.size();
    ClusterResultType result(arraysz);

    for( int j=0; j<2; j++)
    {
      for(int i=0; i<arraysz; i++)
      {
        double d   = xVals(i)-params.means[j];
        double amp = params.ps[j]/sqrt(2*PVA_PI*params.sigmas[j]);

        result.vals[j](i) = amp*exp(-0.5 * (d*d)/params.sigmas[j]);
      }
    }

    for(int i=0; i<arraysz; i++)
    {
      result.mixedVals[0](i) = 0;
    }

    for(double t=0; t<=1; t = t + 1.0/(m_StepsNumIntegration-1.0))
    {
      for(int i=0; i<arraysz; i++)
      {
        double d = xVals(i)-(t*params.means[0]+(1-t)*params.means[1]);
        double v = t*params.sigmas[0]+(1-t)*params.sigmas[1];
        double p = 1.0 - params.ps[0] - params.ps[1];
        double amp = (1.0/m_StepsNumIntegration) * p / sqrt(2.0*PVA_PI*v);

        result.mixedVals[0](i) = result.mixedVals[0](i) + amp*exp(-0.5 * (d*d)/v);

        //        MITK_INFO << "d=" << d << "v=" <<v << "p=" << p << "amp=" << amp << "result=" << amp*exp(-0.5 * (d*d)/v) << std::endl;
      }
      //      MITK_INFO << "t=" << t << std::endl;
      //      params.Print();
      //      result.Print();
    }

    for(int i=0; i<arraysz; i++)
    {
      result.combiVals(i) = result.mixedVals[0](i) + result.vals[0](i) + result.vals[1](i);
    }

    return result;
  }
开发者ID:GHfangxin,项目名称:MITK,代码行数:48,代码来源:mitkPartialVolumeAnalysisClusteringCalculator.cpp

示例15: switch

void Warp::resize_1d(const VecType &in, const InterpType interp_type, 
        double inv_scale, VecType *out) const
{
    // For the anti-aliasing filter
    double scale = 1.0f/inv_scale;
    if(scale>1){
        scale = 1;
    }
    int length = in.rows();

    switch(interp_type){
    case Warp::NEAREST:
    {
        for(double i = 0; i < out->rows(); ++i  )
        {
            double u = i*inv_scale + 0.5f*(-1.0f+inv_scale);
            int l = floor(u);
            int r = l+1;
            if(u-l > r-u ) {
                if((r >=0) && (r<length)){
                    (*out)(i) = in(r);
                }
            }else {
                if((l >=0) && (l<length)){
                    (*out)(i) = in(l);
                }
            }
        }
        break;
    }
    case Warp::BILINEAR:
    {
        int kernel_width = 1;
        for(double i = 0; i < out->rows(); ++i  )
        {
            double u = i*inv_scale + 0.5f*(-1.0f+inv_scale);
            int l = floor(u-kernel_width/2);
            int r = l+kernel_width;
            double val = 0;
            // if(i == out->rows()-1){
            //     printf("%f,%d,%d\n",u,l,r);
            // }
            double w = 0;
            double weight = 0;
            for(int x = l; x<=r; ++x)
            {
                if(x<0 || x>=length){
                    continue;
                }
                w = kernel_linear(u-x,scale);
                val += w*in(x);
                weight += w;
            }
            if(weight>0)
            {
                val/= weight;
            }
            (*out)(i) = val;
        }
        break;
    }
    case Warp::BICUBIC:
    {
        int kernel_width = 4;
        for(double i = 0; i < out->rows(); ++i  )
        {
            double u = i*inv_scale + 0.5f*(-1.0f+inv_scale);
            int l = floor(u-kernel_width/2);
            int r = l+kernel_width;
            double val = 0;
            double w = 0;
            double weight = 0;
            for(int x = l; x<=r; ++x)
            {
                if(x<0 || x>=length){
                    continue;
                }
                w = kernel_cubic(u-x,scale);
                val += w*in(x);
                weight += w;
                // printf("%d, %.2f ", x, w);
            }
            // printf("\n");
            if(weight>0)
            {
                val/= weight;
            }
            (*out)(i) = val;
        }
        break;
    }
    } // switch
}
开发者ID:mgharbi,项目名称:xform_cpp,代码行数:93,代码来源:Warp.cpp


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