Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let SumSquares (theta:Vector<float>) (y:Vector<float>) (trainingData:Matrix<float>) =
- let m = trainingData.RowCount
- let theta' = theta.ToRowMatrix()
- trainingData
- |> Matrix.mapRows(fun a r -> (theta' * r) - y.[a] )
- let tData = matrix [[1.0; 2.0]
- [1.0; 3.0]
- [1.0; 3.0]
- [1.0; 4.0]]
- let yVals = vector [5.0; 6.0; 7.0; 11.0]
- let theta = vector [1.0; 0.2]
- let theta' = theta.ToRowMatrix()
- (theta.ToRowMatrix() * tData.[0, 0 .. 1]) - yVals.[0]
- tData |> SumSquares theta yVals
- let SumSquares (theta:Vector<float>) (y:Vector<float>) (trainingData:Matrix<float>) =
- let m = trainingData.RowCount
- let theta' = theta.ToRowMatrix()
- [0..m-1] |> List.map (fun i -> (((theta' * trainingData.[i,0..1]) |> Seq.exactlyOne) - yVals.[i] ))
- tData
- |> Matrix.toRowSeqi
- |> Seq.map (fun (i,x) -> (theta' * x) - yVals.[i])
- |> DenseMatrix.ofRowSeq
- let square (x:Vector<float>) = x * x
- let subtract (x:Vector<float>) (y:Vector<float>) = y - x
- let divideBy (x:float) (y:float) = y / x
- let SumSquares (theta:Vector<float>) (y:Vector<float>) (trainingData:Matrix<float>) =
- let m = trainingData.RowCount |> float
- (trainingData * theta)
- |> subtract y
- |> square
- |> divideBy m
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement