Merge /home/vsc/yap
This commit is contained in:
commit
3bfaee9226
@ -252,10 +252,11 @@ YAPStringTerm::YAPStringTerm(wchar_t *s, size_t len)
|
||||
YAPApplTerm::YAPApplTerm(YAPFunctor f, YAPTerm ts[]) {
|
||||
BACKUP_H();
|
||||
arity_t arity = ArityOfFunctor(f.f);
|
||||
Term o = Yap_MkNewApplTerm(f.f, arity);
|
||||
Term o = AbsAppl(HR);
|
||||
*HR++ = (CELL)f.f;
|
||||
Term *tt = RepAppl(o) + 1;
|
||||
for (arity_t i = 0; i < arity; i++)
|
||||
tt[i] = ts[i].term();
|
||||
*HR++ = ts[i].term();
|
||||
mk(o);
|
||||
RECOVER_H();
|
||||
}
|
||||
|
42
docker/Dockerfile
Normal file
42
docker/Dockerfile
Normal file
@ -0,0 +1,42 @@
|
||||
# Use an official Python runtime as a parent image
|
||||
FROM ubuntu:18.04
|
||||
|
||||
# Update Software repository
|
||||
RUN apt-get update
|
||||
|
||||
|
||||
# Set the working directory to /app
|
||||
WORKDIR /app
|
||||
|
||||
# Copy the current directory contents into the container at /app
|
||||
COPY . /app
|
||||
|
||||
# Install any needed packages specified in requirements.txt
|
||||
RUN apt install gcc g++ libreadline-dev libgmp-dev git \
|
||||
python3-dev python3-pip python3-notebook python3-wheel python3-setuptools\
|
||||
libgecode-dev r-cran-rcpp cmake libbdd-dev libxml2-dev \
|
||||
bison flex openjdk-11-jdk-headless libraptor2-dev swig
|
||||
|
||||
#RUN git clone ssh://vsc@ssh.dcc.fc.up.pt:31064/yap.git
|
||||
RUN git clone https://github.com/vscosta/cudd.git
|
||||
RUN git clone https://github.com/vscosta/doxygen-yap.git
|
||||
RUN git clone https://github.com/vscosta/cudd.git
|
||||
|
||||
RUN pushd cudd; ./configure --prefix=/usr --enable-shared --enable-obj --enable-dddmp; make -j install; popd
|
||||
|
||||
RUN pushd doxygen-yap; mkdir -p build; cd build; cmake .. -DCMAKE_INSTALL_PREFIX:PATH=/usr && cmake --build . --target install; popd
|
||||
|
||||
RUN pushd yap; mkdir -p build; cd build; cmake .. -DCMAKE_INSTALL_PREFIX:PATH=/usr && cmake --build . --target install; pushd paackages/real; R CMD INSTALL yap4r; popd; popd
|
||||
|
||||
RUN R CMD INSTALL packages/real/yap4r
|
||||
|
||||
# Make port 80 available to the world outside this container
|
||||
EXPOSE 80
|
||||
|
||||
# Define environment variable
|
||||
ENV NAME World
|
||||
|
||||
# Run app.py when the container launches
|
||||
CMD ["python", "app.py"]
|
||||
This Dockerfile refers to a couple of files we haven’t created yet, namely app.py and requirements.txt. Let’s create those next.
|
||||
|
@ -41,7 +41,7 @@ cvt_to_id([E0,E1],VId*true, [Id-VId]) :-
|
||||
cvt_to_id([E0,E1|Es], VId*Ids, [Id-VId|VIds]) :-
|
||||
problog:problog_dir_edge(Id,E0,E1,_Pr),
|
||||
!,
|
||||
cvt_to_id([E1|Es],Id*Ids, VIds).
|
||||
cvt_to_id([E1|Es],Ids, VIds).
|
||||
cvt_to_id([E0,E1|Es], VId*Ids, [Id-VId|VIds]) :-
|
||||
problog:problog_dir_edge(Id,E1,E0,_Pr),
|
||||
!,
|
||||
|
@ -489,7 +489,8 @@ init_learning :-
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% build BDD script for every example
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
once(init_queries),
|
||||
empty_bdd_directory,
|
||||
init_queries,
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% done
|
||||
@ -550,7 +551,7 @@ empty_bdd_directory.
|
||||
|
||||
|
||||
init_queries :-
|
||||
%empty_bdd_directory,
|
||||
empty_bdd_directory,
|
||||
format_learning(2,'Build BDDs for examples~n',[]),
|
||||
forall(user:test_example(ID,Query,_Prob,_),init_one_query(ID,Query,test)),
|
||||
forall(user:example(ID,Query,_Prob,_),init_one_query(ID,Query,training)).
|
||||
@ -584,6 +585,7 @@ init_one_query(QueryID,Query,_Type) :-
|
||||
add_bdd(QueryID,Query, Bdd) :-
|
||||
Bdd = bdd(Dir, Tree0,MapList),
|
||||
user:graph2bdd(Query,1,Bdd),
|
||||
Bdd \= [],
|
||||
!,
|
||||
reverse(Tree0,Tree),
|
||||
%rb_new(H0),
|
||||
@ -592,21 +594,12 @@ init_one_query(QueryID,Query,_Type) :-
|
||||
% ;
|
||||
% Bdd = bdd(-1,[],[]),
|
||||
% Grad=[]
|
||||
store_bdd(QueryID, Dir, Tree, MapList).
|
||||
init_one_query(_,_,_).
|
||||
store_bdd(QueryID, Dir, Tree, MapList).
|
||||
|
||||
store_bdd(QueryID, Dir, Tree, MapList) :-
|
||||
(QueryID mod 100 =:= 0 ->writeln(QueryID) ; true),
|
||||
(
|
||||
recorded(QueryID, Bdd0, R),
|
||||
arg(3, Bdd0, MapList0), variant(MapList0,MapList)
|
||||
->
|
||||
put_char('.')
|
||||
;
|
||||
(nonvar(R) -> erase(R);true),
|
||||
recorda(QueryID,bdd(Dir, Tree, MapList),_),
|
||||
put_char('.')
|
||||
).
|
||||
put_char('.').
|
||||
|
||||
|
||||
%========================================================================
|
||||
@ -786,11 +779,9 @@ inv_sigmoid(T,Slope,InvSig) :-
|
||||
|
||||
% vsc: avoid silly search
|
||||
gradient_descent :-
|
||||
problog_flag(sigmoid_slope,Slope),
|
||||
% current_iteration(Iteration),
|
||||
findall(FactID,tunable_fact(FactID,_GroundTruth),L),
|
||||
length(L,N),
|
||||
lbfgs_run(N,X,_BestF),
|
||||
lbfgs_run(N,_X,_BestF),
|
||||
mse_trainingset,
|
||||
mse_testset.
|
||||
|
||||
@ -830,8 +821,15 @@ user:evaluate(LLH_Training_Queries, X,Grad,N,_,_) :-
|
||||
%Handle = user_error,
|
||||
N1 is N-1,
|
||||
forall(between(0,N1,I),(Grad[I]<==0.0)),
|
||||
go( X,Grad, LLs),
|
||||
sum_list( LLs, LLH_Training_Queries).
|
||||
catch(
|
||||
go( X,Grad, LLs),
|
||||
Error,
|
||||
(writeln(Error), throw(Error) )),
|
||||
length(LLs,NN),
|
||||
V <== array[NN] of LLs,
|
||||
SLL <== sum(V),
|
||||
%sum_list( LLs, SLL),
|
||||
LLH_Training_Queries[0] <== SLL.
|
||||
|
||||
test :-
|
||||
S =.. [f,0-0.9,1-0.8,2-0.6,3-0.7,4-0.5,5-0.4,6-0.7,7-0.2],
|
||||
@ -845,7 +843,8 @@ Grad <== array[N] of floats,
|
||||
LL,
|
||||
compute_gradient(Grad, X, Slope,LL),
|
||||
LLs
|
||||
), sum_list( LLs, _LLH_Training_Queries).
|
||||
), sum_list( LLs, SLL).
|
||||
|
||||
|
||||
|
||||
|
||||
@ -862,8 +861,12 @@ compute_gradient( Grad, X, Slope, LL) :-
|
||||
user:example(QueryID,_Query,QueryProb,_),
|
||||
recorded(QueryID,BDD,_),
|
||||
BDD = bdd(_,_,MapList),
|
||||
MapList = [_|_],
|
||||
bind_maplist(MapList, Slope, X),
|
||||
%writeln(QueryID:MapList),
|
||||
query_probabilities( BDD, BDDProb),
|
||||
(isnan(BDDProb) -> writeln((nan::QueryID)), fail;true),
|
||||
writeln(BDDProb),
|
||||
LL is (BDDProb-QueryProb)*(BDDProb-QueryProb),
|
||||
forall(
|
||||
query_gradients(BDD,I,IProb,GradValue),
|
||||
@ -873,6 +876,7 @@ compute_gradient( Grad, X, Slope, LL) :-
|
||||
gradient_pair(BDDProb, QueryProb, Grad, GradValue, I, Prob) :-
|
||||
G0 <== Grad[I],
|
||||
GN is G0-GradValue*Prob*(1-Prob)*2*(QueryProb-BDDProb),
|
||||
(isnan(GN) -> writeln((nan::I)), fail;true),
|
||||
Grad[I] <== GN.
|
||||
|
||||
wrap( X, Grad, GradCount) :-
|
||||
|
@ -42,13 +42,14 @@ static lbfgsfloatval_t evaluate(void *instance, const lbfgsfloatval_t *x,
|
||||
const lbfgsfloatval_t step) {
|
||||
YAP_Term call;
|
||||
YAP_Bool result;
|
||||
lbfgsfloatval_t rc;
|
||||
lbfgsfloatval_t rc=0.0;
|
||||
YAP_Term v, t1, t12;
|
||||
YAP_Term t[6], t2[2];
|
||||
|
||||
t[0] = v = YAP_MkVarTerm();
|
||||
t1 = YAP_MkIntTerm((YAP_Int)x);
|
||||
t[1] = YAP_MkApplTerm(ffloats, 1, &t1);
|
||||
YAP_Term t_0 = YAP_MkIntTerm((YAP_Int)&rc);
|
||||
t[0] = YAP_MkApplTerm(ffloats, 1, &t_0);
|
||||
YAP_Term t_1 = YAP_MkIntTerm((YAP_Int)x);
|
||||
t[1] = YAP_MkApplTerm(ffloats, 1, &t_1);
|
||||
t12 = YAP_MkIntTerm((YAP_Int)g_tmp);
|
||||
t[2] = YAP_MkApplTerm(ffloats, 1, &t12);
|
||||
t[3] = YAP_MkIntTerm(n);
|
||||
@ -70,12 +71,9 @@ static lbfgsfloatval_t evaluate(void *instance, const lbfgsfloatval_t *x,
|
||||
// Goal did not succeed
|
||||
return FALSE;
|
||||
}
|
||||
YAP_Term o;
|
||||
if (YAP_IsIntTerm((o = YAP_GetFromSlot(sl))))
|
||||
rc = YAP_IntOfTerm(o);
|
||||
else
|
||||
rc = YAP_FloatOfTerm(o);
|
||||
YAP_ShutdownGoal(true);
|
||||
YAP_RecoverSlots(1, sl);
|
||||
fprintf(stderr,"%gxo\n",rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -123,9 +121,10 @@ static int progress(void *instance, const lbfgsfloatval_t *local_x,
|
||||
|
||||
if (YAP_IsIntTerm(o)) {
|
||||
int v = YAP_IntOfTerm(o);
|
||||
return (int)v;
|
||||
YAP_ShutdownGoal(true);
|
||||
return (int)v;
|
||||
}
|
||||
|
||||
YAP_ShutdownGoal(true);
|
||||
fprintf(stderr, "ERROR: The progress call back function did not return an "
|
||||
"integer as last argument\n");
|
||||
return 1;
|
||||
|
Reference in New Issue
Block a user