Neural Network Genetic Algorithm library used for deep learning problems
Project description
nnGA Library - Neural Network Genetic Algorithm Library (v0.0.5)
Off the shelf Genetic Algorithm library for deep learning problems
License
Our code is released under the MIT license (refer to the LICENSE file for details).
Requirements
To use the library you need atleast Python 3.6. Examples may require additional libraries.
Other required dependencies:
- NumPy
- Neptune
Usage/Examples
You can import the library by typing pip install faris-lab-train-model
.
To learn how to use neptune, check the following examples:
import neptune.new as neptune
from nnga import nnGA, GaussianInitializationStrategy, \
GaussianMutationStrategy, BasicCrossoverStrategy, \
PopulationParameters
def make_network(parameters=None):
''' Function that creates a network given a set of parameters '''
neural_network = ...
return neural_network
def fitness(idx, parameters):
''' Fitness function to evaluate a set of parameters '''
# Evaluate parameters
network = make_network(parameters)
return evaluate_network(network)
if __name__ == '__main__':
# Initialize GA parameters
network = make_initial_network()
network_structure = [list(layer.shape) for layer in network] # List of tuples, containing the shape of each layer
# Population parameters
population = PopulationParameters(population_size=200)
# Mutation strategy
mutation = GaussianMutationStrategy(network_structure, 1e-1)
# Crossover strategy
crossover = BasicCrossoverStrategy(network_structure)
# Initialization strategy
init = GaussianInitializationStrategy(
mean=0., std=1., network_structure=network_structure)
ga = nnGA(
epochs=50, # Number of epochs
fitness_function=fitness,
population_parameters=population,
mutation_strategy=mutation,
initialization_strategy=init,
crossover_strategy=crossover,
num_processors=8) # Number of cores
# Run GA with neptune
run = neptune.init(project="common/quickstarts",
api_token="ANONYMOUS",
ga)
In general the code has the following structure
from nnga import nnGA, GaussianInitializationStrategy, \
GaussianMutationStrategy, BasicCrossoverStrategy, \
PopulationParameters
def make_network(parameters=None):
''' Function that creates a network given a set of parameters '''
neural_network = ...
return neural_network
def fitness(idx, parameters):
''' Fitness function to evaluate a set of parameters '''
# Evaluate parameters
network = make_network(parameters)
return evaluate_network(network)
if __name__ == '__main__':
# Initialize GA parameters
network = make_initial_network()
network_structure = [list(layer.shape) for layer in network] # List of tuples, containing the shape of each layer
# Population parameters
population = PopulationParameters(population_size=200)
# Mutation strategy
mutation = GaussianMutationStrategy(network_structure, 1e-1)
# Crossover strategy
crossover = BasicCrossoverStrategy(network_structure)
# Initialization strategy
init = GaussianInitializationStrategy(
mean=0., std=1., network_structure=network_structure)
ga = nnGA(
epochs=50, # Number of epochs
fitness_function=fitness,
population_parameters=population,
mutation_strategy=mutation,
initialization_strategy=init,
crossover_strategy=crossover,
num_processors=8) # Number of cores
# Run GA
network_parameters, best_result, results = ga.run()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file faris-lab-train-model-0.0.10.tar.gz
.
File metadata
- Download URL: faris-lab-train-model-0.0.10.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 139b12146a9c8d79da67f364e5cba9c10a5d816b6558f9ec22c6eb4405378482 |
|
MD5 | e33844714f19cb5c70ca7ef5c2b955b8 |
|
BLAKE2b-256 | cb5dcbb16a46492821c1ebe881d7d15a8f14fea844179354efeaebe58b6bafe0 |
File details
Details for the file faris_lab_train_model-0.0.10-py3-none-any.whl
.
File metadata
- Download URL: faris_lab_train_model-0.0.10-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | adf7630d8c1ee42d7c5cfd872a64436e85752b2cd39166222018677866cf0de7 |
|
MD5 | 061e41e3e8804ef9163d0ec34056c3cc |
|
BLAKE2b-256 | 92b47c1994c9aaef1845a0df41c094ece6aa3dc9fa33284d0666a1b920c1772c |