bool EGPlanner::checkTerminationConditions() { if (!isActive()) { return true; } bool termination = false; //max steps equal to -1 means run forever if (mMaxSteps != -1 && mCurrentStep >= mMaxSteps) { if (!mRepeat) { pausePlanner(); termination = true; } else { resetParameters(); } if (!mMultiThread) { Q_EMIT update(); } } else if (mMaxTime != -1) { //check time limit //for now exceeding the time limit simply kills it for good if (getRunningTime() > mMaxTime) { termination = true; stopPlanner(); } } if (termination) { Q_EMIT complete(); } return termination; }
/*! Deletes any children that are done. If there are seeds available and emtpty children slots it also fires of new children. If a new child is fired and the main planner is still in the area, the main planner is also reset so it goes plan somewhere else. */ void GuidedPlanner::checkChildren() { //first check if any children have stopped SimAnnPlanner *pl; std::vector<SimAnnPlanner*>::iterator it; it = mChildPlanners.begin(); while(it!=mChildPlanners.end()) { pl = (*it); if ( !pl->isActive() ) { stopChild(pl); it = mChildPlanners.erase( it ); delete pl; DBGA("Child stopped."); } else { it++; } } //if the planner is paused, do not fire any new children if (!isActive()) return; //now check if we have seeds and children available while ((int)mChildPlanners.size() < mMaxChildren && !mChildSeeds.empty()) { GraspPlanningState *seed = mChildSeeds.front(); mChildSeeds.pop_front(); //avoid this state in the future since it will be searched by a child mAvoidList.push_back(seed); startChild(seed); if (mCurrentState->distance(seed) < mDistanceThreshold) { //re-anneal to make sure we search in some other area resetParameters(); } } }
BrightnessFilter::BrightnessFilter(QObject *parent) : AbstractImageFilter(parent) { m_params << new ImageFilterParameter("Brightness", -100, 100, this) << new ImageFilterParameter("Contrast", -100, 100, this); resetParameters(); }
/** Set an attribute for the function * * @param attName :: The name of the attribute to set * @param att :: The attribute to set */ void BSpline::setAttribute(const std::string &attName, const API::IFunction::Attribute &att) { bool isUniform = attName == "Uniform" && att.asBool(); storeAttributeValue(attName, att); if (attName == "BreakPoints" || isUniform || attName == "StartX" || attName == "EndX") { resetKnots(); } else if (attName == "NBreak" || attName == "Order") { resetGSLObjects(); resetParameters(); resetKnots(); } }
/*! The only function available externally to set the planner to the READY state. However, before that can actually happen, the planner must receive all needed input, which depends on the type of implementation. It will clear any solutions saved so far and re-start the timer and the step count as well. It can not be used while the planner is running, you must pause the planner first. This function will also move the planner from INIT to READY as long as all the necessary conditions for initialized() have been met. */ bool EGPlanner::resetPlanner() { if ( getState() == RUNNING || getState() == DONE) { DBGA("Planner is either running or dead; cannot reset"); return false; } if (!initialized()) { DBGA("Planner is not ready; not all necessary information has been set"); return false; } clearSolutions(); resetParameters(); mRunningTime = 0; setState(READY); if (!mMultiThread) emit update(); return true; }
/** * Recalculate the B-spline knots */ void BSpline::resetKnots() { bool isUniform = getAttribute("Uniform").asBool(); std::vector<double> breakPoints; if ( isUniform ) { // create uniform knots in the interval [StartX, EndX] double startX = getAttribute("StartX").asDouble(); double endX = getAttribute("EndX").asDouble(); gsl_bspline_knots_uniform( startX, endX, m_bsplineWorkspace.get() ); getGSLBreakPoints( breakPoints ); storeAttributeValue( "BreakPoints", Attribute(breakPoints) ); } else { // set the break points from BreakPoints vector attribute, update other attributes breakPoints = getAttribute( "BreakPoints" ).asVector(); // check that points are in ascending order double prev = breakPoints[0]; for(size_t i = 1; i < breakPoints.size(); ++i) { double next = breakPoints[i]; if ( next <= prev ) { throw std::invalid_argument("BreakPoints must be in ascending order."); } prev = next; } int nbreaks = getAttribute( "NBreak" ).asInt(); // if number of break points change do necessary updates if ( static_cast<size_t>(nbreaks) != breakPoints.size() ) { storeAttributeValue("NBreak", Attribute(static_cast<int>(breakPoints.size())) ); resetGSLObjects(); resetParameters(); } GSLVector bp = breakPoints; gsl_bspline_knots( bp.gsl(), m_bsplineWorkspace.get() ); storeAttributeValue( "StartX", Attribute(breakPoints.front()) ); storeAttributeValue( "EndX", Attribute(breakPoints.back()) ); } }
void FunctionalityTests::performTests(float dt) { _keyTimer += dt; _timer = 0.0f; if (fullScreenToggle()) return; if (resetParameters()) return; if (changeViewPortColor()) return; if (pixelPointScaleChange()) { return; } if (keyboardFocus()) { return ; } }
void FunctionalityTests::performTests(float dt) { _keyTimer += dt; //if (_timer > g_testingInterval) { //Only perform 1 test _timer = 0.0f; if (fullScreenToggle()) return; if (resetParameters()) return; if (changeViewPortColor()) return; if (pixelPointScaleChange()) { return; } //} else { // _timer += dt; //} }
void SlaterDetWithBackflow::testDerivGL(ParticleSet& P) { // testing derivatives of G and L app_log() <<"testing derivatives of G and L \n"; opt_variables_type wfVars,wfvar_prime; checkInVariables(wfVars); checkOutVariables(wfVars); int Nvars= wfVars.size(); wfvar_prime= wfVars; wfVars.print(cout); vector<RealType> dlogpsi; vector<RealType> dhpsi; dlogpsi.resize(Nvars); dhpsi.resize(Nvars); ParticleSet::ParticleGradient_t G0,G1,G2; ParticleSet::ParticleLaplacian_t L0,L1,L2; G0.resize(P.getTotalNum()); G1.resize(P.getTotalNum()); G2.resize(P.getTotalNum()); L0.resize(P.getTotalNum()); L1.resize(P.getTotalNum()); L2.resize(P.getTotalNum()); ValueType psi0 = 1.0; ValueType psi1 = 1.0; ValueType psi2 = 1.0; double dh=0.00001; for(int k=0; k<Dets.size(); k++) { DiracDeterminantWithBackflow* Dets_ = (DiracDeterminantWithBackflow*) Dets[k]; Dets_->testGGG(P); for( int i=0; i<Nvars; i++) { Dets_->testDerivFjj(P,i); Dets_->testDerivLi(P,i); } } app_log() <<"Nvars: " <<Nvars <<endl; for(int i=0; i<Nvars; i++) { for (int j=0; j<Nvars; j++) wfvar_prime[j]=wfVars[j]; resetParameters(wfvar_prime); BFTrans->evaluateDerivatives(P); G0=0.0;G1=0.0;G2=0.0; L0=0.0;L1=0.0;L2=0.0; for(int k=0; k<Dets.size(); k++) { DiracDeterminantWithBackflow* Dets_ = (DiracDeterminantWithBackflow*) Dets[k]; Dets_->evaluateDerivatives(P,wfVars,dlogpsi,dhpsi,&G0,&L0,i); } for (int j=0; j<Nvars; j++) wfvar_prime[j]=wfVars[j]; wfvar_prime[i] = wfVars[i]+ dh; resetParameters(wfvar_prime); BFTrans->evaluate(P); for(int k=0; k<Dets.size(); k++) psi1 += Dets[k]->evaluateLog(P,G1,L1); for (int j=0; j<Nvars; j++) wfvar_prime[j]=wfVars[j]; wfvar_prime[i] = wfVars[i]- dh; resetParameters(wfvar_prime); BFTrans->evaluate(P); for(int k=0; k<Dets.size(); k++) psi2 += Dets[k]->evaluateLog(P,G2,L2); ValueType tmp=0.0; for(int q=0; q<P.getTotalNum(); q++) tmp+=(L1[q]-L2[q])/(2*dh); app_log() <<i <<"\n" <<"Ldiff : " <<L0[0] <<" " <<tmp <<" " <<L0[0]-tmp <<endl; for(int k=0; k<P.getTotalNum(); k++) { app_log()<<G0[k] <<endl <<(G1[k]-G2[k])/(2*dh) <<endl <<"Gdiff: " <<G0[k]-(G1[k]-G2[k])/(2*dh) <<endl <<endl; } } resetParameters(wfVars); //APP_ABORT("Testing bF derivs \n"); }
void DiracDeterminantOpt::evaluateDerivatives(ParticleSet& P, const opt_variables_type& active, vector<RealType>& dlogpsi, vector<RealType>& dhpsioverpsi) { // The dlogpsi part is simple -- just ratios // First, evaluate the basis functions // cerr << "GEMM 1:\n"; // fprintf (stderr, "FirstIndex = %d LastIndex=%d\n", FirstIndex, // LastIndex); resetParameters(active); Phi->evaluateBasis (P, FirstIndex, LastIndex, BasisVals, BasisGrad, BasisLapl); BLAS::gemm ('N', 'T', NumBasis, NumOrbitals, NumOrbitals, 1.0, BasisVals.data(), NumBasis, psiM.data(), NumOrbitals, 0.0, dlogdet_dC.data(), NumBasis); // for (int i=0; i<NumOrbitals; i++) // for (int j=0; j<NumBasis; j++) { // dlogdet_dC(i,j) = 0.0; // for (int n=0; n<NumOrbitals; n++) { // dlogdet_dC(i,j) += psiM(n,i) * BasisVals(n,j); // // fprintf (stderr, "BasisVals(%d,%d) = %12.6e\n", n, j, BasisVals(n,j)); // } // } Gamma = dlogdet_dC; // for (int n=0; n<NumOrbitals; n++) // for (int j=0; j<NumBasis; j++) { // Gamma(n,j) = 0.0; // for (int k=0; k<NumOrbitals; k++) { // Gamma(n,j) += psiM(k,n) * BasisVals(k,j); // // fprintf (stderr, "BasisVals(%d,%d) = %12.6e\n", n, j, BasisVals(n,j)); // } // } // Now, d_dC should hold d/dC_{ij} log(det). // Multiply L matrix by gamma matrix, as shown in eq. 17 of // docs/OrbitalOptimization.tex L_gamma = BasisLapl; BLAS::gemm ('N', 'N', NumBasis, NumOrbitals, NumOrbitals, -1.0, Gamma.data(), NumBasis, d2psiM.data(), NumOrbitals, 1.0, L_gamma.data(), NumBasis); // for (int l=0; l<NumOrbitals; l++) // for (int j=0; j<NumBasis; j++) { // // L_gamma(l,j) = BasisLapl(l,j); // L_gamma(l,j) = BasisLapl(l,j); // G_gamma(l,j) = BasisGrad(l,j); // for (int n=0; n<NumOrbitals; n++) { // L_gamma(l,j) -= d2psiM(l,n)*Gamma(n,j); // G_gamma(l,j) -= dpsiM(l,n)*Gamma(n,j); // } // } for (int l=0; l<NumOrbitals; l++) for (int j=0; j<NumBasis; j++) { G_gamma(l,j) = BasisGrad(l,j); for (int n=0; n<NumOrbitals; n++) G_gamma(l,j) -= dpsiM(l,n)*Gamma(n,j); } // Now, compute d/dC_{ij} lapl(det)/det by multiplying by Ainv BLAS::gemm('N', 'T', NumBasis, NumOrbitals, NumOrbitals, -0.5, L_gamma.data(), NumBasis, psiM.data(), NumOrbitals, 0.0, dlapl_dC.data(), NumBasis); for (int ptcl=0; ptcl<NumOrbitals; ptcl++) { MyG[ptcl] = PosType(); for (int orb=0; orb<NumOrbitals; orb++) MyG[ptcl] += dpsiM(ptcl,orb)*psiM(ptcl,orb); // fprintf (stderr, "myG = %11.4e %11.4e %11.4e\n", // myG[ptcl][0], myG[ptcl][1], myG[ptcl][2]); // fprintf (stderr, "MyG = %11.4e %11.4e %11.4e\n", // MyG[ptcl][0], MyG[ptcl][1], MyG[ptcl][2]); // fprintf (stderr, "P.G = %11.4e %11.4e %11.4e\n", // P.G[ptcl+FirstIndex][0], // P.G[ptcl+FirstIndex][1], // P.G[ptcl+FirstIndex][2]); } for (int i=0; i<NumOrbitals; i++) for (int j=0; j<NumBasis; j++) for (int l=0; l<NumOrbitals; l++) { GradType g = P.G[FirstIndex+l]; GradType dg1 = psiM(l,i)*G_gamma(l,j); GradType dg2 = g*dlogdet_dC(i,j); GradType dg = dg1;// - dg2; // fprintf (stderr, "dg = %9.4f %9.4f %9.4f\n", // dg[0], dg[1], dg[2]); // fprintf (stderr, "g1 = %11.4e %11.4e %11.4e g2 = %11.4e %11.4e %11.4e\n", // dg1[0], dg1[1], dg1[2], dg2[0], dg2[1], dg2[2]); g -= MyG[l]; dlapl_dC(i,j) -= dot(g, dg); } // for (int i=0; i<NumOrbitals; i++) // for (int j=0; j<NumBasis; j++) { // dlapl_dC(i,j) = 0.0; // for (int l=0; l<NumOrbitals; l++) { // // dlapl_dC(i,j) += psiM(n,i)*L_gamma(n,j); // // dlapl_dC(i,j) += psiM(l,i)*L_gamma(l,j); // dlapl_dC(i,j) -= 0.5*psiM(l,i)*L_gamma(l,j); // //dlapl_dC(i,j) += psiM(l,i)*BasisLapl(l,j); // } // } // Pull elements from dense d_dC matrices and put into parameter // derivatives, dlogpsi and dhpsioverpsi Phi->copyParamsFromMatrix(active, dlogdet_dC, dlogpsi); Phi->copyParamsFromMatrix(active, dlapl_dC, dhpsioverpsi); }
Parameters::Parameters(int argc, char * argv[]) { resetParameters(argc, argv); }