Commit 95ea9a80 authored by Benoit Barbot's avatar Benoit Barbot
Browse files

fix computing lim

parent 001cf6e2
Pipeline #1682 passed with stages
in 32 seconds
......@@ -180,7 +180,7 @@ module Make (Bt: ZoneGraphInput.BoundType) (P: WeightStructure) = struct
let comp_exp target s (f,df,ddf) =
Format.printf "f: %a df: %a ddf:%a@." P.print f P.print f P.print ddf;
(*Format.printf "f: %a df: %a ddf:%a@." P.print f P.print f P.print ddf;*)
match to_float ~smp:s f ,to_float ~smp:s df, to_float ~smp:s ddf with
Some v,Some dv,Some ddv -> -. dv /. v -.target , -.ddv /. v +. dv*.dv /. (v*.v)
| _ -> failwith "fail to evaluate"
......@@ -193,18 +193,17 @@ module Make (Bt: ZoneGraphInput.BoundType) (P: WeightStructure) = struct
if dcl - cl < 0 then F.zero
else if dcl -cl = 0 then (
if ddl - dl < 0 then F.zero
else if ddl-dl = 0 then F.sub F.zero (F.div dvl vl)
else if ddl-dl = 0 then F.neg (F.div dvl vl)
else F.infinity
) else F.infinity
let comp_lim_zero_p (cl,dl,vl) (dcl,ddl,dvl) =
(* cl mal calculer *)
if dcl - cl > 0 then F.zero
else if dcl -cl = 0 then (
if ddl - dl > 0 then F.zero
else if ddl-dl = 0 then F.sub F.zero (F.div dvl vl)
else F.infinity
) else F.infinity
let v = F.neg (F.div dvl vl) in
assert (dcl = 0 && cl = 0);
if ddl - dl > 0 then F.zero
else if ddl-dl = 0 then v
else F.mul v F.infinity
let compute_s expected_duration weights rg =
let svar = var_of_int (nb_var-1) in
......@@ -230,14 +229,14 @@ module Make (Bt: ZoneGraphInput.BoundType) (P: WeightStructure) = struct
let de = taylor_exp_s dw (rg.nb_poly+1) in
let dde = taylor_exp_s ddw (rg.nb_poly+2) in
if s=0.0 then
if s=0.0 then (* when s=0 compute limit *)
let _,low_we = dominating_s we in
let _,low_dw = dominating_s de in
let lim = comp_lim_zero_p low_we low_dw in
(*Format.printf "f: %a df: %a ddf:%a@." P.print we P.print de P.print dde;
Format.printf "dominating f: %a df: %a -> %s@." print_dom low_we print_dom low_dw (F.to_string lim);*)
(P.const F.one, P.const lim, P.const F.one)
(*Format.printf "f: %a df: %a ddf:%a@." P.print we P.print de P.print dde;
Format.printf "dominating f: %a df: %a -> %s@." print_dom low_we print_dom low_dw (F.to_string lim);*)
(P.const F.one, P.const (F.neg lim), P.const F.one)
else
let w0 = apply_const ~smp:s we svar (F.of_float s) in
let d0 = apply_const ~smp:s de svar (F.of_float s) in
......@@ -248,15 +247,23 @@ module Make (Bt: ZoneGraphInput.BoundType) (P: WeightStructure) = struct
(* computing limit for s -> 0 *)
let exp0,_ = compv 0.0 in
let range = limsup,exp0 +. expected_duration, liminf in
if expected_duration > liminf || expected_duration < limsup then (
Error range
) else (
let x = Common.newton_raphson_iterate ~max_iter:100 compv (1.0) in
let v,_ = compv x in
Ok (x,range,v+. expected_duration )
)
if exp0 = Float.infinity then
let range = limsup, Float.infinity , Float.infinity in
if expected_duration < limsup then Error range
else (
let x = Common.newton_raphson_iterate ~max_iter:100 compv (1.0) in
let v,_ = compv x in
Ok (x,range,v+. expected_duration )
) else
let range = limsup,exp0 +. expected_duration, liminf in
if expected_duration >= liminf || expected_duration < limsup then (
Error range
) else (
let x = Common.newton_raphson_iterate ~max_iter:100 compv (1.0) in
let v,_ = compv x in
Ok (x,range,v+. expected_duration )
)
(* ----------------------- Sampling -----------------------------------------*)
......
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