Skip to content

Commit

Permalink
fix: Tested various funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
Agrover112 committed Jul 19, 2021
1 parent 86b6c9d commit c40d367
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions test_fn_algorithms.py
Expand Up @@ -3,9 +3,9 @@
from utils import plot_scores
import matplotlib
from matplotlib import pyplot as plt
matplotlib.use('TKAgg')
domain=[(-32,32)]*2
from fitness import ackley_N2
#matplotlib.use('TKAgg')
#domain=[(-32,32)]*2
from fitness import *
def random_search(domain, fitness_function, seed=random.randint(10, 100), seed_init=True, init=[], epochs=100):
""" Random search algorithm implemented
Expand Down Expand Up @@ -44,8 +44,9 @@ def random_search(domain, fitness_function, seed=random.randint(10, 100), seed_i
if i != 0:
solution = [random.randint(domain[i][0], domain[i][1])
for i in range(len(domain))]
print(solution)
if not fitness_function.__name__ == 'fitness_function':
cost = fitness_function(solution[0],solution[1])
cost = fitness_function(solution)
else: cost = fitness_function(solution,'FCO')
nfe += 1
if cost < best_cost:
Expand All @@ -55,5 +56,6 @@ def random_search(domain, fitness_function, seed=random.randint(10, 100), seed_i
return best_solution, best_cost, scores, nfe, seed

if __name__ == '__main__':
soln,cost,scores,nfe,seed=random_search(domain,ackley_N2)
plot_scores(scores,'random_search',save_fig=False)
soln,cost,scores,nfe,seed=random_search(domain['rosenbrock']*12,rosenbrock)
print(cost,soln,"\n",scores)
#plot_scores(scores,'random_search',save_fig=False)

0 comments on commit c40d367

Please sign in to comment.