In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Most people do not understand the knowledge points of this article "what is the calibration method of fitness function in Python genetic algorithm", so the editor summarizes the following contents, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this article "what is the calibration method of fitness function in Python genetic algorithm".
Calibration of fitness function
In general, it is very convenient to take the objective function as the fitness function directly, but it cannot be done in many cases. For example, for the minimum problem, we must invert the objective function to be the fitness function (this is the simplest case).
When the relative difference of the fitness function of different individuals in our genetic algorithm is very small, the selection pressure (Selective pressure) of individual selection according to the fitness value will become smaller, and the ability of selection will be weakened. At this time, we need to calibrate the original fitness function (Scaling). The relative difference between them increases, which increases the selection pressure and enhances the optimization ability of the algorithm.
Several different Calibration methods of fitness function
The calibration methods of objective function generally include linear calibration, dynamic linear calibration, power law calibration, logarithmic calibration and so on.
Cdn2.b0.upaiyun.com/2017/09/a50ee9ef74ba2b16547fb59e1c4e943b.png "alt=" WX20170924-210412mm 2x "span="h5 ="> find the maximum
For finding the maximum value of the objective function, that is, arg max f (x)
We choose axiom 1, which is a small number, where ξ is a small number, so that the worst individuals in the population have a chance to be selected, otherwise they subtract f?fmin=0, and the existence of ξ can increase the diversity of the population.
Add calibration to the objective function in GAFT
Since the calibration of fitness function is not for an objective function, I want to use the decorator to easily calibrate any custom fitness function. For basic linear calibration, I added a decorator with parameters to GAEngine:
Python
Def linear_scaling (self, target='max', ksi=0.5):
''
A decorator constructor for fitness function linear scaling.
: param target: The optimization target, maximization or minimization.
: type target: str, 'max' or' min'
: param ksi: Selective pressure adjustment value.
: type ksi: float
Linear Scaling:
1. Arg max f (x), then f'= f-min {f (x)} + ksi
2. Arg min f (x), then f'= max {f (x)}-f (x) + ksi
''
Def _ linear_scaling (fn):
# For original fitness calculation.
Self.ori_fitness = fn
@ wraps (fn)
Def _ fn_with_linear_scaling (indv):
# Original fitness value.
F = fn (indv)
# Determine the value of an and b.
If target = 'max':
F_prime = f-self.ori_fmin + ksi
Elif target = 'min':
F_prime = self.ori_fmax-f + ksi
Else:
Raise ValueError ('Invalid target type ({})' .format (target))
Return f_prime
Return _ fn_with_linear_scaling
Return _ linear_scaling
At this time, if we define our own objective function and want to calibrate it linearly, we can use the decorator of engine to modify the function, like the following:
Python
# Create a GA engine...
# calibrate first, then register to the engine
@ engine.fitness_register
@ engine.linear_scaling (target='min', ksi=0.5)
Def fitness (indv):
X, = indv.variants
Return x + 10*sin (5roomx) + 7*cos (4roomx)
The parameters in the decorator are:
Target: optimize the objective function to the minimum or maximum. The value can be: 'max'' or 'min''.
Ksi: that is, Zeta in the formula.
On ξ k
The action of ξ k in dynamic linear calibration is the same as that in linear calibration, which is the selective pressure adjustment value, which makes the worst individual in the population still have a chance to be selected, but the value of ξ k ξ k in dynamic calibration will decrease with the increase of kk.
The values of ξ k ξ k are as follows: ξ 0m, ξ k = ξ KZ 1century r ∈ [0.999], we adjust ξ k by adjusting M and r
Through ξ k, which can change dynamically, we can keep the diversity of the population wide and the convergence of the local search, that is, we want the selection to be small at the beginning and the selection pressure to increase gradually after the iteration.
six
Other calibration methods
Logarithmic calibration
Function expression: f'=aLnf+b
Function: narrow the difference between objective functions
Window technology
Function expression: f'=af?fw
Fw is the minimum of the objective function in the previous W generation, and he takes into account the fluctuations of each generation of fmin, so that fw has memory.
How to judge the concentration degree of individual population
It is usually judged by comparing the proximity of the average favg of the fitness value of all individuals in the population to the maximum value fmax. The closer the maximum value is to the average value, the more concentrated the individual is.
Two parameters of large variation operation
Density factor α: determines the proportion of large variation operations in the whole process, and its value is close to 0.5. The more frequent large variation operations are.
Large mutation probability: the greater the probability, the better the stability of the large mutation algorithm, but the convergence speed may decrease. When the value of large mutation probability is 0.5, the large mutation operation is approximately reduced to random search.
The above is the content of this article on "what is the calibration method of fitness function in Python genetic algorithm". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more related knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.