Commit 6b5d255d authored by Benoit Barbot's avatar Benoit Barbot
Browse files

finis time -expectancy

parent cc105e8d
Pipeline #1677 failed with stages
in 42 seconds
......@@ -26,6 +26,7 @@ module type WeightStructure = sig
type t
type fl = F.t
type var
val desc : string
val var_string : VarSet.varset
val nb_var : int
val zero_var : var
......@@ -48,7 +49,8 @@ module type WeightStructure = sig
val apply_all : ?smp:float -> t -> float array -> float
val fully_apply_float : ?smp:float -> t -> var -> float -> float
val taylor_exp_s: t -> int -> t
val dominating_s : t -> (int * t) * (int * t)
val dominating_s : t -> (int * int* F.t) * (int * int* F.t)
end
type 'a transChoice = Label of 'a | Rand of float | Fixed
......
......@@ -4,6 +4,7 @@ module type WeightStructure =
type t
type fl = F.t
type var
val desc : string
val var_string : Common.VarSet.varset
val nb_var : int
val zero_var : var
......@@ -26,7 +27,7 @@ module type WeightStructure =
val apply_all : ?smp:float -> t -> float array -> float
val fully_apply_float : ?smp:float -> t -> var -> float -> float
val taylor_exp_s: t -> int -> t
val dominating_s : t -> (int * t) * (int * t)
val dominating_s : t -> (int * int* F.t) * (int * int* F.t)
end
type 'a transChoice = Label of 'a | Rand of float | Fixed
......
......@@ -51,7 +51,6 @@ module VarSet = struct
type varset = (string*bool) array
let var_of_int x =x
let int_of_var x =x
let zero_var = -1
end
......
......@@ -28,6 +28,7 @@ module type S = sig
type var = P.var
type t = P.t * (P.t array)
type fl = F.t
val desc : string
val var_string : (string*bool) array
val nb_var : int
val zero_var : int
......@@ -67,6 +68,10 @@ module Make (P:Polynome.S) (Param:sig val smp:float option val tvar:P.var val sv
let zero_var = P.zero_var
let iter_on_var = P.iter_on_var
let desc = match Param.smp with
None -> "ExpPoly; s formal"
| Some s -> Printf.sprintf "ExpPoly; s=%g inlined" s
type var = P.var
let int_of_var = P.int_of_var
let var_of_int = P.var_of_int
......@@ -248,7 +253,7 @@ module Make (P:Polynome.S) (Param:sig val smp:float option val tvar:P.var val sv
let dominating_s ep =
match Poly.choose_opt ep with
| None -> (0,zero),(0,zero)
| None -> (0,0,F.zero),(0,0,F.zero)
| Some ((Const ct),vt) ->
let (cl,vl),(ch,vh) = Poly.fold (fun k v (((cl,vl),(ch,vh)) as acc) -> match k with
| Const c when c < cl -> ((c,v),(ch,vh))
......@@ -256,7 +261,9 @@ module Make (P:Polynome.S) (Param:sig val smp:float option val tvar:P.var val sv
| Const _ -> acc
| _ -> assert false) ep
((ct,vt),(ct,vt)) in
(cl,Poly.singleton (Const 0) vl),(ch, Poly.singleton (Const 0) vh)
let _,(_,dl,vlf) = P.dominating_s vl in
let (_,dh,vhf), _ = P.dominating_s vh in
(cl, dl, vlf),(ch, dh, vhf)
| _ -> assert false
......
......@@ -30,6 +30,7 @@ module type S = sig
type fl = F.t
type ftp
type var = VarSet.var
val desc : string
val var_string : VarSet.varset
val nb_var : int
val fold_monome : ((var -> int) -> fl -> 'a -> 'a) -> t -> 'a -> 'a
......@@ -68,7 +69,7 @@ module type S = sig
val map_var : t -> (var -> var) -> t
val elapse_time : t -> var -> t
val taylor_exp_s: t -> int -> t
val dominating_s: t -> (int * t) * (int * t)
val dominating_s: t -> (int *int * F.t) * (int * int* F.t)
end
let iter_fun n f x =
......@@ -86,6 +87,9 @@ module Make (F: Fl.FSIG)(K:sig val var_string:VarSet.varset end) = struct
type t = fl Poly.t
type ftp = float Poly.t
(*let var_string = [|"t"; "x"; "y"; "z"; "x_1"; "x_2";"x_3";"x_4";"x_5";"x_6";"x_7"|]*)
let desc = "Poly; no s"
let nb_var = Array.length var_string
let degree_monome m =
......@@ -375,7 +379,17 @@ module Make (F: Fl.FSIG)(K:sig val var_string:VarSet.varset end) = struct
let taylor_exp_s p _ = p
let dominating_s p = ((0,p),(0,p))
let dominating_s p =
let svar = nb_var -1 in
match Poly.choose_opt p with
| None -> (0,0, F.zero),(0,0,F.zero)
| Some (a,vt) ->
let (cl,vl),(ch,vh) = Poly.fold (fun k v (((cl,vl),(ch,vh)) as acc) -> match k.(svar) with
| c when c < cl -> ((c,v),(ch,vh))
| c when c > ch -> ((cl,vl),(c,v))
| _ -> acc) p
((a.(svar),vt),(a.(svar),vt)) in
(0,cl,vl),(0,ch, vh)
end
......
......@@ -27,6 +27,7 @@ module type S = sig
type ftp
type fl = F.t
type var=Common.VarSet.var
val desc : string
val var_string : Common.VarSet.varset
val nb_var : int
val fold_monome : ((var -> int) -> fl -> 'a -> 'a) -> t -> 'a -> 'a
......@@ -63,7 +64,7 @@ module type S = sig
val map_var : t -> (var -> var) -> t
val elapse_time : t -> var -> t
val taylor_exp_s: t -> int -> t
val dominating_s : t -> (int * t) * (int * t)
val dominating_s : t -> (int * int* F.t) * (int * int* F.t)
end
module Make :
......
......@@ -92,7 +92,10 @@ let _ =
| Some rg,_,_ -> rg
| _, Some rg, true ->
if !verbose>0 then (
printf "Computing Distribution -> %i: [" !npoly; flush stdout;
printf "Computing Distribution[%s; %s] -> %i: ["
(if Weight.F.is_exact then "exact rational" else "floating point")
Weight.desc
!npoly; flush stdout;
print_flush ()
);
let rgp = FunIt.iterate_functionnal ~update:(fun () ->printf "|"; print_flush ())
......@@ -118,28 +121,38 @@ let _ =
Some v,Some dv,Some ddv -> -. dv /. v -.target , -.ddv /. v +. dv*.dv /. (v*.v)
| _ -> failwith "fail to evaluate" in
let comp_lim (cl,dl,vl) (dcl,ddl,dvl) =
if dcl - cl < 0 then Weight.F.zero
else if dcl -cl = 0 then (
if ddl - dl < 0 then Weight.F.zero
else if ddl-dl = 0 then Weight.F.sub Weight.F.zero (Weight.F.div dvl vl)
else Weight.F.infinity
) else Weight.F.infinity in
(* Compute s from expected_duration *)
let smp = match !expected_duration with
None -> !frequency
| Some target ->
if !verbose>0 then (
printf "Computing laplace parameters s : target %g@." target; flush stdout;
printf "Computing laplace parameter s for E[T]=%g " target; flush stdout;
print_flush ();
);
let w = weights.(rgpoly.init) in
let svar = Weight.var_of_int (Weight.nb_var-1) in
(* Weight in initial location *)
let w = weights.(rgpoly.init) in
let dw = Weight.diff w svar in
let ddw = Weight.diff dw svar in
let (cl,vl),(ch,vh) = Weight.dominating_s w in
printf "Computing bound %a -> %i:%a ; %i %a @." Weight.print w cl Weight.print vl ch Weight.print vh;
let (cl,vl),(ch,vh) = Weight.dominating_s dw in
printf "Computing bound %a -> %i:%a ; %i %a @." Weight.print w cl Weight.print vl ch Weight.print vh;
(* computing limit for s -> -infty and s -> + infty *)
let low_w,high_w = Weight.dominating_s w in
let low_dw,high_dw = Weight.dominating_s dw in
let liminf = Weight.F.to_float @@ comp_lim low_w low_dw in
let limsup = Weight.F.to_float @@ comp_lim high_w high_dw in
let compv s =
(*Format.printf "test s: %g@." s;*)
let calc =
(* When s close to 0 use a taylor expansion to compute the duration*)
if abs_float s <= 0.1 then
let svar = Weight.var_of_int (P.nb_var-1) in
let we = Weight.taylor_exp_s w (!npoly) in
......@@ -153,14 +166,20 @@ let _ =
else w,dw,ddw in
comp_exp target s calc in
(* computing limit for s -> 0 *)
let exp0,_ = compv 0.0 in
let expinf,_ = compv 1e30 in
let mexpinf,_ = compv (-100.0) in
if !verbose>0 then printf "Expected time range: [%g; %g; %g]@." (expinf+.target) (exp0+.target) (mexpinf+.target);
if !verbose>0 then (
printf "range:[%g; %g; %g] " limsup (exp0+.target) liminf;
print_flush ()
);
if target > liminf || target < limsup then (
printf "@.Target outside range, aborting@.";
exit 1
);
let x = Common.newton_raphson_iterate ~max_iter:100 compv (1.0) in
let v,_ = compv x in
if !verbose>0 then printf "%g achieved %g [%.2fs]@." x (v+.target) (check_time ());
if !verbose>0 then printf "-> s=%g;E[T]=%g [%.2fs]@." x (v+.target) (check_time ());
Some x
in
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment