virtual bool step(HMMparticle::sequence_vector_iterator_type current_path_ref, boost::random::mt19937& random_generator, bool CollapsedVersion) { bool accepted = false; // define random number generators boost::uniform_int<arma::uword> unidist(0, std::numeric_limits<arma::uword>::max()); boost::random::variate_generator<boost::random::mt19937&, boost::uniform_int<arma::uword> > unirandoms(random_generator, unidist); boost::random::variate_generator<boost::random::mt19937&, boost::uniform_real<> > central_vargen(random_generator, boost::uniform_real<>(0.0, 1.0)); boost::uniform_int<arma::uword> jumpdist(1, parameter); boost::random::variate_generator<boost::random::mt19937&, boost::uniform_int<arma::uword> > jumplength(random_generator, jumpdist); arma::urowvec current_genotype = arma::zeros<arma::urowvec>(associatedParticle->get_emission_matrix().n_cols); arma::urowvec new_sequence = arma::zeros<arma::urowvec>(associatedParticle->MAXDEPTH); bool clockwise = central_vargen() < 0.5; base_pseudo_generator_type new_generator(unirandoms()); bool old_path_found = false; arma::uword aimed_jump = jumplength(); //~ std::cout << "\nAlt: "; std::cout.flush(); //~ for (arma::uword i=0; i < current_path_ref->get<2>().n_elem; ++i ) std::cout << current_path_ref->get<2>()[i] << " "; //~ std::cout << "\nNeu: "; std::cout.flush(); IDRefSequenceCountTuple proposal = *current_path_ref; bool success = recursive_tree_search( proposal, 0, new_sequence, false, current_genotype, 1, clockwise, old_path_found, new_generator, aimed_jump); if (success) { double likelihood_difference; if (!CollapsedVersion) { double likelihood_star = associatedParticle->single_path_likelihood(proposal.get<3>()); double likelihood_old = associatedParticle->single_path_likelihood(current_path_ref->get<3>()); likelihood_difference = likelihood_star - likelihood_old; } else { likelihood_difference = associatedParticle->collapsed_likelihood_difference(current_path_ref->get<3>(), proposal.get<3>()); } if (log(central_vargen()) < likelihood_difference) { accepted = true; if (CollapsedVersion) associatedParticle->update_countmatrix(current_path_ref->get<3>(), proposal.get<3>()); (*current_path_ref) = proposal; } } else throw(std::runtime_error("Some weird error occured!")); return accepted; //~ for (arma::uword i=0; i < current_path_ref->get<2>().n_elem; ++i ) std::cout << current_path_ref->get<2>()[i] << " "; //~ std::cout << " !\n"; std::cout.flush(); }
void create_ic(Particle *p, int npart){ int npoints = 1000; double *kk, *pofk; // Read in and store P(k,z=0) kk = new double[npoints]; pofk = new double[npoints]; ifstream fp("pofk.txt"); for(int i = 0;i < npoints; i++){ fp >> kk[i]; fp >> pofk[i]; } DSpline pofk_spline = DSpline(kk, pofk, npoints, "P(k) spline"); // Integrate growth-factor // ... not implemented // Generate random numbers random_device rd; int seed = rd(); mt19937 rg(seed); uniform_real_distribution<double> unidist(0, 1); int nrandom = npart * 3 * 2; double *randoms = new double[nrandom]; for(int i = 0; i < nrandom; i++){ randoms[i] = unidist(rg); } // Make realisation in Fourier space // ... not implemented // FFT back to get displacement field // ... not implemented // Assign particles and move them // ... not implemented delete[] randoms; }
int main(int argc, char** argv) { double T(1); double L(1.44e-6); unsigned N(100); double R(2.5e-9); double D(1e-12); if (argc == 6) { T = std::stod(argv[1]); L = std::stod(argv[2]); N = std::stoi(argv[3]); R = std::stod(argv[4]); D = std::stod(argv[5]); } const double dt(2*R*R/3/D); const unsigned nSim(T/dt); std::random_device rd; std::mt19937 gen(rd()); std::uniform_real_distribution<> unidist(0, L); std::normal_distribution<> normdist(0, pow(2*D*dt,0.5)); std::vector<Coordinate> mols; for (unsigned i(0); i < N; ++i) { Coordinate mol(unidist(gen), unidist(gen), unidist(gen)); mols.push_back(mol); } auto start = std::chrono::high_resolution_clock::now(); for (unsigned n(0); n < nSim; ++n) { for (unsigned j(0); j < N; ++j) { mols[j].x = mod(mols[j].x+normdist(gen), L); mols[j].y = mod(mols[j].y+normdist(gen), L); mols[j].z = mod(mols[j].z+normdist(gen), L); } } auto finish = std::chrono::high_resolution_clock::now(); std::chrono::duration<double> elapsed = finish - start; std::cout << "elapsed:" << elapsed.count() << " s" << std::endl; }