本文整理汇总了C++中valarray::max方法的典型用法代码示例。如果您正苦于以下问题:C++ valarray::max方法的具体用法?C++ valarray::max怎么用?C++ valarray::max使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类valarray
的用法示例。
在下文中一共展示了valarray::max方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setup_initial_genotypes
/* 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;
}
示例2: updateEigenSystem
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;
}
示例3: max
static double
Linfty(valarray<double> const &vec) {
return std::max(vec.max(), -vec.min());
}