ENH: cycles replaced by numpy vector operations. #725
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I asked a question about the size of arrays here.
So no one answered. After thinking a little more, I came to the conclusion that arrays are two-dimensional. Since there are no vector operations in Python lists and in a row code:
(ind.fitness.values[i] - opt_ind[i])**2
are just numbers.
Therefore, I make a pull request my changes 'convergence' functions.
Cycles replaced by numpy vector operations.
On average, the 'convergence' function speeds up by 20-30 times. In tests, I created separate functions 'convergence_old' and 'convergence_new'. The time spent on calculating each function and its value are printed. In the loop, the parameter mu=i is passed to the 'main' function. I removed part of the code because it takes a long time to wait for the whole calculation, and I just need the 'pop' pseudo array.
tests
Keep in mind that numpy calculations a little differently,
so there are differences after the decimal point after 14 sign.