Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

ICEIT'20 Cython for Speeding-up Genetic Algorithm

The presentation of the paper titled "Cython for Speeding-up Genetic Algorithm". Find it at IEEE Explore:
The abstract of the paper:
This paper proposes a library for implementing the genetic algorithm using Python mainly in NumPy and speeding-up its execution using Cython. The preliminary Python implementation is inspected for possible optimizations. The 4 main changes include statically defining data types for the NumPy arrays, specifying the data type of the array elements in addition to the number of dimensions, using indexing for looping through the arrays, and finally disabling some unnecessary features in Cython. Using Cython, the NumPy array processing is 1250 times faster than CPython. The Cythonized version of the genetic algorithm is 18 times faster than the Python version.

  • Be the first to comment

  • Be the first to like this

ICEIT'20 Cython for Speeding-up Genetic Algorithm

  1. 1. Cython for Speeding-up Genetic Algorithm Ahmed Fawzy Gad Fatima Ezzahra Jarmouni ICEIT’20, Rabat, Morocco
  2. 2. Python ▰ Python is the most popular programming language used at this era. ▰ According to the Python Developers Survey conducted in 2018 by the co-operation between Python Software Foundation and JetBrains, out of over 20,000 developers, 84% use Python as their primary language. 2 Cross-Platform Fast Prototyping using Scripting Mode Easy to Learn
  3. 3. Python for Data Science ▰ Python is regarded the best tool for building data science applications. ▰ Many tools are found in Python: TensorFlow, Keras, Scikit-Learn, Scikit- Image, Pandas, NumPy, and more. ▰ Despite having many algorithms implemented in Python, there is no official implementation for the genetic algorithm (GA). ▰ This paper proposes: 1. An open source project for implementing GA. 2. Using Cython for enhancing performance. 3
  4. 4. Genetic Algorithm Overview ▰ The genetic algorithm is an optimization technique that is based on Dawin’s theory survival of the fittest. ▰ Given a vector X and a function F, what is the best value for X to optimize a function F(x)? This question is answered using the genetic algorithm. 4Ahmed Fawzy Gad. Practical computer vision applications using deep learning with CNNs. Apress, 2018.
  5. 5. Open Source Project ▰ The open source project is available at GitHub and received 127 stars: ▰ The project has a primary Python module named for holding the implementation of the genetic algorithm. ▰ The functions within the module are: 1. cal_pop_fitness: Calculating the fitness value. 2. select_mating_pool: Selecting the mating pool. 3. crossover: Applying crossover. 4. mutation: Applying mutation. 5
  6. 6. Example ▰ Given a function 𝐲 = 𝟒𝒘 𝟏 − 𝟐𝒘 𝟐 + 𝟑. 𝟓𝒘 𝟑 + 𝟓𝒘 𝟒 − 𝟏𝟏𝒘 𝟓 − 𝟒. 𝟕𝒘 𝟔, what are the best parameters 𝒘 𝟏 to 𝒘 𝟔? 6
  7. 7. How to Speed-up the Process? ▰ For optimizing a problem, the genetic algorithm might take hundreds of thousands of generations. Thus, the execution should be fast as possible. ▰ Is Python fast? ▰ Using Python, the code is interpreted each time it is executed. It slows down the process. ▰ Using Cython, the code is executed at C speed and compiled only once. 7
  8. 8. Genetic Algorithm using Cython ▰ Cython is a superset of Python and thus the Python code is already a Cython code without any changes. So, we do not have to rewrite the code again. ▰ To convert the Cython code into C code, here are the steps: 1. Write the code into .pyx file not .py 2. Convert the .pyx file into C file according to the following code. 8▰ The Cython version of the GA is 18 times faster than Python.
  9. 9. Conclusion ▰ This paper proposed an open source project for implementing the genetic algorithm in Python. ▰ Using Cython, the implementation is 18 times faster. 9
  10. 10. For More Information ▰ Computer-Vision-Applications- Learning/dp/1484241665 10 ▰ ▰ jarmouni-341a6b167
  11. 11. 11 THANKS