本文整理汇总了C++中std::valarray::min方法的典型用法代码示例。如果您正苦于以下问题:C++ valarray::min方法的具体用法?C++ valarray::min怎么用?C++ valarray::min使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::valarray
的用法示例。
在下文中一共展示了valarray::min方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: find_histogram
int find_histogram(const std::valarray<T>& vol, std::valarray<int>& hist, unsigned int bins,
T& min, T& max)
{
// size and zero the histogram
hist.resize(bins); hist = 0;
if(min == max) { min = vol.min(); max = vol.max(); }
int validsize(-1);
if(min != max) {
double fA = bins / double(max - min);
double fB = (bins * -min) / double(max - min);
validsize = 0;
for(unsigned int i = 0; i < vol.size(); ++i) {
unsigned int idx = unsigned(fA * vol[i] + fB);
++hist[ std::max(unsigned(0), std::min(idx, bins - 1)) ];
++validsize;
}
}
return validsize;
}
示例2: barPlot
void histogram_plot::barPlot(const std::valarray<double>& data)
{
if (data.size() == 0)
return;
{
QWriteLocker locker(&data_lock);
if (intervals.size() != (int)(data.size()))
{
intervals.resize(data.size());
values.resize(data.size());
for (int i = 0; i < intervals.size(); i++ )
intervals[i] = QwtDoubleInterval(i, i + 1);
}
for (size_t i = 0; i < data.size(); i++ )
values[i] = data[i];
double max_val = data.max();
double min_val = data.min();
if (max_val > 0)
max_val *= 2;
else
max_val = 0;
if (min_val < 0)
min_val *= 2;
else
min_val = 0;
SetYRange(min_val, max_val);
}
replot();
}
示例3: find_thresholds
void find_thresholds(const std::valarray<T>& vol, std::valarray<int>& hist, unsigned int bins,
T& minval, T& maxval)
{
const unsigned int max_passes(10);
unsigned int pass(1);
unsigned int lowest_bin(0), highest_bin(bins-1), bottom_bin(0), top_bin(0);
T min(vol.min()), max(vol.max());
T thresh2(0), thresh98(0);
while((pass == 1) ||
(double(thresh98 - thresh2) < (double(max - min) / 10))) {
if(pass > 1) {
// increase range slightly from the 2-98% range found
bottom_bin = std::max(int(bottom_bin) - 1, 0);
top_bin = std::min(int(top_bin) + 1, int(bins) - 1);
double fA = ((max - min) / double(bins));
T tmpmin = min + ( bottom_bin * fA);
max = min + ((top_bin+1) * fA);
min = tmpmin;
}
if(pass == max_passes) { min = max = max_passes; } // give up and revert to full range ...
int validsize = find_histogram(vol, hist, bins, min, max);
if(validsize < 1) {
minval = thresh2 = min; maxval = thresh98 = max;
return;
}
if(pass == max_passes) { // ... _but_ ignore end bins
validsize -= hist[lowest_bin] + hist[highest_bin];
++lowest_bin; --highest_bin;
}
if (validsize < 0) {
// ie zero range
thresh2=thresh98=min;
break;
}
double fA = ((max-min)/double(bins));
int count;
for(count=0, bottom_bin=lowest_bin; count<validsize/50; ++bottom_bin)
count += hist[bottom_bin];
--bottom_bin;
thresh2 = min + (bottom_bin*fA);
for(count=0, top_bin=highest_bin; count<validsize/50; --top_bin)
count += hist[top_bin];
++top_bin;
thresh98 = min + ((top_bin+1)*fA);
if (pass==max_passes)
break;
++pass;
}
find_histogram(vol, hist, bins, thresh2, thresh98);
minval = thresh2;
maxval = thresh98;
}