Exemple #1
0
	def __init__(self):
		self.Lower = -11
		self.Upper = 11

	def function(self):
		def evaluate(D, sol):
			val = 0.0
			for i in range(D): val += sol[i] ** 2
			return val
		return evaluate

# Common variables
school_size = 10
n_iter = 10
min_w = 1
w_scale = n_iter / 2.0
D = 10

SI_init = 0.1
SI_final = 0.01
SV_init = 10
SV_final = 0.1

logger.info('Running with custom MyBenchmark...')
for i in range(10):
    Algorithm = FishSchoolSearch(
        n_iter=10, school_size=10, D=10, SI_init=0.1, SI_final=0.001, SV_init=1, SV_final=0.1, min_w=1, w_scale=5, benchmark=MyBenchmark()
    )
    Best = Algorithm.run()
    logger.info(Best) 
Exemple #2
0
# encoding=utf8
# This is temporary fix to import module from parent folder
# It will be removed when package is published on PyPI
import sys
sys.path.append('../')
# End of fix

import random
from NiaPy.algorithms.basic import FishSchoolSearch
from NiaPy.util import StoppingTask, OptimizationType
from NiaPy.benchmarks import Sphere

#we will run Fish School Search for 5 independent runs
for i in range(5):
    task = StoppingTask(D=10,
                        nFES=10000,
                        optType=OptimizationType.MINIMIZATION,
                        benchmark=Sphere())
    algo = FishSchoolSearch(NP=20)
    best = algo.run(task=task)
    print('%s -> %f' % (best[0].x, best[1]))