Diferential Evolution.m
The MATLAB script runs a Differential Evolution optimization process over a chosen objective function and displays the population on a 3D surface plot.
The script starts by clearing variables, closing figures, and clearing the command window.
Several objective functions are present, with two commented options and one active option:
- commented Griewank-like expression,
- commented Rastrigin-like expression,
- active sphere function:
f(x, y) = x^2 + y^2.
The script defines:
- lower bounds
xl, - upper bounds
xu, - number of generations
G, - population size
N, - dimensionality
D, - mutation factor
F, - crossover rate
CR.
An initial population matrix x is filled with random values inside the provided bounds.
For each generation, the script performs the following steps:
- choose random individuals,
- create a mutant vector,
- build a trial vector through crossover,
- compare the trial vector with the current individual,
- replace the current individual if the trial vector is better.
At the end of each generation, the script allocates a fitness array and then plots:
- the objective function surface,
- the current population points as 3D markers.
The script does not take external input files or command-line arguments. Its inputs are hard-coded inside the file:
- objective function choice,
- bounds,
- algorithm parameters,
- plotting domain.
The script is designed to produce:
- iterative visual output through a MATLAB figure window,
- an animated or repeatedly updated 3D surface plot,
- no saved data files or exported reports.
- Clear the environment.
- Select the objective function.
- Define bounds and Differential Evolution parameters.
- Create the initial population.
- Iterate over generations.
- Attempt mutation and crossover for each individual.
- Evaluate candidate fitness.
- Plot the surface and current population.
The following observations describe the current code as written.
| Area | Observation |
|---|---|
| Random index selection | The script uses r1, r2, and r3, but the index-generation logic does not guarantee distinct valid indices. |
| Conditional flow | The continue logic around the random indices is inverted relative to the standard Differential Evolution workflow. |
| Vector dimensions | The trial vector u is created as a row vector and later assigned to a population column, creating a dimension mismatch. |
| Fitness comparison | The replacement test does not compare the current individual x(:, i) against the corresponding trial vector in a consistent individual-by-individual form. |
| Fitness loop indexing | The fitness array is filled using i inside a loop indexed by k, producing an indexing inconsistency. |
| Optimization direction | The active objective function is a minimization problem, but the script later uses max on the fitness array. |
| Dimensional consistency | The script sets D = 3, but the active objective function and plotting logic only use two coordinates. |
| Domain consistency | Search bounds are defined in radians, while the visualization surface is drawn over a different numeric range. |
| Unused variables | counter and ind are present but not meaningfully used in the current script. |
- No root
README.mdwas present in the original repository contents. - No test files are present.
- No separate function files are present.
- No report, assignment brief, or deliverable document is present.
- No execution log or expected numerical result is present.
Useful academic example of a population-based optimization script, but not a validated implementation. The source code remains untouched, and the analysis is limited to repository understanding rather than code correction.