ifix
This commit is contained in:
@@ -5,6 +5,7 @@ set (PROGRAMS
|
||||
dtproblog.yap
|
||||
aproblog.yap
|
||||
problog_learning.yap
|
||||
problog_lbfgs.yap
|
||||
problog_learning_lbdd.yap
|
||||
)
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
%xb%%% -*- Mode: Prolog; -*-
|
||||
%%% -*- Mode: Prolog; -*-
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%
|
||||
@@ -285,6 +285,7 @@ save_model:-
|
||||
%=
|
||||
%========================================================================
|
||||
|
||||
|
||||
check_examples :-
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% Check example IDs
|
||||
@@ -602,7 +603,8 @@ init_one_query(QueryID,Query,Type) :-
|
||||
->
|
||||
format_learning(3,' Reuse existing BDD ~q~n~n',[QueryID])
|
||||
;
|
||||
b_setval(problog_required_keep_ground_ids,false),
|
||||
b_setval(problog_required_keep_ground_ids,false),
|
||||
(QueryID mod 100 =:= 0 -> writeln(QueryID) ; true),
|
||||
problog_flag(init_method,(Query,N,Bdd,graph2bdd(X,Y,N,Bdd))),
|
||||
Query =.. [_,X,Y]
|
||||
->
|
||||
@@ -915,13 +917,10 @@ bind_maplist([Node-Theta|MapList], Slope, X) :-
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% start calculate gradient
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
user:evaluate(L, X0,Grad,N,_,_) :-
|
||||
user:evaluate(LLH_Training_Queries, X,Grad,N,_,_) :-
|
||||
Handle = user_error,
|
||||
problog_flag(sigmoid_slope,Slope),
|
||||
forall(between(0,N1,I),
|
||||
(V is random, X[I] <== V) %, sigmoid(X[I],Slope,Probs[I]) )
|
||||
)
|
||||
Probs = X, %<== array[N] of floats,
|
||||
Probs = X,
|
||||
N1 is N-1,
|
||||
forall(between(0,N1,I),
|
||||
(Grad[I] <== 0.0) %, sigmoid(X[I],Slope,Probs[I]) )
|
||||
@@ -931,12 +930,10 @@ user:evaluate(L, X0,Grad,N,_,_) :-
|
||||
LLs
|
||||
),
|
||||
sum_list(LLs,LLH_Training_Queries),
|
||||
forall(tunable_fact(FactID,GroundTruth), (Z<==X[FactID],W<==Grad[FactID])),
|
||||
L = LLH_Training_Queries.
|
||||
forall(tunable_fact(FactID,GroundTruth), (Z<==X[FactID],W<==Grad[FactID],writeln(FactID:(W->Z)))).
|
||||
|
||||
compute_grad(N, X, Grad, Probs, Slope, Handle, LL) :-
|
||||
user:example(QueryID,Query,QueryProb,Type),
|
||||
recorded(QueryID, BDD, _),
|
||||
BDD = bdd(Dir, GradTree, MapList),
|
||||
bind_maplist(MapList, Slope, Probs),
|
||||
qprobability(BDD,Slope,BDDProb),
|
||||
@@ -947,8 +944,8 @@ gradientpair(BDD,Slope,BDDProb, QueryProb, Grad) :-
|
||||
qgradient(BDD, Slope, FactID, GradValue),
|
||||
% writeln(FactID),
|
||||
G0 <== Grad[FactID],
|
||||
GN is G0-GradValue*(QueryProb-BDDProb),
|
||||
%writeln(FactID:(G0->GN)),
|
||||
writeln( GN is G0-GradValue*(QueryProb-BDDProb)), GN is G0-GradValue*(QueryProb-BDDProb),
|
||||
writeln(FactID:(G0->GN)),
|
||||
Grad[FactID] <== GN.
|
||||
gradientpair(_BDD,_Slope,_BDDProb, _Grad).
|
||||
|
||||
|
@@ -624,7 +624,6 @@ init_one_query(QueryID,Query,Type) :-
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% if BDD file does not exist, call ProbLog
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
writeln(QueryID),
|
||||
(
|
||||
recorded(QueryID, _, _)
|
||||
->
|
||||
@@ -659,7 +658,6 @@ init_one_query(QueryID,Query,Type) :-
|
||||
maplist_to_hash(MapList, H0, Hash),
|
||||
Tree \= [],
|
||||
%put_code(0'.),
|
||||
writeln(QueryID),
|
||||
tree_to_grad(Tree, Hash, [], Grad),
|
||||
recordz(QueryID,bdd(Dir, Grad, MapList),_)
|
||||
).
|
||||
@@ -739,7 +737,6 @@ gradient(QueryID, l, Slope) :-
|
||||
bind_maplist(MapList),
|
||||
run_sp(Tree, Slope, 1.0, Prob0),
|
||||
(Dir == 1 -> Prob0 = Prob ; Prob is 1.0-Prob0),
|
||||
%writeln(QueryID:Prob),
|
||||
assert(query_probability_intern(QueryID,Prob)),
|
||||
fail.
|
||||
gradient(_QueryID, l, _).
|
||||
|
@@ -156,10 +156,8 @@ yes
|
||||
|
||||
|
||||
/** @pred lbfgs_initialize(+N, -SolverInfo)
|
||||
The same as before, except that the user module is the default
|
||||
value.
|
||||
|
||||
Example
|
||||
Do initial memory allocation and a reference to a descriptor.
|
||||
~~~~
|
||||
lbfgs_initialize(1, Block)
|
||||
~~~~~
|
||||
@@ -169,26 +167,25 @@ lbfgs_initialize(N,X,t(N,X,U,Params)) :-
|
||||
|
||||
lbfgs_initialize(N,X,U,t(N,X,U,Params)) :-
|
||||
lbfgs_defaults(Params),
|
||||
integer(N),
|
||||
N>0,
|
||||
|
||||
% check whether there are such call back functions
|
||||
|
||||
lbfgs_grab(N,X).
|
||||
integer(N),
|
||||
N>0,
|
||||
lbfgs_grab(N,X).
|
||||
|
||||
% install call back predicates in the user module which call
|
||||
% the predicates given by the arguments
|
||||
|
||||
|
||||
/** @pred lbfgs_finalize/0
|
||||
/** @pred lbfgs_finalize(+State)
|
||||
|
||||
Clean up the memory.
|
||||
*/
|
||||
lbfgs_finalize(t(N,X,U,Params)) :-
|
||||
lbfgs_release(X) ,
|
||||
lbfgs_release_parameters(Params) .
|
||||
|
||||
/** @pred lbfgs_run/2
|
||||
Do the work.
|
||||
/** @pred lbfgs_run(+State, -FinalOutput)
|
||||
|
||||
run the algorithm. output the final score of the function being optimised
|
||||
*/
|
||||
lbfgs_run(t(N,X,U,Params),FX) :-
|
||||
lbfgs(N,X, Params, U, FX).
|
||||
|
Reference in New Issue
Block a user