Example #1
0
        void run(task::TaskDAG& dag, const Arena& arena)
        {
            for (iter = 1;iter <= maxiter && !isConverged();iter++)
            {
                time::Timer timer;
                timer.start();
                iterate();
                timer.stop();
                double dt = timer.seconds(arena);

                int ndigit = (int)(ceil(-log10(convtol))+0.5);

                log(arena) << "Iteration " << iter << " took " << std::fixed <<
                              std::setprecision(3) << dt << " s" << std::endl;
                log(arena) << "Iteration " << iter <<
                              " energy = " << std::fixed << std::setprecision(ndigit) << energy <<
                              ", convergence = " << std::scientific << std::setprecision(3) << conv << std::endl;
            }

            if (!isConverged())
            {
                throw std::runtime_error(std::strprintf("Did not converge in %d iterations", maxiter));
            }
        }
Example #2
0
	vec_float_t CPowell::getParams(float kappa)
	{
		// Assertions
		DGM_ASSERT_MSG(kappa > 0.0f, "Negative kappa values are not allowed");

#ifdef DEBUG_PRINT_INFO
		// Printing out the information
		printf("[%zu]:\t", m_paramID);
		for (float& param : m_vParams) printf("%.2f\t", param);
		printf("%.2f\n", kappa);
#endif

		// If converged, no further steps are required
		if (isConverged()) return m_vParams;

		// =============== Fill all 3 kappa values ===============
			 if (m_vKappa[oD] < 0) { m_vKappa[oD] = kappa; m_midPoint = curArg; } 
		else if (m_vKappa[mD] < 0)   m_vKappa[mD] = kappa;
		else if (m_vKappa[pD] < 0)   m_vKappa[pD] = kappa;

		while (true) {
			// Need kappa: -1
			if (m_vKappa[mD] < 0) {
				if (m_midPoint == minArg) m_vKappa[mD] = 0.0f;
				else {
					curArg = MAX(minArg, m_midPoint - m_koeff * delta);
					return m_vParams;
				}
			}

			// Need kappa: +1
			if (m_vKappa[pD] < 0) {
				if (m_midPoint == maxArg) m_vKappa[pD] = 0.0f;
				else {
					curArg = MIN(maxArg, m_midPoint + m_koeff * delta);
					return m_vParams;
				}
			}

			// =============== All 3 kappas are ready ===============
			float maxKappa = *std::max_element(m_vKappa.begin(), m_vKappa.end());

			if (maxKappa == m_vKappa[oD]) {			// >>>>> Middle value -> Proceed to the next argument
				convArg = true;
				curArg = m_midPoint;

				if (isConverged()) return m_vParams;				// we have converged

				m_paramID = (m_paramID + 1) % m_nParams;			// new argument

				// reset variabels for new argument
				m_vKappa[mD] = -1;
				m_vKappa[pD] = -1;
				m_nSteps = 0;
				m_koeff = 1.0;

				m_midPoint = curArg;							// refresh the middle point
			}
			else if (maxKappa == m_vKappa[mD]) {	// >>>>> Lower value -> Step argument down
				std::fill(m_vConverged.begin(), m_vConverged.end(), false);		// reset convergence

				m_midPoint = MAX(minArg, m_midPoint - m_koeff * delta);			// refresh the middle point

				// shift kappa
				m_vKappa[pD] = m_vKappa[oD];
				m_vKappa[oD] = m_vKappa[mD];
				m_vKappa[mD] = -1.0f;

				// increase the search step
				m_nSteps++;
				m_koeff += m_acceleration * m_nSteps;
			}
			else if (maxKappa == m_vKappa[pD]) {	// >>>>> Upper value -> Step argument up
				std::fill(m_vConverged.begin(), m_vConverged.end(), false);		// reset convergence

				m_midPoint = MIN(maxArg, m_midPoint + m_koeff * delta);			// refresh the middle point

				// shift kappa
				m_vKappa[mD] = m_vKappa[oD];
				m_vKappa[oD] = m_vKappa[pD];
				m_vKappa[pD] = -1.0f;

				// increase the search step
				m_nSteps++;
				m_koeff += m_acceleration * m_nSteps;
			}
		} // infinite loop
	}
Example #3
0
        bool run(task::TaskDAG& dag, const Arena& arena, int nsolution)
        {
            nsolution_ = nsolution;
            energy_.resize(nsolution);
            
            conv_.assign(nsolution, numeric_limits<double>::max());
            
            for (iter_ = 1;iter_ <= maxiter && !isConverged();iter_++)
            {
                time::Timer timer;
                timer.start();
                for (subiter_ = 1;subiter_ <= maxsubiter && !isConverged();subiter_++)
                {
                    for (microiter_ = 1;microiter_ <= maxmicroiter && !isConverged();microiter_++)
                    {
                        microiterate(arena);
                        if (printlevel == 1)
                        {
                            for (int i = 0;i < nsolution;i++)
                            {
                                if (nsolution > 1)
                                {
                                    log(arena) << "      " << iter_  << "." << subiter_ << "." << microiter_ << " sol'n " << (i+1) <<
                                                  " energy = " << printToAccuracy(energy_[i], convtol)  << endl;
                                }
                                else
                                {
                                    log(arena) << "      " << iter_  << "." << subiter_ << "." << microiter_ <<
                                                  " energy = " << printToAccuracy(energy_[i], convtol) << endl;
                                }
                            }
                        }
                    }
                    
                    subiterate(arena);
                    if (printlevel == 1)
                    {
                        for (int i = 0;i < nsolution;i++)
                        {
                            if (nsolution > 1)
                            {
                                log(arena) << "        " << iter_ << "." << subiter_ << " sol'n " << (i+1) <<
                                              " energy = " << printToAccuracy(energy_[i], convtol)  << endl;
                            }
                            else
                            {
                                log(arena) << "        " << iter_ << "." << subiter_ <<
                                              " energy = " << printToAccuracy(energy_[i], convtol) << endl;
                            }
                        }
                    }
                }
                iterate(arena);
                timer.stop();
                double dt = timer.seconds(arena);
                log(arena) << "Iteration " << iter_ << " took " << fixed <<
                              setprecision(3) << dt << " s" << endl;
                for (int i = 0;i < nsolution;i++)
                {
                    if (nsolution > 1)
                    {
                        log(arena) << "Iteration " << iter_ << " sol'n " << (i+1) <<
                                      " energy = " << printToAccuracy(energy_[i], convtol) <<
                                      ", convergence = " << scientific << setprecision(3) << conv_[i] << endl;
                    }
                    else
                    {
                        log(arena) << "Iteration " << iter_ <<
                                      " energy = " << printToAccuracy(energy_[i], convtol) <<
                                      ", convergence = " << scientific << setprecision(3) << conv_[i] << endl;
                    }
                }

            }

            if (!isConverged())
            {
                log(arena) << "Did not converge in " << maxiter << " iterations" << endl;
            }

            return true;
        }