Skip to content

Commit

Permalink
Minor adjustments to Flappy Bird Example project, and more documentat…
Browse files Browse the repository at this point in the history
…ion.
  • Loading branch information
Guled committed Mar 10, 2017
1 parent 9251ac7 commit dcda413
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 7 deletions.
9 changes: 5 additions & 4 deletions Example/MLKit/GameScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,12 @@ class GameScene: SKScene, SKPhysicsContactDelegate {
print("PARENT 2 FITNESS: \(parents.1.fitness)")

// Produce new flappy birds
var offspring = BiologicalProcessManager.onePointCrossover(crossOverRate: 0.5, parentOneGenotype: parents.0.genotypeRepresentation, parentTwoGenotype: parents.1.genotypeRepresentation)
var offspring = BiologicalProcessManager.onePointCrossover(crossOverRate: 0.7, parentOneGenotype: parents.0.genotypeRepresentation, parentTwoGenotype: parents.1.genotypeRepresentation)

// Mutate their genes
BiologicalProcessManager.inverseMutation(mutationRate: 0.5, genotype: &offspring.0)
BiologicalProcessManager.inverseMutation(mutationRate: 0.5, genotype: &offspring.1)
BiologicalProcessManager.swapMutation(mutationRate: 0.5, genotype: &offspring.0)
BiologicalProcessManager.swapMutation(mutationRate: 0.5, genotype: &offspring.1)


// Create a separate neural network for the birds based on their genes
let brainofOffspring1 = GeneticOperations.decode(genotype: offspring.0)
Expand Down Expand Up @@ -437,7 +438,7 @@ class GameScene: SKScene, SKPhysicsContactDelegate {
// Decision AI makes
let decision = (currentBird?.brain?.forward(input: [Float(1), Float(normalizedDistanceOfNextPipe), Float(normalizedPosToGap), Float(birdYPos)]))!

print("DEC: \(decision)")
print("FLAPPY BIRD DECISION: \(decision)")

// 0.95 was arbitrary, tweaking is recommended
if decision[0] >= Float(0.95) {
Expand Down
2 changes: 2 additions & 0 deletions MLKit/Classes/ANN/LayerProtocol.swift .swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public protocol Layer {

}


/// Protcol for Layer Printing and Debugging Methods
public protocol InputandOutputLayerMethods {

/**
Expand Down
1 change: 1 addition & 0 deletions MLKit/Classes/ANN/Learning/ActivationFunctionEnum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import Foundation


/// The ActivationFunctionType enum represents the type of activation function your NueralNet object will use.
public enum ActivationFunctionType {
case STEP // Step Function
case LINEAR // Linear Function
Expand Down
1 change: 1 addition & 0 deletions MLKit/Classes/ANN/Learning/NNOperations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Foundation

/// The NNOperations (Nueral Network Operations) class has the objective of computing activation function values and the derivative of activation functions as well.
final class NNOperations {

/**
Expand Down
1 change: 1 addition & 0 deletions MLKit/Classes/ANN/Learning/Training.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foundation
import Upsurge


/// The Training Protocol defines the methods used for training a NeuralNet Object. Note that the `train` method used in this protocol's extension is used only for Neural Network architectures such as Adaline and Perceptron. There is no backpropagation method within the Training method. The Backpropagation class utilizes the Training protocol in order to implement methods that pertain to printing/debugging values. The Backpropagation algorithm has it's own 'train' method. The way the Adaline and Perceptron architecture's perform weight updates and training are completely different from the techniques found in Backpropagation which is why I have separated them.
public protocol Training {

}
Expand Down
2 changes: 1 addition & 1 deletion MLKit/Classes/ANN/Learning/TrainingTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation


/// The TrainingType enum represents the type of neural network architecture you are using.
public enum TrainingType {
/// Perceptron Architecture
case PERCEPTRON
Expand Down
11 changes: 10 additions & 1 deletion MLKit/Classes/ANN/NeuralNet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,15 @@ open class NeuralNet {
return newNeuralNetwork
}



/**
The forward method allows a NeuralNet object to pass in inputs (corresponding to the number of input layers in your NueralNet Object) and recieve a list of output values (depends on the number of output layer neurons available).

- parameter input: An array of Float values. NOTE: Don't forget to make the first input value a '1' (this is your bias value).

- returns: A list of Float values corresponding to the output of your NeuralNet object.
*/
public func forward(input: [Float]) -> [Float] {

return forwardProcess(network: self, input:input)
Expand Down Expand Up @@ -454,7 +463,7 @@ open class NeuralNet {


/**
The trainNet method trains the Neural Network with the methods available (PERCEPTRON, ADALINE, and BACKPROPAGATION).
The trainNet method trains the Neural Network with the methods available (PERCEPTRON, ADALINE, and BACKPROPAGATION). It is advised that you use this method for supervised learning.

- parameter network: A Neural Net Object.

Expand Down
2 changes: 1 addition & 1 deletion MLKit/Classes/Genetic Algorithms/Genome.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

/// Blueprint for a Genome. It is encouraged that you create your own `generateFitness` method as there are several ways to assess fitness. You are required, on the other hand, to have a genotype representation and a fitness for every Genome.
/// Protocol for a Genome. It is encouraged that you create your own `generateFitness` method as there are several ways to assess fitness. You are required, on the other hand, to have a genotype representation and a fitness for every Genome.
public protocol Genome {

/// Genotype representation of the genome.
Expand Down

0 comments on commit dcda413

Please sign in to comment.