Commit 718af3d3 authored by Benoit Barbot's avatar Benoit Barbot
Browse files

progress bug to fix

parent 7547777a
Pipeline #1672 failed with stages
in 17 seconds
...@@ -47,16 +47,17 @@ module type WeightStructure = sig ...@@ -47,16 +47,17 @@ module type WeightStructure = sig
val to_float : ?smp:float -> t -> float option val to_float : ?smp:float -> t -> float option
val apply_all : ?smp:float -> t -> float array -> float val apply_all : ?smp:float -> t -> float array -> float
val fully_apply_float : ?smp:float -> t -> var -> float -> float val fully_apply_float : ?smp:float -> t -> var -> float -> float
val taylor_exp_s: t -> int -> t
end end
type 'a transChoice = Label of 'a | Rand of float | Fixed type 'a transChoice = Label of 'a | Rand of float | Fixed
module type S = module type S =
sig sig
module P:WeightStructure module P:WeightStructure
module Bt:ZoneGraphInput.BoundType module Bt:ZoneGraphInput.BoundType
val t : P.var val t : P.var
val iterate_functionnal : val iterate_functionnal :
?update:(unit -> unit) -> ?update:(unit -> unit) ->
...@@ -103,10 +104,10 @@ sig ...@@ -103,10 +104,10 @@ sig
(float transChoice * ZoneGraph.l transChoice) array -> (float transChoice * ZoneGraph.l transChoice) array ->
samplers:(int -> float) * (int -> float) -> unit samplers:(int -> float) * (int -> float) -> unit
end end
module Make (Bt: ZoneGraphInput.BoundType) (P: WeightStructure) = struct module Make (Bt: ZoneGraphInput.BoundType) (P: WeightStructure) = struct
module P=P module P=P
module Bt=Bt module Bt=Bt
open P open P
open ZoneGraph open ZoneGraph
type bt = Bt.t type bt = Bt.t
...@@ -156,20 +157,20 @@ module Make (Bt: ZoneGraphInput.BoundType) (P: WeightStructure) = struct ...@@ -156,20 +157,20 @@ module Make (Bt: ZoneGraphInput.BoundType) (P: WeightStructure) = struct
done; done;
!stateweight,rgp !stateweight,rgp
let find_root ?smp ?factor ?max_iter ?bound p ?diffp x guess_p = let find_root ?smp ?factor ?max_iter ?bound p ?diffp x guess_p =
(*let p2 = match smp with (*let p2 = match smp with
None -> p None -> p
| Some s -> apply_const ?smp p (P.var_of_int (P.nb_var-1)) (F.of_float s) in | Some s -> apply_const ?smp p (P.var_of_int (P.nb_var-1)) (F.of_float s) in
Format.eprintf "finding root for %a @." P.print p; *) Format.eprintf "finding root for %a @." P.print p; *)
let pp = match diffp with let pp = match diffp with
None -> diff p x None -> diff p x
| Some pp -> pp in | Some pp -> pp in
let f v = let f v =
let f0 = fully_apply_float ?smp p x v let f0 = fully_apply_float ?smp p x v
and f1 = fully_apply_float ?smp pp x v in and f1 = fully_apply_float ?smp pp x v in
(f0,f1) in (f0,f1) in
try newton_raphson_iterate ?factor ?max_iter ?bound f guess_p with try newton_raphson_iterate ?factor ?max_iter ?bound f guess_p with
| Common.Not_converging (r,v) -> | Common.Not_converging (r,v) ->
Format.eprintf "Alert Not converging %a --> %g -> %g@." P.print p r v; Format.eprintf "Alert Not converging %a --> %g -> %g@." P.print p r v;
r r
...@@ -261,7 +262,7 @@ module Make (Bt: ZoneGraphInput.BoundType) (P: WeightStructure) = struct ...@@ -261,7 +262,7 @@ module Make (Bt: ZoneGraphInput.BoundType) (P: WeightStructure) = struct
List.filter (fun tr -> List.filter (fun tr ->
let low = Bt.eval_max_bound (id,tab) tr.lower_bound let low = Bt.eval_max_bound (id,tab) tr.lower_bound
and up = Bt.eval_min_bound (id,tab) tr.upper_bound in low <= up) l and up = Bt.eval_min_bound (id,tab) tr.upper_bound in low <= up) l
else l in else l in
match filter with match filter with
None -> l2 None -> l2
| Some ff -> | Some ff ->
......
...@@ -25,9 +25,10 @@ module type WeightStructure = ...@@ -25,9 +25,10 @@ module type WeightStructure =
val to_float : ?smp:float -> t -> float option val to_float : ?smp:float -> t -> float option
val apply_all : ?smp:float -> t -> float array -> float val apply_all : ?smp:float -> t -> float array -> float
val fully_apply_float : ?smp:float -> t -> var -> float -> float val fully_apply_float : ?smp:float -> t -> var -> float -> float
val taylor_exp_s: t -> int -> t
end end
type 'a transChoice = Label of 'a | Rand of float | Fixed type 'a transChoice = Label of 'a | Rand of float | Fixed
module type S = module type S =
sig sig
module P:WeightStructure module P:WeightStructure
...@@ -54,7 +55,7 @@ sig ...@@ -54,7 +55,7 @@ sig
val eval_poly_state_full : ?smp:float -> state -> P.t -> float val eval_poly_state_full : ?smp:float -> state -> P.t -> float
val elapse_time : state -> float -> state val elapse_time : state -> float -> state
val fire : state -> ('b,Bt.t) ZoneGraph.transition -> state val fire : state -> ('b,Bt.t) ZoneGraph.transition -> state
val sample_time : ?smp:float -> val sample_time : ?smp:float ->
?max_iter:int -> ?max_iter:int ->
int -> int ->
state -> (P.t,Bt.t) ZoneGraph.transition -> float -> float state -> (P.t,Bt.t) ZoneGraph.transition -> float -> float
...@@ -78,5 +79,5 @@ sig ...@@ -78,5 +79,5 @@ sig
(float transChoice * ZoneGraph.l transChoice) array -> (float transChoice * ZoneGraph.l transChoice) array ->
samplers:(int -> float) * (int -> float) -> unit samplers:(int -> float) * (int -> float) -> unit
end end
module Make (Bt : ZoneGraphInput.BoundType) (P : WeightStructure) : S with type P.t = P.t and type P.var=P.var and type Bt.t=Bt.t and type Bt.state=Bt.state module Make (Bt : ZoneGraphInput.BoundType) (P : WeightStructure) : S with type P.t = P.t and type P.var=P.var and type Bt.t=Bt.t and type Bt.state=Bt.state
...@@ -67,6 +67,7 @@ module type S = sig ...@@ -67,6 +67,7 @@ module type S = sig
val of_bound : bound -> t val of_bound : bound -> t
val map_var : t -> (var -> var) -> t val map_var : t -> (var -> var) -> t
val elapse_time : t -> var -> t val elapse_time : t -> var -> t
val taylor_exp_s: t -> int -> t
end end
let iter_fun n f x = let iter_fun n f x =
...@@ -370,6 +371,10 @@ module Make (F: Fl.FSIG)(K:sig val var_string:VarSet.varset end) = struct ...@@ -370,6 +371,10 @@ module Make (F: Fl.FSIG)(K:sig val var_string:VarSet.varset end) = struct
cip := ci cip := ci
done; done;
!ptilde !ptilde
let taylor_exp_s p _ = p
end end
(* (*
......
...@@ -62,6 +62,7 @@ module type S = sig ...@@ -62,6 +62,7 @@ module type S = sig
val of_bound : Common.bound -> t val of_bound : Common.bound -> t
val map_var : t -> (var -> var) -> t val map_var : t -> (var -> var) -> t
val elapse_time : t -> var -> t val elapse_time : t -> var -> t
val taylor_exp_s: t -> int -> t
end end
module Make : module Make :
......
...@@ -74,10 +74,10 @@ let _ = ...@@ -74,10 +74,10 @@ let _ =
| _,Some b -> b.ZoneGraph.var_string | _,Some b -> b.ZoneGraph.var_string
| None,None -> assert false end) in | None,None -> assert false end) in
(* either P or exp-polynomials *) (* either P or exp-polynomials *)
(* If exact computation or no s parameter given s is symbolic, otherwise it is inlined during computation *) (* If exact computation or no s parameter given s is symbolic, otherwise it is inlined during computation *)
let module Weight = (val if !frequency = None && !expected_duration = None then (module P:Semantic.WeightStructure) let module Weight = (val if !frequency = None && !expected_duration = None then (module P:Semantic.WeightStructure)
else (module ExpPoly.Make(P)(struct else (module ExpPoly.Make(P)(struct
let smp = if P.F.is_exact then None let smp = if P.F.is_exact then None
else !frequency else !frequency
let tvar = P.var_of_int 0 let tvar = P.var_of_int 0
let svar= P.var_of_int (P.nb_var-1) let svar= P.var_of_int (P.nb_var-1)
...@@ -115,7 +115,7 @@ let _ = ...@@ -115,7 +115,7 @@ let _ =
(* Compute s from expected_duration *) (* Compute s from expected_duration *)
let smp = match !expected_duration with let smp = match !expected_duration with
None -> !frequency None -> !frequency
| Some target -> | Some target ->
if !verbose>0 then ( if !verbose>0 then (
printf "Computing laplace parameters s : %g -> " target; flush stdout; printf "Computing laplace parameters s : %g -> " target; flush stdout;
print_flush (); print_flush ();
...@@ -125,6 +125,18 @@ let _ = ...@@ -125,6 +125,18 @@ let _ =
let dw = Weight.diff w svar in let dw = Weight.diff w svar in
let ddw = Weight.diff dw svar in let ddw = Weight.diff dw svar in
let compv s = let compv s =
if s=0.0 then
let svar = P.var_of_int (P.nb_var-1) in
let we = Weight.taylor_exp_s w (!npoly) in
(*Format.printf "vte: %a@." P.print we;*)
let de = Weight.taylor_exp_s dw (!npoly+1) in
Format.printf "vte: %a@." P.print de;
let w0 = P.apply we svar (P.const P.F.zero) in
let d0 = P.apply de svar (P.const P.F.zero) in
match P.to_float w0,P.to_float d0 with
Some v1,Some v2 -> v1,v2
| _ -> failwith "fail to evaluate"
else
match Weight.to_float ~smp:s w ,Weight.to_float ~smp:s dw, Weight.to_float ~smp:s ddw with match Weight.to_float ~smp:s w ,Weight.to_float ~smp:s dw, Weight.to_float ~smp:s ddw with
Some v,Some dv,Some ddv -> -. dv /. v -.target , -.ddv /. v +. dv*.dv /. (v*.v) Some v,Some dv,Some ddv -> -. dv /. v -.target , -.ddv /. v +. dv*.dv /. (v*.v)
| _ -> failwith "fail to evaluate" in | _ -> failwith "fail to evaluate" 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