Summary of heuristic algorithm

Source: Internet
Author: User
Tags rand

Here are some of the learning algorithms, some are not specifically used, so just the concept of interpretation, to facilitate their memories later. first, particle swarm algorithm 1.1 Basic Ideas

Particle swarm optimization (PSO) is an optimized algorithm for simulating swarm intelligence, and the particle swarm algorithm can use random foraging of birds in a space, for example, all birds do not know where the food is, but they know how far it is, the simplest and most effective way is to search the surrounding area of the bird nearest to the food. Therefore, the PSO algorithm is to see the birds as a particle, and they have the position and speed of the two properties, and then according to their own found from the nearest to the food and reference the entire cluster to find the nearest solution to change their flight direction, and finally we will find that the whole cluster to the same place in general aggregation. And this place is the area closest to the food, if the conditions are good, you will find food. This is the particle swarm algorithm. 1.2 Algorithm Description

Therefore, we need a pbest to record the optimal solution of the individual search, and use gbest to record the optimal solution that the whole group searched for in one iteration. The update formula for velocity and particle position is as follows:

V[i] = w * V[i] + C1 * RAND () * (Pbest[i]-present[i]) + C2 * RAND () * (Gbest-present[i])

Present[i]=present[i]+v[i]

Where V[i] represents the speed of the particle I, w represents the inertia weight, C1 and C2 represent the learning parameters, Rand () represents a random number between 0-1, Pbest[i] represents the best value for the first particle search, gbest represents the optimal value for the entire cluster search, Present[i] Represents the current position of the first particle.

1.3 Process of the standard PSO algorithm:

STEP1: Initialize a group of particles (group size m), including random positions and velocities;

STEP2: Evaluate the fitness of each particle;

STEP3: For each particle, its adaptive value and its best position pbest as a comparison, if it is better, it is the best position of the current pbest;

STEP4: For each particle, its adaptive value and its best position gbest as a comparison, if it is better, it is the best position of the current gbest;

STEP5: adjust particle velocity and position according to (2), (3); STEP6: Turn STEP2 If the end condition is not reached.


second, simulated annealing (sa,simulated annealing) thought

The mountain climbing method is the complete greedy method, each time sighted chooses a current optimal solution, therefore can only search to the local optimal value. Simulated annealing is actually a greedy algorithm, but its search process introduces random factors. The simulated annealing algorithm takes a certain probability to accept a solution that is worse than the current solution, so it is possible to jump out of the local optimal solution to achieve the global optimal solution. 2.1 Simulated annealing algorithm description:

If J (Y (i+1)) >= J (Y (i)) (that is, a better solution is obtained after moving), the movement is always accepted

If J (Y (i+1)) < J (Y (i)) (that is, the solution after the move is less than the current solution), the move is accepted at a certain probability, and the probability decreases gradually over time (decreasing gradually to stabilize)

The calculation of "certain probability" here refers to the annealing process of metal smelting, which is the origin of the name of the simulated annealing algorithm.

According to the thermodynamic principle, when the temperature is T, there is a probability that the energy difference is P (DE) for the DE, expressed as: P (DE) = exp (de/(KT))

where k is a constant, exp represents a natural exponent, and de<0. The formula is plainly: the higher the temperature, the greater the probability that the energy difference will reduce the cooling of the de, and the lower the temperature, the less the probability of cooling. And since DE is always less than 0 (otherwise it is not called annealing), so de/kt < 0, so the function value range of P (DE) is (0,1).

As the temperature t decreases, the P (DE) gradually decreases. 2.2 Solving travel quotient problems with simulated annealing algorithm

Traveling salesman problem (TSP, traveling salesman problem): There are N cities, asking for one of these problems, the only way to traverse all cities, and then go back to the city of departure, to find the shortest route.

The traveling salesman problem belongs to the so-called NP complete problem, the accurate solution tsp can only by the exhaustive path combination, its time complexity is O (n!).

The approximate optimal path of TSP can be obtained quickly by using simulated annealing algorithm. The idea of solving tsp by simulated annealing:

1. Generate a new traverse path P (i+1), calculate the length of the path P (i+1) L (P (i+1))

2. If L (P (i+1)) < L (P (i)), accept P (i+1) as a new path, otherwise accept P (i+1) as the probability of simulated annealing, and then cool down

3. Repeat steps until the exit condition is met. 2.3 There are a number of ways to generate a new traversal path, with 3 of them listed below:

1. Randomly select 2 nodes, exchanging the order of the 2 nodes in the path.

2. Randomly select 2 nodes to reverse the sequence of nodes between the 2 nodes in the path.

3. Randomly select 3 node m,n,k, then shift the node between node m and N to after node K. 2.4 Analysis of the reasons for the failure to get good results at the beginning of simulated annealing for Huawei Competition

The annealing algorithm first sets a certain temperature, the outer loop is a process of cooling, and the inner layer loops into a process of traversal.

1, only consider to meet the needs of the server, because it is possible to change the location of a server will meet the demand, and from a local solution over to the global optimal solution, the middle of a large may not meet the traffic demand first.

2. The next cycle is not performed on the basis of the optimal solution of each inner layer cycle. Because for a better solution, may change the location of a server to achieve the global optimization, each time the inner layer of the loop may be a good solution to the middle of a change too much, the next time from this relatively good solution to get a better solution to the probability of reduction. third, what is normalization. (used in neural networks)

Data normalization is the mapping of data to [0,1] or [ -1,1] intervals or smaller intervals, such as (0.1,0.9). 3.1 Why should normalization be processed.

<1> input data units are not the same, some of the data may be particularly large, resulting in a slow convergence of neural networks, long training time.

Input with a large range of <2> data can be too large in the pattern classification, and the input with small data range may be small.

<3> because the value of the activation function of the neural network output layer is limited, it is necessary to map the target data of the network training to the domain of the activation function. For example, if the output layer of the neural network uses the S-shape activation function, because the value of the S-shape function is limited to (0,1), that is, the output of the neural network can only be limited to (0,1), so the output of the training data will be normalized to the [0,1] interval.

The <4>s activation function is flat outside the (0,1) interval, and the sensitivity is too small. For example the S-shape function f (X) when the parameter a=1, F (100) and F (5) are only 0.0067. four, genetic algorithm

Using the theory of biological evolution, genetic algorithm will solve the problem of simulation into a process of biological evolution, through replication, crossover, mutation and other operations to produce the next generation of solutions, and gradually eliminate the low degree of fitness function value of the solution, increase the value of the solution of high fitness function. This evolution of n generation is likely to evolve an individual with a high degree of fitness function. For example, using a genetic algorithm to solve the "0-1 knapsack problem" idea: 0-1 the solution of the backpack can be encoded as a string of 0-1 strings (0: No, 1: take); first, randomly produce m 0-1 strings and then evaluate the merits of these 0-1 strings as a solution to the 0-1 knapsack problem; Randomly select some strings to generate the next generation of M strings by crossing, mutation, and more, and the better solution is chosen in a higher probability. After the evolution of the G generation, it is possible to produce an "approximate optimal solution" for the 0-1 knapsack problem. (Note that conversions, such as Huawei's programming questions, can also convert each point into a 0,1,0 representation, 1 delegates.) The cost of each individual is then calculated by the maximum flow of the minimum cost to solve the problem)


The difference between binary encoding and floating-point encoding is mainly the fast decoding. If an individual has multidimensional information (eye, mouth, nose, etc.), each one should have a different position on a chromosome. (That is, if the binary code, a long binary different positions represent different characteristics, difficult to distinguish.) Two uses floating-point code, as above, is separate, very easy to decode and operation)

The following reprint from Http://www.cnblogs.com/BreezeDust/p/3352090.html

4.1 Basic Ideas

Genetic algorithm is to simulate Darwin's theory of evolution, I think "survival of the fittest", just briefly elaborated the basic characteristics of the algorithm. Using the adaptive function to assess the viability of each gene, the selection of cross-variation to achieve evolution, the search for the approximate optimal solution of the population, the main steps are as follows:

1. Initialize the population

2. Adaptation options

3. Crossover Variant 4.2 algorithm Description

For a better description, here I take a 01 knapsack problem as an example to simply illustrate the genetic algorithm.

Given a backpack c=100,n=5 items, its weight and value are as follows, to find out what the maximum value of this backpack can be

177  
2  
3  
4  
5  99 90  
4.2.1 Encoding

So for the above question, first of all we have to consider the code, that is, to convert it into our genotype form, here, we use a 5-length binary string to represent the corresponding item trade-offs. Its genotype (chromosome) is 10100, then the phenotype is the choice of 1th items and 3rd items. There is encoding nature has decoding, that is, the transformation of the genotype into a phenotype, the coding of the individual is considered to be a crucial step in the genetic algorithm, how to choose the encoding method according to the problem, directly affect the following mentioned adaptation function simplification and complexity.

Mapping the problem to the genotype we have solved, now is how to assess a genotype of the current environment of fitness, in other words, is more likely to survive the inheritance, then we have to design an adaptive function f, because it is the maximum value of the backpack, and because it can not exceed the total weight of the backpack, So using H (x) to denote a second condition that does not exceed the total weight, f (Y) indicates the value of the backpack, so the adaptive function f (h (x)) is obtained. 4.2.2 Selection

Then is the question of how to choose, we use P (x) =f (y)/totall (f (Y)) to indicate the probability of a genotype as a whole, now we use the roulette method, what is roulette, here briefly, we put each probability in a roulette, and then turn this roulette, The last wheel stops, and where the pointer stops, it represents the event that chooses which probability.

For example, in the 01 backpack, we calculate the fitness of each genotype according to the adaptation function, and calculate the proportion of each genotype, then we choose the n genotype from the method of roulette, then the n genotype randomly 22 crosses to produce two offspring. 4.2.3 Crossover

So what is the crossover, and the biological chromosome crossover is the same concept, is to swap a certain section of the gene, as shown here, we are using a single point of intersection.

4.2.4 Mutation

Mutation is that, in a relatively small probability, a gene in the genetic, the gene on a gene from 0 sides into 1, or 1 into 0.

The newly generated genotype, if not in the original population, is added to the population and then iterated as described above until we find a more satisfying genotype, and now that we have everything ready, let them mate and create a race.

In fact, the basic genetic algorithm is a lot of shortcomings, such as easy to select into local convergence, the global search ability is not strong enough, but the basic genetic algorithm is a lot of improvements, such as crossover operator design, mutation operator design, selection strategy, etc. For genetic algorithms, as an intelligent heuristic search algorithm, it is even easier to understand than other common algorithms (such as dynamic programming), and it is particularly easy to combine with other algorithms, design new hybrid algorithms, and derive many other algorithms based on basic genetic algorithms, such as immune genetic algorithm, These are some of the more advanced algorithms. Five, Local search

Local search is a heuristic algorithm to solve the optimization problem. For some of the most complex optimization problems, such as various NP-complete problems, to find the optimal solution required time with the scale of the problem exponential growth, so the emergence of a variety of heuristic algorithm to go back and seek second optimal solution, is an approximate algorithm (approximate algorithms), The idea of changing the precision with time. A local search is one of these methods.

A neighborhood action is a function that, through this function, produces its corresponding neighbor solution set for the current solution S. For example, for a bool type problem, its current solution is: s = 1001, when the neighborhood action is defined as flipping one of the bits, the resulting neighbor solution's set of N (s) ={0001,1101,1011,1000}, where n (s) is ∈s. Similarly, when a neighborhood action is defined as an interchange adjacent bit, the resulting set of Neighbor solutions N (s) ={0101,1001,1010}. 5.1 Process Description

The local search algorithm starts from an initial solution, generates its neighbor solution through the neighborhood action, determines the quality of the neighbor solution, and according to a certain strategy, chooses the neighbor solution, repeats the process to reach the termination condition. The difference between the different local search algorithms is that the definition of neighborhood action and the strategy of choosing neighbor solution are also the key to determine the algorithm's good or bad (centralization and divergence, intensification and diversification). 5.2 Iterative Partial search (iteratedlocal search, ILS)

On the local optimal solution of local search, the perturbation is added and the local search is done again. The idea is: Birds of a feather, good solution will have some common, so in the local optimal solution to do perturbation, than random selection of an initial solution in the local search, the effect is better. 5.3 Variable Neighborhood Search (Variableneighborhood search, VNS)

• The main idea of the variable neighborhood search algorithm is to search the system by using several different neighborhood domains. The smallest neighborhood search is used first, and when the solution cannot be improved, it switches to a slightly larger neighborhood. If you can continue to improve the solution, return to the smallest neighborhood, or continue to the larger neighborhood.

• The characteristic of variable neighborhood search is to use the neighborhood structure of different actions to search alternately, and to achieve a good balance between centralization and evacuation.

• The idea can be summed up as "the change of the pass".

And so on, there are other local search algorithms. Vi. Summary of online good

Heuristic algorithm contains a lot of philosophy of life, although it is not a mathematical method, its thought is more similar to the human problem-solving ideas and some of the summary of the truth, is worth a good experience. Finally, we use an example of a partial search on the web to summarize:

To find the tallest mountain on Earth, a group of aspiring rabbits began to find a way.

· The rabbit is jumping to a place higher than it is now. They found the highest mountain not far away. But this mountain is not necessarily Everest. This is iterative improvement, which cannot guarantee that the local optimal value is the global optimal value.

• Rabbits are drunk. He jumped randomly for a long time. During this period, it may go high, or it may step into the ground. However, he gradually woke up and jumped in the highest direction. This is simulated annealing.

• Rabbits know that the strength of a rabbit is small. They told each other, where the mountains had been searched, and every mountain they had looked for they left a rabbit to mark. They worked out where to look for the next strategy. This is taboo search. The rabbits ate the amnesia pills and were launched into space, and then randomly landed somewhere on earth. They don't know what their mission is. But if you kill some low-altitude rabbits in a few years, the prolific rabbits will find Mt. Everest. This is the genetic algorithm.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.