small fixes

This commit is contained in:
Vitor Santos Costa 2018-10-07 14:27:01 +01:00
parent ba6e0728ae
commit 6d0b702d1c
8 changed files with 473 additions and 490 deletions

View File

@ -218,6 +218,11 @@ X_API YAP_Term YAP_A(int i) {
return (Deref(XREGS[i])); return (Deref(XREGS[i]));
} }
X_API YAP_Term YAP_SetA(int i, YAP_Term t) {
CACHE_REGS
return (Deref(XREGS[i]));
}
X_API YAP_Bool YAP_IsIntTerm(YAP_Term t) { return IsIntegerTerm(t); } X_API YAP_Bool YAP_IsIntTerm(YAP_Term t) { return IsIntegerTerm(t); }
X_API YAP_Bool YAP_IsNumberTerm(YAP_Term t) { X_API YAP_Bool YAP_IsNumberTerm(YAP_Term t) {
@ -288,23 +293,23 @@ X_API Term YAP_MkIntTerm(Int n) {
} }
X_API Term YAP_MkStringTerm(const char *n) { X_API Term YAP_MkStringTerm(const char *n) {
CACHE_REGS CACHE_REGS
Term I; Term I;
BACKUP_H(); BACKUP_H();
I = MkStringTerm(n); I = MkStringTerm(n);
RECOVER_H(); RECOVER_H();
return I; return I;
} }
X_API Term YAP_MkCharPTerm( char *n) { X_API Term YAP_MkCharPTerm(char *n) {
CACHE_REGS CACHE_REGS
Term I; Term I;
BACKUP_H(); BACKUP_H();
I = MkStringTerm(n); I = MkStringTerm(n);
RECOVER_H(); RECOVER_H();
return I; return I;
} }
X_API Term YAP_MkUnsignedStringTerm(const unsigned char *n) { X_API Term YAP_MkUnsignedStringTerm(const unsigned char *n) {
@ -1352,8 +1357,8 @@ X_API void YAP_FreeSpaceFromYap(void *ptr) { Yap_FreeCodeSpace(ptr); }
* @param bufsize bu * @param bufsize bu
* *
* @return * @return
*/ X_API char * */
YAP_StringToBuffer(Term t, char *buf, unsigned int bufsize) { X_API char *YAP_StringToBuffer(Term t, char *buf, unsigned int bufsize) {
CACHE_REGS CACHE_REGS
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
seq_tv_t inp, out; seq_tv_t inp, out;
@ -1464,7 +1469,8 @@ X_API Term YAP_ReadBuffer(const char *s, Term *tp) {
else else
tv = (Term)0; tv = (Term)0;
LOCAL_ErrorMessage = NULL; LOCAL_ErrorMessage = NULL;
while (!(t = Yap_BufferToTermWithPrioBindings(s, TermNil, tv, strlen(s) + 1, GLOBAL_MaxPriority))) { while (!(t = Yap_BufferToTermWithPrioBindings(s, TermNil, tv, strlen(s) + 1,
GLOBAL_MaxPriority))) {
if (LOCAL_ErrorMessage) { if (LOCAL_ErrorMessage) {
if (!strcmp(LOCAL_ErrorMessage, "Stack Overflow")) { if (!strcmp(LOCAL_ErrorMessage, "Stack Overflow")) {
if (!Yap_dogc(0, NULL PASS_REGS)) { if (!Yap_dogc(0, NULL PASS_REGS)) {
@ -1492,7 +1498,7 @@ X_API Term YAP_ReadBuffer(const char *s, Term *tp) {
return 0L; return 0L;
} }
LOCAL_ErrorMessage = NULL; LOCAL_ErrorMessage = NULL;
RECOVER_H(); RECOVER_H();
return 0; return 0;
} else { } else {
break; break;
@ -1731,7 +1737,9 @@ X_API bool YAP_EnterGoal(YAP_PredEntryPtr ape, CELL *ptr, YAP_dogoalinfo *dgi) {
CACHE_REGS CACHE_REGS
PredEntry *pe = ape; PredEntry *pe = ape;
bool out; bool out;
// fprintf(stderr,"EnterGoal: H=%d ENV=%p B=%d TR=%d P=%p CP=%p Slots=%d\n",HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP, LOCAL_CurSlot); // fprintf(stderr,"EnterGoal: H=%d ENV=%p B=%d TR=%d P=%p CP=%p
// Slots=%d\n",HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP,
// LOCAL_CurSlot);
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
LOCAL_ActiveError->errorNo = YAP_NO_ERROR; LOCAL_ActiveError->errorNo = YAP_NO_ERROR;
@ -1748,12 +1756,14 @@ X_API bool YAP_EnterGoal(YAP_PredEntryPtr ape, CELL *ptr, YAP_dogoalinfo *dgi) {
// slot=%d", pe, pe->CodeOfPred->opc, FAILCODE, Deref(ARG1), Deref(ARG2), // slot=%d", pe, pe->CodeOfPred->opc, FAILCODE, Deref(ARG1), Deref(ARG2),
// LOCAL_CurSlot); // LOCAL_CurSlot);
dgi->b = LCL0 - (CELL *)B; dgi->b = LCL0 - (CELL *)B;
dgi->h = HR-H0; dgi->h = HR - H0;
dgi->tr = (CELL*)TR-LCL0; dgi->tr = (CELL *)TR - LCL0;
//fprintf(stderr,"PrepGoal: H=%d ENV=%p B=%d TR=%d P=%p CP=%p Slots=%d\n", // fprintf(stderr,"PrepGoal: H=%d ENV=%p B=%d TR=%d P=%p CP=%p Slots=%d\n",
// HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP, LOCAL_CurSlot); // HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP, LOCAL_CurSlot);
out = Yap_exec_absmi(true, false); out = Yap_exec_absmi(true, false);
// fprintf(stderr,"EnterGoal success=%d: H=%d ENV=%p B=%d TR=%d P=%p CP=%p Slots=%d\n", out,HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP, LOCAL_CurSlot); // fprintf(stderr,"EnterGoal success=%d: H=%d ENV=%p B=%d TR=%d P=%p CP=%p
// Slots=%d\n", out,HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP,
// LOCAL_CurSlot);
dgi->b = LCL0 - (CELL *)B; dgi->b = LCL0 - (CELL *)B;
if (out) { if (out) {
dgi->EndSlot = LOCAL_CurSlot; dgi->EndSlot = LOCAL_CurSlot;
@ -1768,13 +1778,13 @@ X_API bool YAP_EnterGoal(YAP_PredEntryPtr ape, CELL *ptr, YAP_dogoalinfo *dgi) {
X_API bool YAP_RetryGoal(YAP_dogoalinfo *dgi) { X_API bool YAP_RetryGoal(YAP_dogoalinfo *dgi) {
CACHE_REGS CACHE_REGS
choiceptr myB, myB0; choiceptr myB, myB0;
bool out; bool out;
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
myB = (choiceptr)(LCL0 - dgi->b); myB = (choiceptr)(LCL0 - dgi->b);
myB0 = (choiceptr)(LCL0 - dgi->b0); myB0 = (choiceptr)(LCL0 - dgi->b0);
CP = myB->cp_cp; CP = myB->cp_cp;
/* sanity check */ /* sanity check */
if (B >= myB0) { if (B >= myB0) {
return false; return false;
@ -1783,8 +1793,8 @@ X_API bool YAP_RetryGoal(YAP_dogoalinfo *dgi) {
// get rid of garbage choice-points // get rid of garbage choice-points
B = myB; B = myB;
} }
//fprintf(stderr,"RetryGoal: H=%d ENV=%p B=%d TR=%d P=%p CP=%p Slots=%d\n", // fprintf(stderr,"RetryGoal: H=%d ENV=%p B=%d TR=%d P=%p CP=%p Slots=%d\n",
// HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP, LOCAL_CurSlot); // HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP, LOCAL_CurSlot);
P = FAILCODE; P = FAILCODE;
/* make sure we didn't leave live slots when we backtrack */ /* make sure we didn't leave live slots when we backtrack */
ASP = (CELL *)B; ASP = (CELL *)B;
@ -1792,7 +1802,7 @@ X_API bool YAP_RetryGoal(YAP_dogoalinfo *dgi) {
out = run_emulator(PASS_REGS1); out = run_emulator(PASS_REGS1);
if (out) { if (out) {
dgi->EndSlot = LOCAL_CurSlot; dgi->EndSlot = LOCAL_CurSlot;
dgi->b = LCL0-(CELL *)B; dgi->b = LCL0 - (CELL *)B;
} else { } else {
LOCAL_CurSlot = LOCAL_CurSlot =
dgi->CurSlot; // ignore any slots created within the called goal dgi->CurSlot; // ignore any slots created within the called goal
@ -1801,9 +1811,8 @@ X_API bool YAP_RetryGoal(YAP_dogoalinfo *dgi) {
return out; return out;
} }
static void completeInnerCall( bool on_cut, yamop *old_CP, yamop *old_P) static void completeInnerCall(bool on_cut, yamop *old_CP, yamop *old_P) {
{ if (on_cut) {
if (on_cut) {
P = old_P; P = old_P;
ENV = (CELL *)ENV[E_E]; ENV = (CELL *)ENV[E_E];
CP = old_CP; CP = old_CP;
@ -1821,45 +1830,47 @@ static void completeInnerCall( bool on_cut, yamop *old_CP, yamop *old_P)
SET_ASP(ENV, E_CB * sizeof(CELL)); SET_ASP(ENV, E_CB * sizeof(CELL));
// make sure the slots are ok. // make sure the slots are ok.
} }
} }
X_API bool YAP_LeaveGoal(bool successful, YAP_dogoalinfo *dgi) { X_API bool YAP_LeaveGoal(bool successful, YAP_dogoalinfo *dgi) {
CACHE_REGS CACHE_REGS
choiceptr myB, handler; choiceptr myB, handler;
// fprintf(stderr,"LeaveGoal success=%d: H=%d ENV=%p B=%ld myB=%ld TR=%d P=%p CP=%p Slots=%d\n", successful,HR-H0,LCL0-ENV,LCL0-(CELL*)B,dgi->b0,(CELL*)TR-LCL0, P, CP, LOCAL_CurSlot); // fprintf(stderr,"LeaveGoal success=%d: H=%d ENV=%p B=%ld myB=%ld TR=%d
// P=%p CP=%p Slots=%d\n",
// successful,HR-H0,LCL0-ENV,LCL0-(CELL*)B,dgi->b0,(CELL*)TR-LCL0, P, CP,
// LOCAL_CurSlot);
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
myB = (choiceptr)(LCL0 - dgi->b); myB = (choiceptr)(LCL0 - dgi->b);
if (LOCAL_PrologMode & AsyncIntMode) { if (LOCAL_PrologMode & AsyncIntMode) {
Yap_signal(YAP_FAIL_SIGNAL); Yap_signal(YAP_FAIL_SIGNAL);
}
handler = B;
while (handler
&& LCL0-LOCAL_CBorder > (CELL *)handler
//&& handler->cp_ap != NOCODE
&& handler->cp_b != NULL
&& handler != myB
) {
if (handler < myB ) {
handler->cp_ap = TRUSTFAILCODE;
}
B = handler;
handler = handler->cp_b;
if (successful) {
Yap_TrimTrail();
} else if (!(LOCAL_PrologMode & AsyncIntMode)) {
P=FAILCODE;
Yap_exec_absmi(true, YAP_EXEC_ABSMI);
} }
handler = B;
while (handler &&
LCL0 - LOCAL_CBorder > (CELL *)handler
//&& handler->cp_ap != NOCODE
&& handler->cp_b != NULL && handler != myB) {
if (handler < myB) {
handler->cp_ap = TRUSTFAILCODE;
}
B = handler;
handler = handler->cp_b;
if (successful) {
Yap_TrimTrail();
} else if (!(LOCAL_PrologMode & AsyncIntMode)) {
P = FAILCODE;
Yap_exec_absmi(true, YAP_EXEC_ABSMI);
}
} }
if (LOCAL_PrologMode & AsyncIntMode) { if (LOCAL_PrologMode & AsyncIntMode) {
Yap_signal(YAP_FAIL_SIGNAL); Yap_signal(YAP_FAIL_SIGNAL);
} }
P=dgi->p; P = dgi->p;
CP = dgi->cp; CP = dgi->cp;
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
// fprintf(stderr,"LeftGoal success=%d: H=%d ENV=%p B=%d TR=%d P=%p CP=%p Slots=%d\n", successful,HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP, LOCAL_CurSlot); // fprintf(stderr,"LeftGoal success=%d: H=%d ENV=%p B=%d TR=%d P=%p CP=%p
// Slots=%d\n", successful,HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P,
// CP, LOCAL_CurSlot);
return TRUE; return TRUE;
} }
@ -1875,7 +1886,7 @@ X_API Int YAP_RunGoal(Term t) {
LOCAL_PrologMode = UserCCallMode; LOCAL_PrologMode = UserCCallMode;
// should we catch the exception or pass it through? // should we catch the exception or pass it through?
// We'll pass it through // We'll pass it through
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
LOCAL_CurSlot = cslot; LOCAL_CurSlot = cslot;
return out; return out;
} }
@ -1958,7 +1969,7 @@ X_API Int YAP_RunGoalOnce(Term t) {
CSlot = Yap_StartSlots(); CSlot = Yap_StartSlots();
LOCAL_PrologMode = UserMode; LOCAL_PrologMode = UserMode;
// Yap_heap_regs->yap_do_low_level_trace=true; // Yap_heap_regs->yap_do_low_level_trace=true;
out = Yap_RunTopGoal(t, true); out = Yap_RunTopGoal(t, true);
LOCAL_PrologMode = oldPrologMode; LOCAL_PrologMode = oldPrologMode;
// Yap_CloseSlots(CSlot); // Yap_CloseSlots(CSlot);
if (!(oldPrologMode & UserCCallMode)) { if (!(oldPrologMode & UserCCallMode)) {
@ -2114,14 +2125,16 @@ X_API void YAP_ClearExceptions(void) {
Yap_ResetException(worker_id); Yap_ResetException(worker_id);
} }
X_API int YAP_InitConsult(int mode, const char *fname, char **full, int *osnop) { X_API int YAP_InitConsult(int mode, const char *fname, char **full,
int *osnop) {
CACHE_REGS CACHE_REGS
int sno; int sno;
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
const char *fl = NULL; const char *fl = NULL;
int lvl = push_text_stack(); int lvl = push_text_stack();
if (mode == YAP_BOOT_MODE) { if (mode == YAP_BOOT_MODE) {
mode = YAP_CONSULT_MODE; } mode = YAP_CONSULT_MODE;
}
if (fname == NULL || fname[0] == '\0') { if (fname == NULL || fname[0] == '\0') {
fl = Yap_BOOTFILE; fl = Yap_BOOTFILE;
} }
@ -2132,26 +2145,27 @@ X_API int YAP_InitConsult(int mode, const char *fname, char **full, int *osnop)
*full = NULL; *full = NULL;
return -1; return -1;
} else { } else {
*full = pop_output_text_stack(lvl,fl); *full = pop_output_text_stack(lvl, fl);
} }
} else { } else {
pop_text_stack(lvl); pop_text_stack(lvl);
} }
lvl = push_text_stack(); lvl = push_text_stack();
char *d = Malloc(strlen(fl)+1); char *d = Malloc(strlen(fl) + 1);
strcpy(d,fl); strcpy(d, fl);
bool consulted = (mode == YAP_CONSULT_MODE); bool consulted = (mode == YAP_CONSULT_MODE);
Term tat = MkAtomTerm(Yap_LookupAtom(d)); Term tat = MkAtomTerm(Yap_LookupAtom(d));
sno = Yap_OpenStream(tat, "r", MkAtomTerm(Yap_LookupAtom(fname)), LOCAL_encoding); sno = Yap_OpenStream(tat, "r", MkAtomTerm(Yap_LookupAtom(fname)),
if (sno < 0 || LOCAL_encoding);
!Yap_ChDir(dirname((char *)d))) { if (sno < 0 || !Yap_ChDir(dirname((char *)d))) {
pop_text_stack(lvl); pop_text_stack(lvl);
*full = NULL; *full = NULL;
return -1; return -1;
} LOCAL_PrologMode = UserMode; }
LOCAL_PrologMode = UserMode;
Yap_init_consult(consulted, pop_output_text_stack__(lvl,fl)); Yap_init_consult(consulted, pop_output_text_stack__(lvl, fl));
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
UNLOCK(GLOBAL_Stream[sno].streamlock); UNLOCK(GLOBAL_Stream[sno].streamlock);
return sno; return sno;
@ -2179,16 +2193,19 @@ X_API void YAP_EndConsult(int sno, int *osnop, const char *full) {
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
Yap_CloseStream(sno); Yap_CloseStream(sno);
int lvl = push_text_stack(); int lvl = push_text_stack();
char *d = Malloc(strlen(full)+1); char *d = Malloc(strlen(full) + 1);
strcpy(d,full); strcpy(d, full);
Yap_ChDir(dirname(d)); Yap_ChDir(dirname(d));
if (osnop >= 0) if (osnop >= 0)
Yap_AddAlias(AtomLoopStream, *osnop); Yap_AddAlias(AtomLoopStream, *osnop);
Yap_end_consult(); Yap_end_consult();
__android_log_print(ANDROID_LOG_INFO, "YAPDroid ", " closing %s:%s(%d), %d", __android_log_print(ANDROID_LOG_INFO, "YAPDroid ", " closing %s:%s(%d), %d",
CurrentModule == 0? "prolog": RepAtom(AtomOfTerm(CurrentModule))->StrOfAE, full, *osnop, sno); CurrentModule == 0
// LOCAL_CurSlot); ? "prolog"
pop_text_stack(lvl); : RepAtom(AtomOfTerm(CurrentModule))->StrOfAE,
full, *osnop, sno);
// LOCAL_CurSlot);
pop_text_stack(lvl);
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
} }
@ -2215,7 +2232,13 @@ X_API Term YAP_ReadFromStream(int sno) {
X_API Term YAP_ReadClauseFromStream(int sno, Term vs, Term pos) { X_API Term YAP_ReadClauseFromStream(int sno, Term vs, Term pos) {
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
Term t = Yap_read_term(sno,MkPairTerm(Yap_MkApplTerm(Yap_MkFunctor(AtomVariableNames,1),1,&vs), MkPairTerm(Yap_MkApplTerm(Yap_MkFunctor(AtomTermPosition,1),1,&pos), TermNil)), true); Term t = Yap_read_term(
sno,
MkPairTerm(Yap_MkApplTerm(Yap_MkFunctor(AtomVariableNames, 1), 1, &vs),
MkPairTerm(Yap_MkApplTerm(Yap_MkFunctor(AtomTermPosition, 1),
1, &pos),
TermNil)),
true);
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
return t; return t;
} }
@ -2275,7 +2298,7 @@ X_API int YAP_WriteDynamicBuffer(YAP_Term t, char *buf, size_t sze,
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
b = Yap_TermToBuffer(t, flags); b = Yap_TermToBuffer(t, flags);
strncpy(buf, b, sze-1); strncpy(buf, b, sze - 1);
buf[sze] = 0; buf[sze] = 0;
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
return true; return true;
@ -2315,7 +2338,7 @@ X_API bool YAP_CompileClause(Term t) {
} }
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
if (!ok) { if (!ok) {
return NULL; return NULL;
} }
return ok; return ok;
} }
@ -2540,12 +2563,12 @@ X_API int YAP_HaltRegisterHook(HaltHookFunc hook, void *closure) {
X_API char *YAP_cwd(void) { X_API char *YAP_cwd(void) {
CACHE_REGS CACHE_REGS
char *buf = Yap_AllocCodeSpace(FILENAME_MAX+1); char *buf = Yap_AllocCodeSpace(FILENAME_MAX + 1);
int len; int len;
if (!Yap_getcwd(buf, FILENAME_MAX)) if (!Yap_getcwd(buf, FILENAME_MAX))
return FALSE; return FALSE;
len = strlen(buf); len = strlen(buf);
buf = Yap_ReallocCodeSpace(buf,len+1); buf = Yap_ReallocCodeSpace(buf, len + 1);
return buf; return buf;
} }

View File

@ -85,7 +85,7 @@ static void InitConsultStack(void) {
LOCAL_ConsultCapacity = InitialConsultCapacity; LOCAL_ConsultCapacity = InitialConsultCapacity;
LOCAL_ConsultBase = LOCAL_ConsultSp = LOCAL_ConsultBase = LOCAL_ConsultSp =
LOCAL_ConsultLow + LOCAL_ConsultCapacity; LOCAL_ConsultLow + LOCAL_ConsultCapacity;
s }
void Yap_ResetConsultStack(void) { void Yap_ResetConsultStack(void) {
CACHE_REGS CACHE_REGS

View File

@ -102,6 +102,9 @@ extern YAP_Term YAP_A(int);
#define YAP_ARG15 YAP_A(15) #define YAP_ARG15 YAP_A(15)
#define YAP_ARG16 YAP_A(16) #define YAP_ARG16 YAP_A(16)
X_API
extern YAP_Term YAP_SetA(int, YAP_Term);
/* YAP_Bool IsVarTerm(YAP_Term) */ /* YAP_Bool IsVarTerm(YAP_Term) */
extern X_API YAP_Bool YAP_IsVarTerm(YAP_Term); extern X_API YAP_Bool YAP_IsVarTerm(YAP_Term);
@ -268,7 +271,6 @@ extern X_API void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred,
extern X_API void YAP_UserBackCPredicate(const char *, YAP_UserCPred, extern X_API void YAP_UserBackCPredicate(const char *, YAP_UserCPred,
YAP_UserCPred, YAP_Arity, YAP_Arity); YAP_UserCPred, YAP_Arity, YAP_Arity);
/* void UserBackCPredicate(char *name, int *init(), int *cont(), int *cut(), /* void UserBackCPredicate(char *name, int *init(), int *cont(), int *cut(),
int int
arity, int extra) */ arity, int extra) */
@ -371,7 +373,7 @@ extern X_API YAP_Term YAP_CopyTerm(YAP_Term t);
/* bool YAP_CompileClause(YAP_Term) /* bool YAP_CompileClause(YAP_Term)
@short compile the clause _Cl_; on failure it may call the exception handler. */ @short compile the clause _Cl_; on failure it may call the exception handler. */
extern X_API bool YAP_CompileClause(YAP_Term Cl); extern X_API bool YAP_CompileClause(YAP_Term Cl);
extern X_API int YAP_NewExo(YAP_PredEntryPtr ap, size_t data, void *user_di); extern X_API int YAP_NewExo(YAP_PredEntryPtr ap, size_t data, void *user_di);
@ -383,8 +385,7 @@ extern X_API int YAP_AssertTuples(YAP_PredEntryPtr pred, const YAP_Term *ts,
extern X_API void YAP_Init(YAP_init_args *); extern X_API void YAP_Init(YAP_init_args *);
/* int YAP_FastInit(const char *) */ /* int YAP_FastInit(const char *) */
extern X_API void YAP_FastInit(char saved_state[], int argc, extern X_API void YAP_FastInit(char saved_state[], int argc, char *argv[]);
char *argv[]);
#ifndef _PL_STREAM_H #ifndef _PL_STREAM_H
// if we don't know what a stream is, just don't assume nothing about the // if we don't know what a stream is, just don't assume nothing about the
@ -402,7 +403,8 @@ extern X_API YAP_Term YAP_ReadFromStream(int s);
/// read a Prolog clause from a Prolog opened stream $s$. Similar to /// read a Prolog clause from a Prolog opened stream $s$. Similar to
/// YAP_ReadFromStream() but takes /// default options from read_clause/3. /// YAP_ReadFromStream() but takes /// default options from read_clause/3.
extern X_API YAP_Term YAP_ReadClauseFromStream(int s, YAP_Term varNames, YAP_Term); extern X_API YAP_Term YAP_ReadClauseFromStream(int s, YAP_Term varNames,
YAP_Term);
extern X_API void YAP_Write(YAP_Term t, FILE *s, int); extern X_API void YAP_Write(YAP_Term t, FILE *s, int);
@ -411,7 +413,8 @@ extern X_API FILE *YAP_TermToStream(YAP_Term t);
extern X_API int YAP_InitConsult(int mode, const char *filename, char **buf, extern X_API int YAP_InitConsult(int mode, const char *filename, char **buf,
int *previous_sno); int *previous_sno);
extern X_API void YAP_EndConsult(int s, int *previous_sno, const char *previous_cwd); extern X_API void YAP_EndConsult(int s, int *previous_sno,
const char *previous_cwd);
extern X_API void YAP_Exit(int); extern X_API void YAP_Exit(int);
@ -477,7 +480,6 @@ extern X_API void YAP_SetOutputMessage(void);
extern X_API int YAP_StreamToFileNo(YAP_Term); extern X_API int YAP_StreamToFileNo(YAP_Term);
/** /**
* Utility routine to Obtain a pointer to the YAP representation of a stream. * Utility routine to Obtain a pointer to the YAP representation of a stream.
* *
@ -486,7 +488,6 @@ extern X_API int YAP_StreamToFileNo(YAP_Term);
*/ */
extern X_API void *YAP_RepStreamFromId(int sno); extern X_API void *YAP_RepStreamFromId(int sno);
extern X_API void YAP_CloseAllOpenStreams(void); extern X_API void YAP_CloseAllOpenStreams(void);
extern X_API void YAP_FlushAllStreams(void); extern X_API void YAP_FlushAllStreams(void);

View File

@ -1307,7 +1307,6 @@ static bool fill_stream(int sno, StreamDesc *st, Term tin, const char *io_mode,
st->status |= Popen_Stream_f; st->status |= Popen_Stream_f;
pop_text_stack(i); pop_text_stack(i);
} else { } else {
pop_text_stack(i);
Yap_ThrowError(DOMAIN_ERROR_SOURCE_SINK, tin, "open"); Yap_ThrowError(DOMAIN_ERROR_SOURCE_SINK, tin, "open");
} }
} }

View File

@ -19,61 +19,61 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% Artistic License 2.0 % Artistic License 2.0
% %
% Copyright (c) 2000-2006, The Perl Foundation. % Copyright (c) 2000-2006, The Perl Foundation.
% %
% Everyone is permitted to copy and distribute verbatim copies of this % Everyone is permitted to copy and distribute verbatim copies of this
% license document, but changing it is not allowed. Preamble % license document, but changing it is not allowed. Preamble
% %
% This license establishes the terms under which a given free software % This license establishes the terms under which a given free software
% Package may be copied, modified, distributed, and/or % Package may be copied, modified, distributed, and/or
% redistributed. The intent is that the Copyright Holder maintains some % redistributed. The intent is that the Copyright Holder maintains some
% artistic control over the development of that Package while still % artistic control over the development of that Package while still
% keeping the Package available as open source and free software. % keeping the Package available as open source and free software.
% %
% You are always permitted to make arrangements wholly outside of this % You are always permitted to make arrangements wholly outside of this
% license directly with the Copyright Holder of a given Package. If the % license directly with the Copyright Holder of a given Package. If the
% terms of this license do not permit the full use that you propose to % terms of this license do not permit the full use that you propose to
% make of the Package, you should contact the Copyright Holder and seek % make of the Package, you should contact the Copyright Holder and seek
% a different licensing arrangement. Definitions % a different licensing arrangement. Definitions
% %
% "Copyright Holder" means the individual(s) or organization(s) named in % "Copyright Holder" means the individual(s) or organization(s) named in
% the copyright notice for the entire Package. % the copyright notice for the entire Package.
% %
% "Contributor" means any party that has contributed code or other % "Contributor" means any party that has contributed code or other
% material to the Package, in accordance with the Copyright Holder's % material to the Package, in accordance with the Copyright Holder's
% procedures. % procedures.
% %
% "You" and "your" means any person who would like to copy, distribute, % "You" and "your" means any person who would like to copy, distribute,
% or modify the Package. % or modify the Package.
% %
% "Package" means the collection of files distributed by the Copyright % "Package" means the collection of files distributed by the Copyright
% Holder, and derivatives of that collection and/or of those files. A % Holder, and derivatives of that collection and/or of those files. A
% given Package may consist of either the Standard Version, or a % given Package may consist of either the Standard Version, or a
% Modified Version. % Modified Version.
% %
% "Distribute" means providing a copy of the Package or making it % "Distribute" means providing a copy of the Package or making it
% accessible to anyone else, or in the case of a company or % accessible to anyone else, or in the case of a company or
% organization, to others outside of your company or organization. % organization, to others outside of your company or organization.
% %
% "Distributor Fee" means any fee that you charge for Distributing this % "Distributor Fee" means any fee that you charge for Distributing this
% Package or providing support for this Package to another party. It % Package or providing support for this Package to another party. It
% does not mean licensing fees. % does not mean licensing fees.
% %
% "Standard Version" refers to the Package if it has not been modified, % "Standard Version" refers to the Package if it has not been modified,
% or has been modified only in ways explicitly requested by the % or has been modified only in ways explicitly requested by the
% Copyright Holder. % Copyright Holder.
% %
% "Modified Version" means the Package, if it has been changed, and such % "Modified Version" means the Package, if it has been changed, and such
% changes were not explicitly requested by the Copyright Holder. % changes were not explicitly requested by the Copyright Holder.
% %
% "Original License" means this Artistic License as Distributed with the % "Original License" means this Artistic License as Distributed with the
% Standard Version of the Package, in its current version or as it may % Standard Version of the Package, in its current version or as it may
% be modified by The Perl Foundation in the future. % be modified by The Perl Foundation in the future.
% %
% "Source" form means the source code, documentation source, and % "Source" form means the source code, documentation source, and
% configuration files for the Package. % configuration files for the Package.
% %
% "Compiled" form means the compiled bytecode, object code, binary, or % "Compiled" form means the compiled bytecode, object code, binary, or
% any other form resulting from mechanical transformation or translation % any other form resulting from mechanical transformation or translation
% of the Source form. % of the Source form.
@ -81,34 +81,34 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% Permission for Use and Modification Without Distribution % Permission for Use and Modification Without Distribution
% %
% (1) You are permitted to use the Standard Version and create and use % (1) You are permitted to use the Standard Version and create and use
% Modified Versions for any purpose without restriction, provided that % Modified Versions for any purpose without restriction, provided that
% you do not Distribute the Modified Version. % you do not Distribute the Modified Version.
% %
% Permissions for Redistribution of the Standard Version % Permissions for Redistribution of the Standard Version
% %
% (2) You may Distribute verbatim copies of the Source form of the % (2) You may Distribute verbatim copies of the Source form of the
% Standard Version of this Package in any medium without restriction, % Standard Version of this Package in any medium without restriction,
% either gratis or for a Distributor Fee, provided that you duplicate % either gratis or for a Distributor Fee, provided that you duplicate
% all of the original copyright notices and associated disclaimers. At % all of the original copyright notices and associated disclaimers. At
% your discretion, such verbatim copies may or may not include a % your discretion, such verbatim copies may or may not include a
% Compiled form of the Package. % Compiled form of the Package.
% %
% (3) You may apply any bug fixes, portability changes, and other % (3) You may apply any bug fixes, portability changes, and other
% modifications made available from the Copyright Holder. The resulting % modifications made available from the Copyright Holder. The resulting
% Package will still be considered the Standard Version, and as such % Package will still be considered the Standard Version, and as such
% will be subject to the Original License. % will be subject to the Original License.
% %
% Distribution of Modified Versions of the Package as Source % Distribution of Modified Versions of the Package as Source
% %
% (4) You may Distribute your Modified Version as Source (either gratis % (4) You may Distribute your Modified Version as Source (either gratis
% or for a Distributor Fee, and with or without a Compiled form of the % or for a Distributor Fee, and with or without a Compiled form of the
% Modified Version) provided that you clearly document how it differs % Modified Version) provided that you clearly document how it differs
% from the Standard Version, including, but not limited to, documenting % from the Standard Version, including, but not limited to, documenting
% any non-standard features, executables, or modules, and provided that % any non-standard features, executables, or modules, and provided that
% you do at least ONE of the following: % you do at least ONE of the following:
% %
% (a) make the Modified Version available to the Copyright Holder of the % (a) make the Modified Version available to the Copyright Holder of the
% Standard Version, under the Original License, so that the Copyright % Standard Version, under the Original License, so that the Copyright
% Holder may include your modifications in the Standard Version. (b) % Holder may include your modifications in the Standard Version. (b)
@ -127,7 +127,7 @@
% %
% Distribution of Compiled Forms of the Standard Version or % Distribution of Compiled Forms of the Standard Version or
% Modified Versions without the Source % Modified Versions without the Source
% %
% (5) You may Distribute Compiled forms of the Standard Version without % (5) You may Distribute Compiled forms of the Standard Version without
% the Source, provided that you include complete instructions on how to % the Source, provided that you include complete instructions on how to
% get the Source of the Standard Version. Such instructions must be % get the Source of the Standard Version. Such instructions must be
@ -138,13 +138,13 @@
% within thirty days after you become aware that the instructions are % within thirty days after you become aware that the instructions are
% invalid, then you do not forfeit any of your rights under this % invalid, then you do not forfeit any of your rights under this
% license. % license.
% %
% (6) You may Distribute a Modified Version in Compiled form without the % (6) You may Distribute a Modified Version in Compiled form without the
% Source, provided that you comply with Section 4 with respect to the % Source, provided that you comply with Section 4 with respect to the
% Source of the Modified Version. % Source of the Modified Version.
% %
% Aggregating or Linking the Package % Aggregating or Linking the Package
% %
% (7) You may aggregate the Package (either the Standard Version or % (7) You may aggregate the Package (either the Standard Version or
% Modified Version) with other packages and Distribute the resulting % Modified Version) with other packages and Distribute the resulting
% aggregation provided that you do not charge a licensing fee for the % aggregation provided that you do not charge a licensing fee for the
@ -152,7 +152,7 @@
% components in the aggregation are permitted. The terms of this license % components in the aggregation are permitted. The terms of this license
% apply to the use and Distribution of the Standard or Modified Versions % apply to the use and Distribution of the Standard or Modified Versions
% as included in the aggregation. % as included in the aggregation.
% %
% (8) You are permitted to link Modified and Standard Versions with % (8) You are permitted to link Modified and Standard Versions with
% other works, to embed the Package in a larger work of your own, or to % other works, to embed the Package in a larger work of your own, or to
% build stand-alone binary or bytecode versions of applications that % build stand-alone binary or bytecode versions of applications that
@ -160,7 +160,7 @@
% provided the result does not expose a direct interface to the Package. % provided the result does not expose a direct interface to the Package.
% %
% Items That are Not Considered Part of a Modified Version % Items That are Not Considered Part of a Modified Version
% %
% (9) Works (including, but not limited to, modules and scripts) that % (9) Works (including, but not limited to, modules and scripts) that
% merely extend or make use of the Package, do not, by themselves, cause % merely extend or make use of the Package, do not, by themselves, cause
% the Package to be a Modified Version. In addition, such works are not % the Package to be a Modified Version. In addition, such works are not
@ -168,21 +168,21 @@
% terms of this license. % terms of this license.
% %
% General Provisions % General Provisions
% %
% (10) Any use, modification, and distribution of the Standard or % (10) Any use, modification, and distribution of the Standard or
% Modified Versions is governed by this Artistic License. By using, % Modified Versions is governed by this Artistic License. By using,
% modifying or distributing the Package, you accept this license. Do not % modifying or distributing the Package, you accept this license. Do not
% use, modify, or distribute the Package, if you do not accept this % use, modify, or distribute the Package, if you do not accept this
% license. % license.
% %
% (11) If your Modified Version has been derived from a Modified Version % (11) If your Modified Version has been derived from a Modified Version
% made by someone other than you, you are nevertheless required to % made by someone other than you, you are nevertheless required to
% ensure that your Modified Version complies with the requirements of % ensure that your Modified Version complies with the requirements of
% this license. % this license.
% %
% (12) This license does not grant you the right to use any trademark, % (12) This license does not grant you the right to use any trademark,
% service mark, tradename, or logo of the Copyright Holder. % service mark, tradename, or logo of the Copyright Holder.
% %
% (13) This license includes the non-exclusive, worldwide, % (13) This license includes the non-exclusive, worldwide,
% free-of-charge patent license to make, have made, use, offer to sell, % free-of-charge patent license to make, have made, use, offer to sell,
% sell, import and otherwise transfer the Package with respect to any % sell, import and otherwise transfer the Package with respect to any
@ -192,7 +192,7 @@
% that the Package constitutes direct or contributory patent % that the Package constitutes direct or contributory patent
% infringement, then this Artistic License to you shall terminate on the % infringement, then this Artistic License to you shall terminate on the
% date that such litigation is filed. % date that such litigation is filed.
% %
% (14) Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT % (14) Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT
% HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED % HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED
% WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A % WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
@ -308,7 +308,7 @@ check_examples :-
throw(error(examples)) throw(error(examples))
); true ); true
), ),
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Check example probabilities % Check example probabilities
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@ -342,7 +342,7 @@ check_examples :-
user:example(ID,QueryB,_,_), user:example(ID,QueryB,_,_),
QueryA \= QueryB QueryA \= QueryB
) ; ) ;
( (
user:test_example(ID,QueryA,_,_), user:test_example(ID,QueryA,_,_),
user:test_example(ID,QueryB,_,_), user:test_example(ID,QueryB,_,_),
@ -362,7 +362,7 @@ check_examples :-
); true ); true
). ).
%======================================================================== %========================================================================
%= %=
%======================================================================== %========================================================================
reset_learning :- reset_learning :-
@ -413,7 +413,7 @@ do_learning_intern(Iterations,Epsilon) :-
NextIteration is CurrentIteration+1, NextIteration is CurrentIteration+1,
assertz(current_iteration(NextIteration)), assertz(current_iteration(NextIteration)),
EndIteration is CurrentIteration+Iterations-1, EndIteration is CurrentIteration+Iterations-1,
format_learning(1,'~nIteration ~d of ~d~n',[CurrentIteration,EndIteration]), format_learning(1,'~nIteration ~d of ~d~n',[CurrentIteration,EndIteration]),
logger_set_variable(iteration,CurrentIteration), logger_set_variable(iteration,CurrentIteration),
logger_start_timer(duration), logger_start_timer(duration),
@ -422,7 +422,7 @@ do_learning_intern(Iterations,Epsilon) :-
gradient_descent, gradient_descent,
problog_flag(log_frequency,Log_Frequency), problog_flag(log_frequency,Log_Frequency),
( (
( Log_Frequency>0, 0 =:= CurrentIteration mod Log_Frequency) ( Log_Frequency>0, 0 =:= CurrentIteration mod Log_Frequency)
-> ->
@ -431,7 +431,7 @@ do_learning_intern(Iterations,Epsilon) :-
), ),
% update_values, % update_values,
( (
last_mse(Last_MSE) last_mse(Last_MSE)
-> ->
@ -443,7 +443,7 @@ do_learning_intern(Iterations,Epsilon) :-
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
) )
), ),
@ -463,7 +463,7 @@ do_learning_intern(Iterations,Epsilon) :-
!, !,
logger_stop_timer(duration), logger_stop_timer(duration),
logger_write_data, logger_write_data,
@ -489,17 +489,17 @@ init_learning :-
!. !.
init_learning :- init_learning :-
check_examples, check_examples,
% empty_output_directory, % empty_output_directory,
logger_write_header, logger_write_header,
format_learning(1,'Initializing everything~n',[]), format_learning(1,'Initializing everything~n',[]),
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Check, if continuous facts are used. % Check, if continuous facts are used.
% if yes, switch to problog_exact % if yes, switch to problog_exact
% continuous facts are not supported yet. % continuous facts are not supported yet.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
set_default_gradient_method, set_default_gradient_method,
@ -536,7 +536,7 @@ init_learning :-
format_learning(3,'~q training examples~n',[TrainingExampleCount]), format_learning(3,'~q training examples~n',[TrainingExampleCount]),
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% build BDD script for every example % build BDD script for every example
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@ -560,7 +560,7 @@ empty_bdd_directory.
set_default_gradient_method :- set_default_gradient_method :-
problog_flag(continuous_facts, true), problog_flag(continuous_facts, true),
!, !,
problog_flag(init_method,OldMethod), problog_flag(init_method,OldMethod),
format_learning(2,'Theory uses continuous facts.~nWill use problog_exact/3 as initalization method.~2n',[]), format_learning(2,'Theory uses continuous facts.~nWill use problog_exact/3 as initalization method.~2n',[]),
@ -612,12 +612,12 @@ init_one_query(QueryID,Query,Type) :-
-> ->
rb_new(H0), rb_new(H0),
maplist_to_hash(MapList, H0, Hash), maplist_to_hash(MapList, H0, Hash),
Tree \= [],
tree_to_grad(Tree, Hash, [], Grad) tree_to_grad(Tree, Hash, [], Grad)
; % ;
Bdd = bdd(-1,[],[]), % Bdd = bdd(-1,[],[]),
Grad=[] % Grad=[]
), ),
write('.'),
recordz(QueryID,bdd(Dir, Grad, MapList),_) recordz(QueryID,bdd(Dir, Grad, MapList),_)
; ;
problog_flag(init_method,(Query,NOf,Bdd,problog_kbest_as_bdd(Call,NOf,Bdd))) -> problog_flag(init_method,(Query,NOf,Bdd,problog_kbest_as_bdd(Call,NOf,Bdd))) ->
@ -682,7 +682,7 @@ node_to_gradient_node(pn(P-G,X,L,R), H, gnoden(P,G,X,Id,PL,GL,PR,GR)) :-
rb_lookup(X,Id,H), rb_lookup(X,Id,H),
(L == 1 -> GL=0, PL=1 ; L == 0 -> GL = 0, PL=0 ; L = PL-GL), (L == 1 -> GL=0, PL=1 ; L == 0 -> GL = 0, PL=0 ; L = PL-GL),
(R == 1 -> GR=0, PR=1 ; R == 0 -> GR = 0, PR=0 ; R = PR-GR). (R == 1 -> GR=0, PR=1 ; R == 0 -> GR = 0, PR=0 ; R = PR-GR).
run_sp([], _, P0, P0). run_sp([], _, P0, P0).
run_sp(gnodep(P,_G, EP, _Id, PL, _GL, PR, _GR).Tree, Slope, _, PF) :- run_sp(gnodep(P,_G, EP, _Id, PL, _GL, PR, _GR).Tree, Slope, _, PF) :-
P is EP*PL+ (1.0-EP)*PR, P is EP*PL+ (1.0-EP)*PR,
@ -793,7 +793,7 @@ mse_testset :-
format(Handle,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%~n",[]), format(Handle,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%~n",[]),
format(Handle,"% Iteration, train/test, QueryID, Query, GroundTruth, Prediction %~n",[]), format(Handle,"% Iteration, train/test, QueryID, Query, GroundTruth, Prediction %~n",[]),
format(Handle,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%~n",[]), format(Handle,"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%~n",[]),
format_learning(2,'MSE_Test ',[]), format_learning(2,'MSE_Test ',[]),
update_values, update_values,
bb_put(llh_test_queries,0.0), bb_put(llh_test_queries,0.0),
@ -888,10 +888,8 @@ gradient_descent :-
N1 is N-1, N1 is N-1,
forall(tunable_fact(FactID,GroundTruth), (X[FactID] <== 0.5)), forall(tunable_fact(FactID,GroundTruth), (X[FactID] <== 0.5)),
problog_flag(sigmoid_slope,Slope), problog_flag(sigmoid_slope,Slope),
lbfgs_run(Solver,BestFA), lbfgs_run(Solver,BestF),
BestF <== BestFA[0], format('~2nOptimization done~nWe found a minimum ~4f.~n',[BestF]),
format('~2nOptimization done~nWe found a minimum ~4f
.~2n',[BestF]),
forall(tunable_fact(FactID,GroundTruth), set_tunable(FactID,GroundTruth,X)), forall(tunable_fact(FactID,GroundTruth), set_tunable(FactID,GroundTruth,X)),
lbfgs_finalize(Solver). lbfgs_finalize(Solver).
@ -917,9 +915,12 @@ bind_maplist([Node-Theta|MapList], Slope, X) :-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% start calculate gradient % start calculate gradient
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
user:evaluate(L, X,Grad,N,_,_) :- user:evaluate(L, X0,Grad,N,_,_) :-
Handle = user_error, Handle = user_error,
problog_flag(sigmoid_slope,Slope), 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, %<== array[N] of floats,
N1 is N-1, N1 is N-1,
forall(between(0,N1,I), forall(between(0,N1,I),
@ -931,7 +932,7 @@ user:evaluate(L, X,Grad,N,_,_) :-
), ),
sum_list(LLs,LLH_Training_Queries), sum_list(LLs,LLH_Training_Queries),
forall(tunable_fact(FactID,GroundTruth), (Z<==X[FactID],W<==Grad[FactID])), forall(tunable_fact(FactID,GroundTruth), (Z<==X[FactID],W<==Grad[FactID])),
L[0] <== LLH_Training_Queries. L = LLH_Training_Queries.
compute_grad(N, X, Grad, Probs, Slope, Handle, LL) :- compute_grad(N, X, Grad, Probs, Slope, Handle, LL) :-
user:example(QueryID,Query,QueryProb,Type), user:example(QueryID,Query,QueryProb,Type),
@ -957,7 +958,7 @@ gradientpair(_BDD,_Slope,_BDDProb, _Grad).
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,0) :-
problog_flag(sigmoid_slope,Slope), problog_flag(sigmoid_slope,Slope),
X0 <== X[0], X0 <== X[0],
X1 <== X[1], 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]). 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]).
@ -973,7 +974,7 @@ init_flags :-
problog_define_flag(output_directory, problog_flag_validate_directory, 'directory for logfiles etc', Output_Folder,learning_general,flags:learning_output_dir_handler), problog_define_flag(output_directory, problog_flag_validate_directory, 'directory for logfiles etc', Output_Folder,learning_general,flags:learning_output_dir_handler),
problog_define_flag(log_frequency, problog_flag_validate_posint, 'log results every nth iteration', 1, learning_general), problog_define_flag(log_frequency, problog_flag_validate_posint, 'log results every nth iteration', 1, learning_general),
problog_define_flag(rebuild_bdds, problog_flag_validate_nonegint, 'rebuild BDDs every nth iteration', 0, learning_general), problog_define_flag(rebuild_bdds, problog_flag_validate_nonegint, 'rebuild BDDs every nth iteration', 0, learning_general),
problog_define_flag(reuse_initialized_bdds,problog_flag_validate_boolean, 'Reuse BDDs from previous runs',false, learning_general), problog_define_flag(reuse_initialized_bdds,problog_flag_validate_boolean, 'Reuse BDDs from previous runs',false, learning_general),
problog_define_flag(check_duplicate_bdds,problog_flag_validate_boolean,'Store intermediate results in hash table',true,learning_general), problog_define_flag(check_duplicate_bdds,problog_flag_validate_boolean,'Store intermediate results in hash table',true,learning_general),
problog_define_flag(init_method,problog_flag_validate_dummy,'ProbLog predicate to search proofs',(Query,Tree,problog:problog_kbest_as_bdd(Query,100,Tree)),learning_general,flags:learning_libdd_init_handler), problog_define_flag(init_method,problog_flag_validate_dummy,'ProbLog predicate to search proofs',(Query,Tree,problog:problog_kbest_as_bdd(Query,100,Tree)),learning_general,flags:learning_libdd_init_handler),
problog_define_flag(alpha,problog_flag_validate_number,'weight of negative examples (auto=n_p/n_n)',auto,learning_general,flags:auto_handler), problog_define_flag(alpha,problog_flag_validate_number,'weight of negative examples (auto=n_p/n_n)',auto,learning_general,flags:auto_handler),
@ -1009,4 +1010,3 @@ init_logger :-
:- initialization(init_flags). :- initialization(init_flags).
:- initialization(init_logger). :- initialization(init_logger).

View File

@ -44,13 +44,11 @@ progress(FX,X,G,X_Norm,G_Norm,Step,_N,Iteration,Ls,0) :-
demo :- demo :-
format('Optimizing the function f(x0) = sin(x0)~n',[]), format('Optimizing the function f(x0) = sin(x0)~n',[]),
lbfgs_initialize(1,X,0,Solver), lbfgs_initialize(1,X,FX,Solver),
StartX is random*10, StartX is random*10,
format('We start the search at the random position x0=~5f~2n',[StartX]), format('We start the search at the random position x0=~5f~2n',[StartX]),
X[0] <== StartX, X[0] <== StartX,
lbfgs_run(Solver,BestF,Status), lbfgs_run(Solver,BestF),
BestX0 <== X[0], BestX0 <== X[0],
lbfgs_finalize(Solver), lbfgs_finalize(Solver),
format('~2nOptimization done~nWe found a minimum at format('~2nOptimization done~nWe found a minimum at

View File

@ -71,7 +71,7 @@ if you port it to another system, ... please send me an email.
### Usage</h2> ### Usage</h2>
The module lbfgs provides the following predicates after you loaded The module lbfgs provides the following predicates after you loaded
it by it by
~~~~ ~~~~
:-use_module(library(lbfgs)). :-use_module(library(lbfgs)).
~~~~ ~~~~
@ -119,7 +119,7 @@ demo :-
StartX is random*10, StartX is random*10,
format('We start the search at the random position x0=~5f~2n',[StartX]), format('We start the search at the random position x0=~5f~2n',[StartX]),
X[0] <== StartX, X[0] <== StartX,
lbfgs_run(Solver,BestF,Status), lbfgs_run(Solver,BestF,Status),
BestX0 <== X[0], BestX0 <== X[0],
lbfgs_finalize(Solver), lbfgs_finalize(Solver),
@ -151,7 +151,6 @@ yes
@{ @{
*/ */
:- dynamic initialized/0.
:- load_foreign_files(['libLBFGS'],[],'init_lbfgs_predicates'). :- load_foreign_files(['libLBFGS'],[],'init_lbfgs_predicates').
@ -178,17 +177,15 @@ lbfgs_initialize(N,X,U,t(N,X,U,Params)) :-
lbfgs_grab(N,X). lbfgs_grab(N,X).
% install call back predicates in the user module which call % install call back predicates in the user module which call
% the predicates given by the arguments % the predicates given by the arguments
/** @pred lbfgs_finalize/0 /** @pred lbfgs_finalize/0
Clean up the memory. Clean up the memory.
*/ */
lbfgs_finalize(t(N,X,U,Params)) :- lbfgs_finalize(t(N,X,U,Params)) :-
initialized,
lbfgs_release(X) , lbfgs_release(X) ,
lbfgs_release_parameters(Params) , lbfgs_release_parameters(Params) .
retractall(initialized).
/** @pred lbfgs_run/2 /** @pred lbfgs_run/2
Do the work. Do the work.
@ -205,14 +202,14 @@ of libLBFGS</a> for the meaning of each parameter.
~~~~ ~~~~
?- lbfgs_parameters. ?- lbfgs_parameters.
========================================================================================== ==========================================================================================
Type Name Value Description Type Name Value Description
========================================================================================== ==========================================================================================
int m 6 The number of corrections to approximate the inverse hessian matrix. int m 6 The number of corrections to approximate the inverse hessian matrix.
float epsilon 1e-05 Epsilon for convergence test. float epsilon 1e-05 Epsilon for convergence test.
int past 0 Distance for delta-based convergence test. int past 0 Distance for delta-based convergence test.
float delta 1e-05 Delta for convergence test. float delta 1e-05 Delta for convergence test.
int max_iterations 0 The maximum number of iterations int max_iterations 0 The maximum number of iterations
int linesearch 0 The line search algorithm. int linesearch 0 The line search algorithm.
int max_linesearch 40 The maximum number of trials for the line search. int max_linesearch 40 The maximum number of trials for the line search.
float min_step 1e-20 The minimum step of the line search routine. float min_step 1e-20 The minimum step of the line search routine.
float max_step 1e+20 The maximum step of the line search. float max_step 1e+20 The maximum step of the line search.
@ -223,12 +220,12 @@ float orthantwise_c 0.0 Coefficient for the L1 norm of varia
int orthantwise_start 0 Start index for computing the L1 norm of the variables. int orthantwise_start 0 Start index for computing the L1 norm of the variables.
int orthantwise_end -1 End index for computing the L1 norm of the variables. int orthantwise_end -1 End index for computing the L1 norm of the variables.
========================================================================================== ==========================================================================================
~~~~ ~~~~
*/ */
lbfgs_parameters :- lbfgs_parameters :-
lbfgs_defaults(Params), lbfgs_defaults(Params),
lbfgs_parameters(t(_X,_,_,Params)). lbfgs_parameters(t(_X,_,_,Params)).
lbfgs_parameters(t(_,_,_,Params)) :- lbfgs_parameters(t(_,_,_,Params)) :-
lbfgs_get_parameter(m,M ,Params), lbfgs_get_parameter(m,M ,Params),
lbfgs_get_parameter(epsilon,Epsilon ,Params), lbfgs_get_parameter(epsilon,Epsilon ,Params),

View File

@ -1,7 +1,7 @@
#include <string.h>
#include "YapInterface.h" #include "YapInterface.h"
#include <lbfgs.h> #include <lbfgs.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
/* /*
This file is part of YAP-LBFGS. This file is part of YAP-LBFGS.
@ -21,89 +21,72 @@
along with YAP-LBFGS. If not, see <http://www.gnu.org/licenses/>. along with YAP-LBFGS. If not, see <http://www.gnu.org/licenses/>.
*/ */
// These constants describe the internal state // These constants describe the internal state
#define LBFGS_STATUS_NONE 0 #define LBFGS_STATUS_NONE 0
#define LBFGS_STATUS_INITIALIZED 1 #define LBFGS_STATUS_INITIALIZED 1
#define LBFGS_STATUS_RUNNING 2 #define LBFGS_STATUS_RUNNING 2
#define LBFGS_STATUS_CB_EVAL 3 #define LBFGS_STATUS_CB_EVAL 3
#define LBFGS_STATUS_CB_PROGRESS 4 #define LBFGS_STATUS_CB_PROGRESS 4
X_API void init_lbfgs_predicates( void ) ; X_API void init_lbfgs_predicates(void);
YAP_Functor fevaluate, fprogress, fmodule, ffloats; YAP_Functor fevaluate, fprogress, fmodule, ffloats;
YAP_Term tuser; YAP_Term tuser;
static lbfgsfloatval_t evaluate( static lbfgsfloatval_t evaluate(void *instance, const lbfgsfloatval_t *x,
void *instance, lbfgsfloatval_t *g_tmp, const int n,
const lbfgsfloatval_t *x, const lbfgsfloatval_t step) {
lbfgsfloatval_t *g_tmp,
const int n,
const lbfgsfloatval_t step
)
{
YAP_Term call; YAP_Term call;
YAP_Bool result; YAP_Bool result;
lbfgsfloatval_t rc; lbfgsfloatval_t rc;
YAP_Term v;
YAP_Term t[6], t2[2]; YAP_Term t[6], t2[2];
t[0] = YAP_MkIntTerm((YAP_Int)&rc); t[0] = v = YAP_MkVarTerm();
t[0] = YAP_MkApplTerm(ffloats, 1, t);
t[1] = YAP_MkIntTerm((YAP_Int)x); t[1] = YAP_MkIntTerm((YAP_Int)x);
t[1] = YAP_MkApplTerm(ffloats, 1, t+1); t[1] = YAP_MkApplTerm(ffloats, 1, t + 1);
t[2] = YAP_MkIntTerm((YAP_Int)g_tmp); t[2] = YAP_MkIntTerm((YAP_Int)g_tmp);
t[2] = YAP_MkApplTerm(ffloats, 1, t+2); t[2] = YAP_MkApplTerm(ffloats, 1, t + 2);
t[3] = YAP_MkIntTerm(n); t[3] = YAP_MkIntTerm(n);
t[4] = YAP_MkFloatTerm(step); t[4] = YAP_MkFloatTerm(step);
t[5] = YAP_MkIntTerm((YAP_Int)instance); t[5] = YAP_MkIntTerm((YAP_Int)instance);
t2[0] = tuser; t2[0] = tuser;
t2[1] = YAP_MkApplTerm(fevaluate, 6, t); t2[1] = YAP_MkApplTerm(fevaluate, 6, t);
call = YAP_MkApplTerm(fmodule, 2, t2);
call = YAP_MkApplTerm( fmodule, 2, t2 ); int sl = YAP_InitSlot(v);
// lbfgs_status=LBFGS_STATUS_CB_EVAL;
result = YAP_RunGoalOnce(call);
// lbfgs_status=LBFGS_STATUS_RUNNING;
if (result == FALSE) {
// s1 = YAP_InitSlot(v);
//lbfgs_status=LBFGS_STATUS_CB_EVAL;
result=YAP_RunGoalOnce(call);
//lbfgs_status=LBFGS_STATUS_RUNNING;
if (result==FALSE) {
printf("ERROR: the evaluate call failed in YAP.\n"); printf("ERROR: the evaluate call failed in YAP.\n");
// Goal did not succeed // Goal did not succeed
return FALSE; return FALSE;
} }
rc = YAP_FloatOfTerm(YAP_GetFromSlot(sl));
YAP_RecoverSlots(1, sl);
return rc; return rc;
} }
static int progress( static int progress(void *instance, const lbfgsfloatval_t *local_x,
void *instance, const lbfgsfloatval_t *local_g,
const lbfgsfloatval_t *local_x,
const lbfgsfloatval_t *local_g,
const lbfgsfloatval_t fx, const lbfgsfloatval_t fx, const lbfgsfloatval_t xnorm,
const lbfgsfloatval_t xnorm, const lbfgsfloatval_t gnorm, const lbfgsfloatval_t step,
const lbfgsfloatval_t gnorm, int n, int k, int ls) {
const lbfgsfloatval_t step,
int n,
int k,
int ls
)
{
YAP_Term call; YAP_Term call;
YAP_Bool result; YAP_Bool result;
YAP_Int s1; YAP_Int s1;
YAP_Term t[10],t2[2], v; YAP_Term t[10], t2[2], v;
t[0] = YAP_MkFloatTerm(fx); t[0] = YAP_MkFloatTerm(fx);
t[1] = YAP_MkIntTerm((YAP_Int)local_x); t[1] = YAP_MkIntTerm((YAP_Int)local_x);
t[1] = YAP_MkApplTerm(ffloats, 1, t+1); t[1] = YAP_MkApplTerm(ffloats, 1, t + 1);
t[2] = YAP_MkIntTerm((YAP_Int)local_g); t[2] = YAP_MkIntTerm((YAP_Int)local_g);
t[2] = YAP_MkApplTerm(ffloats, 1, t+2); t[2] = YAP_MkApplTerm(ffloats, 1, t + 2);
t[3] = YAP_MkFloatTerm(xnorm); t[3] = YAP_MkFloatTerm(xnorm);
t[4] = YAP_MkFloatTerm(gnorm); t[4] = YAP_MkFloatTerm(gnorm);
t[5] = YAP_MkFloatTerm(step); t[5] = YAP_MkFloatTerm(step);
@ -113,29 +96,30 @@ static int progress(
t[9] = v = YAP_MkVarTerm(); t[9] = v = YAP_MkVarTerm();
t2[0] = tuser; t2[0] = tuser;
t2[1] = YAP_MkApplTerm( fprogress, 10, t); t2[1] = YAP_MkApplTerm(fprogress, 10, t);
call = YAP_MkApplTerm( fmodule, 2, t2 ); call = YAP_MkApplTerm(fmodule, 2, t2);
s1 = YAP_InitSlot(v); s1 = YAP_InitSlot(v);
//lbfgs_status=LBFGS_STATUS_CB_PROGRESS; // lbfgs_status=LBFGS_STATUS_CB_PROGRESS;
result=YAP_RunGoalOnce(call); result = YAP_RunGoalOnce(call);
//lbfgs_status=LBFGS_STATUS_RUNNING; // lbfgs_status=LBFGS_STATUS_RUNNING;
YAP_Term o = YAP_GetFromSlot( s1 ); YAP_Term o = YAP_GetFromSlot(s1);
if (result==FALSE) { if (result == FALSE) {
printf("ERROR: the progress call failed in YAP.\n"); printf("ERROR: the progress call failed in YAP.\n");
// Goal did not succeed // Goal did not succeed
return -1; return -1;
} }
if (YAP_IsIntTerm(o)) { if (YAP_IsIntTerm(o)) {
int v = YAP_IntOfTerm(o); int v = YAP_IntOfTerm(o);
return (int)v; return (int)v;
} }
fprintf(stderr, "ERROR: The progress call back function did not return an integer as last argument\n"); fprintf(stderr, "ERROR: The progress call back function did not return an "
"integer as last argument\n");
return 1; return 1;
} }
@ -190,424 +174,405 @@ value will terminate the optimization process.
* @Arg[X0]: user data * @Arg[X0]: user data
* @Arg[FX]: status * @Arg[FX]: status
*/ */
static YAP_Bool p_lbfgs(void) static YAP_Bool p_lbfgs(void) {
{ YAP_Term t1 = YAP_ARG1, t;
YAP_Term t1 = YAP_ARG1; int n, sl;
int n;
lbfgsfloatval_t *x; lbfgsfloatval_t *x;
lbfgsfloatval_t fx; lbfgsfloatval_t fx;
if (! YAP_IsIntTerm(t1)) { if (!YAP_IsIntTerm(t1)) {
return false; return false;
} }
n=YAP_IntOfTerm(t1); n = YAP_IntOfTerm(t1);
if (n<1) { if (n < 1) {
return FALSE; return FALSE;
} }
x = ( lbfgsfloatval_t*) YAP_IntOfTerm(YAP_ArgOfTerm(1,YAP_ARG2)); sl = YAP_InitSlot(YAP_ARG6);
lbfgs_parameter_t* param = ( lbfgs_parameter_t*) YAP_IntOfTerm(YAP_ARG3);
void* ui = ( void*) YAP_IntOfTerm(YAP_ARG4); x = (lbfgsfloatval_t *)YAP_IntOfTerm(YAP_ArgOfTerm(1, YAP_ARG2));
{ lbfgs_parameter_t *param = (lbfgs_parameter_t *)YAP_IntOfTerm(YAP_ARG3);
YAP_Term t = YAP_MkIntTerm((YAP_Int)&fx); void *ui = (void *)YAP_IntOfTerm(YAP_ARG4);
if (!YAP_Unify(YAP_ARG5,YAP_MkApplTerm(ffloats,1,&t))) int ret = lbfgs(n, x, &fx, evaluate, progress, ui, param);
return false; t = YAP_GetFromSlot(sl);
} YAP_Unify(t, YAP_MkFloatTerm(fx));
signal(SIGFPE, SIG_IGN); YAP_RecoverSlots(1, sl);
int ret = lbfgs(n, x, &fx, evaluate, progress, ui, param); if (ret == 0)
if (ret == 0) return true;
return true; const char *s;
const char *s; switch (ret) {
switch(ret) { case LBFGS_CONVERGENCE:
case LBFGS_CONVERGENCE: case LBFGS_STOP:
case LBFGS_STOP: return true;
return true;
/** The initial variables already minimize the objective function. */ /** The initial variables already minimize the objective function. */
case LBFGS_ALREADY_MINIMIZED: case LBFGS_ALREADY_MINIMIZED:
s = "The initial variables already minimize the objective function."; s = "The initial variables already minimize the objective function.";
break;
case LBFGSERR_UNKNOWNERROR:
s = "Unknownerror";
break;
case LBFGSERR_LOGICERROR:
s = "logic error.";
break;
case LBFGSERR_OUTOFMEMORY:
s = "out of memory";
break;
case LBFGSERR_CANCELED:
s = "canceled.";
break;
case LBFGSERR_INVALID_N:
s = "Invalid number of variables specified.";
break;
case LBFGSERR_INVALID_N_SSE:
s = "Invalid number of variables (for SSE) specified.";
break;
case LBFGSERR_INVALID_X_SSE:
s = "The array x must be aligned to 16 (for SSE).";
break;
case LBFGSERR_INVALID_EPSILON:
s = "Invalid parameter lbfgs_parameter_t::epsilon specified.";
break;
case LBFGSERR_INVALID_TESTPERIOD:
s = "Invalid parameter lbfgs_parameter_t::past specified.";
break;
case LBFGSERR_INVALID_DELTA:
s = "Invalid parameter lbfgs_parameter_t::delta specified.";
break;
case LBFGSERR_INVALID_LINESEARCH:
s = "Invalid parameter lbfgs_parameter_t::linesearch specified.";
break;
case LBFGSERR_INVALID_MINSTEP:
s = "Invalid parameter lbfgs_parameter_t::max_step specified.";
break;
case LBFGSERR_INVALID_MAXSTEP:
s = "Invalid parameter lbfgs_parameter_t::max_step specified.";
break;
case LBFGSERR_INVALID_FTOL:
s = "Invalid parameter lbfgs_parameter_t::ftol specified.";
break;
case LBFGSERR_INVALID_WOLFE:
s = "Invalid parameter lbfgs_parameter_t::wolfe specified.";
break;
case LBFGSERR_INVALID_GTOL:
s = "Invalid parameter lbfgs_parameter_t::gtol specified.";
break;
case LBFGSERR_INVALID_XTOL:
s = "Invalid parameter lbfgs_parameter_t::xtol specified.";
break;
case LBFGSERR_INVALID_MAXLINESEARCH:
s = "Invalid parameter lbfgs_parameter_t::max_linesearch specified.";
break;
case LBFGSERR_INVALID_ORTHANTWISE:
s = "Invalid parameter lbfgs_parameter_t::orthantwise_c specified.";
break;
case LBFGSERR_INVALID_ORTHANTWISE_START:
s = "Invalid parameter lbfgs_parameter_t::orthantwise_start specified.";
break;
case LBFGSERR_INVALID_ORTHANTWISE_END:
s = "Invalid parameter lbfgs_parameter_t::orthantwise_end specified.";
break;
case LBFGSERR_OUTOFINTERVAL:
s = "The line-search step went out of the interval of uncertainty.";
break;
case LBFGSERR_INCORRECT_TMINMAX:
s = "A logic error occurred; alternatively, the interval of uncertaity became too small.";
break;
case LBFGSERR_ROUNDING_ERROR:
s = "A rounding error occurred; alternatively, no line-search s";
break;
case LBFGSERR_MINIMUMSTEP:
s = "The line-search step became smaller than lbfgs_parameter_t::min_step.";
break;
case LBFGSERR_MAXIMUMSTEP:
s = "The line-search step became larger than lbfgs_parameter_t::max_step.";
break;
case LBFGSERR_MAXIMUMLINESEARCH:
s = "The line-search routine reaches the maximum number of evaluations.";
break;
case LBFGSERR_MAXIMUMITERATION:
s = "The algorithm routine reaches the maximum number of iterations lbfgs_parameter_t::xtol.";
break; break;
case LBFGSERR_WIDTHTOOSMALL: case LBFGSERR_UNKNOWNERROR:
s = "Unknownerror";
break;
case LBFGSERR_LOGICERROR:
s = "logic error.";
break;
case LBFGSERR_OUTOFMEMORY:
s = "out of memory";
break;
case LBFGSERR_CANCELED:
s = "canceled.";
break;
case LBFGSERR_INVALID_N:
s = "Invalid number of variables specified.";
break;
case LBFGSERR_INVALID_N_SSE:
s = "Invalid number of variables (for SSE) specified.";
break;
case LBFGSERR_INVALID_X_SSE:
s = "The array x must be aligned to 16 (for SSE).";
break;
case LBFGSERR_INVALID_EPSILON:
s = "Invalid parameter lbfgs_parameter_t::epsilon specified.";
break;
case LBFGSERR_INVALID_TESTPERIOD:
s = "Invalid parameter lbfgs_parameter_t::past specified.";
break;
case LBFGSERR_INVALID_DELTA:
s = "Invalid parameter lbfgs_parameter_t::delta specified.";
break;
case LBFGSERR_INVALID_LINESEARCH:
s = "Invalid parameter lbfgs_parameter_t::linesearch specified.";
break;
case LBFGSERR_INVALID_MINSTEP:
s = "Invalid parameter lbfgs_parameter_t::max_step specified.";
break;
case LBFGSERR_INVALID_MAXSTEP:
s = "Invalid parameter lbfgs_parameter_t::max_step specified.";
break;
case LBFGSERR_INVALID_FTOL:
s = "Invalid parameter lbfgs_parameter_t::ftol specified.";
break;
case LBFGSERR_INVALID_WOLFE:
s = "Invalid parameter lbfgs_parameter_t::wolfe specified.";
break;
case LBFGSERR_INVALID_GTOL:
s = "Invalid parameter lbfgs_parameter_t::gtol specified.";
break;
case LBFGSERR_INVALID_XTOL:
s = "Invalid parameter lbfgs_parameter_t::xtol specified.";
break;
case LBFGSERR_INVALID_MAXLINESEARCH:
s = "Invalid parameter lbfgs_parameter_t::max_linesearch specified.";
break;
case LBFGSERR_INVALID_ORTHANTWISE:
s = "Invalid parameter lbfgs_parameter_t::orthantwise_c specified.";
break;
case LBFGSERR_INVALID_ORTHANTWISE_START:
s = "Invalid parameter lbfgs_parameter_t::orthantwise_start specified.";
break;
case LBFGSERR_INVALID_ORTHANTWISE_END:
s = "Invalid parameter lbfgs_parameter_t::orthantwise_end specified.";
break;
case LBFGSERR_OUTOFINTERVAL:
s = "The line-search step went out of the interval of uncertainty.";
break;
case LBFGSERR_INCORRECT_TMINMAX:
s = "A logic error occurred; alternatively, the interval of uncertaity "
"became too small.";
break;
case LBFGSERR_ROUNDING_ERROR:
s = "A rounding error occurred; alternatively, no line-search s";
break;
case LBFGSERR_MINIMUMSTEP:
s = "The line-search step became smaller than lbfgs_parameter_t::min_step.";
break;
case LBFGSERR_MAXIMUMSTEP:
s = "The line-search step became larger than lbfgs_parameter_t::max_step.";
break;
case LBFGSERR_MAXIMUMLINESEARCH:
s = "The line-search routine reaches the maximum number of evaluations.";
break;
case LBFGSERR_MAXIMUMITERATION:
s = "The algorithm routine reaches the maximum number of iterations "
"lbfgs_parameter_t::xtol.";
break;
case LBFGSERR_WIDTHTOOSMALL:
s = "Relative width of the interval of uncertainty is at m"; s = "Relative width of the interval of uncertainty is at m";
break; break;
case LBFGSERR_INVALIDPARAMETERS: case LBFGSERR_INVALIDPARAMETERS:
s = "A logic error (negative line-search step) occurred."; s = "A logic error (negative line-search step) occurred.";
break; break;
}
fprintf(stderr, "optimization terminated with code %d: %s\n", ret, s);
} return true;
fprintf(stderr, "optimization terminated with code %d: %s\n", ret, s);
return true;
} }
static YAP_Bool lbfgs_grab(void) {
int n = YAP_IntOfTerm(YAP_ARG1);
if (n < 1) {
static YAP_Bool lbfgs_grab (void)
{
int n=YAP_IntOfTerm(YAP_ARG1);
if (n<1) {
return FALSE; return FALSE;
} }
lbfgsfloatval_t * x = lbfgs_malloc(n); lbfgsfloatval_t *x = lbfgs_malloc(n);
YAP_Term t = YAP_MkIntTerm((YAP_Int)x); YAP_Term t = YAP_MkIntTerm((YAP_Int)x);
return YAP_Unify(YAP_ARG2,YAP_MkApplTerm(ffloats,1,&t)); return YAP_Unify(YAP_ARG2, YAP_MkApplTerm(ffloats, 1, &t));
}
} static YAP_Bool lbfgs_parameters(void) {
lbfgs_parameter_t *x = malloc(sizeof(lbfgs_parameter_t));
lbfgs_parameter_init(x);
return YAP_Unify(YAP_ARG1, YAP_MkIntTerm((YAP_Int)x));
}
static YAP_Bool lbfgs_release_parameters(void) {
free((void *)YAP_IntOfTerm(YAP_ARG1));
return true;
}
static YAP_Bool lbfgs_release(void) {
static YAP_Bool lbfgs_parameters( void )
{
lbfgs_parameter_t *x = malloc(sizeof(lbfgs_parameter_t));
lbfgs_parameter_init(x);
return YAP_Unify(YAP_ARG1,YAP_MkIntTerm((YAP_Int)x));
}
static YAP_Bool lbfgs_release_parameters( void )
{
free((void *)YAP_IntOfTerm(YAP_ARG1));
return true;
}
static YAP_Bool lbfgs_release( void ) {
/* if (lbfgs_status == LBFGS_STATUS_NONE) { */ /* if (lbfgs_status == LBFGS_STATUS_NONE) { */
/* printf("Error: Lbfgs is not initialized.\n"); */ /* printf("Error: Lbfgs is not initialized.\n"); */
/* return FALSE; */ /* return FALSE; */
/* } */ /* } */
/* if (lbfgs_status == LBFGS_STATUS_INITIALIZED) { */ /* if (lbfgs_status == LBFGS_STATUS_INITIALIZED) { */
lbfgs_free((lbfgsfloatval_t *)YAP_IntOfTerm(YAP_ArgOfTerm(1,(YAP_ARG1)))); lbfgs_free((lbfgsfloatval_t *)YAP_IntOfTerm(YAP_ArgOfTerm(1, (YAP_ARG1))));
return TRUE; return TRUE;
/* return FALSE; */ /* return FALSE; */
} }
/** @pred lbfgs_set_parameter(+Name,+Value,+Parameters) /** @pred lbfgs_set_parameter(+Name,+Value,+Parameters)
Set the parameter Name to Value. Only possible while the lbfgs Set the parameter Name to Value. Only possible while the lbfgs
is not running. is not running.
*/ */
static YAP_Bool lbfgs_set_parameter( void ) { static YAP_Bool lbfgs_set_parameter(void) {
YAP_Term t1 = YAP_ARG1; YAP_Term t1 = YAP_ARG1;
YAP_Term t2 = YAP_ARG2; YAP_Term t2 = YAP_ARG2;
lbfgs_parameter_t *param = (lbfgs_parameter_t *) YAP_IntOfTerm(YAP_ARG3); lbfgs_parameter_t *param = (lbfgs_parameter_t *)YAP_IntOfTerm(YAP_ARG3);
/* if (lbfgs_status != LBFGS_STATUS_NONE && lbfgs_status != LBFGS_STATUS_INITIALIZED){ */ /* if (lbfgs_status != LBFGS_STATUS_NONE && lbfgs_status !=
/* printf("ERROR: Lbfgs is running right now. Please wait till it is finished.\n"); */ * LBFGS_STATUS_INITIALIZED){ */
/* printf("ERROR: Lbfgs is running right now. Please wait till it is
* finished.\n"); */
/* return FALSE; */ /* return FALSE; */
/* } */ /* } */
if (!YAP_IsAtomTerm(t1)) {
if (! YAP_IsAtomTerm(t1)) {
return FALSE; return FALSE;
} }
const char* name=YAP_AtomName(YAP_AtomOfTerm(t1)); const char *name = YAP_AtomName(YAP_AtomOfTerm(t1));
if ((strcmp(name, "m") == 0)) { if ((strcmp(name, "m") == 0)) {
if (! YAP_IsIntTerm(t2)) { if (!YAP_IsIntTerm(t2)) {
return FALSE; return FALSE;
} }
param->m = YAP_IntOfTerm(t2); param->m = YAP_IntOfTerm(t2);
} else if ((strcmp(name, "epsilon") == 0)) { } else if ((strcmp(name, "epsilon") == 0)) {
lbfgsfloatval_t v; lbfgsfloatval_t v;
if (YAP_IsFloatTerm(t2)) { if (YAP_IsFloatTerm(t2)) {
v=YAP_FloatOfTerm(t2); v = YAP_FloatOfTerm(t2);
} else if (YAP_IsIntTerm(t2)) { } else if (YAP_IsIntTerm(t2)) {
v=(lbfgsfloatval_t) YAP_IntOfTerm(t2); v = (lbfgsfloatval_t)YAP_IntOfTerm(t2);
} else { } else {
return FALSE; return FALSE;
} }
param->epsilon=v; param->epsilon = v;
} else if ((strcmp(name, "past") == 0)) { } else if ((strcmp(name, "past") == 0)) {
if (! YAP_IsIntTerm(t2)) { if (!YAP_IsIntTerm(t2)) {
return FALSE; return FALSE;
} }
param->past = YAP_IntOfTerm(t2); param->past = YAP_IntOfTerm(t2);
} else if ((strcmp(name, "delta") == 0)) { } else if ((strcmp(name, "delta") == 0)) {
lbfgsfloatval_t v; lbfgsfloatval_t v;
if (YAP_IsFloatTerm(t2)) { if (YAP_IsFloatTerm(t2)) {
v=YAP_FloatOfTerm(t2); v = YAP_FloatOfTerm(t2);
} else if (YAP_IsIntTerm(t2)) { } else if (YAP_IsIntTerm(t2)) {
v=(lbfgsfloatval_t) YAP_IntOfTerm(t2); v = (lbfgsfloatval_t)YAP_IntOfTerm(t2);
} else { } else {
return FALSE; return FALSE;
} }
param->delta=v; param->delta = v;
} else if ((strcmp(name, "max_iterations") == 0)) { } else if ((strcmp(name, "max_iterations") == 0)) {
if (! YAP_IsIntTerm(t2)) { if (!YAP_IsIntTerm(t2)) {
return FALSE; return FALSE;
} }
param->max_iterations = YAP_IntOfTerm(t2); param->max_iterations = YAP_IntOfTerm(t2);
} else if ((strcmp(name, "linesearch") == 0)) { } else if ((strcmp(name, "linesearch") == 0)) {
if (! YAP_IsIntTerm(t2)) { if (!YAP_IsIntTerm(t2)) {
return FALSE; return FALSE;
} }
param->linesearch = YAP_IntOfTerm(t2); param->linesearch = YAP_IntOfTerm(t2);
} else if ((strcmp(name, "max_linesearch") == 0)) { } else if ((strcmp(name, "max_linesearch") == 0)) {
if (! YAP_IsIntTerm(t2)) { if (!YAP_IsIntTerm(t2)) {
return FALSE; return FALSE;
} }
param->max_linesearch = YAP_IntOfTerm(t2); param->max_linesearch = YAP_IntOfTerm(t2);
} else if ((strcmp(name, "min_step") == 0)) { } else if ((strcmp(name, "min_step") == 0)) {
lbfgsfloatval_t v; lbfgsfloatval_t v;
if (YAP_IsFloatTerm(t2)) { if (YAP_IsFloatTerm(t2)) {
v=YAP_FloatOfTerm(t2); v = YAP_FloatOfTerm(t2);
} else if (YAP_IsIntTerm(t2)) { } else if (YAP_IsIntTerm(t2)) {
v=(lbfgsfloatval_t) YAP_IntOfTerm(t2); v = (lbfgsfloatval_t)YAP_IntOfTerm(t2);
} else { } else {
return FALSE; return FALSE;
} }
param->min_step=v; param->min_step = v;
} else if ((strcmp(name, "max_step") == 0)) { } else if ((strcmp(name, "max_step") == 0)) {
lbfgsfloatval_t v; lbfgsfloatval_t v;
if (YAP_IsFloatTerm(t2)) { if (YAP_IsFloatTerm(t2)) {
v=YAP_FloatOfTerm(t2); v = YAP_FloatOfTerm(t2);
} else if (YAP_IsIntTerm(t2)) { } else if (YAP_IsIntTerm(t2)) {
v=(lbfgsfloatval_t) YAP_IntOfTerm(t2); v = (lbfgsfloatval_t)YAP_IntOfTerm(t2);
} else { } else {
return FALSE; return FALSE;
} }
param->max_step=v; param->max_step = v;
} else if ((strcmp(name, "ftol") == 0)) { } else if ((strcmp(name, "ftol") == 0)) {
lbfgsfloatval_t v; lbfgsfloatval_t v;
if (YAP_IsFloatTerm(t2)) { if (YAP_IsFloatTerm(t2)) {
v=YAP_FloatOfTerm(t2); v = YAP_FloatOfTerm(t2);
} else if (YAP_IsIntTerm(t2)) { } else if (YAP_IsIntTerm(t2)) {
v=(lbfgsfloatval_t) YAP_IntOfTerm(t2); v = (lbfgsfloatval_t)YAP_IntOfTerm(t2);
} else { } else {
return FALSE; return FALSE;
} }
param->ftol=v; param->ftol = v;
} else if ((strcmp(name, "gtol") == 0)) { } else if ((strcmp(name, "gtol") == 0)) {
lbfgsfloatval_t v; lbfgsfloatval_t v;
if (YAP_IsFloatTerm(t2)) { if (YAP_IsFloatTerm(t2)) {
v=YAP_FloatOfTerm(t2); v = YAP_FloatOfTerm(t2);
} else if (YAP_IsIntTerm(t2)) { } else if (YAP_IsIntTerm(t2)) {
v=(lbfgsfloatval_t) YAP_IntOfTerm(t2); v = (lbfgsfloatval_t)YAP_IntOfTerm(t2);
} else { } else {
return FALSE; return FALSE;
} }
param->gtol=v; param->gtol = v;
} else if ((strcmp(name, "xtol") == 0)) { } else if ((strcmp(name, "xtol") == 0)) {
lbfgsfloatval_t v; lbfgsfloatval_t v;
if (YAP_IsFloatTerm(t2)) { if (YAP_IsFloatTerm(t2)) {
v=YAP_FloatOfTerm(t2); v = YAP_FloatOfTerm(t2);
} else if (YAP_IsIntTerm(t2)) { } else if (YAP_IsIntTerm(t2)) {
v=(lbfgsfloatval_t) YAP_IntOfTerm(t2); v = (lbfgsfloatval_t)YAP_IntOfTerm(t2);
} else { } else {
return FALSE; return FALSE;
} }
param->xtol=v; param->xtol = v;
} else if ((strcmp(name, "orthantwise_c") == 0)) { } else if ((strcmp(name, "orthantwise_c") == 0)) {
lbfgsfloatval_t v; lbfgsfloatval_t v;
if (YAP_IsFloatTerm(t2)) { if (YAP_IsFloatTerm(t2)) {
v=YAP_FloatOfTerm(t2); v = YAP_FloatOfTerm(t2);
} else if (YAP_IsIntTerm(t2)) { } else if (YAP_IsIntTerm(t2)) {
v=(lbfgsfloatval_t) YAP_IntOfTerm(t2); v = (lbfgsfloatval_t)YAP_IntOfTerm(t2);
} else { } else {
return FALSE; return FALSE;
} }
param->orthantwise_c=v; param->orthantwise_c = v;
} else if ((strcmp(name, "orthantwise_start") == 0)) { } else if ((strcmp(name, "orthantwise_start") == 0)) {
if (! YAP_IsIntTerm(t2)) { if (!YAP_IsIntTerm(t2)) {
return FALSE; return FALSE;
} }
param->orthantwise_start = YAP_IntOfTerm(t2); param->orthantwise_start = YAP_IntOfTerm(t2);
} else if ((strcmp(name, "orthantwise_end") == 0)) { } else if ((strcmp(name, "orthantwise_end") == 0)) {
if (! YAP_IsIntTerm(t2)) { if (!YAP_IsIntTerm(t2)) {
return FALSE; return FALSE;
} }
param->orthantwise_end = YAP_IntOfTerm(t2); param->orthantwise_end = YAP_IntOfTerm(t2);
} else { } else {
printf("ERROR: The parameter %s is unknown.\n",name); printf("ERROR: The parameter %s is unknown.\n", name);
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
} }
/** @pred lbfgs_get_parameter(+Name,-Value)</h3> /** @pred lbfgs_get_parameter(+Name,-Value)</h3>
Get the current Value for Name Get the current Value for Name
*/ */
static YAP_Bool lbfgs_get_parameter( void ) { static YAP_Bool lbfgs_get_parameter(void) {
YAP_Term t1 = YAP_ARG1; YAP_Term t1 = YAP_ARG1;
YAP_Term t2 = YAP_ARG2; YAP_Term t2 = YAP_ARG2;
lbfgs_parameter_t *param = (lbfgs_parameter_t *) YAP_IntOfTerm(YAP_ARG3); lbfgs_parameter_t *param = (lbfgs_parameter_t *)YAP_IntOfTerm(YAP_ARG3);
if (! YAP_IsAtomTerm(t1)) { if (!YAP_IsAtomTerm(t1)) {
return FALSE; return FALSE;
} }
const char* name=YAP_AtomName(YAP_AtomOfTerm(t1)); const char *name = YAP_AtomName(YAP_AtomOfTerm(t1));
if ((strcmp(name, "m") == 0)) { if ((strcmp(name, "m") == 0)) {
return YAP_Unify(t2,YAP_MkIntTerm(param->m)); return YAP_Unify(t2, YAP_MkIntTerm(param->m));
} else if ((strcmp(name, "epsilon") == 0)) { } else if ((strcmp(name, "epsilon") == 0)) {
return YAP_Unify(t2,YAP_MkFloatTerm(param->epsilon)); return YAP_Unify(t2, YAP_MkFloatTerm(param->epsilon));
} else if ((strcmp(name, "past") == 0)) { } else if ((strcmp(name, "past") == 0)) {
return YAP_Unify(t2,YAP_MkIntTerm(param->past)); return YAP_Unify(t2, YAP_MkIntTerm(param->past));
} else if ((strcmp(name, "delta") == 0)) { } else if ((strcmp(name, "delta") == 0)) {
return YAP_Unify(t2,YAP_MkFloatTerm(param->delta)); return YAP_Unify(t2, YAP_MkFloatTerm(param->delta));
} else if ((strcmp(name, "max_iterations") == 0)) { } else if ((strcmp(name, "max_iterations") == 0)) {
return YAP_Unify(t2,YAP_MkIntTerm(param->max_iterations)); return YAP_Unify(t2, YAP_MkIntTerm(param->max_iterations));
} else if ((strcmp(name, "linesearch") == 0)) { } else if ((strcmp(name, "linesearch") == 0)) {
return YAP_Unify(t2,YAP_MkIntTerm(param->linesearch)); return YAP_Unify(t2, YAP_MkIntTerm(param->linesearch));
} else if ((strcmp(name, "max_linesearch") == 0)) { } else if ((strcmp(name, "max_linesearch") == 0)) {
return YAP_Unify(t2,YAP_MkIntTerm(param->max_linesearch)); return YAP_Unify(t2, YAP_MkIntTerm(param->max_linesearch));
} else if ((strcmp(name, "min_step") == 0)) { } else if ((strcmp(name, "min_step") == 0)) {
return YAP_Unify(t2,YAP_MkFloatTerm(param->min_step)); return YAP_Unify(t2, YAP_MkFloatTerm(param->min_step));
} else if ((strcmp(name, "max_step") == 0)) { } else if ((strcmp(name, "max_step") == 0)) {
return YAP_Unify(t2,YAP_MkFloatTerm(param->max_step)); return YAP_Unify(t2, YAP_MkFloatTerm(param->max_step));
} else if ((strcmp(name, "ftol") == 0)) { } else if ((strcmp(name, "ftol") == 0)) {
return YAP_Unify(t2,YAP_MkFloatTerm(param->ftol)); return YAP_Unify(t2, YAP_MkFloatTerm(param->ftol));
} else if ((strcmp(name, "gtol") == 0)) { } else if ((strcmp(name, "gtol") == 0)) {
return YAP_Unify(t2,YAP_MkFloatTerm(param->gtol)); return YAP_Unify(t2, YAP_MkFloatTerm(param->gtol));
} else if ((strcmp(name, "xtol") == 0)) { } else if ((strcmp(name, "xtol") == 0)) {
return YAP_Unify(t2,YAP_MkFloatTerm(param->xtol)); return YAP_Unify(t2, YAP_MkFloatTerm(param->xtol));
} else if ((strcmp(name, "orthantwise_c") == 0)) { } else if ((strcmp(name, "orthantwise_c") == 0)) {
return YAP_Unify(t2,YAP_MkFloatTerm(param->orthantwise_c)); return YAP_Unify(t2, YAP_MkFloatTerm(param->orthantwise_c));
} else if ((strcmp(name, "orthantwise_start") == 0)) { } else if ((strcmp(name, "orthantwise_start") == 0)) {
return YAP_Unify(t2,YAP_MkIntTerm(param->orthantwise_start)); return YAP_Unify(t2, YAP_MkIntTerm(param->orthantwise_start));
} else if ((strcmp(name, "orthantwise_end") == 0)) { } else if ((strcmp(name, "orthantwise_end") == 0)) {
return YAP_Unify(t2,YAP_MkIntTerm(param->orthantwise_end)); return YAP_Unify(t2, YAP_MkIntTerm(param->orthantwise_end));
} }
printf("ERROR: The parameter %s is unknown.\n",name); printf("ERROR: The parameter %s is unknown.\n", name);
return false; return false;
} }
X_API void init_lbfgs_predicates(void) {
X_API void init_lbfgs_predicates( void )
{
fevaluate = YAP_MkFunctor(YAP_LookupAtom("evaluate"), 6); fevaluate = YAP_MkFunctor(YAP_LookupAtom("evaluate"), 6);
fprogress = YAP_MkFunctor(YAP_LookupAtom("progress"), 10); fprogress = YAP_MkFunctor(YAP_LookupAtom("progress"), 10);
fmodule = YAP_MkFunctor(YAP_LookupAtom(":"), 2); fmodule = YAP_MkFunctor(YAP_LookupAtom(":"), 2);
ffloats = YAP_MkFunctor(YAP_LookupAtom("floats"), 1); ffloats = YAP_MkFunctor(YAP_LookupAtom("floats"), 1);
tuser = YAP_MkAtomTerm(YAP_LookupAtom("user")); tuser = YAP_MkAtomTerm(YAP_LookupAtom("user"));
//Initialize the parameters for the L-BFGS optimization. // Initialize the parameters for the L-BFGS optimization.
// lbfgs_parameter_init(&param); // lbfgs_parameter_init(&param);
YAP_UserCPredicate("lbfgs_grab", lbfgs_grab, 2);
YAP_UserCPredicate("lbfgs", p_lbfgs, 5);
YAP_UserCPredicate("lbfgs_release", lbfgs_release, 1);
YAP_UserCPredicate("lbfgs_grab",lbfgs_grab,2); YAP_UserCPredicate("lbfgs_defaults", lbfgs_parameters, 1);
YAP_UserCPredicate("lbfgs",p_lbfgs, 5); YAP_UserCPredicate("lbfgs_release_parameters", lbfgs_release_parameters, 1);
YAP_UserCPredicate("lbfgs_release",lbfgs_release,1); YAP_UserCPredicate("lbfgs_set_parameter", lbfgs_set_parameter, 3);
YAP_UserCPredicate("lbfgs_get_parameter", lbfgs_get_parameter, 3);
YAP_UserCPredicate("lbfgs_defaults",lbfgs_parameters,1);
YAP_UserCPredicate("lbfgs_release_parameters",lbfgs_release_parameters,1);
YAP_UserCPredicate("lbfgs_set_parameter",lbfgs_set_parameter,3);
YAP_UserCPredicate("lbfgs_get_parameter",lbfgs_get_parameter,3);
} }