This commit is contained in:
Vitor Santos Costa
2019-04-04 13:27:06 +01:00
parent c04298c1d7
commit 13982dcc94
6 changed files with 49 additions and 194 deletions

View File

@@ -28,7 +28,6 @@ graph2bdd(Query,1,bdd(D,T,Vs)) :-
:- set_problog_flag(init_method,(Q,N,Bdd,user:graph2bdd(Q,N,Bdd))).
:- nb_heap(100000,Q), nb_setval(heap,Q).
%:- leash(0), spy graph2bdd.
@@ -59,8 +58,7 @@ graph(X,Y,Trie_Completed_Proofs,Vs) :-
!,
export_answer([Y|Final], Trie_Completed_Proofs,Vs).
graph(X,Y,Trie_Completed_Proofs, Vs) :-
nb_getval(heap, Q),
nb_heap_reset(Q),
nb_heap(100000,Q),
path(X,Y,X,[X],Final, 0, _Pr, Q),
!,
export_answer(Final, Trie_Completed_Proofs, Vs).

View File

@@ -263,8 +263,6 @@ user:test_example(A,B,C,=) :-
user:test_example(A,B,C),
\+ user:problog_discard_example(B).
solver_iterations(0,0).
%========================================================================
%= store the facts with the learned probabilities to a file
%========================================================================
@@ -565,19 +563,10 @@ init_one_query(QueryID,Query,_Type) :-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% if BDD file does not exist, call ProbLog
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
problog_flag(init_method,(Query,N,Bdd,user:graph2bdd(Query,N,Bdd))),
problog_flag(init_method,(Query,1,Bdd,user:graph2bdd(Query,1,Bdd))),
!,
b_setval(problog_required_keep_ground_ids,false),
Bdd = bdd(Dir, Tree0,MapList),
user:graph2bdd(Query,N,Bdd),
reverse(Tree0,Tree),
%rb_new(H0),
%maplist_to_hash(MapList, H0, Hash),
%tree_to_grad(Tree, Hash, [], Grad),
% ;
% Bdd = bdd(-1,[],[]),
% Grad=[]
store_bdd(QueryID, Dir, Tree, MapList).
add_bdd(QueryID, Query, Bdd).
init_one_query(QueryID,Query,_Type) :-
% format_learning(3,' ~q example ~q: ~q~n',[Type,QueryID,Query]),
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -592,6 +581,19 @@ init_one_query(QueryID,Query,_Type) :-
reverse(Tree0,Tree),
store_bdd(QueryID, Dir, Tree, MapList).
add_bdd(QueryID,Query, Bdd) :-
Bdd = bdd(Dir, Tree0,MapList),
user:graph2bdd(Query,1,Bdd),
!,
reverse(Tree0,Tree),
%rb_new(H0),
%maplist_to_hash(MapList, H0, Hash),
%tree_to_grad(Tree, Hash, [], Grad),
% ;
% Bdd = bdd(-1,[],[]),
% Grad=[]
store_bdd(QueryID, Dir, Tree, MapList).
init_one_query(_,_,_).
store_bdd(QueryID, Dir, Tree, MapList) :-
(QueryID mod 100 =:= 0 ->writeln(QueryID) ; true),
@@ -788,12 +790,7 @@ gradient_descent :-
% current_iteration(Iteration),
findall(FactID,tunable_fact(FactID,_GroundTruth),L),
length(L,N),
lbfgs_initialize(N,X,0,Solver),
forall(tunable_fact(FactID,_GroundTruth),
set_fact( FactID, Slope, X)
),
lbfgs_run(Solver,_BestF),
lbfgs_finalize(Solver),
lbfgs_run(N,X,_BestF),
mse_trainingset,
mse_testset.
@@ -862,7 +859,7 @@ go( X,Grad, LLs) :-
compute_gradient( Grad, X, Slope, LL) :-
user:example(QueryID,_Query,QueryProb),
user:example(QueryID,_Query,QueryProb,_),
recorded(QueryID,BDD,_),
BDD = bdd(_,_,MapList),
bind_maplist(MapList, Slope, X),