let goal_length g = let n = ref 0 in let s = ref 0. in Array.iter (function | None -> () | Some a -> incr n ; s := !s+.a*.a) g ; !s/.(float !n)