示例#1
0
  HillClimbing::HillClimbing()
      : OptimisationAlgorithm() {
    bestFoundParameter_ = 2.0 * arma::ones<arma::vec>(3);

    setInitialisingFunctions({{[this](
                                   const arma::uword numberOfDimensions_,
                                   const arma::mat& initialParameters_) {
                                 if (getMinimalStepSize() > getMaximalStepSize()) {
                                   throw std::logic_error("HillClimbing.initialisingFunctions: The maximal step size must be must be greater than or equal to the minimal one.");
                                 }

                                 return initialParameters_;
                               },
        "Step size validation"}});

    setNextParametersFunctions({{[this](
                                     const arma::uword numberOfDimensions_,
                                     const arma::mat& parameters_,
                                     const arma::rowvec& objectiveValues_,
                                     const arma::rowvec& differences_) {
                                   return randomNeighbour(getBestFoundParameter(), getMinimalStepSize(), getMaximalStepSize());
                                 },
        "Return a random neighbour of the best parameter within the step sizes"}});

    setMinimalStepSize(0.0);
    setMaximalStepSize(0.1);
  }
示例#2
0
SimulatedAnnealing::SimulatedAnnealing()
    : OptimisationAlgorithm() {
    setInitialisingFunctions({{
            [this](
                const arma::uword numberOfDimensions_,
                const arma::mat& initialParameters_) {
                if (minimalStepSize_ > maximalStepSize_) {
                    throw std::logic_error("SimulatedAnnealing.initialisingFunctions: The maximal step size must be must be greater than or equal to the minimal one.");
                }

                return initialParameters_;
            },
            "Step size validation"
        }
    });

    setNextParametersFunctions({{
            [this](
                const arma::uword numberOfDimensions_,
                const arma::mat& parameters_,
                const arma::rowvec& objectiveValues_,
                const arma::rowvec& differences_) {
                if (differences_(0) < 0) {
                    state_ = getBestFoundParameter();
                } else {
                    double durationEnergy = getUsedDuration() / getMaximalDuration();
                    double numberOfIterationsEnergy = getUsedNumberOfIterations() / getMaximalNumberOfIterations();

                    double energy;
                    if (durationEnergy > numberOfIterationsEnergy) {
                        energy = std::exp(-(objectiveValues_(0) - getBestFoundObjectiveValue()) / (1.0 - durationEnergy));
                    } else {
                        energy = std::exp(-(objectiveValues_(0) - getBestFoundObjectiveValue()) / (1.0 - numberOfIterationsEnergy));
                    }

                    if (std::bernoulli_distribution(energy)(Rng::generator_)) {
                        state_ = parameters_.col(0);
                    }
                }

                return randomNeighbour(state_, minimalStepSize_, maximalStepSize_);
            },
            "Simulated annealing"
        }
    });

    setMinimalStepSize(0);
    setMaximalStepSize(0.1);
}
示例#3
0
 SimulatedAnnealing::SimulatedAnnealing(
     const std::shared_ptr<OptimisationProblem> optimisationProblem)
     : TrajectoryBasedOptimisationAlgorithm(optimisationProblem) {
   setMaximalStepSize((getUpperBounds() - getLowerBounds()) * 0.1);
 }
示例#4
0
 HillClimbing<T>::HillClimbing(
     const std::shared_ptr<OptimisationProblem<T>> optimisationProblem) noexcept
   : TrajectoryBasedOptimisationAlgorithm<T>(optimisationProblem) {
   setMaximalStepSize(arma::norm(this->getLowerBounds(), this->getUpperBounds()) / static_cast<T>(10.0L));
 }