Last active
September 26, 2017 11:48
-
-
Save jknthn/495a87bca543e4ecd312be097ad90bba to your computer and use it in GitHub Desktop.
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 | |
} | |
private func layersBackward(y: Matrix) { | |
let m = Double(y.shape.columns) | |
for layer in layers.reversed() { | |
layer.backward(m: m, y: layer === layers.last ? y : nil) | |
} | |
} | |
private func layersUpdate() { | |
for layer in layers { | |
layer.update(learningRate: learningRate) | |
} | |
} | |
private func cost(yHat: Matrix, y: Matrix) -> Double { | |
let logprobs = yHat.log() * y | |
let cost = -logprobs.sum() | |
return cost | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment