Stochastic Hill

I am trying to implement Stoachastic Hill Climbing in Java. I understand that this algorthim creates a new solution that is randomly selected and then makes a decision based on how bad / good it is. For example, if it is very bad, then he will have a small chance, and if he has a bad result he will have more chances to be selected, but I'm not sure how to implement this probability in java.

While I'm on Google, I came across this equation, where:

  • f represents old fitness
  • f 'represents new fitness
  • T - parameter

enter image description here

I am not sure how to interpret this equation.

Can someone please help me on how I can implement this in Java?

+5
source share
2 answers

The left side of the equation p will be double between 0 and 1 inclusive. oldFitness , newFitness and T can also be doubled.

There will be something similar in your code:

 double p = 1 / (1 + Math.exp((oldFitness - newFitness) / T)); if (Math.random() < p) { // accept the new solution 
+4
source

You can find a good understatement of the mountain climbing algorithm in this book. Artificial Intelligence - A Modern Approach . This book also has a code repository, here you can find it.

And here is the implementation of HillClimbing (HillclimbingSearch.java) in java. But for this java file you need to import another source file. This is better if you look at the code repository. In this class, you have a public search () method -

 public List<Action> search(Problem p){} 

From the signature of the method, you can see that this method requires Problem p and returns a List of Action . To get these Problem and Action , you must use aima .

You can find some more explanations about stochastic hill climbing here.

Hope this helps.
Many thanks.

0
source

Source: https://habr.com/ru/post/1214601/


All Articles