本文整理汇总了C++中DataContainer::GetID方法的典型用法代码示例。如果您正苦于以下问题:C++ DataContainer::GetID方法的具体用法?C++ DataContainer::GetID怎么用?C++ DataContainer::GetID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataContainer
的用法示例。
在下文中一共展示了DataContainer::GetID方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetData
/**
* Get the data from the given container.
*/
void Plot::GetData(DataContainer &cont, PLData & pld) {
pld.len = cont.size();
if (pld.len == 0) {
cerr << "No data available!" << endl;
return;
}
pld.x_axis = new PLFLT[pld.len];
pld.y_axis = new PLFLT[pld.len];
assert (cont.GetID() >= 0);
pld.id = cont.GetID();
switch (plot_type) {
case PT_DEFAULT:
// cout << "Plot values" << endl;
for (int i = 0; i < pld.len; ++i) {
pair<DataDecoratorType,int> item = cont.item< pair<DataDecoratorType,int> >(i);
DataDecoratorType x = item.first;
int y = item.second;
pld.x_axis[i] = Scale(x, true);
pld.y_axis[i] = Scale(y, false);
}
break;
case PT_DENSITY:
case PT_CUMULATIVE_DENSITY:
// Total number of samples
long int N = 0;
for (int i = 0; i < pld.len; ++i) {
pair<DataDecoratorType,int> item = cont.item< pair<DataDecoratorType,int> >(i);
int y = item.second;
N += y;
}
#ifdef VERBOSE
cout << "Total number of samples is " << N << endl;
#endif
if (N == 0) break;
// calculate cumulative density function
bool reverse_cdf = false;
long int sum = 0;
for (int i = 0; i < pld.len; ++i) {
int index = (reverse_cdf ? pld.len - 1 - i : i);
pair<DataDecoratorType,int> item = cont.item< pair<DataDecoratorType,int> >(index);
DataDecoratorType x = item.first;
int y = item.second;
if (plot_type == PT_DENSITY) {
PLFLT delta = 1;
pld.x_axis[index] = Scale(x, true);
if (reverse_cdf) {
if (index != pld.len-1) delta = pld.x_axis[index+1] - pld.x_axis[index];
} else
if (index != 0) delta = pld.x_axis[index-1] - pld.x_axis[index];
sum = y;
pld.y_axis[index] = Scale((sum / (float)N) / delta, false);
} else {
sum += y;
pld.x_axis[index] = Scale(x, true);
pld.y_axis[index] = Scale(sum / (float)N, false);
}
}
}
// For debugging purposes
if (plot_type == PT_DENSITY) {
PLFLT lazy_integration = 0;
for (int i = 1; i < pld.len; ++i) {
PLFLT delta = pld.x_axis[i] - pld.x_axis[i-1];
lazy_integration += pld.y_axis[i] * delta;
}
cout << "Integration of density plot: " << lazy_integration << " (should be around 1)" << endl;
}
if (!dimensions_set) {
pld.x_min = *min_element(pld.x_axis,pld.x_axis+pld.len);
pld.x_max = *max_element(pld.x_axis,pld.x_axis+pld.len);
pld.y_min = *min_element(pld.y_axis,pld.y_axis+pld.len);
pld.y_max = *max_element(pld.y_axis,pld.y_axis+pld.len);
}
// Remove all values smaller than 1/resolution of the maximum value
bool remove_below_resolution = false;
int resolution = 1000;
if (remove_below_resolution) {
int j = 0;
for (int i = 0; i < pld.len; ++i) {
PLFLT x = pld.x_axis[i];
PLFLT y = pld.y_axis[i];
if (!dimensions_set) {
if ((y * resolution) > pld.y_max) {
pld.x_axis[j] = x;
pld.y_axis[j] = y;
j++;
}
} else {
if (y > y_min) {
pld.x_axis[j] = x;
pld.y_axis[j] = y;
j++;
//.........这里部分代码省略.........