本文整理汇总了C++中MatrixXf::cwiseSqrt方法的典型用法代码示例。如果您正苦于以下问题:C++ MatrixXf::cwiseSqrt方法的具体用法?C++ MatrixXf::cwiseSqrt怎么用?C++ MatrixXf::cwiseSqrt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MatrixXf
的用法示例。
在下文中一共展示了MatrixXf::cwiseSqrt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: maximization
gaussian_model EMclustering::maximization(MatrixXf x, MatrixXf r)
{
int d = x.rows();
int n = x.cols();
int k = r.cols();
//cerr<<x<<endl;
VectorXf nk(r.rows());
nk = r.colwise().sum();
VectorXf w(nk.size());
w = nk/n;
MatrixXf tmp1(x.rows(),r.cols());
tmp1 = x * r;
VectorXf tmp2(nk.size());
tmp2 = nk.array().inverse();
//cerr<<tmp2<<endl<<endl;
MatrixXf mu(x.rows(),r.cols());
mu = tmp1 * tmp2.asDiagonal() ;
MatrixXf *sigma = new MatrixXf[k];
for(int i=0;i<k;i++)
sigma[i].setZero(d,d);
MatrixXf sqrtr(r.rows(),r.cols());
sqrtr = r.cwiseSqrt();
MatrixXf xo(d,n);
MatrixXf tmp3(d,d);
tmp3.setIdentity(d,d);
for(int i=0;i<k;i++)
{
xo = x.colwise() - mu.col(i);
VectorXf tmp4(sqrtr.rows());
tmp4 = sqrtr.col(i);
tmp4 = tmp4.adjoint();
xo = xo* tmp4.asDiagonal();
sigma[i] = xo*xo.adjoint()/nk(i);
sigma[i] = sigma[i] + tmp3*1e-6;
//cerr<<sigma[i]<<endl<<endl;
}
gaussian_model model;
model.mu = mu;
model.sigma = new MatrixXf[k];
for(int i=0;i<k;i++)
model.sigma[i] = sigma[i];
model.weight = w;
nk.resize(0);
w.resize(0);
tmp1.resize(0,0);
tmp2.resize(0);
tmp3.resize(0,0);
mu.resize(0,0);
for(int i=0;i<k;i++)
sigma[i].resize(0,0);
delete [] sigma;
sqrtr.resize(0,0);
xo.resize(0,0);
tmp3.resize(0,0);
//cerr<<"---"<<endl;
model.weight = model.weight.adjoint();
//cerr<<model.weight<<endl<<endl;
//cerr<<model.mu<<endl<<endl;
//for(int i=0;i<k;i++)
//{
// cerr<<model.sigma[i]<<endl<<endl;
//}
return model;
}