February 2018
Intermediate to advanced
378 pages
10h 14m
English
This is the code that implements hypotheses for one sample input and for a matrix of inputs:
public func predict(xVec: [Double]) -> Double { if normalization { let input = xVec let differenceVec = vecSubtract(input, xMeanVec) let normalizedInputVec = vecDivide(differenceVec, xStdVec) let h = hypothesis(xVec: [1.0]+normalizedInputVec) return h } else { return hypothesis(xVec: [1.0]+xVec) } } private func hypothesis(xVec: [Double]) -> Double { var result = 0.0 vDSP_dotprD(xVec, 1, weights, 1, &result, vDSP_Length(xVec.count)) return 1.0 / (1.0 + exp(-result)) } public func predict(xMat: [[Double]]) -> [Double] { let rows = xMat.count precondition(rows > 0) let columns = xMat.first!.count precondition(columns ...Read now
Unlock full access