• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Aug 20th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. let SumSquares (theta:Vector<float>) (y:Vector<float>) (trainingData:Matrix<float>) =
2.     let m = trainingData.RowCount
3.     let theta' = theta.ToRowMatrix()
4.     trainingData
5.     |> Matrix.mapRows(fun a r -> (theta' * r) - y.[a] )
6.
7. let tData = matrix [[1.0; 2.0]
8.                     [1.0; 3.0]
9.                     [1.0; 3.0]
10.                     [1.0; 4.0]]
11. let yVals = vector [5.0; 6.0; 7.0; 11.0]
12. let theta = vector [1.0; 0.2]
13.
14. let theta' = theta.ToRowMatrix()
15. (theta.ToRowMatrix() * tData.[0, 0 .. 1]) - yVals.[0]
16.
17. tData |> SumSquares theta yVals
18.
19. let SumSquares (theta:Vector<float>) (y:Vector<float>) (trainingData:Matrix<float>) =
20.     let m = trainingData.RowCount
21.     let theta' = theta.ToRowMatrix()
22.     [0..m-1] |> List.map (fun i -> (((theta' * trainingData.[i,0..1]) |> Seq.exactlyOne) - yVals.[i] ))
23.
24. tData
25.     |> Matrix.toRowSeqi
26.     |> Seq.map (fun (i,x) -> (theta' * x) - yVals.[i])
27.     |> DenseMatrix.ofRowSeq
28.
29. let square (x:Vector<float>) = x * x
30. let subtract (x:Vector<float>) (y:Vector<float>) = y - x
31. let divideBy (x:float) (y:float) = y / x
32.
33. let SumSquares (theta:Vector<float>) (y:Vector<float>) (trainingData:Matrix<float>) =
34.     let m = trainingData.RowCount |> float
35.     (trainingData * theta)
36.     |> subtract y
37.     |> square
38.     |> divideBy m
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?