I am trying to implement Stoachastic Hill Climbing in Java. I understand that this algorthim makes a new solution which is picked randomly and then accept the solution based on how bad/good it is. For example, if its very bad then it will have a small chance and if its slighlty bad then it will have more chances of being selected but I am not sure how I can implement this probability in java.
Whilst browing on Google, I came across this equation, where;
I am not really sure how to interpret this equation.
Can someone please help me on how I can implement this in Java?
The left hand side of the equation p
will be a double between 0 and 1, inclusively. oldFitness
, newFitness
and T
can also be doubles.
You will have something similar to this in your code:
double p = 1 / (1 + Math.exp((oldFitness - newFitness) / T));
if (Math.random() < p) {
// accept the new solution
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With