本文整理汇总了C++中Histogram1D::sum方法的典型用法代码示例。如果您正苦于以下问题:C++ Histogram1D::sum方法的具体用法?C++ Histogram1D::sum怎么用?C++ Histogram1D::sum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Histogram1D
的用法示例。
在下文中一共展示了Histogram1D::sum方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: splitHistogramsUsingEntropy
// Split several histograms within the indexes l0 and lF so that
// the entropy after division is maximized
int splitHistogramsUsingEntropy(const std::vector<Histogram1D> &hist,
size_t l0, size_t lF)
{
// Number of classes
int K = hist.size();
// Set everything outside l0 and lF to zero, and make it a PDF
std::vector<Histogram1D> histNorm;
for (int k = 0; k < K; k++)
{
Histogram1D histaux = hist[k];
for (size_t l = 0; l < XSIZE(histaux); l++)
if (l < l0 || l > lF)
DIRECT_A1D_ELEM(histaux,l) = 0;
histaux *= 1.0/histaux.sum();
histNorm.push_back(histaux);
}
// Compute for each class the probability of being l<=l0 and l>l0
MultidimArray<double> p(K, 2);
for (int k = 0; k < K; k++)
{
const Histogram1D& histogram=histNorm[k];
DIRECT_A2D_ELEM(p,k, 0) = DIRECT_A1D_ELEM(histogram,l0);
DIRECT_A2D_ELEM(p,k, 1) = 0;
for (size_t l = l0 + 1; l <= lF; l++)
DIRECT_A2D_ELEM(p,k, 1) += DIRECT_A1D_ELEM(histogram,l);
}
// Compute the splitting l giving maximum entropy
double maxEntropy = 0;
int lmaxEntropy = -1;
size_t l = l0;
while (l < lF)
{
// Compute the entropy of the classes if we split by l
double entropy = 0;
FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(p)
{
double aux=DIRECT_MULTIDIM_ELEM(p,n);
if (aux != 0)
entropy -= aux * log10(aux);
}
#ifdef DEBUG_SPLITTING_USING_ENTROPY
std::cout << "Splitting at " << l << " entropy=" << entropy
<< std::endl;
#endif
// Check if this is the maximum
if (entropy > maxEntropy)
{
maxEntropy = entropy;
lmaxEntropy = l;
}
// Move to next split point
++l;
// Update probabilities of being l<=l0 and l>l0
for (int k = 0; k < K; k++)
{
const Histogram1D& histogram=histNorm[k];
double aux=DIRECT_A1D_ELEM(histogram,l);
DIRECT_A2D_ELEM(p,k, 0) += aux;
DIRECT_A2D_ELEM(p,k, 1) -= aux;
}
}
#ifdef DEBUG_SPLITTING_USING_ENTROPY
std::cout << "Finally in l=[" << l0 << "," << lF
<< " Max Entropy:" << maxEntropy
<< " lmax=" << lmaxEntropy << std::endl;
#endif
// If the point giving the maximum entropy is too much on the extreme,
// substitute it by the middle point
if (lmaxEntropy<=2 || lmaxEntropy>=(int)lF-2)
lmaxEntropy = (int)ceil((lF + l0)/2.0);
return lmaxEntropy;
}