本文整理汇总了C++中Histogram1D::resize方法的典型用法代码示例。如果您正苦于以下问题:C++ Histogram1D::resize方法的具体用法?C++ Histogram1D::resize怎么用?C++ Histogram1D::resize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Histogram1D
的用法示例。
在下文中一共展示了Histogram1D::resize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: newBins
/* Constructor ------------------------------------------------------------- */
LeafNode::LeafNode(const std::vector < MultidimArray<double> > &leafFeatures,
int discrete_levels)
{
__discreteLevels = discrete_levels;
K = leafFeatures.size();
if (__discreteLevels==0)
{
// This is a dummy node for features that cannot classify
MultidimArray<int> newBins(1);
A1D_ELEM(newBins,0)=0;
Histogram1D hist;
hist.resize(1);
A1D_ELEM(hist,0)=1;
IrregularHistogram1D irregHist;
for (int k=0; k<K; k++)
{
irregHist.init(hist, newBins);
irregHist.selfNormalize();
__leafPDF.push_back(irregHist);
}
}
else
{
// Compute the minimum and maximum of each class
double minval=0., maxval=0.;
for(int k=0; k<K; k++)
{
double minvalk=0., maxvalk=0.;
leafFeatures[k].computeDoubleMinMax(minvalk, maxvalk);
if (k==0)
{
minval=minvalk;
maxval=maxvalk;
}
else
{
minval=std::min(minval,minvalk);
maxval=std::max(maxval,maxvalk);
}
}
if (minval==maxval)
{
__discreteLevels=0;
return;
}
// Compute the PDF of each class
std::vector<Histogram1D> hist(K);
for (int k=0; k<K; k++)
{
// There is variation of this feature for this class
compute_hist(leafFeatures[k], hist[k], minval, maxval, 100);
hist[k] += 1; // Apply Laplace correction
}
// Split the histograms into discrete_level (power of 2) bins
std::queue< Matrix1D<int> > intervals, splittedIntervals;
Matrix1D<int> limits(2);
VECTOR_R2(limits,0,99);
intervals.push(limits);
int imax=ROUND(log2(__discreteLevels));
for (int i=0; i<imax; i++)
{
// Split all the intervals in the queue
while (!intervals.empty())
{
Matrix1D<int> currentInterval = intervals.front();
intervals.pop();
int lsplit = splitHistogramsUsingEntropy(hist,
currentInterval(0), currentInterval(1));
VECTOR_R2(limits,currentInterval(0),lsplit);
splittedIntervals.push(limits);
VECTOR_R2(limits,lsplit+1, currentInterval(1));
splittedIntervals.push(limits);
}
// Copy the splitted intervals to the interval list
while (!splittedIntervals.empty())
{
intervals.push(splittedIntervals.front());
splittedIntervals.pop();
}
}
// Compute the bins of the split
MultidimArray<int> newBins(__discreteLevels);
imax=intervals.size();
for (int i=0; i<imax; i++)
{
A1D_ELEM(newBins,i) = intervals.front()(1);
intervals.pop();
}
// Compute now the irregular histograms
IrregularHistogram1D irregHist;
for (int k=0; k<K; k++)
{
irregHist.init(hist[k], newBins);
irregHist.selfNormalize();
//.........这里部分代码省略.........