Skip to content
Snippets Groups Projects
Commit 84eff242 authored by Aymeric Varasse's avatar Aymeric Varasse :innocent:
Browse files

[stdlib] Add metamorphic robust predicate.

parent 7e7ad138
No related branches found
No related tags found
No related merge requests found
...@@ -34,7 +34,7 @@ let re_aimos_output = Re__Pcre.regexp "((,\\s)(\\d+\\.\\d+))" ...@@ -34,7 +34,7 @@ let re_aimos_output = Re__Pcre.regexp "((,\\s)(\\d+\\.\\d+))"
let build_answer predicate_kind prover_result = let build_answer predicate_kind prover_result =
let threshold = let threshold =
match predicate_kind with match predicate_kind with
| Dataset.MetaRobust f -> Float.of_string (Dataset.string_of_eps f) | Dataset.MetaRobust f -> Float.of_string (Dataset.string_of_threshold f)
| _ -> failwith "Unsupported property" | _ -> failwith "Unsupported property"
in in
match prover_result.Call_provers.pr_answer with match prover_result.Call_provers.pr_answer with
......
...@@ -120,7 +120,7 @@ let theory_of_input env input = ...@@ -120,7 +120,7 @@ let theory_of_input env input =
in in
let t_eps = Dataset.term_of_eps env eps in let t_eps = Dataset.term_of_eps env eps in
Term.t_app_infer ls_robust [ t_model; t_dataset; t_eps ] Term.t_app_infer ls_robust [ t_model; t_dataset; t_eps ]
| CondRobust _ -> invalid_arg "Not yet supported property" | CondRobust _ | MetaRobust _ -> invalid_arg "Not yet supported property"
in in
let prsymbol = Decl.create_prsymbol (Ident.id_fresh "property") in let prsymbol = Decl.create_prsymbol (Ident.id_fresh "property") in
Theory.add_prop_decl th_uc Decl.Pgoal prsymbol t_property Theory.add_prop_decl th_uc Decl.Pgoal prsymbol t_property
......
...@@ -74,12 +74,14 @@ let re_group_number_of_predicate = function ...@@ -74,12 +74,14 @@ let re_group_number_of_predicate = function
| Dataset.Correct -> 2 | Dataset.Correct -> 2
| Robust _ -> 3 | Robust _ -> 3
| CondRobust _ -> 4 | CondRobust _ -> 4
| MetaRobust _ -> failwith "Unsupported metamorphic robustness predicate"
let negative_answer = function let negative_answer = function
| Dataset.Correct -> | Dataset.Correct ->
(* SAVer is complete wrt [Correct] predicate. *) (* SAVer is complete wrt [Correct] predicate. *)
Call_provers.Invalid Call_provers.Invalid
| Robust _ | CondRobust _ -> Call_provers.Unknown "" | Robust _ | CondRobust _ -> Call_provers.Unknown ""
| MetaRobust _ -> failwith "Unsupported metamorphic robustness predicate"
let build_answer predicate_kind prover_result = let build_answer predicate_kind prover_result =
match prover_result.Call_provers.pr_answer with match prover_result.Call_provers.pr_answer with
...@@ -114,6 +116,7 @@ let call_prover limit config config_prover predicate = ...@@ -114,6 +116,7 @@ let call_prover limit config config_prover predicate =
match predicate.property with match predicate.property with
| Dataset.Correct -> None | Dataset.Correct -> None
| Robust e | CondRobust e -> Some e | Robust e | CondRobust e -> Some e
| MetaRobust _ -> failwith "Unsupported metamorphic robustness predicate"
in in
build_command config_prover svm dataset eps build_command config_prover svm dataset eps
in in
......
...@@ -49,10 +49,15 @@ let term_of_eps env eps = ...@@ -49,10 +49,15 @@ let term_of_eps env eps =
let ty = Ty.ty_app (Theory.ns_find_ts th.th_export [ "t" ]) [] in let ty = Ty.ty_app (Theory.ns_find_ts th.th_export [ "t" ]) [] in
Term.t_const (real_constant_of_float eps) ty Term.t_const (real_constant_of_float eps) ty
type threshold = float [@@deriving yojson, show]
let string_of_threshold threshold = Float.to_string threshold
type property = type property =
| Correct | Correct
| Robust of eps | Robust of eps
| CondRobust of eps | CondRobust of eps
| MetaRobust of threshold
[@@deriving yojson, show] [@@deriving yojson, show]
type ('a, 'b) predicate = { type ('a, 'b) predicate = {
...@@ -65,6 +70,7 @@ let string_of_predicate_kind = function ...@@ -65,6 +70,7 @@ let string_of_predicate_kind = function
| Correct -> "correct" | Correct -> "correct"
| Robust _ -> "robust" | Robust _ -> "robust"
| CondRobust _ -> "condrobust" | CondRobust _ -> "condrobust"
| MetaRobust _ -> "meta_robust"
let find_predicate_ls env p = let find_predicate_ls env p =
let th = Pmodule.read_module env [ "caisar" ] "DatasetClassificationProps" in let th = Pmodule.read_module env [ "caisar" ] "DatasetClassificationProps" in
...@@ -95,11 +101,14 @@ let interpret_predicate env ~on_model ~on_dataset task = ...@@ -95,11 +101,14 @@ let interpret_predicate env ~on_model ~on_dataset task =
| [ { t_node = Tconst (Constant.ConstReal e); _ } ] -> | [ { t_node = Tconst (Constant.ConstReal e); _ } ] ->
let robust_predicate = find_predicate_ls env "robust" in let robust_predicate = find_predicate_ls env "robust" in
let cond_robust_predicate = find_predicate_ls env "cond_robust" in let cond_robust_predicate = find_predicate_ls env "cond_robust" in
let meta_robust_predicate = find_predicate_ls env "meta_robust" in
let f = float_of_real_constant e in let f = float_of_real_constant e in
if Term.ls_equal ls robust_predicate if Term.ls_equal ls robust_predicate
then Robust f then Robust f
else if Term.ls_equal ls cond_robust_predicate else if Term.ls_equal ls cond_robust_predicate
then CondRobust f then CondRobust f
else if Term.ls_equal ls meta_robust_predicate
then MetaRobust f
else failwith_unsupported_ls ls else failwith_unsupported_ls ls
| _ -> failwith_unsupported_term term | _ -> failwith_unsupported_term term
in in
...@@ -150,6 +159,7 @@ let add_input_decls predicate_kind ~inputs ~record th task = ...@@ -150,6 +159,7 @@ let add_input_decls predicate_kind ~inputs ~record th task =
| Correct -> None | Correct -> None
| Robust eps -> Some (string_of_eps eps) | Robust eps -> Some (string_of_eps eps)
| CondRobust _ -> failwith "Unsupported conditional robustness predicate" | CondRobust _ -> failwith "Unsupported conditional robustness predicate"
| MetaRobust _ -> failwith "Unsupported metamorphic robustness predicate"
in in
List.fold2_exn inputs features ~init:task ~f:(add_axioms ?eps th) List.fold2_exn inputs features ~init:task ~f:(add_axioms ?eps th)
......
...@@ -27,10 +27,15 @@ type eps [@@deriving yojson, show] ...@@ -27,10 +27,15 @@ type eps [@@deriving yojson, show]
val string_of_eps : eps -> string val string_of_eps : eps -> string
val term_of_eps : Env.env -> eps -> Term.term val term_of_eps : Env.env -> eps -> Term.term
type threshold [@@deriving yojson, show]
val string_of_threshold : threshold -> string
type property = private type property = private
| Correct | Correct
| Robust of eps | Robust of eps
| CondRobust of eps | CondRobust of eps
| MetaRobust of threshold
[@@deriving yojson, show] [@@deriving yojson, show]
type ('model, 'dataset) predicate = private { type ('model, 'dataset) predicate = private {
......
...@@ -68,6 +68,8 @@ theory DatasetClassificationProps ...@@ -68,6 +68,8 @@ theory DatasetClassificationProps
predicate cond_robust (m: model) (d: dataset) (eps: t) = predicate cond_robust (m: model) (d: dataset) (eps: t) =
correct m d /\ robust m d eps correct m d /\ robust m d eps
predicate meta_robust (m: model) (d: dataset) (threshold: t)
end end
theory NN theory NN
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment