From 5bf1274c7caa589c8dae1aff2c488a5926cf0f67 Mon Sep 17 00:00:00 2001
From: Johannes Middeke
Date: Wed, 4 May 2016 22:21:07 +0200
Subject: [PATCH] Cleaned up HTML/SVG generation, included a new script for
running the degree experiments.
---
commonSVG.ml | 46 +++++++++++++++++++++++++++-------------------
degrees.sh | 34 ++++++++++++++++++++++++++++++++++
makeHTML.ml | 8 ++++----
makeHTMLdegrees.ml | 44 ++++++++++++++++++++++++++++++++++++--------
test.ml | 42 ------------------------------------------
5 files changed, 101 insertions(+), 73 deletions(-)
create mode 100644 degrees.sh
diff --git a/commonSVG.ml b/commonSVG.ml
index 1e15e1d..2e79d15 100644
--- a/commonSVG.ml
+++ b/commonSVG.ml
@@ -39,8 +39,10 @@ let map_coords ?(bottom_left=(25.,25.)) ?(top_right=(425.,425.))
let (bx,by) = bottom_left
and (tx,ty) = top_right
in
- (* We need [0] mapsto [bx] and [width] mapsto [tx]; same for [y]. *)
- (bx +. x*.(tx -. bx)/.width, by +. y*.(ty -. by)/.height)
+ (* For the [x]-coordinate, we need [0] mapsto [bx] and [width]
+ mapsto [tx]; for the [y]-coordinate on the other hand, we
+ need [0] mapsto [ty] and [height] mapsto [by]. *)
+ (bx +. x*.(tx -. bx)/.width, ty +. y*.(by -. ty)/.height)
(* Format a (SVG) coordinate. *)
@@ -107,16 +109,18 @@ let axes () = Printf.printf "
+ Printf.printf "
%d
- " coord (x1,y1) coord (x2,y2) x2 (y2 +. 12.) x
+ " x1 y1 x2 y2 x2 (y2 +. 12.) x
and y_tick y =
let (x1,y1) = coords (0.,float y) and (x2,y2) = coords (-1.,float y) in
- Printf.printf "
+ Printf.printf "
%d
- " coord (x1,y1) coord (x2,y2) (x2 -. 1.) (y2 +. 5.) y
+ " x1 y1 x2 y2 (x2 -. 1.) (y2 +. 5.) y
in
for i = 1 to x/step_x do x_tick (i*step_x) done;
for i = 1 to y/step_y do y_tick (i*step_y) done
@@ -140,17 +144,21 @@ and predict3 = "#1C4D20"
let graph map_coords colour marker = function
| [] -> ()
- | x :: xs ->
- Printf.printf " Printf.printf " L%a" coord y) xs;
- Printf.printf "\" style=\"stroke:%s; fill:none;\" " colour;
- Printf.printf " marker-start=\"url(#circle-%s)\"" marker;
- Printf.printf " marker-mid=\"url(#circle-%s)\"" marker;
- Printf.printf " marker-end=\"url(#circle-%s)\" />" marker;
- let z = ExtList.last (x :: xs) in
- let (x,y) = map_coords z in
- Printf.printf " %s " marker
+ | x :: xs ->
+ let coord ff c =
+ let (x,y) = map_coords c in
+ Printf.fprintf ff "%.3f,%.3f" x y
+ in
+ Printf.printf " Printf.printf " L%a" coord y) xs;
+ Printf.printf "\" style=\"stroke:%s; fill:none;\" " colour;
+ Printf.printf " marker-start=\"url(#circle-%s)\"" marker;
+ Printf.printf " marker-mid=\"url(#circle-%s)\"" marker;
+ Printf.printf " marker-end=\"url(#circle-%s)\" />" marker;
+ let z = ExtList.last (x :: xs) in
+ let (x,y) = map_coords z in
+ Printf.printf " %s " marker
diff --git a/degrees.sh b/degrees.sh
new file mode 100644
index 0000000..249e04f
--- /dev/null
+++ b/degrees.sh
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+# N counts the number of samples generated so far. We do 20 samples in
+# each iteration and we already have 20 from the test run. Maximale
+# sample number is 300.
+
+for N in `seq 40 20 300`
+do
+ # Run experiment
+ echo > DATA.degrees.$N
+ for I in `seq 5 5 80`
+ do
+ ./test.native --degrees --size $I --times 20 \
+ >> DATA.degrees.$N
+ done
+
+ # Clean up results
+ echo 'let data = ['
+
+ cat DATA.* \
+ | sed 's/[a-z =]//g' \
+ | cut -d, -f1,3,5 \
+ | sed 's/\.$/;/' \
+ > dataDEGREES.ml
+
+ echo ']'
+
+ # Generate an deploy HTML
+ ocaml makeHTMLdegrees.ml --samples $N \
+ > Bareiss2.html
+
+ scp Bareiss*.html jmiddeke@www:/home/www/people/jmiddeke/
+done
+
diff --git a/makeHTML.ml b/makeHTML.ml
index cda0003..eded866 100644
--- a/makeHTML.ml
+++ b/makeHTML.ml
@@ -25,18 +25,18 @@ let description ~degree ~number ~ratio ~deviation = Printf.printf "
(* Putting everything together. *)
let main total predict =
- let coords = map_coords ~width:80. ~height:80. in
+ let coords = map_coords ~width:60. ~height:60. in
head "Common Factor Count" "Common Factor Count over GF(2)[x]";
defs total predict;
axes ();
- ticks coords ~x:80 ~step_x:5 ~y:80 ~step_y:5 ();
+ ticks coords ~x:50 ~step_x:5 ~y:50 ~step_y:5 ();
axes ();
mean
|> List.map (fun (n,(_,t)) -> (float n, t))
- |> svg_poly_line total "total";
+ |> graph coords total "total";
mean
|> List.map (fun (n,(p,_)) -> (float n, p))
- |> svg_poly_line predict "prediction";
+ |> graph coords predict "prediction";
description
~degree:5 ~number:300 ~ratio:mean_ratio ~deviation:deviation_ratio;
foot ()
diff --git a/makeHTMLdegrees.ml b/makeHTMLdegrees.ml
index f92b140..a480e56 100644
--- a/makeHTMLdegrees.ml
+++ b/makeHTMLdegrees.ml
@@ -1,6 +1,6 @@
-#use "common.SVG.ml";;
#use "dataDEGREES.ml";;
#use "prepareData.ml";;
+#use "commonSVG.ml";;
(* End the SVG picture and show the description of the experiment. *)
@@ -17,24 +17,52 @@ let description ~degree ~number ~ratio ~deviation = Printf.printf "
was on average %.2f%% (with a deviation of %.2f%%).
" number degree (100.*.ratio) (100.*.deviation)
+
+
(* Putting everything together. *)
-let main total predict =
- let coords = map_coords ~width:80. ~height:80. in
+let main samples total predict =
+ let coords = map_coords ~width:90. ~height:120. in
head "Common Factor Degrees" "Common Factor Degrees over GF(2)[x]";
defs total predict;
axes ();
- ticks coords ~x:80 ~step_x:5 ~y:80 ~step_y:5 ();
+ ticks coords ~x:80 ~step_x:5 ~y:110 ~step_y:10 ();
mean
|> List.map (fun (n,(_,t)) -> (float n, t))
- |> svg_poly_line total "total";
+ |> graph coords total "total";
mean
|> List.map (fun (n,(p,_)) -> (float n, p))
- |> svg_poly_line predict "prediction";
+ |> graph coords predict "prediction";
description
- ~degree:5 ~number:300 ~ratio:mean_ratio ~deviation:deviation_ratio;
+ ~degree:5 ~number:samples ~ratio:mean_ratio ~deviation:deviation_ratio;
foot ()
-let () = main total3 predict3
+
+(* *)
+
+let samples = ref 0
+let set_samples n = samples := n
+
+let degrees = ref 5
+let set_degrees n = degrees := n
+
+let argspec =
+ [ "--samples",
+ Arg.Int set_samples,
+ "Number of samples for the experiment.";
+
+ "--degrees",
+ Arg.Int set_degrees,
+ "Maximal degree of the matrix entries."]
+and anonarg s =
+ failwith ("Unknown argument " ^ s ^ ".")
+and usage =
+ Sys.executable_name ^ " --samples "
+
+
+
+let () =
+ Arg.parse argspec anonarg usage;
+ main !samples total3 predict3
diff --git a/test.ml b/test.ml
index 9099b3f..38ca6ce 100644
--- a/test.ml
+++ b/test.ml
@@ -19,26 +19,6 @@ let factorCountGF2 n =
(* Print factors and prediction: *)
Printf.printf "G := %s:\n" (M.as_maple [|g|]);
Printf.printf "W := %s:\n" (M.as_maple [|w|]);
- (* Check prediction: *)
- assert(ExtArray.map2 R.rem g w
- |> Array.map (R.eql R.nul)
- |> Array.fold_left ( && ) true);
- (* Print the results: *)
- Printf.printf "A := %s:\n" (M.as_maple a);
- Printf.printf "Pr := %s:\n" (M.as_maple p);
- Printf.printf "LL := %s:\n" (M.as_maple l);
- Printf.printf "DD := %s:\n" (M.as_maple d);
- Printf.printf "UU := %s:\n" (M.as_maple u);
- Printf.printf "Pc := %s:\n" (M.as_maple q);
- (* Check decomposition: *)
- Printf.printf "Dinv := Inverse(DD) mod 2:\n";
- Printf.printf "A - Pr.LL.Dinv.UU.Pc:\n";
- Printf.printf "simplify(%%) mod 2:\n";
- Printf.printf "if not Equal(%%, ZeroMatrix(%d,%d)) then\n" n n;
- Printf.printf " printf(\"Faulty Decomposition!\\n\"):\n";
- Printf.printf " lprint(A):\n";
- Printf.printf " `quit`(1):\n";
- Printf.printf "end if:\n";
(* Total amount of factors (leave out last row): *)
Printf.printf "map(f -> Factors(f) mod 2, G[1..-2]):\n";
Printf.printf "map(f -> map(e -> e[2], f[2]), %%):\n";
@@ -105,28 +85,6 @@ let degreesGF2 n times =
!predicted (float !predicted/.float times)
-(* This function was used for debugging purposes and will soon be
- removed. *)
-
-let testInts () =
- let b =
- ExtArray.init_matrix 15 15 (fun _ _ -> 5 - Random.int 11)
- |> ExtArray.map_matrix Integers.of_int
- in
- let (p,l,d,u,q) = N.bareiss b in
- let g = N.rowgcds u
- and w = N.prediction l
- in
-
- Printf.printf "G := %s:\n%!" (N.as_maple [|g|]);
- Printf.printf "W := %s:\n%!" (N.as_maple [|w|]);
-
- assert(ExtArray.map2 Integers.rem g w
- |> Array.map (Integers.eql Integers.nul)
- |> Array.fold_left ( && ) true);
-
- Printf.printf "A - Pr.LL.DD^(-1).UU.Pc;\n"
-
--
2.1.4