コード例 #1
0
void InferenceEngine::allocateShuffledIndicesToThreads(vector<vector<uint> > * thread_index_allocation, const uint num_indices) {

    mt19937 prng = mt19937(prng_seed);

    assert(thread_index_allocation->empty());

    uint num_indices_per_thread = num_indices/num_threads + 1;
    uint num_last_indices = num_indices%num_threads;

    for (uint i = 0; i < num_threads; i++) {

        thread_index_allocation->push_back(vector<uint>(num_indices_per_thread));

        for (uint j = 0; j < thread_index_allocation->back().size(); j++) {

            thread_index_allocation->back().at(j) = i + j * num_threads; 
        }

        if (i >= num_last_indices) {

            thread_index_allocation->back().pop_back();
        }

        shuffle(thread_index_allocation->back().begin(), thread_index_allocation->back().end(), prng);
    }
}
コード例 #2
0
ファイル: swapround.cpp プロジェクト: kylegenova/best-of-many
vector<vector<LPEdge>> swapRound(const vector<vector<LPEdge>> &trees, const vector<double> &betas)
{
	//srand((unsigned)time(NULL));
	system_clock::rep seed = system_clock::now().time_since_epoch().count();
	mt19937 mersenne_generator = mt19937((unsigned int)seed);
	vector<vector<LPEdge>> ts;
	//sort all the tries such than e.end0 < e.end1 for all edges;
	for (unsigned i = 0; i < trees.size(); i++)
	{
		vector<LPEdge> t;
		for (unsigned j = 0; j < trees[i].size(); j++)
		{
			if (trees[i][j].end0 == trees[i][j].end1)
				throw invalid_argument("");
			if (trees[i][j].end0 < trees[i][j].end1)
				t.push_back(LPEdge(trees[i][j].end0, trees[i][j].end1, trees[i][j].weight));
			else
				t.push_back(LPEdge(trees[i][j].end1, trees[i][j].end0, trees[i][j].weight));
		}
		ts.push_back(t);
	}
	//
	vector<vector<LPEdge>> C;
	C.push_back(ts[0]);
	for (int i = 0; i <= (int)ts.size() - 2; i++)
	{
		double nextBeta = sum(betas, 0, i + 1);
		//cout << "Next beta: " << nextBeta << endl;
		vector<LPEdge> CNext = mergeBasesFast(nextBeta, C.back(), betas[i + 1], ts[i + 1], mersenne_generator);
		C.push_back(CNext);
	}
	return C;
}
コード例 #3
0
ファイル: World.cpp プロジェクト: mike42/forestry
World::World(int id, simulation_options_t *options)
{
    this -> solarLuminosity = 0;
    this -> options = options;

    size_t y;
    this -> cell = new Cell*[WORLD_HEIGHT];
    for(y = 0; y < WORLD_HEIGHT; y++) {
       this -> cell[y] = new Cell[WORLD_WIDTH];
    }

    if(options -> seed == -1) {
        random_device rd;
        gen = mt19937(rd());
    } else {
        gen = mt19937(options -> seed);
    }
    dis = uniform_real_distribution<>(0, 1);

    d = new Display(this, id);
}
コード例 #4
0
ファイル: world.cpp プロジェクト: Stro21/tsp
void make_world(World* world, int width, int height, int num_cities, int seed)
{
	/*
		Makes a new world struct
		
		world      : Pointer to the world to create
		width      : The width of the world
		height     : The height of the world
		num_cities : The number of cities in the world
		seed       : The random seed to use to select the cities
	*/
	
	// Random number generation
	mt19937::result_type rseed = seed;
	auto rgen = bind(uniform_real_distribution<>(0, 1), mt19937(rseed));
	
	// Initialize the world
	init_world(world, width, height, num_cities);
	
	// Create a set to deal with uniqueness
	set<tuple<int, int>> coordinates;
	set<tuple<int, int>>::iterator it;
	pair<set<tuple<int, int>>::iterator,bool> ret;
	
	// Create some unique random cities
	for (int i=0; i<num_cities; i++)
	{
		while (true)
		{
			// Try to add a new set of coordinates
			tuple<int,int> coors((int)(rgen() * width), \
				(int)(rgen() * height));
			ret = coordinates.insert(coors);
			
			// Break if the city was added successfully
			if (ret.second)
				break;
		}
	}
	
	// Add those cities to the world
	{
		int i = 0;
		for (it=coordinates.begin(); it!=coordinates.end(); it++)
		{
			world->cities[i].x = get<0>(*it);
			world->cities[i].y = get<1>(*it);
			i++;
		}
	}
}
コード例 #5
0
ファイル: linear.cpp プロジェクト: minad/analyzer
void run() {
	variate_generator<mt19937, normal_distribution<> > rand(mt19937(), normal_distribution<>(0, 10));

	table table("table");
	table.add<double>("x").add<double>("y");
	for (int i = 0; i < 200; ++i)
		table << double(i) << double(i) + rand();

	table.write_file("test.csv");

	linear_fit fit("fn", table);
	cout << fit << endl;
	plot("plot <table>, <fn>");
}
コード例 #6
0
ファイル: Simulation.cpp プロジェクト: galizur/Ptyxiakh_2
void Simulation_running::on_entry()
{
    /*****************************/
    //auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();

    //mt19937 mt_rand(seed);
    auto dice_rand = std::bind(std::uniform_int_distribution<int>(1,9999),
                               mt19937(seed));

    mt19937 nrg;
    poisson_distribution<int> poisson(4.9);

    /*****************************/

    std::cout << "Simulation_running on_entry()\n";
    std::cout<<"State: "<<state_to_text(
                 m_state_machine_controller.m_current_state->get_state())<<std::endl;
    bool flag = false;
    auto sim_run_thread = sim_running_thread(m_state_machine_controller);

    while (!flag) // Infinite loop producing random numbers every "poisson" time
    {
        flag = check_me2(m_state_machine_controller);

        int job = dice_rand();
        int sth = random_disp();

        std::cout<<"DA FAQ "<<flag<<" - - - Random Disp Number: "<<sth<<" - - - Random Job: "<<job<<std::endl;
        std::cout<<"Job sending"<<std::endl;
        vDisp.at(sth)->add_job_q(job);
        vDisp.at(sth)->schedule_event(Events::DISP_JOB);


        std::this_thread::sleep_for(std::chrono::seconds(poisson(nrg)));
        //std::this_thread::sleep_for(std::chrono::milliseconds(2000));
    }

    //sim_run_thread.get();


    //std::cout<<"State: "<<state_to_text(m_state_machine_controller.m_previous_state)<<std::endl;
}
コード例 #7
0
UUIDGenerator::UUIDGenerator() : m_generator(mt19937(random_device()())) {}
コード例 #8
0
ファイル: SLRay.cpp プロジェクト: liguangzheng/slproject
SLuint  SLRay::subsampledRays = 0;
SLuint  SLRay::subsampledPixels = 0;
SLuint  SLRay::tirRays = 0;
SLuint  SLRay::tests = 0;
SLuint  SLRay::intersections = 0;
SLint   SLRay::depthReached = 1;
SLint   SLRay::maxDepthReached = 0;
SLfloat SLRay::avgDepth = 0;

//-----------------------------------------------------------------------------
/*! Global uniform random number generator for numbers between 0 and 1 that are
used in SLRay, SLLightRect and SLPathtracer. So far they work perfectly with 
CPP11 multithreading.
*/
auto random01 = bind(uniform_real_distribution<SLfloat>(0.0, 1.0),
                    mt19937((SLuint)time(nullptr)));
SLfloat rnd01();
SLfloat rnd01(){return random01();}
//-----------------------------------------------------------------------------
/*! 
SLRay::SLRay default constructor
*/
SLRay::SLRay()
{  
    origin      = SLVec3f::ZERO;
    setDir(SLVec3f::ZERO);
    type        = PRIMARY;
    length      = FLT_MAX;
    depth       = 1;
    hitTriangle = -1;
    hitPoint    = SLVec3f::ZERO;
コード例 #9
0
ファイル: SLRay.cpp プロジェクト: flair2005/VirtualRoom
SLuint  SLRay::subsampledPixels = 0;
SLuint  SLRay::tirRays = 0;
SLuint  SLRay::tests = 0;
SLuint  SLRay::intersections = 0;
SLint   SLRay::depthReached = 1;
SLint   SLRay::maxDepthReached = 0;
SLfloat SLRay::avgDepth = 0;

//-----------------------------------------------------------------------------
/*! Global uniform random number generator for numbers between 0 and 1 that are
used in SLRay, SLLightRect and SLPathtracer. So far they work perfectly with 
CPP11 multithreading.
*/
#ifdef SL_CPP11
    auto random01 = bind(uniform_real_distribution<SLfloat>(0.0, 1.0),
                        mt19937((SLuint)time(NULL)));
    SLfloat rnd01();
    SLfloat rnd01(){return random01();}
#else
    SLfloat rnd01(){return (SLfloat)rand() / (SLfloat)RAND_MAX;}
#endif
//-----------------------------------------------------------------------------
/*! 
SLRay::SLRay default constructor
*/
SLRay::SLRay()
{  
    origin      = SLVec3f::ZERO;
    setDir(SLVec3f::ZERO);
    type        = PRIMARY;
    length      = FLT_MAX;
コード例 #10
0
void InferenceEngine::genotypeVariantClusterGroupsCallback(ProducerConsumerQueue<VariantClusterGroupBatch> * variant_cluster_group_batch_queue, KmerHash * kmer_hash, const CountDistribution & count_distribution, const vector<Sample> & samples, GenotypeWriter * genotype_writer, VariantClusterGroupCounts * variant_cluster_group_counts, mutex * thread_lock) {

	assert(samples.size() == num_samples);

    mt19937 prng = mt19937(prng_seed);

	VariantClusterGroupCounts variant_cluster_group_counts_local;
	VariantClusterGroupBatch variant_cluster_group_batch;

	while (variant_cluster_group_batch_queue->pop(&variant_cluster_group_batch)) {

		vector<Genotypes*> * variant_genotypes = new vector<Genotypes*>();
		variant_genotypes->reserve(variant_cluster_group_batch.number_of_variants);

		auto variant_cluster_group_it = variant_cluster_group_batch.start_it;

		while (variant_cluster_group_it != variant_cluster_group_batch.end_it) {

			if ((*variant_cluster_group_it)->isInChromosomeRegions(chromosome_regions)) {

				for (ushort chain_idx = 0; chain_idx < num_gibbs_sampling_chains; chain_idx++) {

					(*variant_cluster_group_it)->initialise(kmer_hash, samples, prng_seed, num_noise_sources, num_haplotype_candidates_per_sample, max_multicluster_kmers);
					(*variant_cluster_group_it)->shuffleBranches(&prng);

					for (ushort i = 0; i < gibbs_burn; i++) {

						(*variant_cluster_group_it)->estimateGenotypes(count_distribution, chromosome_ploidy, false);
					}

					for (ushort i = 0; i < gibbs_samples; i++) {

						(*variant_cluster_group_it)->estimateGenotypes(count_distribution, chromosome_ploidy, true);
					}
				}

				if ((*variant_cluster_group_it)->hasMulticlusterKmer()) {

					assert((*variant_cluster_group_it)->numberOfVariantClusters() > 1);
					variant_cluster_group_counts_local.num_multicluster++;

				} else if ((*variant_cluster_group_it)->hasInterclusterKmer()) {

					variant_cluster_group_counts_local.num_intercluster++;
				
				} else {

					variant_cluster_group_counts_local.num_unique++;
				}

				(*variant_cluster_group_it)->collectGenotypes(variant_genotypes, chromosome_ploidy);

			} else {

				variant_cluster_group_counts_local.num_skipped++;
			}
	
			delete *variant_cluster_group_it;			
			variant_cluster_group_it++;
		}

		genotype_writer->addGenotypes(variant_genotypes);
	}

	lock_guard<mutex> tread_locker(*thread_lock);
	*variant_cluster_group_counts += variant_cluster_group_counts_local;
}