Genetic Algorithm output is different than manual calculation
6 visualizzazioni (ultimi 30 giorni)
below is a code to minimize a function y using genetic algorithm.
function P= decay_one(k,n)
x = 78.4000, fval = -9.9894e+05
But If i plot the same in matlab manually using below code, I get response as attached below.
In the plot the minimum value of Y seems to be somehwere btn -0.02 to -0.03, but GA minimum comes out to be fval = -9.9894e+05.
PLEASE HELP ME UNDERSTAND THE VARIATION IN MANUAL PLOT AND GA OUTPUT.
Sam Chak il 3 Apr 2023
Hi @Kalyan Dash
Look at the angular frequency of the sinusoidal component, you will see it is a high-frequency signal.
In your code, the sampling rate is very coarse t = 1:1:100;. Thus, it cannot capture all details in that spectrum.
If the step size is much smaller, then you can see the plot.
x = 99.9:0.000001:100;
y = 1000000*exp(0.000005*x).*sin(2*pi*5000*x.^2);
Più risposte (3)
Alan Weiss il 3 Apr 2023
The issue is that your objective function varies extremely quickly, with about 10000 squiggles per unit near x = 1. The exponential term does verly little except to ensure that any optimum you find is more likely to be near the upper end of your range than the lower end. Near your upper bound of 100 the function is oscillating so rapidly that you cannot plot it accurately on the scale you have chosen. Try this:
t = linspace(99,99.00001); % Equally spaced points from 99 to 99.00001
Do you see how your exponential term does nothing, and the function oscillates so rapidly that you are essentially sampling random noise?
MATLAB mathematical toolbox documentation
Walter Roberson il 3 Apr 2023
Consider sin(2*pi*5000*t): that would be a sine wave with frequency 5000 cycles per 2*pi, so with sin(2*pi*5000*t) you would expect 5000 cycles approximately every 6.3, or approximately 796 cycles per unit. But your t is 1:100 so you are sampling less than 1/796 th of the peaks per unit.
But you do not have sin(2*pi*5000*t) you have sin(2*pi*5000*t^2) . Does that increase or decrease the frequency? Clearly it increases the frequency -- by 75-ish your sine frequency is over 2 megahertz.
Where is the true minima?
Well, exp(0.000005*t) is exponential increasing in t, and sin() of real values stays in the range -1 to +1 so for any t that gives a positive S, a value of t that leads to exactly one cycle later in the sine wave would give the same sin() value but would have increasing exp(0.000005*t) (because larger t) and so would lead to a larger value of S. Likewise, for any given t that gives a positive S, there is a slightly larger value of t1 that is going to lead to the sin() being -1, and then there would be a t2 slightly larger than that which would lead to the same point on the sin() cycle but with t2>t1 then exp(0.000005*t2) > exp(0.000005*t1) and it follows that S for t2 would be more negative than the S for t1.
We thus see that no matter what minima we find for S, there is a time nearby that will give more of a minima. Therefore the true minima is arbitrarily small.
(In this case you would not say that the minima is -infinity at t = infinity because sin(infinity) is not defined.)