let do_measurement ~time =
let config = !configuration in
Array.iteri
(fun i n ->
assert (Array.length n = 8);
let me = config.(i) in
psi_x.(i) <- float (g config.(n.(6)) me + g me config.(n.(1)))
+. 0.5 *. float ( g config.(n.(5)) me + g me config.(n.(2))
+ g config.(n.(7)) me + g me config.(n.(0)));
psi_y.(i) <- float (g config.(n.(4)) me + g me config.(n.(3)))
+. 0.5 *. float ( g config.(n.(2)) me + g me config.(n.(5))
+ g config.(n.(7)) me + g me config.(n.(0))))
neighbourhoods;
for i = 0 to pred length do
phase.(i) <- atan (psi_y.(i) /. psi_x.(i)) +. (if psi_y.(i) < 0. then pi else 0.)
done;
let phase = Array.mapi (fun i x ->
if classify_float x <> FP_nan
then x
else
let n = neighbourhoods.(i) in
mean_no_nan
[|phase.(n.(1)); phase.(n.(4)); phase.(n.(3)); phase.(n.(6));
0.5 *. phase.(n.(0)); 0.5 *. phase.(n.(2));
0.5 *. phase.(n.(5)); 0.5 *. phase.(n.(7));|])
phase in
let msd = mod_squared_distance (2. *. pi) in
Array.iteri
(fun i neighb ->
let phase_i = phase.(i) in
complexities.(i) <- mean_no_nan
[|msd phase.(neighb.(6)) phase_i; msd phase_i phase.(neighb.(1));
msd phase.(neighb.(4)) phase_i; msd phase_i phase.(neighb.(3))|]
)
neighbourhoods;
let complexity = mean_no_nan complexities in
let min_complexity = Array.fold_left min_no_nan infinity complexities in
let max_complexity = Array.fold_left max_no_nan neg_infinity complexities in
let color_of_cmplx = match User_interface.Text.Experiment_parameters.contrast_range with
| None ->
let range = max_complexity -. min_complexity in
let range = if range = 0. then 1. else range in
(function compl ->
if classify_float compl = FP_nan then Graphics.red else
Femtolib.Colors.gray ((max_complexity -. compl) /. range)
)
| Some (minc, maxc) ->
let range = maxc -. minc in
(function compl ->
if classify_float compl = FP_nan then Graphics.red else
(maxc -. compl)/.range |> max 0. |> min 1. |> Femtolib.Colors.gray) in
(fun time ->
Printf.printf "%6i %#8.3f %#8.3f %#8.3f\n%!" time min_complexity max_complexity complexity),
(fun time ->
draw_cmplx color_of_cmplx complexities time;
)