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


C++ Mat::init方法代码示例

本文整理汇总了C++中Mat::init方法的典型用法代码示例。如果您正苦于以下问题:C++ Mat::init方法的具体用法?C++ Mat::init怎么用?C++ Mat::init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mat的用法示例。


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

示例1: pwd

Mat pwd(Mat a, int b) {
	Mat r;
	r.init();
	for (; b; b >>= 1, a = a * a)
		if (b & 1)
			r = r * a;
	return r;
}
开发者ID:ichn,项目名称:3-code-for-ac,代码行数:8,代码来源:E.cpp

示例2: Sum

void Mat::Sum(size_t dim, Mat &vect) const {
  
  if (dim == 1) {
    vect.init(1, mat_.size2(), 0);
    for (size_t i = 0; i < mat_.size1(); ++i) {
      for (size_t j = 0; j < mat_.size2(); ++j) {
        vect(0, j) += mat_(i, j);
      }
    }    
  } else if (dim == 2) {    
    vect.init(mat_.size1(), 1, 0);
    for (size_t i = 0; i < mat_.size1(); ++i) {
      for (size_t j = 0; j < mat_.size2(); ++j) {
        vect(i, 0) += mat_(i, j);
      }     
    }    
  } else {
    mexAssert(false, "In Mat::Sum the dimension parameter must be either 1 or 2");
  }  
}
开发者ID:andylulu,项目名称:ConvNet,代码行数:20,代码来源:mat.cpp

示例3:

Mat operator ^ (Mat a, long long k) {
	Mat c;
	c.init(1);
	while (k)
	{
		if (k & 1)
			c = a * c;
		a = a*a;
		k >>= 1;
	}
	return c;
}
开发者ID:lonelam,项目名称:SolveSet,代码行数:12,代码来源:ACMTemplete.cpp

示例4: Sum

Mat Sum(const Mat &a, size_t dim) {
  
  Mat vect;
  if (dim == 1) {    
    vect.init(1, a.size2_, 0);
    for (size_t i = 0; i < a.size1_; ++i) {
      for (size_t j = 0; j < a.size2_; ++j) {
        vect(0, j) += a(i, j);        
      }
    }    
  } else if (dim == 2) {    
    vect.init(a.size1_, 1, 0);
    for (size_t i = 0; i < a.size1_; ++i) {
      for (size_t j = 0; j < a.size2_; ++j) {
        vect(i, 0) += a(i, j);        
      }     
    }    
  } else {
    mexAssert(false, "In Mat Sum(a, dim) the dimension parameter must be either 1 or 2");
  }
  return vect;
}
开发者ID:khunglongs73,项目名称:ConvNet,代码行数:22,代码来源:mat.cpp

示例5: ProcessOffline

bool SpeechRec::ProcessOffline(data_format inpf, data_format outpf, void *inpSig, int sigNBytes, Mat<float> *inpMat, Mat<float> *outMat)
{
	assert((int)inpf < (int)outpf);
	assert(outMat || outpf == dfStrings);
	assert(inpMat || inpf == dfWaveform);

	Mat<float> *paramMat = 0;
	Mat<float> *posteriorsMat = 0;

	// waveform -> parameters
	int nFrames;
	if(inpf == dfWaveform)
	{
		if(!ConvertWaveformFormat(waveFormat, inpSig, sigNBytes, &waveform, &waveformLen))
			return false;

		nFrames = (waveformLen > actualParams->GetVectorSize() ? (waveformLen - actualParams->GetVectorSize()) / actualParams->GetStep() + 1 : 1);
				
		actualParams->AddWaveform(waveform, waveformLen);
			
		if(outpf == dfParams)
		{
			paramMat = outMat;
		}
		else
		{
			paramMat = new Mat<float>; 
			if(!paramMat)
			{
				MERROR("Insufficient memory\n");
				return false;
			}
		}
		if(actualParams->GetNParams() != paramMat->columns() || nFrames != paramMat->rows())
		   paramMat->init(nFrames, actualParams->GetNParams());

		int fr = 0;
		while(actualParams->GetFeatures(params))
		{				
			FrameBasedNormalization(params, actualParams->GetNParams());
			paramMat->set(fr, fr, 0, actualParams->GetNParams() - 1, params);
			fr++;
		}

		if(outpf == dfParams)
			return true;
	}

	// sentence based normalization
	if(inpf == dfWaveform || inpf == dfParams)
	{
		if(inpf == dfParams)
			paramMat = inpMat;

                if(paramMat->columns() < actualParams->GetNParams())
                {
			MERROR("Invalid dimensionality of parameter vectors\n");
			return false;
                }
		else if(paramMat->columns() > actualParams->GetNParams())
		{
			Mat<float> *tmpMat = new Mat<float>;
			tmpMat->init(paramMat->rows(), actualParams->GetNParams());
			tmpMat->copy(*paramMat, 0, paramMat->rows() - 1, 0, actualParams->GetNParams() - 1, 
                                                   0, paramMat->rows() - 1, 0, actualParams->GetNParams() - 1);
			delete paramMat;
			paramMat = tmpMat;
			inpMat = paramMat;
		}

		SentenceBasedNormalization(paramMat);
	}

	// parameters -> posteriors
	if(outpf == dfPosteriors && !mTrapsEnabled)
        {
		MERROR("The 'traps' module have to be enabled for generating posteriors\n");
		return false;
        }

	if((inpf == dfWaveform || inpf == dfParams) && mTrapsEnabled)
	{
		if(inpf == dfParams)
			paramMat = inpMat;

		if(outpf == dfPosteriors)
		{
			posteriorsMat = outMat;
		}
		else
		{
			posteriorsMat = new Mat<float>;
			if(!posteriorsMat)
			{
				if(inpf != dfParams)
						delete paramMat;
				MERROR("Insufficient memory\n");
				return false;
			}
		}
//.........这里部分代码省略.........
开发者ID:alongwithyou,项目名称:PhnRec,代码行数:101,代码来源:srec.cpp

示例6: SentenceBasedNormalization

void SpeechRec::SentenceBasedNormalization(Mat<float> *mat)
{
//        mat->saveAscii("c:\\before");

	// sentence mean and variance normalization
	bool mean_norm = C.GetBool("offlinenorm", "sent_mean_norm");
	bool var_norm = C.GetBool("offlinenorm", "sent_var_norm");

	if(mean_norm || var_norm)
	{
		Mat<float> mean;

		// mean calcualtion
		mat->sumColumns(mean);
		mean.div((float)mat->rows());

		// mean norm
		int i, j;
		for(i = 0; i < mat->columns(); i++)
			mat->sub(0, mat->rows() - 1, i, i, mean.get(0, i));

		if(var_norm)
		{
			// variance calculation
			Mat<float> var;
			var.init(mean.rows(), mean.columns());
			var.set(0.0f);
			for(i = 0; i < mat->columns(); i++)
			{
				for(j = 0; j < mat->rows(); j++)
				{
					float v = mat->get(j, i);
					var.add(0, i, v * v);
				}
			}
			var.div((float)mat->rows());
			var.sqrt();

			// lower threshold
			float lowerThr = C.GetFloat("melbanks", "sent_std_thr");
			var.lowerLimit(lowerThr);

			// variance norm
			for(i = 0; i < mat->columns(); i++)
				mat->mul(0, mat->rows() - 1, i, i, 1.0f / var.get(0, i));

			// add mean if not mean norm
			if(!mean_norm)
			{
				for(i = 0; i < mat->columns(); i++)
					mat->add(0, mat->rows() - 1, i, i, mean.get(0, i));
			}
		}
	}

	// sentence maximum normalization
	bool max_norm = C.GetBool("offlinenorm", "sent_max_norm");
	bool channel_max_norm = C.GetBool("offlinenorm", "sent_chmax_norm");

	if(max_norm || channel_max_norm)
	{
		Mat<float> max;
		max.init(1, mat->columns());
		max.set(-9999.9f);
		int i, j;

		for(i = 0; i < mat->columns(); i++)
		{
			for(j = 0; j < mat->rows(); j++)
			{
				float v = mat->get(j, i);
				if(v > max.get(0, i))
				{
				   max.set(0, i, v);
				}
			}
		}

		// global sentence maximum normalization
		if(max_norm)
		{
			float global_max = -9999.9f;
			for(i = 0; i < max.columns(); i++)
			{
				if(max.get(0, i) > global_max)
				{
				   global_max = max.get(0, i);
				}
				max.set(global_max);
			}
		}

		for(i = 0; i < mat->columns(); i++)
		{
			for(j = 0; j < mat->rows(); j++)
			{
	            		mat->set(j, i, mat->get(j, i) - max.get(0, i));
			}
		}
	}
//.........这里部分代码省略.........
开发者ID:alongwithyou,项目名称:PhnRec,代码行数:101,代码来源:srec.cpp


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