本文整理汇总了C++中arma::mat::shed_rows方法的典型用法代码示例。如果您正苦于以下问题:C++ mat::shed_rows方法的具体用法?C++ mat::shed_rows怎么用?C++ mat::shed_rows使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arma::mat
的用法示例。
在下文中一共展示了mat::shed_rows方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Apply
/**
* Use PCA for dimensionality reduction on the given dataset. This will save
* as many dimensions as necessary to retain at least the given amount of
* variance (specified by parameter varRetained). The amount should be
* between 0 and 1; if the amount is 0, then only 1 dimension will be
* retained. If the amount is 1, then all dimensions will be retained.
*
* The method returns the actual amount of variance retained, which will
* always be greater than or equal to the varRetained parameter.
*/
double PCA::Apply(arma::mat& data, const double varRetained) const
{
// Parameter validation.
if (varRetained < 0)
Log::Fatal << "PCA::Apply(): varRetained (" << varRetained << ") must be "
<< "greater than or equal to 0." << endl;
if (varRetained > 1)
Log::Fatal << "PCA::Apply(): varRetained (" << varRetained << ") should be "
<< "less than or equal to 1." << endl;
arma::mat coeffs;
arma::vec eigVal;
Apply(data, data, eigVal, coeffs);
// Calculate the dimension we should keep.
size_t newDimension = 0;
double varSum = 0.0;
eigVal /= arma::sum(eigVal); // Normalize eigenvalues.
while ((varSum < varRetained) && (newDimension < eigVal.n_elem))
{
varSum += eigVal[newDimension];
++newDimension;
}
// varSum is the actual variance we will retain.
if (newDimension < eigVal.n_elem)
data.shed_rows(newDimension, data.n_rows - 1);
return varSum;
}
示例2: Apply
void KernelPCA<KernelType, KernelRule>::Apply(arma::mat& data,
const size_t newDimension)
{
arma::mat coeffs;
arma::vec eigVal;
Apply(data, data, eigVal, coeffs, newDimension);
if (newDimension < coeffs.n_rows && newDimension > 0)
data.shed_rows(newDimension, data.n_rows - 1);
}