Advanced Functional Prog.
Introduction
Finally, the process has to be repeated to a full dataset of input/output and a certain time:
let sign x = if x>0.0 then 1.0 else 0.0
let remind ws xs = sign (ws <.> (1.0::xs))
let ws = [0.3;-0.5;0.1]
let xss= [[0.0;0.0];[1.0;0.0];[0.0;1.0];[1.0;1.0]]
let ys = [0.0;0.0;0.0;1.0]
let learn ws xs y =
let y1 = remind ws xs
let e = y-y1
let k = 0.01
ws <+> (List.map (fun v->v*k*e) (1.0::xs))
let rec teach xss1 ys1 ws n =
match n, xss1, ys1 with
| 0 , _ , _ -> ws (** end **)
| _ , [] , [] -> teach xss ys ws n (** restart dataset **)
| _ , xs::xss2, y::ys2 -> teach xss2 ys2 (learn ws xs y) (n-1)
let wsf = teach xss ys ws 1000
Exercices:
- Try to learn OR gate.
- By using two neurons, how to get both AND and OR gates
- Try to do a XOR gate... then try to generalize to code to 2 layers of neurons to get a correct result.
8 - 9
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp