示例#1
0
    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;

    }
示例#2
0
static double 
Linfty(valarray<double> const &vec) {
    return std::max(vec.max(), -vec.min());
}