Merge ssh://ssh.dcc.fc.up.pt:31064//home/vsc/yap
This commit is contained in:
commit
337bf7b136
@ -632,7 +632,7 @@ void Yap_ThrowError__(const char *file, const char *function, int lineno,
|
|||||||
// fprintf(stderr, "warning: ");
|
// fprintf(stderr, "warning: ");
|
||||||
Yap_Error__(true, file, function, lineno, type, where, tmpbuf);
|
Yap_Error__(true, file, function, lineno, type, where, tmpbuf);
|
||||||
} else {
|
} else {
|
||||||
Yap_Error__(true, file, function, lineno, type, where);
|
Yap_Error__(true, file, function, lineno, type, where, NULL);
|
||||||
}
|
}
|
||||||
if (LOCAL_RestartEnv && !LOCAL_delay) {
|
if (LOCAL_RestartEnv && !LOCAL_delay) {
|
||||||
Yap_RestartYap(5);
|
Yap_RestartYap(5);
|
||||||
|
677
C/utilpreds.c
677
C/utilpreds.c
File diff suppressed because it is too large
Load Diff
@ -28,21 +28,20 @@
|
|||||||
:- dynamic gensym_key/2.
|
:- dynamic gensym_key/2.
|
||||||
|
|
||||||
init_gensym(Key) :-
|
init_gensym(Key) :-
|
||||||
assert(gensym_key(Atom,0) ).
|
retractall(gensym_key(Key,_)),
|
||||||
|
assert(gensym_key(Key,0) ).
|
||||||
|
|
||||||
gensym(Atom, New) :-
|
gensym(Key, New) :-
|
||||||
retract(gensym_key(Atom,Id)), !,
|
retract(gensym_key(Key,Id)), !,
|
||||||
atomic_concat(Atom,Id,New),
|
atomic_concat(Key,Id,New),
|
||||||
NId is Id+1,
|
NId is Id+1,
|
||||||
assert(gensym_key(Atom,NId)).
|
assert(gensym_key(Key,NId)).
|
||||||
gensym(Atom, New) :-
|
gensym(Atom, New) :-
|
||||||
atomic_concat(Atom,1,New),
|
atomic_concat(Atom,0,New),
|
||||||
assert(gensym_key(Atom,2)).
|
assert(gensym_key(Atom,1)).
|
||||||
|
|
||||||
reset_gensym(Atom) :-
|
reset_gensym(Atom) :-
|
||||||
retract(gensym_key(Atom,_)).
|
retract(gensym_key(Atom,_)).
|
||||||
|
|
||||||
reset_gensym :-
|
reset_gensym :-
|
||||||
retractall(gensym_key(_,_)).
|
retractall(gensym_key(_,_)).
|
||||||
|
|
||||||
|
|
||||||
|
@ -317,7 +317,7 @@ check_examples :-
|
|||||||
(user:example(ID,_,P,_), (\+ number(P); P>1 ; P<0))
|
(user:example(ID,_,P,_), (\+ number(P); P>1 ; P<0))
|
||||||
->
|
->
|
||||||
(
|
(
|
||||||
format(user_error,'The training example ~q does not have a valid probability value (~q).~n',[ID,P]),
|
format(user_error,'The trianing example ~q does not have a valid probability value (~q).~n',[ID,P]),
|
||||||
throw(error(examples))
|
throw(error(examples))
|
||||||
); true
|
); true
|
||||||
),
|
),
|
||||||
@ -422,40 +422,26 @@ do_learning_intern(Iterations,Epsilon) :-
|
|||||||
% ground_truth_difference,
|
% ground_truth_difference,
|
||||||
gradient_descent,
|
gradient_descent,
|
||||||
|
|
||||||
problog_flag(log_frequency,Log_Frequency),
|
once(save_model),
|
||||||
|
|
||||||
(
|
|
||||||
( Log_Frequency>0, 0 =:= CurrentIteration mod Log_Frequency)
|
|
||||||
->
|
|
||||||
once(save_model);
|
|
||||||
true
|
|
||||||
),
|
|
||||||
|
|
||||||
update_values,
|
update_values,
|
||||||
|
mse_trainingset,
|
||||||
(
|
(
|
||||||
last_mse(Last_MSE)
|
last_mse(Last_MSE)
|
||||||
->
|
->
|
||||||
(
|
|
||||||
retractall(last_mse(_)),
|
retractall(last_mse(_)),
|
||||||
logger_get_variable(mse_trainingset,Current_MSE),
|
logger_get_variable(mse_trainingset,Current_MSE),
|
||||||
assertz(last_mse(Current_MSE)),
|
assertz(last_mse(Current_MSE)),
|
||||||
!,
|
!,
|
||||||
MSE_Diff is abs(Last_MSE-Current_MSE)
|
MSE_Diff is abs(Last_MSE-Current_MSE)
|
||||||
); (
|
;
|
||||||
logger_get_variable(mse_trainingset,Current_MSE),
|
logger_get_variable(mse_trainingset,Current_MSE),
|
||||||
assertz(last_mse(Current_MSE)),
|
assertz(last_mse(Current_MSE)),
|
||||||
MSE_Diff is Epsilon+1
|
MSE_Diff is Epsilon+1
|
||||||
)
|
|
||||||
),
|
|
||||||
|
|
||||||
(
|
|
||||||
retractall(values_correct),
|
|
||||||
retractall(query_is_similar(_,_)),
|
|
||||||
retractall(query_md5(_,_,_)),
|
|
||||||
empty_bdd_directory,
|
|
||||||
init_queries
|
|
||||||
),
|
),
|
||||||
|
init_queries,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
!,
|
!,
|
||||||
@ -466,7 +452,8 @@ do_learning_intern(Iterations,Epsilon) :-
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
RemainingIterations is Iterations-1,
|
current_iteration(ThisCurrentIteration),
|
||||||
|
RemainingIterations is Iterations-ThisCurrentIteration,
|
||||||
|
|
||||||
(
|
(
|
||||||
MSE_Diff>Epsilon
|
MSE_Diff>Epsilon
|
||||||
@ -499,6 +486,9 @@ init_learning :-
|
|||||||
succeeds_n_times(user:example(_,_,_,_),TrainingExampleCount),
|
succeeds_n_times(user:example(_,_,_,_),TrainingExampleCount),
|
||||||
assertz(example_count(TrainingExampleCount)),
|
assertz(example_count(TrainingExampleCount)),
|
||||||
format_learning(3,'~q training examples~n',[TrainingExampleCount]),
|
format_learning(3,'~q training examples~n',[TrainingExampleCount]),
|
||||||
|
forall(tunable_fact(FactID,GroundTruth),
|
||||||
|
set_fact_probability(FactID,0.5)
|
||||||
|
),
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -709,8 +699,8 @@ mse_trainingset :-
|
|||||||
format_learning(2,'MSE_Training ',[]),
|
format_learning(2,'MSE_Training ',[]),
|
||||||
update_values,
|
update_values,
|
||||||
findall(t(LogCurrentProb,SquaredError),
|
findall(t(LogCurrentProb,SquaredError),
|
||||||
(user:training_example(QueryID,Query,TrueQueryProb,_Type),
|
(user:example(QueryID,Query,TrueQueryProb,_Type),
|
||||||
once(update_query(QueryID,'+',probability)),
|
% once(update_query(QueryID,'+',probability)),
|
||||||
query_probability(QueryID,CurrentProb),
|
query_probability(QueryID,CurrentProb),
|
||||||
format(Handle,'ex(~q,training,~q,~q,~10f,~10f).~n',[Iteration,QueryID,Query,TrueQueryProb,CurrentProb]),
|
format(Handle,'ex(~q,training,~q,~q,~10f,~10f).~n',[Iteration,QueryID,Query,TrueQueryProb,CurrentProb]),
|
||||||
|
|
||||||
@ -814,7 +804,7 @@ sigmoid(T,Slope,Sig) :-
|
|||||||
Sig <== OUT.
|
Sig <== OUT.
|
||||||
|
|
||||||
inv_sigmoid(T,Slope,InvSig) :-
|
inv_sigmoid(T,Slope,InvSig) :-
|
||||||
InvSig <== -log(1/T-1)/Slope.
|
InvSig is -log(1/T-1)/Slope.
|
||||||
|
|
||||||
|
|
||||||
%========================================================================
|
%========================================================================
|
||||||
@ -835,15 +825,30 @@ save_old_probabilities :-
|
|||||||
gradient_descent :-
|
gradient_descent :-
|
||||||
problog_flag(sigmoid_slope,Slope),
|
problog_flag(sigmoid_slope,Slope),
|
||||||
% current_iteration(Iteration),
|
% current_iteration(Iteration),
|
||||||
findall(FactID,tunable_fact(FactID,GroundTruth),L), length(L,N),
|
findall(FactID,tunable_fact(FactID,_GroundTruth),L),
|
||||||
|
length(L,N),
|
||||||
% leash(0),trace,
|
% leash(0),trace,
|
||||||
lbfgs_initialize(N,X,0,Solver),
|
lbfgs_initialize(N,X,0,Solver),
|
||||||
forall(tunable_fact(FactID,GroundTruth),
|
forall(tunable_fact(FactID,_GroundTruth),
|
||||||
(XZ is 0.0, X[FactID] <== XZ,sigmoid(XZ,Slope,Pr),set_fact_probability(FactID,Pr))),
|
set_fact( FactID, Slope, X)
|
||||||
problog_flag(sigmoid_slope,Slope),
|
),
|
||||||
lbfgs_run(Solver,_BestF),
|
lbfgs_run(Solver,_BestF),
|
||||||
lbfgs_finalize(Solver).
|
lbfgs_finalize(Solver).
|
||||||
|
|
||||||
|
set_fact(FactID, Slope, X ) :-
|
||||||
|
get_fact_probability(FactID,Pr),
|
||||||
|
(Pr > 0.99
|
||||||
|
->
|
||||||
|
NPr = 0.99
|
||||||
|
;
|
||||||
|
Pr < 0.01
|
||||||
|
->
|
||||||
|
NPr = 0.01 ;
|
||||||
|
Pr = NPr ),
|
||||||
|
inv_sigmoid(NPr, Slope, XZ),
|
||||||
|
X[FactID] <== XZ.
|
||||||
|
|
||||||
|
|
||||||
set_tunable(I,Slope,P) :-
|
set_tunable(I,Slope,P) :-
|
||||||
X <== P[I],
|
X <== P[I],
|
||||||
sigmoid(X,Slope,Pr),
|
sigmoid(X,Slope,Pr),
|
||||||
@ -866,9 +871,7 @@ user:evaluate(LLH_Training_Queries, X,Grad,N,_,_) :-
|
|||||||
full_example(QueryID,QueryProb,BDD),
|
full_example(QueryID,QueryProb,BDD),
|
||||||
compute_grad(QueryID, BDD, QueryProb,Grad, Probs, Slope,LLs)
|
compute_grad(QueryID, BDD, QueryProb,Grad, Probs, Slope,LLs)
|
||||||
),
|
),
|
||||||
LLH_Training_QueriesSum <== sum(LLs),
|
LLH_Training_Queries <== sum(LLs).
|
||||||
LLH_Training_Queries is LLH_Training_QueriesSum/TrainingExampleCount .
|
|
||||||
%wrap(X, Grad, GradCount).
|
|
||||||
|
|
||||||
full_example(QueryID,QueryProb,BDD) :-
|
full_example(QueryID,QueryProb,BDD) :-
|
||||||
user:example(QueryID,_Query,QueryProb,_),
|
user:example(QueryID,_Query,QueryProb,_),
|
||||||
@ -985,18 +988,21 @@ bind_maplist([Node-Pr|MapList], Slope, X) :-
|
|||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
% stop calculate gradient
|
% stop calculate gradient
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
user:progress(FX,X,_G,X_Norm,G_Norm,Step,_N,Iteration,Ls,0) :-
|
user:progress(FX,_X,_G,X_Norm,_G_Norm,_Step,_N,_Iteration,_Ls,-1) :-
|
||||||
|
FX < 0, !,
|
||||||
|
format('stopped on bad FX=~4f~n',[FX]).
|
||||||
|
user:progress(FX,X,_G,X_Norm,G_Norm,Step,_N,_Iteration,Ls,0) :-
|
||||||
problog_flag(sigmoid_slope,Slope),
|
problog_flag(sigmoid_slope,Slope),
|
||||||
forall(tunable_fact(FactID,_GroundTruth), set_tunable(FactID,Slope,X)),
|
forall(tunable_fact(FactID,_GroundTruth), set_tunable(FactID,Slope,X)),
|
||||||
current_iteration(CurrentIteration),
|
current_iteration(CurrentIteration),
|
||||||
retractall(current_iteration(_)),
|
retractall(current_iteration(_)),
|
||||||
NextIteration is CurrentIteration+1,
|
NextIteration is CurrentIteration+1,
|
||||||
assertz(current_iteration(NextIteration)),
|
assertz(current_iteration(NextIteration)),
|
||||||
save_model,
|
|
||||||
logger_set_variable(mse_trainingset, FX),
|
logger_set_variable(mse_trainingset, FX),
|
||||||
|
save_model,
|
||||||
X0 <== X[0], sigmoid(X0,Slope,P0),
|
X0 <== X[0], sigmoid(X0,Slope,P0),
|
||||||
X1 <== X[1], sigmoid(X1,Slope,P1),
|
X1 <== X[1], sigmoid(X1,Slope,P1),
|
||||||
format('~d. Iteration : (x0,x1)=(~4f,~4f) f(X)=~4f |X|=~4f |X\'|=~4f Step=~4f Ls=~4f~n',[Iteration,P0 ,P1,FX,X_Norm,G_Norm,Step,Ls]).
|
format('~d. Iteration : (x0,x1)=(~4f,~4f) f(X)=~4f |X|=~4f |X\'|=~4f Step=~4f Ls=~4f~n',[CurrentIteration,P0 ,P1,FX,X_Norm,G_Norm,Step,Ls]).
|
||||||
|
|
||||||
|
|
||||||
%========================================================================
|
%========================================================================
|
||||||
|
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user