Skip to main content

Neural Networks optimization with Genetic Algorithms

Based on the BSc thesis by

  • Author: Luis Liñán Villafranca

  • Mentor: Juan Julián Merelo Guervós



Installation

The first prerequisite is to have Python 3.6, 3.7 or 3.8 and pip installed on the system. It is recommended to create a virtual environment to isolate the used package versions. For more information about pip and venv check the official tutorial.

If you are using pyenv, remember to compile your version with the –enable-shared configuration option:

First, you need to install a version of python that’s been compiled with -fPIC. pyenv versions by default are not, so you will need to issue something like this:

env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 3.8.6

Virtual environment creation

We can use a core module to create the virtual environment, it’s been working since version 3.3

python -m venv .venv

Please make sure when you do this that all __pycache__ directories have been deleted; otherwise, it might fail in some unexpected place.

This will create a virtual environment in the .venv directory. Once that’s been done, we need to activate it; use one of the following commands (depending on the interpreter) (obtained from the official venv documentation):

Platform

Shell

Command to activate virtual environment

POSIX

bash/zsh

$ source <venv>/bin/activate

fish

$ . <venv>/bin/activate.fish

csh/tcsh

$ source <venv>/bin/activate.csh

PowerShell Core

$ <venv>/bin/Activate.ps1

Windows

cmd.exe

C:\> <venv>\Scripts\activate.bat

PowerShell

PS C:\> <venv>\Scripts\Activate.ps1

Table 1.1: Activating the virtual environment.

You won’t need to create the virtual environment in the case you’re using global installation of modules via version managers such as pyenv.

Installing the DeepGProp CLI

To run DeepGProp first we need to install its cli. You can install it with pip:

pip install -U DeepGProp

Or downloading the repository with:

pip install .

On the other hand, if we want the code to be updated as we change it, we will need to install DeepGProp in editable mode. To do this, we need to add the option -e/--editable to the installation command:

pip install -e .

All the available options can be listed using:

dgp --help

Extra modules

I’ve divided all the used packages in different groups to avoid installing undesirable ones for specific use of the repository:

Purpose

File path

Description

Test

requirements/tests.txt

Necessary packages for tests. Nox installs them automaticly when running the tests.

Lint

requirements/lint.txt

Necessary packages for linting. Nox installs them automaticly when linting the code.

Format

requirements/format.txt

Necessary packages for formatting. Nox installs them automaticly when running format command.

Dev

requirements/dev.txt

All above packages.

To install any of these packages you can run:

pip install -r <file path>

If you are not using any virtual environment, make sure you install these packages so that they are available in the required Python version.

Tutorials

Tests and formatting

First, we need to install the Nox tool:

pip install -U nox

To run all the tests:

nox -k test

To run the linters:

nox -k lint

You can check all the possible sessions with the following command:

nox -l

Frameworks

  • Keras - base library to create and run the neural networks.

  • DEAP - genetic algorithms library used to optimize the models hyper parametters.

Utilities

  • Automation:

    • Nox - automation tool to run different tasks as the tests or the code formatting check.

  • Tests:

    • pytest - Python test framework to run the tests.

Datasets

All datasets need to have a first row with the column names, and one of the columns needs to be named class. For the time being, it’s prepared to run only classification problems.

Licence

The original code can be found in the DeepGProp repo under GPLv3 License.

Release files for DeepGProp 1.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for DeepGProp 1.0.8
File Size Uploaded
DeepGProp-1.0.8.tar.gz 581.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for DeepGProp 1.0.8
File Interpreter ABI Platform
DeepGProp-1.0.8-py3-none-any.whl Python 3 none any Details

Total release size: 1.2 MB

Release files / DeepGProp-1.0.8.tar.gz

Download URL DeepGProp-1.0.8.tar.gz
Size 581.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d1bfd76419354664a2400942700e5bd8ae19ea36dd791b64c3fcac2afcb2468c
BLAKE2b-256 checksum
How to use checksums
768a465047770dc62f4f6e7906da091e43355fe30f4041fdbc24c53eaf2e7904
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.9

Release files / DeepGProp-1.0.8-py3-none-any.whl

Download URL DeepGProp-1.0.8-py3-none-any.whl
Size 633.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6791dbd20cf03f4a33691ee6e794f8c2355908fc71d2220e7b55eb6e593e05d5
BLAKE2b-256 checksum
How to use checksums
0d11a2978b903dd27e8b552edd98481896f062b2f47858c3e9b92a2e65d9f15c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.9

Release history Release notifications | RSS feed

This release

1.0.8 This release

2 release files

1.0.7

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page