本文整理汇总了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;
}
示例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");
}
}
示例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;
}
示例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;
}
示例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;
}
}
//.........这里部分代码省略.........
示例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));
}
}
}
//.........这里部分代码省略.........