void itsHybridContinuousInteractingAntColony::diversification() { if ( antsNb != getSampleSizeCurrent() ) { ostringstream msg; msg << "ErrorSize: antsNb (" << antsNb << ")" << " and sample size (" << getSampleSizeCurrent() << ")" << " does not match"; throw Exception_Size_Match( msg.str(), EXCEPTION_INFOS ); } // move ants for ( unsigned int i=0; i < getSampleSizeCurrent(); i++ ) { antMove( i ); } // ants -> sample for ( unsigned int i=0; i < antsNb; i++ ) { itsPoint p; p.setSolution( antCurrentPoint[i] ); vector<double> val; val.push_back( antCurrentValue[i] ); p.setValues( val ); setSamplePoint( i, p ); } }
void itsRandom::diversification() { // reinit all setSampleSize( getSampleSize() ); // draw each point in an hyper cube for( unsigned int i=0; i < getSampleSize(); i++) { // draw solution itsPoint p; p.setSolution( randomUniform( this->getProblem()->boundsMinima(), this->getProblem()->boundsMaxima() ) ); // get values setSamplePoint(i, evaluate(p) ); } }
void itsHybridEstimationOfDistribution::simplex() { // if no given NMS evaluations number if( getSimplexEvaluations() == -1 ) { //setSimplexEvaluations( (int)floor( pow( (this->problem->getDimension() + 1 ), 2.0 ) ) ); setSimplexEvaluations( this->getProblem()->getDimension() + 10 ); } for( unsigned int i=0; i < getSampleSizeCurrent(); i++ ) { itsNelderMead nms; // problem optimized nms.setProblem( this->getProblem() ); // no ending stopping criteria nms.setValueMin(0.0); nms.setIterationsMaxNumber( this->getIterationsMaxNumber() ); // used stopping criterion nms.setEvaluationsMaxNumber( this->simplexEvaluations ); // edges from sample hypercube vector<double> edges = multiply( substraction( this->getProblem()->boundsMaxima(), this->getProblem()->boundsMinima() ), 1 / ( pow( (double)getSampleSizeCurrent(), (double)1.0/this->getProblem()->getDimension() ) - 1 ) ); // init on current point nms.initSimplexFromBasePoint( getSamplePoint(i), edges ); // silent launch nms.startSilent(); // change the point to the new local optimum setSamplePoint( i, nms.getOptimum() ); } }
std::shared_ptr<Opm::UniformTabulated2DFunction<Scalar> > createUniformTabulatedFunction(Fn &f) { Scalar xMin = -2.0; Scalar xMax = 3.0; unsigned m = 50; Scalar yMin = -1/2.0; Scalar yMax = 1/3.0; unsigned n = 40; auto tab = std::make_shared<Opm::UniformTabulated2DFunction<Scalar>>( xMin, xMax, m, yMin, yMax, n); for (unsigned i = 0; i < m; ++i) { Scalar x = xMin + Scalar(i)/(m - 1) * (xMax - xMin); for (unsigned j = 0; j < n; ++j) { Scalar y = yMin + Scalar(j)/(n - 1) * (yMax - yMin); tab->setSamplePoint(i, j, f(x, y)); } } return tab; }
void itsSimulatedAnnealing::diversification() { // reinit all setSampleSize( getSampleSize() ); // draw each point in an hyper cube for( unsigned int i=0; i < getSampleSize(); i++) { // draw solution p_new.setSolution( randomUniform( this->getProblem()->boundsMinima(), this->getProblem()->boundsMaxima() ) ); p_new = evaluate(p_new); setSamplePoint( i, p_new ); // Metropolis rule // if the value is the better than the previous point, accept if( isValueSmaller(p_current,p_new) ) { p_current = p_new; } else { // else, draw a random number and see if we accept the new point if( randomUniform(0.0,temperature_max) < temperature ) { p_current = p_new; } // else the current point is kept } } }
void PolyBezierCurve::generateSamplePoints( const curvedef::MapEvaluators & evalMap, const int & rate ) { assert( !evalMap.empty() ); mathdef::resize( m_samplePoints, rate * getNumSegments() + 1 ); mathdef::setZero( m_samplePoints ); // Evaluate the first point on the first curve, then // Loop through all segment to sample 1st sample to last sample. resetToFirstSegment(); int samp_i = 0; // Sample temp index int j; curvedef::Degree deg; VectorX2s segCtrlPts; while (m_iter != pointsEnd()) { deg = getSegmentDegree( m_currentSegment ); const BezierEvaluator & evaluator = evalMap.find( deg )->second; assert( evaluator.isBasesComputed() ); assert( deg > 0); segCtrlPts = m_controlPoints.block( m_iter.getCurrentRow(), 0, deg + 1, 2 ); // Compute first end point if we are at first segment if (m_currentSegment == 0) { j = 0; // std::cout << "eval first t = " << computeParameterT(j, rate) << ": " << std::endl; setSamplePoint(samp_i, evaluator.eval(segCtrlPts, j)); // std::cout << m_samplePoints.block(samp_i, 0, 1, 2) << std::endl; ++samp_i; } j = 1; while (j <= rate) { // Sample segment point from index 1 to rate // std::cout << "eval t = " << computeParameterT(j, rate) << ": " << std::endl; setSamplePoint(samp_i, evaluator.eval(segCtrlPts, j)); // std::cout << m_samplePoints.block(samp_i, 0, 1, 2) << std::endl; ++samp_i; ++j; } advanceSegment(); } // // int segment = 0; // Segment index // int samp_i = 0; // Sample temp index // int ctrl_i = 0; // Control point temp index // int j; // curvedef::Degree deg; int numPts; // VectorX2s segCtrlPts; // while (segment < getNumSegments()) // { // deg = getSegmentDegree( segment ); // const BezierEvaluator & evaluator = evalMap.find( deg )->second; // // assert( evaluator.isBasesComputed() ); // assert( deg > 0); // // std::cout << "CONTROL POINTS:\n" << m_controlPoints << std::endl; // std::cout << "deg, ctrl_i, samp_i: " << deg << " " << ctrl_i << " " << samp_i << std::endl; // std::cout << m_controlPoints.block( ctrl_i, 0, deg + 1, 2) << std::endl; // // segCtrlPts = m_controlPoints.block( ctrl_i, 0, deg + 1, 2); // // // Compute first end point if we are at first segment // if (segment == 0) // { // j = 0; // std::cout << "eval first t = " << computeParameterT(j, rate) << ": " << std::endl; // setSamplePoint(samp_i, evaluator.eval(segCtrlPts, j)); // std::cout << m_samplePoints.block(samp_i, 0, 1, 2) << std::endl; // ++samp_i; // } // // j = 1; // while (j <= rate) // { // // Sample segment point from index 1 to rate // std::cout << "eval t = " << computeParameterT(j, rate) << ": " << std::endl; // setSamplePoint(samp_i, evaluator.eval(segCtrlPts, j)); // std::cout << m_samplePoints.block(samp_i, 0, 1, 2) << std::endl; // ++samp_i; // ++j; // } // // ctrl_i += deg; // ++segment; // } }