This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy | |
import ga | |
""" | |
The y=target is to maximize this equation ASAP: | |
y = w1x1+w2x2+w3x3+w4x4+w5x5+6wx6 | |
where (x1,x2,x3,x4,x5,x6)=(4,-2,3.5,5,-11,-4.7) | |
What are the best values for the 6 weights w1 to w6? | |
We are going to use the genetic algorithm for the best possible values after a number of generations. | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy | |
# This project is extended and a library called PyGAD is released to build the genetic algorithm. | |
# PyGAD documentation: https://pygad.readthedocs.io | |
# Install PyGAD: pip install pygad | |
# PyGAD source code at GitHub: https://github.com/ahmedfgad/GeneticAlgorithmPython | |
def cal_pop_fitness(equation_inputs, pop): | |
# Calculating the fitness value of each solution in the current population. | |
# The fitness function caulcuates the sum of products between each input and its corresponding weight. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import RPi.GPIO | |
# Initializing the GPIO pins. The numbering using is board. | |
RPi.GPIO.setmode(RPi.GPIO.BOARD) | |
# Configuring the GPIO pin number 8 to be an output pin. | |
RPi.GPIO.setup(8, RPi.GPIO.OUT) | |
print("Running Motor.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import pygame, sys | |
from pygame.locals import * | |
import pygame.camera |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import RPi.GPIO | |
import numpy | |
import os | |
import pygame.camera | |
import pygame | |
#####GPIO##### | |
# Initializing the GPIO bins. The numbering using is board. | |
RPi.GPIO.setmode(RPi.GPIO.BOARD) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def crossover(parents, img_shape, n_individuals=8): | |
new_population = numpy.empty(shape=(n_individuals, functools.reduce(operator.mul, img_shape)), dtype=numpy.uint8) | |
#Previous parents (best elements). | |
new_population[0:parents.shape[0], :] = parents | |
# Getting how many offspring to be generated. If the population size is 8 and number of parents mating is 4, then number of offspring to be generated is 4. | |
num_newly_generated = n_individuals-parents.shape[0] | |
# Getting all possible permutations of the selected parents. | |
parents_permutations = list(itertools.permutations(iterable=numpy.arange(0, parents.shape[0]), r=2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import numpy | |
import scipy.misc | |
import itertools | |
import GARI | |
""" | |
Reproduce a single image using Genetic Algorithm (GA) by evolving | |
single pixel values. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kivy.app | |
import kivy.uix.label | |
import kivy.uix.boxlayout | |
class FirstApp(kivy.app.App): | |
def build(self): | |
self.label = kivy.uix.label.Label(text="Hello Kivy") | |
self.layout = kivy.uix.boxlayout.BoxLayout() | |
self.layout.add_widget(widget=self.label) | |
return self.layout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kivy.app | |
import kivy.uix.button | |
import kivy.uix.boxlayout | |
class FirstApp(kivy.app.App): | |
def build(self): | |
self.button1 = kivy.uix.button.Button(text="Button 1") | |
self.button2 = kivy.uix.button.Button(text="Button 2") | |
self.button3 = kivy.uix.button.Button(text="Button 3") | |
self.button4 = kivy.uix.button.Button(text="Button 4") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kivy.app | |
import kivy.uix.button | |
import kivy.uix.label | |
import kivy.uix.textinput | |
import kivy.uix.boxlayout | |
import numpy | |
class TestApp(kivy.app.App): | |
def add_nums(self, btn): |
OlderNewer