-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_diversities.py
53 lines (36 loc) · 1.11 KB
/
plot_diversities.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 3 20:58:08 2021
@author: qtckp
"""
import sys
sys.path.append('..')
import numpy as np
from geneticalgorithm2 import GeneticAlgorithm2 as ga
from geneticalgorithm2 import MiddleCallbacks
dim = 6
rd = np.random.random(size = dim)
def f(X):
return np.mean(X - rd)
varbound = np.array([[0, 1]]*dim)
model = ga(function=f, dimension = dim,
variable_type='real', variable_boundaries=varbound,
algorithm_parameters = {
'max_num_iteration': 1000,
'population_size':50,
'mutation_probability':0.1,
'elit_ratio': 0.01,
'crossover_probability': 0.5,
'parents_portion': 0.3,
'crossover_type':'uniform',
'mutation_type': 'uniform_by_center',
'selection_type': 'roulette',
'max_iteration_without_improv':None
}
)
model.run(
no_plot = False,
middle_callbacks = [
MiddleCallbacks.GeneDiversityStats(20)
]
)