Skip to main content

Genetic Algorithm for Python

Project description

Genetic Machine Learning for Python

GMLP or Genetic Machine Learning for Python, is a user friendly python machine learning package. GMLP is intuitive and can be used for lots of Machine Learning Projects.

What is GMLP?

GMLP helps you with your genetic programming! You can turn 90 lines of code into 18 lines of code!


Examples

GMLP can be used for evolutionary neural networks, and genetic programming! Here are some Examples:


# GMLP Example 1. - Phrase Guesser.
# This Evolutionary Neural Network will have you put in a phrase and the E.N.N will guess it.
import random

import gmlp as gp
# Importing our modules.

# Our characters that we will be using.
characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,.?!: '

# We make our characters into a list.
characters = list(characters)

# The phrase.
phrase = "Hello World!"

# Making the phrase into numbers by using ord() so working with the phrase will be easier.
ord_phrase = [ord(target) for target in phrase]

# Having the population generate random letters and turn them into numbers using the ord() function.
starting_population = [[ord(random.choice(characters))for gene in range(len(ord_phrase))]for pop_size in range(10000)]

print("Our goal phrase is:", phrase)
# Setting up the enviroment.
env = gp.Enviroment(ord_phrase, .9)

# Our population.
population = env.generate_population(settings=starting_population)

# Our fitnesses.
scores = gp.calculate_fitness(population, env.goal)

# Our maximum number of generations.
max_generations = 500

for generation in range(max_generations):
	# Calculating the scores for the population.
	scores = gp.calculate_fitness(population, env.goal)

	# The best score is the minimum of the scores because the scores are how far you are away from your goal.
	best = min(scores)

	# getting the score index of the best score.
	best_score = scores[scores.index(best)]

	# the population organism of the best score index.
	Output = population[scores.index(best)]

	print("Generation:%1s, Best Score:%2s, Output->%3s"%(generation, str(best_score), ''.join([chr(c) for c in Output])))

	# Our new population is the mutated population of the crossover of the fittest population .
	population = gp.ValueEncodingMut(env.crossover(env.tournament_selection(population, scores, 3), ord_phrase), .15)

	# If we are 0% away from our goal we print the output and phrase and break the loop.
	if min(scores) == 0:
		print(f'Our Output -> {"".join([chr(c) for c in Output])}')
		print(f'Our Phrase -> {phrase}')
		break

Game

This Feature is new to GMLP and is still in progress


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gmlp-0.2.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gmlp-0.2-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file gmlp-0.2.tar.gz.

File metadata

  • Download URL: gmlp-0.2.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for gmlp-0.2.tar.gz
Algorithm Hash digest
SHA256 50b0db66f9c7a1c9c83f7525c92e33a4ce70e1411ca6be60ee76171962b9905d
MD5 d9a377da450920e167168bd98702e852
BLAKE2b-256 4f69d18a28861dc4aa1d80ef080c7183f6fe9cdce769db800caf646c3fa21dd4

See more details on using hashes here.

File details

Details for the file gmlp-0.2-py3-none-any.whl.

File metadata

  • Download URL: gmlp-0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for gmlp-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b291ec50d9a91ceb08ebf868926d56724bde8dc212239c36928619fd88bd50e8
MD5 d05290bea4c1ccc0fd26ce7f06a61a2a
BLAKE2b-256 8b187618b4a4a22ea192d8f8f87c9a2b9b60a8ab1cd7cac0e24a415d34a1cd52

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page