UNIOA can help:
- design your own swarm-based algorithms with only math knowledge, without any nature/bio knowledge.
- benchmark your optimization algorithm Your_Opt with other seven existing algorithms with the help of IOHprofiler.
UNIOA is a small python package in which the user can design his/her own algorithm like nature-inspired algorithms. This package is inspired by standardizing nature-inspired algorithms project in which we build up a generic framework based on studying seven popular swarm-based algorithm.
We built up this generic framework that can cover seven algorithms now. The generic framework is :
Python = 3.7
ioh = 0.3.2.3
numpy = 1.18.2
numba = 0.54.1
sklearn = 1.0
- install relative packages
pip install ioh == 0.3.2.3
pip install UNIOA
- open a empty
.py
file.
for example, an empty example.py
- only import UNIOA
from UNIOA import *
-
make sure what components will exist in your optimizer.
You want to use follows to design the optimizer.
(1) assisting vector influencing factor .
(2) related vector influencing factor .
(3) dynamic numberical influencing factor .
(4) static numberical influencing factors .
# optimize method customized by yourself
def your_Opt_X(old_x, y, x_ip, z, w):
new_x = ( old_x * z - y )*w + x_ip
return new_x
Opt_X.your = your_Opt_X
# initialize method selected in UNIOA
Init_Delta_Y.your = Init_Delta_Y.interval_type
# optimize method customized by yourself
def your_Opt_Delta_Y(old_y, w):
new_y = old_y * w
return new_y
Opt_Delta_Y.your = your_Opt_Delta_Y
(2)To , the optimize method selected in UNIOA
# initialize method selected in UNIOA
Init_Delta_X.your = Init_Delta_X.Personal_best
# optimize method selected in UNIOA
Opt_Delta_X.your = Opt_Delta_X.Personal_best
(3)To , the optimize method designed as
# initialize and optimize method customized by yourself
def your_InitOpt_Delta_z(t, old_z, w):
if t == 0:
new_z = old_z
else:
new_z = old_z * w
return new_z
InitOpt_Delta_z.your = your_InitOpt_Delta_z
(4)To , summarize all pre-set static parameters.
# initialize/setup static numerical influencing factors
M = 10
z_0 = 1 # assizt z
w1 = 0.8 # assist z
w2 = 0.6 # assist to update y
w3 = 0.7 # assist to update x
- put each component in fixed position.
# fixed
class Your_Opt(NatureOpt):
def __init__(self, func, hyperparams_set, budget_factor=1e4):
super().__init__(func, budget_factor)
# open to the user
self.M = hyperparams_set.get('M')
self.z_0 = hyperparams_set.get('z_0')
self.w1 = hyperparams_set.get('w1')
self.w2 = hyperparams_set.get('w2')
self.w3 = hyperparams_set.get('w3')
# fixed
def __call__(self):
t = 0
X = self.Init_X.Init_X(M=self.M, n=self.n, lb_x=self.lb_x, ub_x=self.ub_x)
X_Fit = self.Evaluate_X(X=X)
# fixed position, open inputs
Y = self.Init_Delta_Y.interval_type(M=self.M, n=self.n, interval=[-1,1])
X_ip, X_ip_Fit = self.Init_Delta_X.Personal_best(new_X=X, new_X_Fit=X_Fit)
z = self.InitOpt_Delta_z.your(t=t, old_z=self.z_0,w=self.w1)
# fixed
while not self.stop:
# fixed position, open inputs
new_Y = self.Opt_Delta_Y.your(old_y=Y, w=self.w2)
temp_X = self.Opt_X.your(old_x=X, y=new_Y, x_ip=X_ip, z=z, w=self.w3)
temp_X_Fit = self.Evaluate_X(X=X)
new_X, new_X_Fit = self.Selection.your(temp_X=temp_X, temp_X_Fit=temp_X_Fit, old_X=X, old_X_Fit=X_Fit)
t = t + 1
z = self.InitOpt_Delta_z.your(t=t, old_z=z,w=self.w1)
X_ip, X_ip_Fit = self.Opt_Delta_X.your(new_X=new_X, new_X_Fit=new_X_Fit, old_X_p=X_ip, old_X_p_Fit=X_ip_Fit)
X = new_X
X_Fit = new_X_Fit
Want to benchmark and compare Bat-optimizer and Your_Opt on 4 problems with 2 instances and 5 runs.
if __name__ == '__main__':
Algs = ['BA_UNIOA', 'Your_Opt']
problems = [1,2,3,4]
instances = [1,2]
dimensions = [5]
num_runs = 5
paras_sets = {'BA_UNIOA': {},
'Your_Opt':{'M':10,
'z_0':1,
'w1': 0.8,
'w2': 0.6,
'w3': 0.7}}
comparison.comparing(Algs, problems, instances, dimensions, num_runs, paras_sets)
Upload data to IOHanalyzer. Conclude Your_Opt performs worse than Bat_UNIOA.