Exercise 5: Warm-up Temperature ?!
import random
import numpy as np
def accept_prob(S_old, S_new, T):
# this is the acceptance "probability" in the greedy hill-climbing method
# where new solutions are accepted if and only if they are better
# than the old one.
# change it to be the acceptance probability in simulated annealing
prob = np.exp(-(S_old - S_new) / T)
if random.random() < prob:
return 0.0
else:
return 1.0
# the above function will be used as follows. this is shown just for
# your information; you don't have to change anything here
def accept(S_old, S_new, T):
if random.random() < accept_prob(S_old, S_new, T):
print(True)
else:
print(False)
accept(65, 70, 1)
"What I supposed to do here now? The task is asking to change the greedy hill-climbing method to the acceptance probability in simulated annealing or someting. And now the error says, “The algorithm should greedily select S_new if it is greater than S_old.” So what the f….?