当前位置: 首页>>代码示例>>C++>>正文


C++ DataContainer::GetID方法代码示例

本文整理汇总了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++;
//.........这里部分代码省略.........
开发者ID:mrquincle,项目名称:ilvq,代码行数:101,代码来源:Plot.cpp


注:本文中的DataContainer::GetID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。