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. *)
let ticks coords ~x ~step_x ~y ~step_y () =
let x_tick x =
let (x1,y1) = coords (float x,0.) and (x2,y2) = coords (float x,-1.) in
- Printf.printf "<path d=\"M%a L%a\" stroke-width=\"1\" />
+ Printf.printf "<path d=\"M%.2f,%.2f L%.2f,%.2f\"
+ stroke-width=\"1\" stroke=\"black\"/>
<text x=\"%.2f\" y=\"%.2f\" style=\"font-size:12px\" text-anchor=\"middle\">
%d
- </text>" coord (x1,y1) coord (x2,y2) x2 (y2 +. 12.) x
+ </text>" 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 "<path d=\"M%a L%a\" stroke-width=\"1\" />
+ Printf.printf "<path d=\"M%.2f,%.2f L%.2f,%.2f\"
+ stroke-width=\"1\" stroke=\"black\"/>
<text x=\"%.2f\" y=\"%.2f\" style=\"font-size:12px\" text-anchor=\"end\">
%d
- </text>" coord (x1,y1) coord (x2,y2) (x2 -. 1.) (y2 +. 5.) y
+ </text>" 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
let graph map_coords colour marker = function
| [] -> ()
- | x :: xs ->
- Printf.printf "<path d=\"M%a" coord x;
- List.iter (fun y -> 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 "<text x=\"%.2f\" y=\"%.2f\" " (x +. 5.) (y +. 3.);
- Printf.printf "fill=\"%s\" " colour;
- Printf.printf "style=\"font-size:14px\" ";
- Printf.printf "text-anchor=\"start\"> %s </text>" marker
+ | x :: xs ->
+ let coord ff c =
+ let (x,y) = map_coords c in
+ Printf.fprintf ff "%.3f,%.3f" x y
+ in
+ Printf.printf "<path d=\"M%a" coord x;
+ List.iter (fun y -> 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 "<text x=\"%.2f\" y=\"%.2f\" " (x +. 5.) (y +. 3.);
+ Printf.printf "fill=\"%s\" " colour;
+ Printf.printf "style=\"font-size:14px\" ";
+ Printf.printf "text-anchor=\"start\"> %s </text>" marker
--- /dev/null
+#!/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
+
(* 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)[<i>x</i>]";
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 ()
-#use "common.SVG.ml";;
#use "dataDEGREES.ml";;
#use "prepareData.ml";;
+#use "commonSVG.ml";;
(* End the SVG picture and show the description of the experiment. *)
was on average %.2f%% (with a deviation of %.2f%%).
</p>" 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)[<i>x</i>]";
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 <INT>"
+
+
+
+let () =
+ Arg.parse argspec anonarg usage;
+ main !samples total3 predict3
(* 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";
!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"
-