Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let rec gradientDescent epsilon learningRate h (x : float array array) (y : _ array) (theta : _ array) prevError =
- let delta j =
- Array.sum [| for i in 0..(x.Length - 1) -> (h theta x.[i] - y.[i]) * (if j <> 0 then x.[i].[j - 1] else 1.) |]
- let m = theta.Length
- let newTheta = [| for j in 0..(m - 1) -> theta.[j] - (learningRate / (float m)) * (delta j) |]
- let error = Array.sum <| Array.map2 (fun (x : float) y -> (x - y) ** 2.) newTheta theta
- printfn "%f" error
- if prevError - error < epsilon then newTheta else gradientDescent epsilon learningRate h x y newTheta error
Add Comment
Please, Sign In to add comment