



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A comparative analysis of various numerical optimization algorithms, including scipy optimization, random walk, fletcher-reeves, and particle swarm optimization (pso). It details the iterative process of each algorithm, tracking the point (xb) and function value (fb) at each iteration. Insights into the convergence behavior of these algorithms, highlighting the number of iterations required to achieve convergence. Specific results, such as the optimized point and corresponding function value, are presented for each method. The document also includes initial conditions, random number generation, and updates to local and global best positions in pso. This analysis is valuable for understanding the performance and characteristics of different optimization techniques, aiding in the selection of appropriate algorithms for specific optimization problems. Useful for students and researchers in mathematics, computer science, and engineering.
Typology: Cheat Sheet
1 / 7
This page cannot be seen from the preview
Don't miss anything!




Take linear congruential generator(LCG) as an example: Let X be a sequence of pseudo-random numbers. with X 0 as a seed. Then the generator is defined as a recurrence relation:
Xn+1 = (a · Xn + b) mod m
Set a = 1664525, b = 1013904223, m = 2^32 , seed = 20 and generate 10000 pseudo-random numbers and plot the results using histogram:
Figure 1: 10000 pseudo-random numbers generated by linear congruential generator and numpy
As seen from above, it has great uniformity. The code is implemented in random number.py.
Here I use np.random.uniform(low=0, high=1, size=3) to generate 3 uniform random numbers between 0 and 1. Initially the position is at (0.5, 0.5, 0.5) and the objective function value is -0.628022. These 2 values are set as currently best (xb, fb). At each iterations, 3 uniform random numbers are generated to be the position within the unit hypercube. Then the correponding objective function value is calculated. If the new objective function value is less than fb, then (xb, fb) will be updated. The random sampling algorithm is implemented in hw2 1b.py.
Iteration Point (xb) Function Value (fb) 1
Scipy Optimization Result: [0.114589, 0.555649, 0.852547], with function value: -3.862780.
Here I define same mutation function as taught in the lecture. First generate 3 random numbers between -1 and 1 to be the random vectoru⃗ , then normalized it ˆu =u/⃗ u|⃗ |. The new point is calculated as follows: −x−→ new =^ −x−→ old +^ step^ ·^ uˆ.^ If one of the coordinate of the new point exceed either lower or upper bound, the correponding coordinate of the new point is set to the bound value. For example, if the new point is (1.2, 0.8, 0.7), x coordinate exceeds 1.0, so the new point will be (1.0, 0.8, 0.7). This critirion is the same for hill climbing and random walk. And the mutation function is called ”update” in hw2 1d.py and hw2 1e.py.
Step Iteration Point (xb) Function Value (fb)
New direction in Cauchy method is simply: S 1 = −∇(f (X))|X 0 = [− 1. 046557 , 2. 742792 , 3 .643449]. Next use direction exploitation to find optimal step along this direction. Given a maximal step λ 1 = 0.1, slice it into 100 equally spaced points and perform a complete search. The result is λ∗ 1 = 0.080808, so the new point is X 1 = X 0 + λ∗ 1 S 1 = [0. 4154300. 7216400 .794420], with correponding function value: f (X 1 ) = − 2 .750658.
Start with X 1 calculated from 2(b), first calculate −∇f (X)|X 1 = [− 0. 730195 , − 7. 537728 , 5 .682158]. So
the ratio: r = |∇f^ (X)|X^1 |
2 |∇f (X)|X 0 |^2 = 4.094360. New direction: S 2 = −∇f (X)|X 1 +r·(−∇f (X)|X 0 ) = [− 5. 015177 , 3. 692249 , 20 .599747]. Set the maximal step to be λ 1 = 0.1 and use the same direction exploitation technique to find λ∗ 2 = 0.002020. So the new point is: X 2 = X 1 + λ∗ 2 S 2 = [0. 405298 , 0. 729099 , 0 .836036], with function value: f (X 2 ) : − 2 .866772.
Step (λ∗) Iteration Point (xb) Function Value (fb)
3 Problem 3 (hw2 3.py)
10 random points are the columns of the following matrix:
The initial temperature is the mean function values of these 10 points: -1.319623.
New point: pnew.x = [0. 536213 , 0. 479619 , 0 .457870] with new function value: pnew.y = − 0 .429740. dE = pcur.y − pnew.y = − 0. 628022 − (− 0 .429740) = − 0. 198282 < 0 (Note that I changed the definition of dE since the initial temperature is negative) Although dE < 0, there’s a chance to accept it using the following procedure: Generate a uniform random number between 0 and 1: 0.805223. It is less then exp−dE/T^ = 0.860487, so this point is accepted as pcur.
Next point: pnew.x = [0. 540542 , 0. 561349 , 0 .421717] with new function value: pnew.y = − 0 .471208. dE = pcur.y − pnew.y = − 0. 429740 − (− 0 .471208) = 0. 041468 > 0. Since pnew is better then pcur, it is accepted as pcur.
Iteration Point (xb) Function Value (fb) 3
It takes 196843 iterations for the function value to converge. For the sake of curiosity, I tried another value of search range = ± 0 .01. It shows better convergence behavior:
Using 0-based indexing, 0th, 1st, 3rd, 4th, 5th, 6th, 7th and 8th particles have lower function values. So their local best positions should be updated acoordingly.
−−−−−−→ Plocalbest =
Also, 8th particle has lowest function value now, so global best position is updated as:
−−−−−−→ Pglobalbest =
With global best function value: -2.843445.
Using similar procedure, new random numbers, velocities and positions are:
r 1 , r 2 = 0. 908649 , 0. 319236
V 2 =
h− 0. 400000 0. 057913 − 0. 096924 − 0. 400000 − 0. 264264 − 0. 079686 − 0. 061658 − 0. 400000 − 0. 042134 0. 012334
i
h 0. 015046 0. 113921 0. 252266 0. 004275 0. 020281 0. 073928 0. 079168 0. 009884 0. 084843 0. 100674
i
Their function values are:
[− 2. 676097 − 2. 579238 − 1. 306032 − 2. 831252 − 2. 566089 − 2. 688510 − 2. 738507 − 2. 773287 − 2. 563926 − 2. 744254 ]
−−−−−−→ Plocalbest =
−−−−−−→ Pglobalbest =
Global best function value is: − 2 .843445.
Next set the maximum iterations = 200000. Convergence critirion: If the variance of particle positions is less than 1e − 6 for 3 coordinates, then break the while loop. Result: iterations break at 3609.
−−−−−−→ Pglobalbest =
With function value: − 3 .862313.