From 7666a005dc7cbcf3e1fbfac0b15cfcf13ca091fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Wed, 10 Oct 2018 13:47:47 +0100 Subject: [PATCH 1/4] missing file --- include/YapInit.h | 133 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 include/YapInit.h diff --git a/include/YapInit.h b/include/YapInit.h new file mode 100644 index 000000000..de631e71a --- /dev/null +++ b/include/YapInit.h @@ -0,0 +1,133 @@ +#ifndef YAPINIT_H +#define YAPINIT_H 1 + +#define YAP_BOOT_FROM_SAVED_CODE 1 +#define YAP_BOOT_FROM_SAVED_STACKS 2 +#define YAP_BOOT_ERROR -1 + +#define YAP_CONSULT_MODE 0 +#define YAP_RECONSULT_MODE 1 +#define YAP_BOOT_MODE 2 + +X_API YAP_file_type_t Yap_InitDefaults(void *init_args, char saved_state[], + int Argc, char *Argv[]); + +typedef struct yap_boot_params { + //> boot type as suggested by the user + YAP_file_type_t boot_file_type; + //> how files are organised: NULL is GNU/Linux way + // const char *directory_structure; + //> if NON-NULL, set value for Yap_ROOTDIR + const char *ROOTDIR; + //> if NON-NULL, location of yaap, sets Yap_BINDIR + const char *BINDIR; + //> if NON-NULL, location of libYap, sets Yap_LIBDIR + const char *LIBDIR; + //> if NON-NULL, architecture independent files, sets Yap_SHAREDIR + const char *SHAREDIR; + //> if NON-NULL, include files, sets Yap_INCLUDEDIR + const char *INCLUDEDIR; + //> if NON-NULL, Prolog DLL location, sets Yap_DLLDIR + const char *DLLDIR; + //> if NON-NULL, Prolog library, sets Yap_DLLDIR + const char *PLDIR; + //> if NON-NULL, Prolog library, sets Yap_COMMONSDIR + const char *COMMONSDIR; + //> if NON-NULL, name for a Prolog file to use when booting at run-time + const char *BOOTFILE; + //> if NON-NULL, name for a Prolog file to use when booting at compile-time + const char *BOOTSTRAP; + //> if NON-NULL, path where we can find the saved state + const char *INPUT_STARTUP; + //> bootstrapping mode: YAP is not properly installed + bool install; + //> jupyter mode: YAP is in space + bool jupyter; + //> generats a saved space at this path + const char *OUTPUT_STARTUP; + //> if NON-0, minimal size for Heap or Code Area + size_t HeapSize; + //> if NON-0, maximal size for Heap or Code Area + size_t MaxHeapSize; + //> if NON-0, minimal size for Local+Global Stack + size_t StackSize; + //> if NON-0, maximal size for Local+Global Stack +size_t MaxStackSize; + //*> deprecated + size_t MaxGlobalSize; + //> if NON-0, minimal size for Trail + size_t TrailSize; + //> if NON-0, maximal size for Trail + size_t MaxTrailSize; + //> if NON-0, minimal size for AttributeVarStack + size_t AttsSize; + //> if NON-0, maximal size for AttributeVarStack + size_t MaxAttsSize; + //> if NON-NULL, name for a Prolog file to use when initializing + const char *YapPrologInitGoal; + //> if NON-NULL, name for a Prolog file to consult before entering top-level + const char *PrologRCFile; + //> if NON-NULL, a goal to run before top-level + const char *PrologGoal; + //> if NON-NULL, a goal to run as top-level + const char *PrologTopLevelGoal; + //> if NON-NULL, a path to extend file-search-path + const char *PrologAddPath; + //> if previous NON-NULL and TRUE, halt after consulting that file + bool HaltAfterBoot; + //> ignore .yaprc, .prolog.ini, etc. files. + bool FastBoot; + //> the next field only interest YAPTAB + //> if NON-0, maximum size for Table Space + size_t MaxTableSpaceSize; + /* the next three fields only interest YAPOR, but we keep them so that + users don't need to recompile DLL in order to use YAPOR */ + //> if NON-0, number of workers we want to have (default=1) + unsigned long int NumberWorkers; + //> if NON-0, manage the inner scheduler loop (default = 10) + unsigned long int SchedulerLoop; + //> if NON-0, say how long to keep nodes (default = 3) + unsigned long int DelayedReleaseLoad; + //> end of YAPOR fields + /* whether Prolog should handle interrupts. Note that + interrupts will always be disabled in embedded mode. */ + bool PrologCannotHandleInterrupts; + //> flag for JIT mode + int ExecutionMode; + //> number of arguments that Prolog will see + int Argc; + //> array of arguments as seen by Prolog + char **Argv; + //> embedded in some other system: no signals, readline, etc + bool Embedded; + //> QuietMode + int QuietMode; + //> 0, maintain default, > 0 use fd-1, < 0 close + int inp, out, err; +#if __ANDROID__ + //> android asset support + AAssetManager *assetManager; +#endif +/* support nf's ypp preprocessor code */ +#define YAP_MAX_YPP_DEFS 100 + char *def_var[YAP_MAX_YPP_DEFS]; + char *def_value[YAP_MAX_YPP_DEFS]; + int def_c; + /* End preprocessor code */ + +#ifdef MYDDAS_MYSQL + //> If any myddas option was given + short myddas; + //> MYDDAS Fields + char *myddas_user; + char *myddas_pass; + char *myddas_db; + char *myddas_host; +#endif + /* errornumber */ + int ErrorNo; + //> errorstring + char *ErrorCause; +} YAP_init_args; + +#endif From 6096c6407a9a1b551cb8cb25900295b36db9ca38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Wed, 10 Oct 2018 19:20:32 +0100 Subject: [PATCH 2/4] fix bad patch --- pl/preds.yap | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pl/preds.yap b/pl/preds.yap index b417a8448..bd7e00245 100644 --- a/pl/preds.yap +++ b/pl/preds.yap @@ -596,9 +596,9 @@ Defines the relation: _P_ is a currently defined predicate whose name is the at */ current_predicate(A,T0) :- '$yap_strip_module'(T0, M, T), - ( var(Mod) + ( var(M) -> - '$all_current_modules'(Mod) + '$all_current_modules'(M) ; true ), From 67cc23725f4d0cf7f0ca88c95ed72621762f9db9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Thu, 11 Oct 2018 07:47:28 +0100 Subject: [PATCH 3/4] verbose vs verbosity --- C/flags.c | 9 +++++++-- C/yap-args.c | 6 +++--- H/YapFlags.h | 6 ++++-- H/YapGFlagInfo.h | 4 ++-- library/maplist.yap | 2 +- packages/ProbLog/problog_lbfgs.yap | 4 ++-- pl/consult.yap | 6 +++--- pl/debug.yap | 4 ++-- pl/messages.yap | 2 +- pl/preds.yap | 1 - pl/qly.yap | 20 +++++++++++--------- 11 files changed, 36 insertions(+), 28 deletions(-) diff --git a/C/flags.c b/C/flags.c index 61f29f6e5..158671cf1 100644 --- a/C/flags.c +++ b/C/flags.c @@ -1207,8 +1207,9 @@ Term Yap_UnknownFlag(Term mod) { Term getYapFlag(Term tflag) { FlagEntry *fv; - flag_term *tarr; - if (IsVarTerm(tflag)) { + flag_term *tarr; + tflag = Deref(tflag); + if (IsVarTerm(tflag)) { Yap_Error(INSTANTIATION_ERROR, tflag, "yap_flag/2"); return (FALSE); } @@ -1234,6 +1235,10 @@ Term getYapFlag(Term tflag) { Yap_Error(TYPE_ERROR_ATOM, tflag, "yap_flag/2"); return (FALSE); } + if (tflag == TermSilent) + { + Yap_DebugPlWriteln(TermSilent); + } fv = GetFlagProp(AtomOfTerm(tflag)); if (!fv) { Term fl = GLOBAL_Flags[USER_FLAGS_FLAG].at; diff --git a/C/yap-args.c b/C/yap-args.c index 78c30e4ba..6e196d16e 100755 --- a/C/yap-args.c +++ b/C/yap-args.c @@ -1052,13 +1052,13 @@ X_API void YAP_Init(YAP_init_args *yap_init) { MkAtomTerm(Yap_LookupAtom(Yap_BOOTFILE))); setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, false); } else { + if (yap_init->QuietMode) { + setVerbosity(TermSilent); + } Yap_Restore(Yap_INPUT_STARTUP); init_globals(yap_init); start_modules(); - if (yap_init->QuietMode) { - setVerbosity(TermSilent); - } if (yap_init->install && Yap_OUTPUT_STARTUP) { setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG, MkAtomTerm(Yap_LookupAtom(Yap_INPUT_STARTUP))); diff --git a/H/YapFlags.h b/H/YapFlags.h index 0a81832c6..a3232f22c 100644 --- a/H/YapFlags.h +++ b/H/YapFlags.h @@ -357,6 +357,8 @@ static inline bool verboseMode(void) { static inline void setVerbosity(Term val) { GLOBAL_Flags[VERBOSE_FLAG].at = val; + if (val == TermSilent) + GLOBAL_Flags[VERBOSE_LOAD_FLAG].at = TermFalse; } static inline bool setSyntaxErrorsFlag(Term val) { @@ -418,12 +420,12 @@ extern xarg *Yap_ArgListToVector__(const char *file, const char *function, int #define Yap_ArgListToVector(l, def, n, e) \ Yap_ArgListToVector__(__FILE__, __FUNCTION__, __LINE__, l, def, n, e) - + extern xarg *Yap_ArgList2ToVector__(const char *file, const char *function, int lineno, Term listl, const param2_t *def, int n, yap_error_number e); #define Yap_ArgList2ToVector(l, def, n, e) \ Yap_ArgList2ToVector__(__FILE__, __FUNCTION__, __LINE__, l, def, n, e) - + #endif // YAP_FLAGS_H /// @} diff --git a/H/YapGFlagInfo.h b/H/YapGFlagInfo.h index 8a35204b3..3e9ba6246 100644 --- a/H/YapGFlagInfo.h +++ b/H/YapGFlagInfo.h @@ -579,12 +579,12 @@ and if it is bound to `off` disable them. The default for YAP is is `false` by default except if YAP is booted with the `-L` flag. */ - YAP_FLAG(VERBOSE_LOAD_FLAG, "verbose_load", true, isatom, "normal", NULL), + YAP_FLAG(VERBOSE_LOAD_FLAG, "verbose_load", true, booleanFlag, "true", NULL), /**< `verbose_load ` If `true` allow printing of informational messages when consulting files. If `false` disable printing these messages. It - is `normal` by default except if YAP is booted with the `-L` + is `true` by default except if YAP is booted with the `-L` flag. */ YAP_FLAG(VERSION_FLAG, "version", false, nat, YAP_NUMERIC_VERSION, NULL), diff --git a/library/maplist.yap b/library/maplist.yap index a6f7bd999..22741f480 100644 --- a/library/maplist.yap +++ b/library/maplist.yap @@ -65,7 +65,7 @@ sumnodes_body(3,+,+,-,+,+), include(1,+,-), exclude(1,+,-), - partition(2,+,-,-), + partition(1,+,-,-), partition(2,+,-,-,-), foldl(3, +, +, -), foldl2(5, +, +, -, +, -), diff --git a/packages/ProbLog/problog_lbfgs.yap b/packages/ProbLog/problog_lbfgs.yap index e18049a1d..ec79506a6 100644 --- a/packages/ProbLog/problog_lbfgs.yap +++ b/packages/ProbLog/problog_lbfgs.yap @@ -826,17 +826,17 @@ gradient_descent :- format(Handle,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%~n",[]), format(Handle,"% Iteration, train/test, QueryID, Query, GroundTruth, Prediction %~n",[]), format(Handle,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%~n",[]), - format_learning(2,'Gradient ',[]), findall(FactID,tunable_fact(FactID,GroundTruth),L), length(L,N), % leash(0),trace, lbfgs_initialize(N,X,0,Solver), forall(tunable_fact(FactID,GroundTruth), (XZ is 0.5, X[FactID] <== XZ,set_fact_probability(FactID,XZ))), problog_flag(sigmoid_slope,Slope), - lbfgs_set_parameter(min_step, Solver, 0.0), + lbfgs_set_parameter(min_step, 0.0, Solver), lbfgs_run(Solver,BestF), format('~2nOptimization done~nWe found a minimum ~4f.~n',[BestF]), forall(tunable_fact(FactID,GroundTruth), set_tunable(FactID,X)), + set_problog_flag(mse_trainset, BestF), lbfgs_finalize(Solver). set_tunable(I,P) :- diff --git a/pl/consult.yap b/pl/consult.yap index 2e607535d..d50a531c0 100644 --- a/pl/consult.yap +++ b/pl/consult.yap @@ -411,8 +411,8 @@ load_files(Files0,Opts) :- Val == large -> true ; '$do_error'(domain_error(unknown_option,qcompile(Val)),Call) ). '$process_lf_opt'(silent, Val, Call) :- - ( Val == false -> yap_flag(verbose_load, full) ; - Val == true -> yap_flag(verbose_load, silent) ; + ( Val == false -> yap_flag(verbose_load, true) ; + Val == true -> yap_flag(verbose_load, false) ; '$do_error'(domain_error(out_of_domain_option,silent(Val)),Call) ). '$process_lf_opt'(skip_unix_header, Val, Call) :- ( Val == false -> true ; @@ -925,7 +925,7 @@ nb_setval('$if_le1vel',0). '$init_win_graphics', fail. '$do_startup_reconsult'(X) :- - catch(load_files(user:X, [silent(false)]), Error, '$LoopError'(Error, consult)), + catch(load_files(user:X, [silent(true)]), Error, '$LoopError'(Error, consult)), !, ( current_prolog_flag(halt_after_consult, false) -> true ; halt). '$do_startup_reconsult'(_). diff --git a/pl/debug.yap b/pl/debug.yap index 501fdc93f..d7ae2575f 100644 --- a/pl/debug.yap +++ b/pl/debug.yap @@ -603,13 +603,13 @@ be lost. % - redo resets the goal % - fail gives up on the goal. '$re_trace_query'(abort, _G, _Module, _GoalNumber, _H) :- - !, + !, abort. '$re_trace_query'(forward(fail,G0), _G, __Module, GoalNumber, _H) :- GoalNumber =< G0, !, fail. - '$re_trace_query'(forward(redo,G0), G, M, GoalNumber, H) :- +'$re_trace_query'(forward(redo,G0), G, M, GoalNumber, H) :- GoalNumber > G0, !, catch( diff --git a/pl/messages.yap b/pl/messages.yap index 0fd0f8fec..91835c752 100644 --- a/pl/messages.yap +++ b/pl/messages.yap @@ -1009,7 +1009,7 @@ prolog:print_message(Severity, Msg) :- ), !. prolog:print_message(Level, _Msg) :- - current_prolog_flag(verbose_load, silent), + current_prolog_flag(verbose_load, false), stream_property(_Stream, alias(loop_stream) ), Level = informational, !. diff --git a/pl/preds.yap b/pl/preds.yap index bd7e00245..1e7f116c2 100644 --- a/pl/preds.yap +++ b/pl/preds.yap @@ -578,7 +578,6 @@ predicate_statistics(P0,NCls,Sz,ISz) :- Given predicate _P_, _NCls_ is the number of erased clauses for _P_ that could not be discarded yet, _Sz_ is the amount of space -taken to store those clauses (in bytes), and _IndexSz_ is the amount of space required to store indices to those clauses (in bytes). */ diff --git a/pl/qly.yap b/pl/qly.yap index 1e5731909..c683224c8 100755 --- a/pl/qly.yap +++ b/pl/qly.yap @@ -229,6 +229,9 @@ qend_program :- % there is some ordering between flags. 'x_yap_flag'(language, V) :- yap_flag(language, V). + %if silent keep silent, otherwise use the saved state. + 'x_yap_flag'(verbose, _) :- !. + 'x_yap_flag'(verbose_load, _) :- !. 'x_yap_flag'(M:P, V) :- current_module(M), yap_flag(M:P, V). @@ -357,12 +360,9 @@ available it tries reconsulting the source file. */ qload_module(Mod) :- - ( current_prolog_flag(verbose_load, true) - -> - Verbosity = informational - ; - current_prolog_flag(verbose_load, Verbosity) - ), + prolog_flag(verbose_load, OldF, false), + prolog_flag(verbose, OldV, silent), + Verbosity = silent StartMsg = loading_module, EndMsg = module_loaded, '$current_module'(SourceModule, Mod), @@ -375,6 +375,8 @@ qload_module(Mod) :- H is heapused-H0, '$cputime'(TF,_), T is TF-T0, print_message(Verbosity, loaded(EndMsg, File, Mod, T, H)), '$current_module'(_, SourceModule), + prolog_flag(verbose_load, _, OldF), + prolog_flag(verbose, _, OldV), working_directory(_, OldD). '$qload_module'(Mod, S, SourceModule) :- @@ -558,11 +560,11 @@ Restores a previously saved state of YAP contaianing a qly file _F_. */ qload_file( F0 ) :- - ( current_prolog_flag(verbose_load, true) + ( current_prolog_flag(verbose_load, false) -> - Verbosity = informational - ; Verbosity = silent + ; + current_prolog_flag(verbose, Verbosity) ), StartMsg = loading_module, EndMsg = module_loaded, From a33f2be18b57f6175be0b55bc0d2e8586665bbc1 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Sat, 13 Oct 2018 08:42:41 +0100 Subject: [PATCH 4/4] docs --- docs/yap.yap | 8 ++++++- include/YapErrors.h | 6 ++--- os/streams.c | 38 ++++++++++++++++-------------- packages/ProbLog/problog_lbfgs.yap | 30 ++++++++++++----------- utils/analysis/load.yap | 2 +- 5 files changed, 47 insertions(+), 37 deletions(-) diff --git a/docs/yap.yap b/docs/yap.yap index 5cff0285c..7a498fe63 100644 --- a/docs/yap.yap +++ b/docs/yap.yap @@ -1,3 +1,9 @@ +2:- use_module( library(lineutils) ). +3 +4main :- +5 unix(argv[Dir,Out]), +6 open(Out,write,O), -:- module( prolog, [] ). + 7 go(Dir,O). + 9go(Dir,O) :- diff --git a/include/YapErrors.h b/include/YapErrors.h index d8ba0054c..84f40ed11 100644 --- a/include/YapErrors.h +++ b/include/YapErrors.h @@ -27,13 +27,13 @@ ECLASS(RESOURCE_ERROR, "resource_error", 2) /// bad text ECLASS(SYNTAX_ERROR_CLASS, "syntax_error", 1) /// OS or internal -ECLASS(SYSTEM_ERROR_CLASS, "system_error", 2) +ECLASS(SYSTEM_ERROR_CLASS, "system_error", 1) /// bad typing ECLASS(TYPE_ERROR, "type_error", 2) /// should be unbound ECLASS(UNINSTANTIATION_ERROR_CLASS, "uninstantiation_error", 1) -/// escape hatch -ECLASS(EVENT, "event", 2) +/// user defined escape hatch +ECLASS(EVENT, "event", 1) END_ERROR_CLASSES(); diff --git a/os/streams.c b/os/streams.c index 8ecffcf20..a56838f64 100644 --- a/os/streams.c +++ b/os/streams.c @@ -316,7 +316,7 @@ bool Yap_SetCurInpPos( } Atom Yap_guessFileName(FILE *file, int sno, size_t max) { - size_t maxs = Yap_Max(1023, max-1); + size_t maxs = Yap_Max(1023, max - 1); if (!file) { Atom at = Yap_LookupAtom("mem"); return at; @@ -329,24 +329,26 @@ Atom Yap_guessFileName(FILE *file, int sno, size_t max) { int i = push_text_stack(); #if __linux__ - char *path = Malloc(1024), *nameb = Malloc(maxs+1); + char *path = Malloc(1024), *nameb = Malloc(maxs + 1); size_t len; if ((len = snprintf(path, 1023, "/proc/self/fd/%d", f)) >= 0 && (len = readlink(path, nameb, maxs)) > 0) { nameb[len] = '\0'; Atom at = Yap_LookupAtom(nameb); - pop_text_stack(i); - return at; + pop_text_stack(i); + return at; } #elif __APPLE__ + char *nameb = Malloc(maxs + 1); if (fcntl(f, F_GETPATH, nameb) != -1) { Atom at = Yap_LookupAtom(nameb); - pop_text_stack(i); - return at; + pop_text_stack(i); + return at; } #else - TCHAR *path = Malloc(MAX_PATH + 1); - if (!GetFullPathName(path, MAX_PATH, path, NULL)) { + TCHAR *path = Malloc(MAX_PATH + 1), *nameb = Malloc(MAX_PATH + 1); + + if (!GetFullPathName(path, MAX_PATH, nameb, NULL)) { pop_text_stack(i); return NULL; } else { @@ -356,8 +358,8 @@ Atom Yap_guessFileName(FILE *file, int sno, size_t max) { ptr += put_utf8(ptr, path[i]); *ptr = '\0'; Atom at = Yap_LookupAtom(nameb); - pop_text_stack(i); - return at; + pop_text_stack(i); + return at; } #endif if (!StreamName(sno)) { @@ -721,7 +723,7 @@ static Int cont_stream_property(USES_REGS1) { /* current_stream */ i = Yap_CheckAlias(AtomOfTerm(args[STREAM_PROPERTY_ALIAS].tvalue)); UNLOCK(GLOBAL_Stream[i].streamlock); if (i < 0 || !Yap_unify(ARG1, Yap_MkStream(i))) { - free(args); + free(args); cut_fail(); } det = true; @@ -1001,11 +1003,11 @@ static void CloseStream(int sno) { CACHE_REGS // fflush(NULL); -// __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "close stream <%d>", -// sno); + // __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "close stream <%d>", + // sno); VFS_t *me; - //fprintf( stderr, "- %d\n",sno); -if ((me = GLOBAL_Stream[sno].vfs) != NULL && + // fprintf( stderr, "- %d\n",sno); + if ((me = GLOBAL_Stream[sno].vfs) != NULL && GLOBAL_Stream[sno].file == NULL) { if (me->close) { me->close(sno); @@ -1043,7 +1045,8 @@ if ((me = GLOBAL_Stream[sno].vfs) != NULL && GLOBAL_Stream[sno].vfs = NULL; GLOBAL_Stream[sno].file = NULL; GLOBAL_Stream[sno].status = Free_Stream_f; - // __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "close stream <%d>", sno); + // __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "close stream <%d>", + // sno); /* if (st->status == Socket_Stream_f|Input_Stream_f|Output_Stream_f) { Yap_CloseSocket(); @@ -1556,8 +1559,7 @@ FILE *Yap_FileDescriptorFromStream(Term t) { return rc; } -void Yap_InitBackIO(void) -{ +void Yap_InitBackIO(void) { Yap_InitCPredBack("stream_property", 2, 2, stream_property, cont_stream_property, SafePredFlag | SyncPredFlag); } diff --git a/packages/ProbLog/problog_lbfgs.yap b/packages/ProbLog/problog_lbfgs.yap index ec79506a6..5ba888481 100644 --- a/packages/ProbLog/problog_lbfgs.yap +++ b/packages/ProbLog/problog_lbfgs.yap @@ -830,17 +830,18 @@ gradient_descent :- % leash(0),trace, lbfgs_initialize(N,X,0,Solver), forall(tunable_fact(FactID,GroundTruth), - (XZ is 0.5, X[FactID] <== XZ,set_fact_probability(FactID,XZ))), + (XZ is 0.0, X[FactID] <== XZ,sigmoid(XZ,Slope,Pr),set_fact_probability(FactID,Pr))), problog_flag(sigmoid_slope,Slope), - lbfgs_set_parameter(min_step, 0.0, Solver), + %lbfgs_set_parameter(min_step, 0.0, Solver), lbfgs_run(Solver,BestF), format('~2nOptimization done~nWe found a minimum ~4f.~n',[BestF]), - forall(tunable_fact(FactID,GroundTruth), set_tunable(FactID,X)), + forall(tunable_fact(FactID,GroundTruth), set_tunable(FactID,Slope,X)), set_problog_flag(mse_trainset, BestF), lbfgs_finalize(Solver). -set_tunable(I,P) :- - Pr <== P[I], +set_tunable(I,Slope,P) :- + X <== P[I], + sigmoid(X,Slope,Pr), set_fact_probability(I,Pr). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -849,12 +850,12 @@ set_tunable(I,P) :- user:evaluate(LLH_Training_Queries, X,Grad,N,_,_) :- %Handle = user_error, GradCount <== array[N] of ints, + Probs <== array[N] of floats, problog_flag(sigmoid_slope,Slope), - Probs = X, N1 is N-1, forall(between(0,N1,I), - (Grad[I] <== 0.0) %, sigmoid(X[I],Slope,Probs[I]) ) + (Grad[I] <== 0.0, S <== X[I], sigmoid(S,Slope, P), Probs[I] <== P) ), findall(LL, compute_grad(Grad, GradCount, Probs, Slope, LL), @@ -876,15 +877,16 @@ compute_grad(Grad, GradCount, Probs, Slope, LL) :- %writeln( qprobability(BDD,Slope,BDDProb) ), forall( member(I-_, MapList), - gradientpair(I, BDD,Slope,BDDProb, QueryProb, Grad, GradCount) + gradientpair(I, BDD,Slope,BDDProb, QueryProb, Grad, Probs, GradCount) ). -gradientpair(I, BDD,Slope,BDDProb, QueryProb, Grad, GradCount) :- +gradientpair(I, BDD,Slope,BDDProb, QueryProb, Grad, Probs, GradCount) :- qgradient(I, BDD, Slope, FactID, GradValue), % writeln(FactID), G0 <== Grad[FactID], + Prob <== Probs[FactID], %writeln( GN is G0-GradValue*(QueryProb-BDDProb)), - GN is G0-GradValue*2*(QueryProb-BDDProb), + GN is G0-GradValue*2*Prob*(1-Prob)*(QueryProb-BDDProb), %writeln(FactID:(G0->GN)), GC <== GradCount[FactID], GC1 is GC+1, @@ -978,10 +980,10 @@ bind_maplist([Node-Pr|MapList], Slope, X) :- % stop calculate gradient %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% user:progress(FX,X,_G,X_Norm,G_Norm,Step,_N,Iteration,Ls,0) :- - % problog_flag(sigmoid_slope,Slope), - X0 <== X[0], - X1 <== X[1], - format('~d. Iteration : (x0,x1)=(~4f,~4f) f(X)=~4f |X|=~4f |X\'|=~4f Step=~4f Ls=~4f~n',[Iteration,X0 ,X1,FX,X_Norm,G_Norm,Step,Ls]). + problog_flag(sigmoid_slope,Slope), + X0 <== X[0], sigmoid(X0,Slope,P0), + 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]). %======================================================================== diff --git a/utils/analysis/load.yap b/utils/analysis/load.yap index d5619295c..7bea06527 100644 --- a/utils/analysis/load.yap +++ b/utils/analysis/load.yap @@ -41,7 +41,7 @@ rdir( FRoot ) :- absolute_file_name( FRoot, [glob(*), solutions(all), file_errors(fail)], File ), \+ doskip( File ), ( - catch( file_property( File, type(directory) ), _, fail ) + cat zzch( file_property( File, type(directory) ), _, fail ) -> assert_new( dir( File ) ), assert_new( sub_dir( FRoot, File ) ),