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


C++ mt19937::max方法代码示例

本文整理汇总了C++中std::mt19937::max方法的典型用法代码示例。如果您正苦于以下问题:C++ mt19937::max方法的具体用法?C++ mt19937::max怎么用?C++ mt19937::max使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::mt19937的用法示例。


在下文中一共展示了mt19937::max方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: sampleAlpha

vector<double> sampleAlpha( std::mt19937& rng )
{
	vector<double> res(3);
	res[0] = (double)rng()/rng.max();
	res[1] = (double)rng()/rng.max();
	std::sort(res.begin(), res.begin() + 2);
	res[2] = 1.0 - res[1];
	res[1] = res[1] - res[0];
	res[0] = res[0] - 0.0;
	return res;
}
开发者ID:sambofra,项目名称:mopo16s,代码行数:11,代码来源:localsearch.cpp

示例2: train

void SeedFeatureFactory::train( const std::vector< std::shared_ptr<ImageOverSegmentation> > &ios, const std::vector<VectorXs> & lbl ) {
	printf("  * Training SeedFeature\n");
	static std::mt19937 rand;
	const int N_SAMPLES = 5000;
	int n_pos=0, n_neg=0;
	for( VectorXs l: lbl ) {
		n_pos += (l.array()>=0).cast<int>().sum();
		n_neg += (l.array()==-1).cast<int>().sum();
	}
	
	// Collect training examples
	float sampling_freq[] = {0.5f*N_SAMPLES / n_neg, 0.5f*N_SAMPLES / n_pos};
	std::vector<RowVectorXf> f;
	std::vector<float> l;
#pragma omp parallel for
	for( int i=0; i<ios.size(); i++ ) {
		RMatrixXf ftr = SeedFeature::computeObjFeatures( *ios[i] );
		for( int j=0; j<ios[i]->Ns(); j++ )
			if( lbl[i][j] >= -1 && rand() < rand.max()*sampling_freq[ lbl[i][j]>=0 ] ) {
#pragma omp critical
				{
					l.push_back( lbl[i][j]>=0 );
					f.push_back( ftr.row(j) );
				}
			}
	}
	
	printf("    - Computing parameters\n");
	// Fit the ranking functions
	RMatrixXf A( f.size(), f[0].size() );
	VectorXf b( l.size() );
	for( int i=0; i<f.size(); i++ ) {
		A.row(i) = f[i];
		b[i] = l[i];
	}
	
	// Solve A*x = b
	param_ = A.colPivHouseholderQr().solve(b);
	printf("    - done %f\n",(A*param_-b).array().abs().mean());
}
开发者ID:ClarkWang12,项目名称:object-proposals,代码行数:40,代码来源:seedfeature.cpp

示例3: rndf

inline double rndf()
{
	return fabs(rng())/rng.max();
}
开发者ID:sisu,项目名称:taistoe,代码行数:4,代码来源:util.hpp


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