/* set up sites based on initial genotypes */ void Population::setup_initial_genotypes(valarray<int> &hets, valarray<int> &homs) { if (hets.size() != homs.size()) throw SimError("len(hets) != len(homs)"); if (hets.max() > popsize) throw SimError("too many heterozygotes"); if (homs.max() > popsize) throw SimError("too many homozygotes"); if ((hets+homs).max() > popsize) throw SimError("negative homozygote-ancestral"); /* used to randomize individuals */ valarray<int> ranout(popsize); mutation_loc loc; int ind; for (int k=0; k < (int)hets.size(); k++) { ranint(popsize,ranout); if (sites_model == infinite_sites) loc = create_site(GenomeInfiniteSites::sample_effect_size()); else loc = (mutation_loc)k; /* haploid can't have homozygote_derived */ if (Site::ploidy_level == haploid && homs[k] > 0) throw SimError("haploid can't have homozygote derived site"); /* mutate heterozygote sites once */ for (ind=0; ind < hets[k]; ind++) genomes[ranout[ind]]->mutate_site(loc, up); /* mutate homozygote sites twice */ for (; ind < hets[k]+homs[k]; ind++) { genomes[ranout[ind]]->mutate_site(loc, up); genomes[ranout[ind]]->mutate_site(loc, up); } } /* compute fitnesses */ for (ind = 0; ind < popsize; ind++) { genomes[ind]->update_phenotype(); genomes[ind]->update_fitness(); } return; }
bool updateEigenSystem(unsigned max_tries, unsigned max_iters) { if (max_iters==0) max_iters = 30 * p.n; static double lastGoodMinimumEigenValue = 1.0; /* Try to get a valid calculation */ for (unsigned tries = 0; tries < max_tries; ++tries) { unsigned iters = eig( p.n, C, d, B, max_iters); if (iters < max_iters) { // all is well /* find largest/smallest eigenvalues */ double minEV = d.min(); double maxEV = d.max(); /* (MK Original comment was) :Limit Condition of C to dMaxSignifKond+1 * replaced dMaxSignifKond with 1./numeric_limits<double>::epsilon() * */ if (maxEV * numeric_limits<double>::epsilon() > minEV) { double tmp = maxEV * numeric_limits<double>::epsilon() - minEV; minEV += tmp; for (unsigned i=0;i<p.n;++i) { C[i][i] += tmp; d[i] += tmp; } } /* if */ lastGoodMinimumEigenValue = minEV; d = sqrt(d); //flgEigensysIsUptodate = 1; //genOfEigensysUpdate = gen; //clockeigensum += clock() - clockeigenbegin; return true; } /* if cIterEig < ... */ // numerical problems, ignore them and try again /* Addition des letzten minEW auf die Diagonale von C */ /* Add the last known good eigen value to the diagonal of C */ double summand = lastGoodMinimumEigenValue * exp((double) tries); for (unsigned i = 0; i < p.n; ++i) C[i][i] += summand; } /* for iEigenCalcVers */ return false; }
static double Linfty(valarray<double> const &vec) { return std::max(vec.max(), -vec.min()); }