void NoisyRprop::init(const ObjectiveFunctionType & objectiveFunction, const SearchPointType& startingPoint,const RealVector& delta0P){ SIZE_CHECK(startingPoint.size()==delta0P.size()); m_best.point=startingPoint; m_minEpisodeLength = 40; size_t pc = startingPoint.size(); m_episodeLength.resize(pc); m_sample.resize(pc); m_sampleIteration.resize(pc); m_iteration.resize(pc); m_toTheRight.resize(pc); m_position.resize(pc); m_leftmost.resize(pc); m_rightmost.resize(pc); m_leftsum.resize(pc); m_rightsum.resize(pc); m_current.resize(pc); m_numberOfAverages.resize(pc); m_gradient.resize(pc); m_delta = delta0P; std::fill(m_episodeLength.begin(),m_episodeLength.end(),m_minEpisodeLength); std::fill(m_sample.begin(),m_sample.end(),0); std::fill(m_sampleIteration.begin(),m_sampleIteration.end(),m_minEpisodeLength / 100); std::fill(m_iteration.begin(),m_iteration.end(),0); std::fill(m_position.begin(),m_position.end(),0); std::fill(m_leftmost.begin(),m_leftmost.end(),0); std::fill(m_rightmost.begin(),m_rightmost.end(),0); std::fill(m_toTheRight.begin(),m_toTheRight.end(),0); m_leftsum.clear(); m_rightsum.clear(); std::fill(m_current.begin(),m_current.end(),0); std::fill(m_numberOfAverages.begin(),m_numberOfAverages.end(),1); m_gradient.clear(); }
void RpropMinus::init( ObjectiveFunctionType & objectiveFunction, SearchPointType const& startingPoint, double initDelta ) { checkFeatures(objectiveFunction); objectiveFunction.init(); m_parameterSize = startingPoint.size(); m_delta.resize(m_parameterSize); m_oldDerivative.resize(m_parameterSize); std::fill(m_delta.begin(),m_delta.end(),initDelta); m_oldDerivative.clear(); m_best.point = startingPoint; //evaluate initial point m_best.value = objectiveFunction.evalDerivative(m_best.point,m_derivative); }
double eval(const SearchPointType &p) const { m_evaluationCounter++; // Setup the parameters Eigen::VectorXd params( p. size() ); for (int i = 0; i < p.size(); i++) params(i) = p(i); mPolicy->setParams(params); mSim->reset(); for (int i = 0; i < 2000; i++) { mSim->step(); } double value = mSim->eval()->cost(); LOG(INFO) << "# " << m_evaluationCounter << " : " << params.transpose() << " -> " << value; return value; }
void AbstractLineSearchOptimizer::init(ObjectiveFunctionType& objectiveFunction, SearchPointType const& startingPoint) { checkFeatures(objectiveFunction); objectiveFunction.init(); m_linesearch.init(objectiveFunction); m_dimension = startingPoint.size(); m_best.point = startingPoint; m_best.value = objectiveFunction.evalDerivative(m_best.point,m_derivative); // Get space for the different vectors we store. m_lastPoint.resize(m_dimension); m_searchDirection = -m_derivative; m_initialStepLength = 0.0;//1.0 as step length might be very wrong. for (size_t i = 0; i < m_derivative.size(); ++i) m_initialStepLength += std::abs(m_derivative(i)); m_initialStepLength = std::min(1.0, 1.0 / m_initialStepLength); initModel(); }
void proposeStartingPoint(SearchPointType &x) const { x.resize(numberOfVariables()); for (unsigned int i = 0; i < x.size(); i++) { x(i) = shark::Rng::uni(MIN_PARAM, MAX_PARAM); } }
void NoisyRprop::init(const ObjectiveFunctionType & objectiveFunction, const SearchPointType& startingPoint,double delta0P){ checkFeatures(objectiveFunction); RealVector d(startingPoint.size()); std::fill(d.begin(),d.end(),delta0P); init(objectiveFunction,startingPoint, d); }