Skip to content

Huilin-Li/UNIOA

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Description

UNIOA can help:

  1. design your own swarm-based algorithms with only math knowledge, without any nature/bio knowledge.
  2. 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.

Ideas

We built up this generic framework that can cover seven algorithms now. The generic framework is : framework

Environment

Python = 3.7
ioh = 0.3.2.3
numpy = 1.18.2
numba = 0.54.1
sklearn = 1.0

Example

customized optimizer

  1. install relative packages
pip install ioh == 0.3.2.3
pip install UNIOA
  1. open a empty .py file.
for example, an empty example.py
  1. only import UNIOA
from UNIOA import *
  1. 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 .

  2. design a method to update as

# 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
  1. design each component in math and code.
    (1)To , the optimize method designed as
# 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
  1. 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

benchmark and comparison

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)

results of example experiment

Upload data to IOHanalyzer. Conclude Your_Opt performs worse than Bat_UNIOA.

ERT_Mult-2021-12-31

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages