We can make this file beautiful and searchable if this error is corrected: It looks like row 4 should actually have 5 columns, instead of 1. in line 3.
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
5.1,3.5,1.4,0.2,Iris-setosa | |
4.9,3.0,1.4,0.2,Iris-setosa | |
4.7,3.2,1.3,0.2,Iris-setosa | |
... | |
7.0,3.2,4.7,1.4,Iris-versicolor | |
6.4,3.2,4.5,1.5,Iris-versicolor | |
6.9,3.1,4.9,1.5,Iris-versicolor | |
... | |
6.4,2.8,5.6,2.1,Iris-virginica | |
7.2,3.0,5.8,1.6,Iris-virginica |
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
class Layer { | |
let size: Int | |
let activation: Activation | |
init(size: Int, activation: Activation) { | |
self.size = size | |
self.activation = activation | |
} |
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
class Layer { | |
var A: Matrix! | |
var Z: Matrix! | |
... | |
func forward(X: Matrix) -> Matrix { | |
if activation != .none { | |
Z = weights.dot(X) + biases |
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
class Layer { | |
... | |
var dW: Matrix! | |
var db: Matrix! | |
var dZ: Matrix! | |
func backward(m: Double, y: Matrix? = nil) { | |
if let nextLayer = nextLayer, let previousLayer = previousLayer { |
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
class Layer { | |
... | |
func update(learningRate: Double) { | |
if previousLayer != nil { | |
weights = weights - (learningRate * dW) | |
biases = biases - (learningRate * db) | |
} | |
} |
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
class DeepNeuralNetwork { | |
let iterations: Int | |
let learningRate: Double | |
private var layers = [Layer]() | |
init(iterations: Int, learningRate: Double) { | |
self.iterations = iterations | |
self.learningRate = learningRate |
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
class DeepNeuralNetwork { | |
... | |
private func layersForward(X: Matrix) -> Matrix { | |
var output = X | |
for layer in layers { | |
output = layer.forward(X: output) | |
} | |
return output |
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
class DeepNeuralNetwork { | |
func fit(X: Matrix, y: Matrix) { | |
for i in 1...iterations { | |
let AL = layersForward(X: X) | |
let c = cost(yHat: AL, y: y) | |
layersBackward(y: y) | |
layersUpdate() | |
if i % 100 == 0 { |
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
Iteration: 5000 | |
Cost: 11.6211340518401 | |
Accuracy: 0.958677685950413 | |
Testing | |
Prediction: 0.0, Real: 0.0 | |
Prediction: 1.0, Real: 1.0 | |
Prediction: 0.0, Real: 0.0 | |
Prediction: 0.0, Real: 0.0 | |
Prediction: 1.0, Real: 1.0 |
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 Matswift | |
let matrix1 = Matrix(values: [[2.0, 1.0], [3.0, 1.0]]) | |
let matrix2 = Matrix(values: [[1.0, 3.0], [2.0, 4.0]]) | |
let multiplication = matrix1 * matrix2 | |
let division = matrix1 / matrix2 | |
let addition = matrix1 + matrix2 | |
let subtraction = matrix1 - matrix2 |