Commit e71ec71c authored by Sylvain Soliman's avatar Sylvain Soliman
Browse files

almost internal robustness

parent 3c26af77
......@@ -317,6 +317,46 @@ search_parameters_aux(Parameters, Conditions, Result) :-
).
% Prolog version of robustness computation for Prolog methods
robustness_aux(
ParameterList, [(Formula, [], Objective)], NSamples, _RelativeError,
VariationCoefficient
) :-
get_option(method, M),
gsl_methods(GSL),
\+ member(M, GSL),
!,
nb_setval(robustness_mean, 0),
nb_setval(robustness_ssd, 0),
store_parameters(ParameterList),
statistics(walltime, _),
(
between(1, NSamples, J),
debug(robustness, "Sample ~w~n", [J]),
normal_sample(ParameterList, VariationCoefficient),
numerical_simulation,
debug(robustness, "Satisfaction for ~w with ~w~n", [Formula, Objective]),
satisfaction_degree(Formula, Objective, Degree),
debug(robustness, "Satisfaction: ~w~n", [Degree]),
nb_getval(robustness_mean, Mean),
% nb_getval(robustness_ssd, Ssd),
Delta is min(1.0, Degree) - Mean,
NMean is Mean + Delta / J,
nb_setval(robustness_mean, NMean),
debug(robustness, "New Satisfaction mean: ~w~n", [NMean]),
% Delta2 is Degree - NMean,
% NSsd is Ssd + Delta * Delta2,
% nb_setval(robustness_ssd, NSsd),
fail
;
nb_getval(robustness_mean, Degree)
),
statistics(walltime, [_, MilliTime]),
restore_parameters,
Time is MilliTime / 1000,
format('Time: ~p s\n', [Time]),
format('Robustness degree: ~p~n', [Degree]).
robustness_aux(ParameterList, Conditions, Samples, RelativeError, Variation) :-
retractall(free_variable_index(_, _, _)),
GslCFilename = 'ode.inc',
......@@ -386,6 +426,42 @@ robustness_aux(ParameterList, Conditions, Samples, RelativeError, Variation) :-
).
:- dynamic(parameters_initial_value/2).
store_parameters(L) :-
retractall(parameters_initial_value(_, _)),
maplist(store_parameter, L).
store_parameter(K) :-
parameter_value(K, V),
!,
assertz(parameters_initial_value(K, V)).
restore_parameters :-
forall(
retract(parameters_initial_value(P, V)),
set_parameter(P, V)
).
normal_sample([], _).
normal_sample([P | L], Rho) :-
debug(robustness, "Sampling for ~w~n", [P]),
parameters_initial_value(P, P0),
normal_random(X),
Normal is sqrt(Rho * P0) * X + P0,
debug(robustness, "~w with ~w gives ~w~n", [P0, Rho, Normal]),
set_parameter(P, Normal),
normal_sample(L, Rho).
normal_random(X) :-
random(X).
generate_random_seed :-
(
toplevel:random_seed(Seed)
......
......@@ -61,4 +61,27 @@ test('robustness') :-
).
test('robustness_pl') :-
clear_model,
command('k for a => b. present(a, 10). parameter(k=0.7).'),
command('option(method: rsbk).'),
with_output_to(
atom(Result),
command('robustness(G(Time < T => a > b), [k], [T -> 5]).')
),
(
sub_atom(Result, _, _, _, 'degree: 0.9')
->
true
;
sub_atom(Result, _, _, _, 'degree: 1.0')
->
true
;
write(user_error, Result),
nl(user_error),
false
).
:- end_tests(search).
Supports Markdown
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