Skip to content

Instantly share code, notes, and snippets.

@jknthn jknthn/nnUtils.swift
Last active Sep 26, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.