This commit is contained in:
commit
92181e534e
2
C/exec.c
2
C/exec.c
@ -980,7 +980,7 @@ static bool watch_retry(Term d0 USES_REGS) {
|
|||||||
|
|
||||||
while (B->cp_ap->opc == FAIL_OPCODE)
|
while (B->cp_ap->opc == FAIL_OPCODE)
|
||||||
B = B->cp_b;
|
B = B->cp_b;
|
||||||
|
ASP = (CELL *) PROTECT_FROZEN_B(B);
|
||||||
// just do the frrpest
|
// just do the frrpest
|
||||||
if (B >= B0 && !ex_mode && !active)
|
if (B >= B0 && !ex_mode && !active)
|
||||||
return true;
|
return true;
|
||||||
|
@ -215,10 +215,7 @@ failloop:
|
|||||||
}
|
}
|
||||||
/* pointer to code space */
|
/* pointer to code space */
|
||||||
/* or updatable variable */
|
/* or updatable variable */
|
||||||
#if defined(TERM_EXTENSIONS) || defined(FROZEN_STACKS) || \
|
|
||||||
defined(MULTI_ASSIGNMENT_VARIABLES)
|
|
||||||
if (IsPairTerm(d1))
|
if (IsPairTerm(d1))
|
||||||
#endif /* TERM_EXTENSIONS || FROZEN_STACKS || MULTI_ASSIGNMENT_VARIABLES */
|
|
||||||
{
|
{
|
||||||
register CELL flags;
|
register CELL flags;
|
||||||
CELL *pt1 = RepPair(d1);
|
CELL *pt1 = RepPair(d1);
|
||||||
@ -245,19 +242,20 @@ failloop:
|
|||||||
goto failloop;
|
goto failloop;
|
||||||
} else
|
} else
|
||||||
#endif /* FROZEN_STACKS */
|
#endif /* FROZEN_STACKS */
|
||||||
if (IN_BETWEEN(H0, pt1, HR)) {
|
if (IN_BETWEEN(H0, pt1, LCL0)) {
|
||||||
if (IsAttVar(pt1)) {
|
if (IsAttVar(pt1)) {
|
||||||
goto failloop;
|
goto failloop;
|
||||||
} else {
|
} else {
|
||||||
TR = pt0;
|
TR = pt0;
|
||||||
Yap_CleanOpaqueVariable(d1);
|
|
||||||
|
Yap_CleanOpaqueVariable(d1);
|
||||||
|
|
||||||
goto failloop;
|
goto failloop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef FROZEN_STACKS /* TRAIL */
|
#ifdef FROZEN_STACKS /* TRAIL */
|
||||||
/* don't reset frozen variables */
|
/* don't reset frozen variables */
|
||||||
if (pt0 < TR_FZ)
|
else if (pt0 < TR_FZ)
|
||||||
goto failloop;
|
goto failloop;
|
||||||
#endif
|
#endif
|
||||||
flags = *pt1;
|
flags = *pt1;
|
||||||
@ -306,9 +304,7 @@ hence we don't need to have a lock it */
|
|||||||
} else {
|
} else {
|
||||||
LogUpdClause *cl = ClauseFlagsToLogUpdClause(pt1);
|
LogUpdClause *cl = ClauseFlagsToLogUpdClause(pt1);
|
||||||
int erase;
|
int erase;
|
||||||
#if PARALLEL_YAP
|
|
||||||
PredEntry *ap = cl->ClPred;
|
PredEntry *ap = cl->ClPred;
|
||||||
#endif
|
|
||||||
/* BB support */
|
/* BB support */
|
||||||
if (ap) {
|
if (ap) {
|
||||||
|
|
||||||
|
78
C/globals.c
78
C/globals.c
@ -286,10 +286,9 @@ static Term GrowArena(Term arena, size_t size,
|
|||||||
XREGS[arity + 1] = arena;
|
XREGS[arity + 1] = arena;
|
||||||
if (!Yap_gcl(size * sizeof(CELL), arity + 1, ENV, gc_P(P, CP))) {
|
if (!Yap_gcl(size * sizeof(CELL), arity + 1, ENV, gc_P(P, CP))) {
|
||||||
Yap_Error(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage);
|
Yap_Error(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage);
|
||||||
return false;
|
return 0;
|
||||||
}
|
}
|
||||||
arena = XREGS[arity + 1];
|
arena = XREGS[arity + 1];
|
||||||
adjust_cps(size PASS_REGS);
|
|
||||||
}
|
}
|
||||||
pt = ArenaLimit(arena);
|
pt = ArenaLimit(arena);
|
||||||
if (pt == HR) {
|
if (pt == HR) {
|
||||||
@ -301,8 +300,8 @@ static Term GrowArena(Term arena, size_t size,
|
|||||||
}
|
}
|
||||||
arena = XREGS[arity + 1];
|
arena = XREGS[arity + 1];
|
||||||
}
|
}
|
||||||
CreateNewArena(RepAppl(arena), size+old_size);
|
arena = CreateNewArena(RepAppl(arena), size+old_size);
|
||||||
return size+old_size;
|
return arena;
|
||||||
}
|
}
|
||||||
|
|
||||||
CELL *Yap_GetFromArena(Term *arenap, UInt cells, UInt arity) {
|
CELL *Yap_GetFromArena(Term *arenap, UInt cells, UInt arity) {
|
||||||
@ -329,11 +328,11 @@ CELL *Yap_GetFromArena(Term *arenap, UInt cells, UInt arity) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Term CloseArena(cell_space_t *region, Term arena,
|
static Term CloseArena(cell_space_t *region,
|
||||||
UInt old_size USES_REGS) {
|
UInt old_size USES_REGS) {
|
||||||
UInt new_size;
|
UInt new_size;
|
||||||
new_size = old_size - (HR - RepAppl(arena));
|
new_size = old_size - (HR - HB);
|
||||||
arena = CreateNewArena(HR, new_size);
|
Term arena = CreateNewArena(HR, new_size);
|
||||||
exit_cell_space( region );
|
exit_cell_space( region );
|
||||||
return arena;
|
return arena;
|
||||||
}
|
}
|
||||||
@ -649,10 +648,10 @@ static Term CopyTermToArena(Term t, Term arena, bool share, bool copy_att_vars,
|
|||||||
cell_space_t cspace;
|
cell_space_t cspace;
|
||||||
int res = 0, restarts = 0;
|
int res = 0, restarts = 0;
|
||||||
Term tn;
|
Term tn;
|
||||||
|
old_size = ArenaSz(arena);
|
||||||
|
|
||||||
restart:
|
restart:
|
||||||
enter_cell_space(&cspace);
|
enter_cell_space(&cspace);
|
||||||
old_size = ArenaSz(arena);
|
|
||||||
t = Deref(t);
|
t = Deref(t);
|
||||||
if (IsVarTerm(t)) {
|
if (IsVarTerm(t)) {
|
||||||
ASP = ArenaLimit(arena);
|
ASP = ArenaLimit(arena);
|
||||||
@ -668,12 +667,12 @@ static Term CopyTermToArena(Term t, Term arena, bool share, bool copy_att_vars,
|
|||||||
Hi PASS_REGS)) < 0) {
|
Hi PASS_REGS)) < 0) {
|
||||||
goto error_handler;
|
goto error_handler;
|
||||||
}
|
}
|
||||||
*newarena = CloseArena(&cspace, arena, old_size PASS_REGS);
|
*newarena = CloseArena(&cspace, old_size PASS_REGS);
|
||||||
return Hi[0];
|
return Hi[0];
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (share && VarOfTerm(t) > ArenaPt(arena)) {
|
if (share && VarOfTerm(t) > ArenaPt(arena)) {
|
||||||
*newarena = CloseArena(&cspace, arena, old_size PASS_REGS);
|
*newarena = CloseArena(&cspace, old_size PASS_REGS);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
tn = MkVarTerm();
|
tn = MkVarTerm();
|
||||||
@ -681,7 +680,7 @@ static Term CopyTermToArena(Term t, Term arena, bool share, bool copy_att_vars,
|
|||||||
res = -1;
|
res = -1;
|
||||||
goto error_handler;
|
goto error_handler;
|
||||||
}
|
}
|
||||||
*newarena = CloseArena(&cspace, arena, old_size PASS_REGS);
|
*newarena = CloseArena(&cspace, old_size PASS_REGS);
|
||||||
return tn;
|
return tn;
|
||||||
} else if (IsAtomOrIntTerm(t)) {
|
} else if (IsAtomOrIntTerm(t)) {
|
||||||
return t;
|
return t;
|
||||||
@ -703,7 +702,7 @@ static Term CopyTermToArena(Term t, Term arena, bool share, bool copy_att_vars,
|
|||||||
Hi PASS_REGS)) < 0) {
|
Hi PASS_REGS)) < 0) {
|
||||||
goto error_handler;
|
goto error_handler;
|
||||||
}
|
}
|
||||||
*newarena = CloseArena(&cspace, arena, old_size PASS_REGS);
|
*newarena = CloseArena(&cspace, old_size PASS_REGS);
|
||||||
return tf;
|
return tf;
|
||||||
} else {
|
} else {
|
||||||
Functor f;
|
Functor f;
|
||||||
@ -724,7 +723,7 @@ static Term CopyTermToArena(Term t, Term arena, bool share, bool copy_att_vars,
|
|||||||
if (IsExtensionFunctor(f)) {
|
if (IsExtensionFunctor(f)) {
|
||||||
switch ((CELL) f) {
|
switch ((CELL) f) {
|
||||||
case (CELL) FunctorDBRef:
|
case (CELL) FunctorDBRef:
|
||||||
*newarena = CloseArena(&cspace, arena, old_size PASS_REGS);
|
*newarena = CloseArena(&cspace, old_size PASS_REGS);
|
||||||
return t;
|
return t;
|
||||||
case (CELL) FunctorLongInt:
|
case (CELL) FunctorLongInt:
|
||||||
if (HR > ASP - (MIN_ARENA_SIZE + 3)) {
|
if (HR > ASP - (MIN_ARENA_SIZE + 3)) {
|
||||||
@ -783,32 +782,32 @@ static Term CopyTermToArena(Term t, Term arena, bool share, bool copy_att_vars,
|
|||||||
goto error_handler;
|
goto error_handler;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*newarena = CloseArena(&cspace, arena, old_size PASS_REGS);
|
*newarena = CloseArena(&cspace, old_size PASS_REGS);
|
||||||
return tf;
|
return tf;
|
||||||
}
|
}
|
||||||
error_handler:
|
error_handler:
|
||||||
XREGS[arity + 1] = t;
|
XREGS[arity + 1] = t;
|
||||||
XREGS[arity + 2] = arena;
|
|
||||||
exit_cell_space(&cspace);
|
|
||||||
switch (res) {
|
switch (res) {
|
||||||
case -1:
|
case -1:
|
||||||
if (arena == LOCAL_GlobalArena)
|
if (arena == LOCAL_GlobalArena)
|
||||||
LOCAL_GlobalArenaOverflows++;
|
LOCAL_GlobalArenaOverflows++;
|
||||||
restarts++;
|
restarts++;
|
||||||
min_grow += (restarts < 16 ? 16*1024*restarts*restarts : 128*1024*1024);
|
min_grow += (restarts < 16 ? 16*1024*restarts*restarts : 128*1024*1024);
|
||||||
CreateNewArena (RepAppl(arena),old_size);
|
HR = HB;
|
||||||
if((arena=GrowArena(arena, min_grow, arity + 2, &cspace PASS_REGS))==0) {
|
arena = CloseArena (&cspace, old_size PASS_REGS);
|
||||||
|
if((arena=GrowArena(arena, min_grow, arity + 1, &cspace PASS_REGS))==0) {
|
||||||
Yap_ThrowError(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage);
|
Yap_ThrowError(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage);
|
||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
break;
|
t = XREGS[arity+1];
|
||||||
|
enter_cell_space(&cspace);
|
||||||
|
old_size = ArenaSz(arena);
|
||||||
|
break;
|
||||||
default: /* temporary space overflow */
|
default: /* temporary space overflow */
|
||||||
return 0;
|
exit_cell_space(&cspace);
|
||||||
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
enter_cell_space(&cspace);
|
|
||||||
arena = Deref(XREGS[arity + 2]);
|
|
||||||
t = XREGS[arity + 1];
|
|
||||||
goto restart;
|
goto restart;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -836,7 +835,7 @@ restart:
|
|||||||
// CELL *old_top = ArenaLimit(*nsizeof(CELL)ewarena);
|
// CELL *old_top = ArenaLimit(*nsizeof(CELL)ewarena);
|
||||||
if (arena == LOCAL_GlobalArena)
|
if (arena == LOCAL_GlobalArena)
|
||||||
LOCAL_GlobalArenaOverflows++;
|
LOCAL_GlobalArenaOverflows++;
|
||||||
CreateNewArena (RepAppl(arena),old_size);
|
arena = CreateNewArena (RepAppl(arena),old_size);
|
||||||
if ((arena=GrowArena(arena, Nar * sizeof(CELL),
|
if ((arena=GrowArena(arena, Nar * sizeof(CELL),
|
||||||
arity + 1, &cells PASS_REGS))==0) {
|
arity + 1, &cells PASS_REGS))==0) {
|
||||||
Yap_Error(RESOURCE_ERROR_STACK, TermNil,
|
Yap_Error(RESOURCE_ERROR_STACK, TermNil,
|
||||||
@ -856,7 +855,7 @@ restart:
|
|||||||
HB0[i] = init;
|
HB0[i] = init;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*newarena = CloseArena(&cells, arena, ArenaSz(arena) PASS_REGS);
|
*newarena = CloseArena(&cells, ArenaSz(arena) PASS_REGS);
|
||||||
return tf;
|
return tf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1658,19 +1657,18 @@ static Int p_nb_queue_enqueue(USES_REGS1) {
|
|||||||
} else {
|
} else {
|
||||||
min_size = 0L;
|
min_size = 0L;
|
||||||
}
|
}
|
||||||
to = CopyTermToArena(ARG2, arena, FALSE, TRUE, 2, qd + QUEUE_ARENA,
|
Term newarena = arena;
|
||||||
|
to = CopyTermToArena(Deref(ARG2), arena, FALSE, TRUE, 2, &newarena,
|
||||||
min_size PASS_REGS);
|
min_size PASS_REGS);
|
||||||
if (to == 0L)
|
if (to == 0L)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
cell_space_t cspace;
|
cell_space_t cspace;
|
||||||
qd = GetQueue(ARG1, "enqueue");
|
arena = newarena;
|
||||||
arena = GetQueueArena(qd, "enqueue");
|
|
||||||
/* garbage collection ? */
|
/* garbage collection ? */
|
||||||
enter_cell_space(&cspace);
|
|
||||||
HR = HB = ArenaPt(arena);
|
HR = HB = ArenaPt(arena);
|
||||||
old_sz = ArenaSz(arena);
|
old_sz = ArenaSz(arena);
|
||||||
|
qd = GetQueue(ARG1, "enqueue");
|
||||||
qsize = IntegerOfTerm(qd[QUEUE_SIZE]);
|
qsize = IntegerOfTerm(qd[QUEUE_SIZE]);
|
||||||
|
|
||||||
qd[QUEUE_SIZE] = Global_MkIntegerTerm(qsize + 1);
|
qd[QUEUE_SIZE] = Global_MkIntegerTerm(qsize + 1);
|
||||||
if (qsize == 0) {
|
if (qsize == 0) {
|
||||||
qd[QUEUE_HEAD] = AbsPair(HR);
|
qd[QUEUE_HEAD] = AbsPair(HR);
|
||||||
@ -1681,7 +1679,7 @@ static Int p_nb_queue_enqueue(USES_REGS1) {
|
|||||||
RESET_VARIABLE(HR);
|
RESET_VARIABLE(HR);
|
||||||
qd[QUEUE_TAIL] = (CELL)HR;
|
qd[QUEUE_TAIL] = (CELL)HR;
|
||||||
HR++;
|
HR++;
|
||||||
qd[QUEUE_ARENA] = CloseArena(&cspace, qd[ QUEUE_ARENA ], old_sz PASS_REGS);
|
qd[QUEUE_ARENA] =CloseArena(&cspace, old_sz PASS_REGS);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1705,7 +1703,7 @@ static Int p_nb_queue_dequeue(USES_REGS1) {
|
|||||||
/* garbage collection ? */
|
/* garbage collection ? */
|
||||||
enter_cell_space(&cspace);
|
enter_cell_space(&cspace);
|
||||||
qd[QUEUE_SIZE] = Global_MkIntegerTerm(qsz - 1);
|
qd[QUEUE_SIZE] = Global_MkIntegerTerm(qsz - 1);
|
||||||
qd[QUEUE_ARENA] = CloseArena(&cspace, arena, old_sz PASS_REGS);
|
qd[QUEUE_ARENA] = CloseArena(&cspace, old_sz PASS_REGS);
|
||||||
return Yap_unify(out, ARG2);
|
return Yap_unify(out, ARG2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1955,7 +1953,7 @@ restart:
|
|||||||
old_sz = ArenaSz(arena);
|
old_sz = ArenaSz(arena);
|
||||||
HR = HB = ArenaPt(arena);
|
HR = HB = ArenaPt(arena);
|
||||||
qd[HEAP_MAX] = Global_MkIntegerTerm(hmsize);
|
qd[HEAP_MAX] = Global_MkIntegerTerm(hmsize);
|
||||||
qd[HEAP_ARENA] = CloseArena(&cspace, arena, old_sz PASS_REGS);
|
qd[HEAP_ARENA] = CloseArena(&cspace, old_sz PASS_REGS);
|
||||||
goto restart;
|
goto restart;
|
||||||
}
|
}
|
||||||
arena = qd[HEAP_ARENA];
|
arena = qd[HEAP_ARENA];
|
||||||
@ -1966,14 +1964,14 @@ restart:
|
|||||||
mingrow PASS_REGS);
|
mingrow PASS_REGS);
|
||||||
qd = GetHeap(ARG1, "add_to_heap");
|
qd = GetHeap(ARG1, "add_to_heap");
|
||||||
arena = qd[HEAP_ARENA];
|
arena = qd[HEAP_ARENA];
|
||||||
to = CopyTermToArena(ARG3, arena, FALSE, TRUE, 3, qd + HEAP_ARENA,
|
to = CopyTermToArena(ARG3, arena, FALSE, TRUE, 3, &arena,
|
||||||
mingrow PASS_REGS);
|
mingrow PASS_REGS);
|
||||||
/* protect key in ARG2 in case there is an overflow while copying to */
|
/* protect key in ARG2 in case there is an overflow while copying to */
|
||||||
key = ARG2;
|
key = ARG2;
|
||||||
if (key == 0 || to == 0L)
|
if (key == 0 || to == 0L)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
qd = GetHeap(ARG1, "add_to_heap");
|
qd = GetHeap(ARG1, "add_to_heap");
|
||||||
arena = qd[HEAP_ARENA];
|
qd[HEAP_ARENA] = arena;
|
||||||
/* garbage collection ? */
|
/* garbage collection ? */
|
||||||
enter_cell_space(&cspace);
|
enter_cell_space(&cspace);
|
||||||
HR = HB = ArenaPt(arena);
|
HR = HB = ArenaPt(arena);
|
||||||
@ -1987,7 +1985,7 @@ restart:
|
|||||||
gsiz = 1024;
|
gsiz = 1024;
|
||||||
}
|
}
|
||||||
ARG3 = to;
|
ARG3 = to;
|
||||||
CreateNewArena (RepAppl(arena),old_sz);
|
arena = CreateNewArena (RepAppl(arena),old_sz);
|
||||||
if ((arena=GrowArena(arena, gsiz, 3, &cspace PASS_REGS))==0) {
|
if ((arena=GrowArena(arena, gsiz, 3, &cspace PASS_REGS))==0) {
|
||||||
Yap_Error(RESOURCE_ERROR_STACK, arena, LOCAL_ErrorMessage);
|
Yap_Error(RESOURCE_ERROR_STACK, arena, LOCAL_ErrorMessage);
|
||||||
return 0L;
|
return 0L;
|
||||||
@ -2003,7 +2001,7 @@ restart:
|
|||||||
pt[2 * hsize + 1] = to;
|
pt[2 * hsize + 1] = to;
|
||||||
PushHeap(pt, hsize);
|
PushHeap(pt, hsize);
|
||||||
qd[HEAP_SIZE] = Global_MkIntegerTerm(hsize + 1);
|
qd[HEAP_SIZE] = Global_MkIntegerTerm(hsize + 1);
|
||||||
qd[HEAP_ARENA] = CloseArena(&cspace, qd[ HEAP_ARENA ], old_sz PASS_REGS);
|
qd[HEAP_ARENA] = CloseArena(&cspace, old_sz PASS_REGS);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2347,7 +2345,7 @@ cell_space_t cspace;
|
|||||||
}
|
}
|
||||||
ARG3 = to;
|
ARG3 = to;
|
||||||
/* fprintf(stderr,"growing %ld cells\n",(unsigned long int)gsiz);*/
|
/* fprintf(stderr,"growing %ld cells\n",(unsigned long int)gsiz);*/
|
||||||
CreateNewArena (RepAppl(arena),old_sz);
|
arena = CreateNewArena (RepAppl(arena),old_sz);
|
||||||
if (!GrowArena(arena, gsiz, 3, &cspace PASS_REGS)) {
|
if (!GrowArena(arena, gsiz, 3, &cspace PASS_REGS)) {
|
||||||
Yap_Error(RESOURCE_ERROR_STACK, arena, LOCAL_ErrorMessage);
|
Yap_Error(RESOURCE_ERROR_STACK, arena, LOCAL_ErrorMessage);
|
||||||
return 0L;
|
return 0L;
|
||||||
@ -2360,7 +2358,7 @@ cell_space_t cspace;
|
|||||||
pt = qd + HEAP_START;
|
pt = qd + HEAP_START;
|
||||||
PushBeam(pt, pt + 2 * hmsize, hsize, key, to);
|
PushBeam(pt, pt + 2 * hmsize, hsize, key, to);
|
||||||
qd[HEAP_SIZE] = Global_MkIntegerTerm(hsize + 1);
|
qd[HEAP_SIZE] = Global_MkIntegerTerm(hsize + 1);
|
||||||
qd[HEAP_ARENA] = CloseArena(&cspace, qd[ HEAP_ARENA ], old_sz PASS_REGS);
|
qd[HEAP_ARENA] = CloseArena(&cspace, old_sz PASS_REGS);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2383,7 +2381,7 @@ static Int p_nb_beam_del(USES_REGS1) {
|
|||||||
/* garbage collection ? */
|
/* garbage collection ? */
|
||||||
enter_cell_space(&cspace);
|
enter_cell_space(&cspace);
|
||||||
qd[HEAP_SIZE] = Global_MkIntegerTerm(qsz - 1);
|
qd[HEAP_SIZE] = Global_MkIntegerTerm(qsz - 1);
|
||||||
qd[ HEAP_ARENA] = CloseArena(&cspace, arena, old_sz PASS_REGS);
|
qd[ HEAP_ARENA] = CloseArena(&cspace, old_sz PASS_REGS);
|
||||||
tk = qd[HEAP_START];
|
tk = qd[HEAP_START];
|
||||||
tv = DelBeamMin(qd + HEAP_START,
|
tv = DelBeamMin(qd + HEAP_START,
|
||||||
qd + (HEAP_START + 2 * IntegerOfTerm(qd[HEAP_MAX])), qsz);
|
qd + (HEAP_START + 2 * IntegerOfTerm(qd[HEAP_MAX])), qsz);
|
||||||
|
@ -1576,6 +1576,7 @@ void Yap_InitCPreds(void) {
|
|||||||
Yap_InitDBPreds();
|
Yap_InitDBPreds();
|
||||||
Yap_InitErrorPreds();
|
Yap_InitErrorPreds();
|
||||||
Yap_InitExecFs();
|
Yap_InitExecFs();
|
||||||
|
Yap_InitErrorPreds();
|
||||||
Yap_InitGlobals();
|
Yap_InitGlobals();
|
||||||
Yap_InitInlines();
|
Yap_InitInlines();
|
||||||
Yap_InitIOPreds();
|
Yap_InitIOPreds();
|
||||||
|
16
C/write.c
16
C/write.c
@ -77,7 +77,6 @@ typedef struct write_globs {
|
|||||||
UInt last_atom_minus;
|
UInt last_atom_minus;
|
||||||
UInt MaxDepth, MaxArgs;
|
UInt MaxDepth, MaxArgs;
|
||||||
wtype lw;
|
wtype lw;
|
||||||
CELL *visited, *visited0, *visited_top;
|
|
||||||
} wglbs;
|
} wglbs;
|
||||||
|
|
||||||
#define lastw wglb->lw
|
#define lastw wglb->lw
|
||||||
@ -732,9 +731,10 @@ static void write_list(Term t, int direction, int depth,
|
|||||||
struct rewind_term nrwt;
|
struct rewind_term nrwt;
|
||||||
nrwt.parent = rwt;
|
nrwt.parent = rwt;
|
||||||
nrwt.u_sd.s.ptr = 0;
|
nrwt.u_sd.s.ptr = 0;
|
||||||
bool loop = true;
|
|
||||||
while (loop) {
|
while (1) {
|
||||||
loop = false;
|
|
||||||
|
PROTECT(t, writeTerm(HeadOfTerm(t), 999, depth + 1, FALSE, wglb, &nrwt));
|
||||||
ti = TailOfTerm(t);
|
ti = TailOfTerm(t);
|
||||||
if (IsVarTerm(ti))
|
if (IsVarTerm(ti))
|
||||||
break;
|
break;
|
||||||
@ -786,6 +786,7 @@ static void writeTerm(Term t, int p, int depth, int rinfixarg,
|
|||||||
if (IsVarTerm(t)) {
|
if (IsVarTerm(t)) {
|
||||||
write_var((CELL *)t, wglb, &nrwt);
|
write_var((CELL *)t, wglb, &nrwt);
|
||||||
} else if (IsIntTerm(t)) {
|
} else if (IsIntTerm(t)) {
|
||||||
|
|
||||||
wrputn((Int)IntOfTerm(t), wglb);
|
wrputn((Int)IntOfTerm(t), wglb);
|
||||||
} else if (IsAtomTerm(t)) {
|
} else if (IsAtomTerm(t)) {
|
||||||
putAtom(AtomOfTerm(t), wglb->Quote_illegal, wglb);
|
putAtom(AtomOfTerm(t), wglb->Quote_illegal, wglb);
|
||||||
@ -876,8 +877,7 @@ static void writeTerm(Term t, int p, int depth, int rinfixarg,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!wglb->Ignore_ops && Arity == 1 && Yap_IsPrefixOp(atom, &op, &rp)) {
|
||||||
if (!wglb->Ignore_ops && Arity == 1 && Yap_IsPrefixOp(atom, &op, &rp)) {
|
|
||||||
Term tright = ArgOfTerm(1, t);
|
Term tright = ArgOfTerm(1, t);
|
||||||
int bracket_right = !IsVarTerm(tright) && IsAtomTerm(tright) &&
|
int bracket_right = !IsVarTerm(tright) && IsAtomTerm(tright) &&
|
||||||
Yap_IsOp(AtomOfTerm(tright));
|
Yap_IsOp(AtomOfTerm(tright));
|
||||||
@ -1110,8 +1110,8 @@ void Yap_plwrite(Term t, StreamDesc *mywrite, int max_depth, int flags,
|
|||||||
wglb.lw = separator;
|
wglb.lw = separator;
|
||||||
Term tp;
|
Term tp;
|
||||||
|
|
||||||
if ( 0&& (flags & Handle_cyclics_f) ){
|
if ((flags & Handle_cyclics_f) ){
|
||||||
tp = Yap_BreakCyclesInTerm(t PASS_REGS);
|
tp = Yap_CyclesInTerm(t PASS_REGS);
|
||||||
} else {
|
} else {
|
||||||
tp = t;
|
tp = t;
|
||||||
}
|
}
|
||||||
|
@ -175,6 +175,7 @@ extern int Yap_DBTrailOverflow(void);
|
|||||||
extern CELL Yap_EvalMasks(Term, CELL *);
|
extern CELL Yap_EvalMasks(Term, CELL *);
|
||||||
extern void Yap_InitBackDB(void);
|
extern void Yap_InitBackDB(void);
|
||||||
extern void Yap_InitDBPreds(void);
|
extern void Yap_InitDBPreds(void);
|
||||||
|
extern void Yap_InitDBLoadPreds(void);
|
||||||
|
|
||||||
/* errors.c */
|
/* errors.c */
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
@ -31,6 +31,12 @@
|
|||||||
#define register
|
#define register
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if TABLING
|
||||||
|
#define FROZEN_STACKS 1
|
||||||
|
//#define MULTIPLE_STACKS 1
|
||||||
|
#endif
|
||||||
|
|
||||||
/***************************************************************
|
/***************************************************************
|
||||||
* Macros for register manipulation *
|
* Macros for register manipulation *
|
||||||
***************************************************************/
|
***************************************************************/
|
||||||
|
@ -48,6 +48,7 @@ typedef struct regstore_t *regstruct_ptr;
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
typedef Int (*CPredicate)(CACHE_TYPE1);
|
typedef Int (*CPredicate)(CACHE_TYPE1);
|
||||||
|
|
||||||
typedef Int (*CmpPredicate)(Term, Term);
|
typedef Int (*CmpPredicate)(Term, Term);
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
|
|
||||||
#ifdef FROZEN_STACKS
|
#ifdef FROZEN_STACKS
|
||||||
|
|
||||||
|
#define RESET_TRAIL_ENTRY(pt) { TrailTerm(pt) = (CELL)(pt); TrailVal(pt) = (CELL)(pt); }
|
||||||
{
|
{
|
||||||
tr_fr_ptr pt0, pt1, pbase, ptop;
|
tr_fr_ptr pt1, pbase;
|
||||||
pbase = B->cp_tr, ptop = TR;
|
pbase = B->cp_tr;
|
||||||
pt0 = pt1 = TR - 1;
|
pt1 = TR - 1;
|
||||||
while (pt1 >= pbase) {
|
while (pt1 >= pbase) {
|
||||||
BEGD(d1);
|
BEGD(d1);
|
||||||
d1 = TrailTerm(pt1);
|
d1 = TrailTerm(pt1);
|
||||||
if (IsVarTerm(d1)) {
|
if (IsVarTerm(d1)) {
|
||||||
if (d1 < (CELL)HBREG || d1 > Unsigned(B->cp_b)) {
|
if (d1 >= (CELL)HBREG && d1 < Unsigned(HR)) {
|
||||||
TrailTerm(pt0) = d1;
|
RESET_TRAIL_ENTRY(pt1);
|
||||||
TrailVal(pt0) = TrailVal(pt1);
|
|
||||||
pt0--;
|
|
||||||
}
|
}
|
||||||
pt1--;
|
pt1--;
|
||||||
} else if (IsPairTerm(d1)) {
|
} else if (IsPairTerm(d1)) {
|
||||||
@ -28,14 +28,14 @@
|
|||||||
/* skip, this is a problem because we lose information,
|
/* skip, this is a problem because we lose information,
|
||||||
namely active references */
|
namely active references */
|
||||||
pt1 = (tr_fr_ptr)pt;
|
pt1 = (tr_fr_ptr)pt;
|
||||||
} else if (IN_BETWEEN(H0, pt, HR) && IsApplTerm(HeadOfTerm(d1))) {
|
} else if (IN_BETWEEN(H0, pt, LCL0) && IsApplTerm(HeadOfTerm(d1))) {
|
||||||
Term t = HeadOfTerm(d1);
|
Term t = HeadOfTerm(d1);
|
||||||
Functor f = FunctorOfTerm(t);
|
Functor f = FunctorOfTerm(t);
|
||||||
if (f == FunctorBigInt) {
|
if (f == FunctorBigInt) {
|
||||||
Int tag = Yap_blob_tag(t);
|
Int tag = Yap_blob_tag(t);
|
||||||
GLOBAL_OpaqueHandlers[tag].cut_handler(d1);
|
GLOBAL_OpaqueHandlers[tag].cut_handler(d1);
|
||||||
} else {
|
RESET_TRAIL_ENTRY(pt1);
|
||||||
pt0--;
|
|
||||||
}
|
}
|
||||||
pt1--;
|
pt1--;
|
||||||
continue;
|
continue;
|
||||||
@ -48,6 +48,7 @@
|
|||||||
|
|
||||||
LOCK(ap->PELock);
|
LOCK(ap->PELock);
|
||||||
DEC_CLREF_COUNT(cl);
|
DEC_CLREF_COUNT(cl);
|
||||||
|
RESET_TRAIL_ENTRY(pt1);
|
||||||
cl->ClFlags &= ~InUseMask;
|
cl->ClFlags &= ~InUseMask;
|
||||||
erase = (cl->ClFlags & (ErasedMask | DirtyMask)) && !(cl->ClRefCount);
|
erase = (cl->ClFlags & (ErasedMask | DirtyMask)) && !(cl->ClRefCount);
|
||||||
if (erase) {
|
if (erase) {
|
||||||
@ -59,43 +60,23 @@
|
|||||||
Yap_CleanUpIndex(cl);
|
Yap_CleanUpIndex(cl);
|
||||||
}
|
}
|
||||||
UNLOCK(ap->PELock);
|
UNLOCK(ap->PELock);
|
||||||
} else {
|
|
||||||
TrailTerm(pt0) = d1;
|
|
||||||
TrailVal(pt0) = TrailVal(pt1);
|
|
||||||
pt0--;
|
|
||||||
}
|
}
|
||||||
pt1--;
|
pt1--;
|
||||||
} else if (IsApplTerm(d1)) {
|
} else if (IsApplTerm(d1)) {
|
||||||
if (IN_BETWEEN(HBREG, RepAppl(d1), B->cp_b)) {
|
if (IN_BETWEEN(HBREG, RepAppl(d1), B->cp_b)) {
|
||||||
/* deterministic binding to multi-assignment variable */
|
RESET_TRAIL_ENTRY(pt1);
|
||||||
pt1 -= 2;
|
pt1--;
|
||||||
|
RESET_TRAIL_ENTRY(pt1);
|
||||||
|
/* deterministic binding to multi-assignment variable */
|
||||||
|
pt1 --;
|
||||||
} else {
|
} else {
|
||||||
TrailVal(pt0) = TrailVal(pt1);
|
|
||||||
TrailTerm(pt0) = d1;
|
|
||||||
TrailVal(pt0 - 1) = TrailVal(pt1 - 1);
|
|
||||||
TrailTerm(pt0 - 1) = TrailTerm(pt1 - 1);
|
|
||||||
pt0 -= 2;
|
|
||||||
pt1 -= 2;
|
pt1 -= 2;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
TrailTerm(pt0) = d1;
|
pt1--;
|
||||||
TrailVal(pt0) = TrailVal(pt1);
|
|
||||||
pt0--;
|
|
||||||
pt1--;
|
|
||||||
}
|
}
|
||||||
ENDD(d1);
|
ENDD(d1);
|
||||||
}
|
}
|
||||||
if (pt0 != pt1) {
|
|
||||||
int size;
|
|
||||||
pt0++;
|
|
||||||
size = ptop - pt0;
|
|
||||||
memmove(pbase, pt0, size * sizeof(struct trail_frame));
|
|
||||||
if (ptop != TR) {
|
|
||||||
memmove(pbase + size, ptop, (TR - ptop) * sizeof(struct trail_frame));
|
|
||||||
size += (TR - ptop);
|
|
||||||
}
|
|
||||||
TR = pbase + size;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
|
@ -845,7 +845,7 @@ term_expansion_intern(Head :: Goal,Module,problog:ProbFact) :-
|
|||||||
|
|
||||||
% handles probabilistic facts
|
% handles probabilistic facts
|
||||||
term_expansion_intern(P :: Goal,Module,problog:ProbFact) :-
|
term_expansion_intern(P :: Goal,Module,problog:ProbFact) :-
|
||||||
copy_term((P,Goal),(P_Copy,Goal_Copy)),
|
copy_term((P,Goal),(P_Copy,Goal_Copy)),
|
||||||
functor(Goal, Name, Arity),
|
functor(Goal, Name, Arity),
|
||||||
atomic_concat([problog_,Name],ProblogName),
|
atomic_concat([problog_,Name],ProblogName),
|
||||||
Goal =.. [Name|Args],
|
Goal =.. [Name|Args],
|
||||||
|
@ -91,6 +91,7 @@ gradient(QueryID, g, Slope) :-
|
|||||||
query_probabilities( DBDD, Prob) :-
|
query_probabilities( DBDD, Prob) :-
|
||||||
DBDD = bdd(Dir, Tree, _MapList),
|
DBDD = bdd(Dir, Tree, _MapList),
|
||||||
findall(P, evalp(Tree,P), [Prob0]),
|
findall(P, evalp(Tree,P), [Prob0]),
|
||||||
|
% nonvar(Prob0),
|
||||||
(Dir == 1 -> Prob0 = Prob ; Prob is 1.0-Prob0).
|
(Dir == 1 -> Prob0 = Prob ; Prob is 1.0-Prob0).
|
||||||
|
|
||||||
evalp( Tree, Prob0) :-
|
evalp( Tree, Prob0) :-
|
||||||
|
@ -14,20 +14,9 @@
|
|||||||
% will run 20 iterations of learning with default settings
|
% will run 20 iterations of learning with default settings
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
:- use_module('../problog_lbfgs').
|
:- use_module('../problog_learning_lbdd').
|
||||||
|
|
||||||
|
|
||||||
:- if(true).
|
|
||||||
|
|
||||||
:- use_module('kbgraph').
|
|
||||||
|
|
||||||
|
|
||||||
%%%%
|
|
||||||
% background knowledge
|
|
||||||
%%%%
|
|
||||||
% definition of acyclic path using list of visited nodes
|
|
||||||
|
|
||||||
:- else.
|
|
||||||
|
|
||||||
:- Query=path(X,Y), set_problog_flag(init_method,(Query,K,Bdd,problog:problog_exact_lbdd(Query,Bdd))).
|
:- Query=path(X,Y), set_problog_flag(init_method,(Query,K,Bdd,problog:problog_exact_lbdd(Query,Bdd))).
|
||||||
|
|
||||||
@ -48,7 +37,6 @@ edge(X,Y) :- dir_edge(X,Y).
|
|||||||
absent(_,[]).
|
absent(_,[]).
|
||||||
absent(X,[Y|Z]):-X \= Y, absent(X,Z).
|
absent(X,[Y|Z]):-X \= Y, absent(X,Z).
|
||||||
|
|
||||||
:- endif.
|
|
||||||
|
|
||||||
%%%%
|
%%%%
|
||||||
% probabilistic facts
|
% probabilistic facts
|
||||||
|
113
packages/ProbLog/problog_examples/learn_graph_lbfgs.pl
Normal file
113
packages/ProbLog/problog_examples/learn_graph_lbfgs.pl
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
%%% -*- mode: Prolog; -*-
|
||||||
|
|
||||||
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
% ProbLog program describing a probabilistic graph
|
||||||
|
% (running example from ProbLog presentations)
|
||||||
|
% $Id: learn_graph.pl 4875 2010-10-05 15:28:35Z theo $
|
||||||
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
% example for parameter learning with LeProbLog
|
||||||
|
%
|
||||||
|
% training and test examples are included at the end of the file
|
||||||
|
% query ?- do_learning(20).
|
||||||
|
% will run 20 iterations of learning with default settings
|
||||||
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
|
:- use_module('../problog_lbfgs').
|
||||||
|
|
||||||
|
|
||||||
|
:- if(true).
|
||||||
|
|
||||||
|
:- use_module('kbgraph').
|
||||||
|
|
||||||
|
|
||||||
|
%%%%
|
||||||
|
% background knowledge
|
||||||
|
%%%%
|
||||||
|
% definition of acyclic path using list of visited nodes
|
||||||
|
|
||||||
|
:- else.
|
||||||
|
|
||||||
|
:- Query=path(X,Y), set_problog_flag(init_method,(Query,K,Bdd,problog:problog_exact_lbdd(Query,Bdd))).
|
||||||
|
|
||||||
|
path(X,Y) :- path(X,Y,[X],_).
|
||||||
|
|
||||||
|
path(X,X,A,A).
|
||||||
|
path(X,Y,A,R) :-
|
||||||
|
X\==Y,
|
||||||
|
edge(X,Z),
|
||||||
|
absent(Z,A),
|
||||||
|
path(Z,Y,[Z|A],R).
|
||||||
|
|
||||||
|
% using directed edges in both directions
|
||||||
|
edge(X,Y) :- dir_edge(Y,X).
|
||||||
|
edge(X,Y) :- dir_edge(X,Y).
|
||||||
|
|
||||||
|
% checking whether node hasn't been visited before
|
||||||
|
absent(_,[]).
|
||||||
|
absent(X,[Y|Z]):-X \= Y, absent(X,Z).
|
||||||
|
|
||||||
|
:- endif.
|
||||||
|
|
||||||
|
%%%%
|
||||||
|
% probabilistic facts
|
||||||
|
% - probability represented by t/1 term means learnable parameter
|
||||||
|
% - argument of t/1 is real value (used to compare against in evaluation when known), use t(_) if unknown
|
||||||
|
%%%%
|
||||||
|
t(0.9)::dir_edge(1,2).
|
||||||
|
t(0.8)::dir_edge(2,3).
|
||||||
|
t(0.6)::dir_edge(3,4).
|
||||||
|
t(0.7)::dir_edge(1,6).
|
||||||
|
t(0.5)::dir_edge(2,6).
|
||||||
|
t(0.4)::dir_edge(6,5).
|
||||||
|
t(0.7)::dir_edge(5,3).
|
||||||
|
t(0.2)::dir_edge(5,4).
|
||||||
|
|
||||||
|
%%%%%%%%%%%%%%
|
||||||
|
% training examples of form example(ID,Query,DesiredProbability)
|
||||||
|
%%%%%%%%%%%%%%
|
||||||
|
|
||||||
|
example(1,path(1,2),0.94).
|
||||||
|
example(2,path(1,3),0.81).
|
||||||
|
example(3,path(1,4),0.54).
|
||||||
|
example(4,path(1,5),0.70).
|
||||||
|
example(5,path(1,6),0.87).
|
||||||
|
example(6,path(2,3),0.85).
|
||||||
|
example(7,path(2,4),0.57).
|
||||||
|
example(8,path(2,5),0.72).
|
||||||
|
example(9,path(2,6),0.86).
|
||||||
|
example(10,path(3,4),0.66).
|
||||||
|
example(11,path(3,5),0.80).
|
||||||
|
example(12,path(3,6),0.75).
|
||||||
|
example(13,path(4,5),0.57).
|
||||||
|
example(14,path(4,6),0.51).
|
||||||
|
example(15,path(5,6),0.69).
|
||||||
|
% some examples for learning from proofs:
|
||||||
|
/*example(16,(dir_edge(2,3),dir_edge(2,6),dir_edge(6,5),dir_edge(5,4)),0.032).
|
||||||
|
example(17,(dir_edge(1,6),dir_edge(2,6),dir_edge(2,3),dir_edge(3,4)),0.168).
|
||||||
|
example(18,(dir_edge(5,3),dir_edge(5,4)),0.14).
|
||||||
|
example(19,(dir_edge(2,6),dir_edge(6,5)),0.2).
|
||||||
|
example(20,(dir_edge(1,2),dir_edge(2,3),dir_edge(3,4)),0.432).
|
||||||
|
*/
|
||||||
|
%%%%%%%%%%%%%%
|
||||||
|
% test examples of form test_example(ID,Query,DesiredProbability)
|
||||||
|
% note: ID namespace is shared with training example IDs
|
||||||
|
%%%%%%%%%%%%%%
|
||||||
|
|
||||||
|
test_example(21,path(2,1),0.94).
|
||||||
|
test_example(22,path(3,1),0.81).
|
||||||
|
test_example(23,path(4,1),0.54).
|
||||||
|
test_example(24,path(5,1),0.70).
|
||||||
|
test_example(25,path(6,1),0.87).
|
||||||
|
test_example(26,path(3,2),0.85).
|
||||||
|
test_example(27,path(4,2),0.57).
|
||||||
|
test_example(28,path(5,2),0.72).
|
||||||
|
test_example(29,path(6,2),0.86).
|
||||||
|
test_example(30,path(4,3),0.66).
|
||||||
|
test_example(31,path(5,3),0.80).
|
||||||
|
test_example(32,path(6,3),0.75).
|
||||||
|
test_example(33,path(5,4),0.57).
|
||||||
|
test_example(34,path(6,4),0.51).
|
||||||
|
test_example(35,path(6,5),0.69).
|
||||||
|
|
@ -893,10 +893,8 @@ compute_gradient( Grad, X, Slope, LL) :-
|
|||||||
BDD = bdd(_,_,MapList),
|
BDD = bdd(_,_,MapList),
|
||||||
MapList = [_|_],
|
MapList = [_|_],
|
||||||
bind_maplist(MapList, Slope, X),
|
bind_maplist(MapList, Slope, X),
|
||||||
%writeln(QueryID:MapList),
|
|
||||||
query_probabilities( BDD, BDDProb),
|
query_probabilities( BDD, BDDProb),
|
||||||
(isnan(BDDProb) -> writeln((nan::QueryID)), fail;true),
|
(isnan(BDDProb) -> writeln((nan::QueryID)), fail;true),
|
||||||
writeln(BDDProb),
|
|
||||||
LL is (BDDProb-QueryProb)*(BDDProb-QueryProb),
|
LL is (BDDProb-QueryProb)*(BDDProb-QueryProb),
|
||||||
forall(
|
forall(
|
||||||
query_gradients(BDD,I,IProb,GradValue),
|
query_gradients(BDD,I,IProb,GradValue),
|
||||||
@ -925,8 +923,9 @@ wrap( _X, _Grad, _GradCount).
|
|||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
user:progress(FX,_X,_G, _X_Norm,_G_Norm,_Step,_N,_CurrentIteration,_Ls,-1) :-
|
user:progress(FX,_X,_G, _X_Norm,_G_Norm,_Step,_N,_CurrentIteration,_Ls,-1) :-
|
||||||
FX < 0, !,
|
FX < 0, !,
|
||||||
format('stopped on bad FX=~4f~n',[FX]).
|
format('Bad FX=~4f~n',[FX]).
|
||||||
user:progress(FX,X,G,X_Norm,G_Norm,Step,_N, LBFGSIteration,Ls,0) :-
|
user:progress(FX,X,G,X_Norm,G_Norm,Step,_N, LBFGSIteration,Ls,0) :-
|
||||||
|
writeln(fx=FX),
|
||||||
problog_flag(sigmoid_slope,Slope),
|
problog_flag(sigmoid_slope,Slope),
|
||||||
save_state(X, Slope, G),
|
save_state(X, Slope, G),
|
||||||
logger_set_variable(mse_trainingset, FX),
|
logger_set_variable(mse_trainingset, FX),
|
||||||
@ -946,22 +945,6 @@ save_state(X,Slope,_Grad) :-
|
|||||||
tunable_fact(FactID,_GroundTruth),
|
tunable_fact(FactID,_GroundTruth),
|
||||||
set_tunable(FactID,Slope,X),
|
set_tunable(FactID,Slope,X),
|
||||||
fail.
|
fail.
|
||||||
save_state(X, Slope, _) :-
|
|
||||||
user:example(QueryID,_Query,_QueryProb),
|
|
||||||
recorded(QueryID,BDD,_),
|
|
||||||
BDD = bdd(_,_,MapList),
|
|
||||||
bind_maplist(MapList, Slope, X),
|
|
||||||
query_probabilities( BDD, BDDProb),
|
|
||||||
assert( query_probability_intern(QueryID,BDDProb)),
|
|
||||||
fail.
|
|
||||||
save_state(X, Slope, _) :-
|
|
||||||
user:test_example(QueryID,_Query,_QueryProb),
|
|
||||||
recorded(QueryID,BDD,_),
|
|
||||||
BDD = bdd(_,_,MapList),
|
|
||||||
bind_maplist(MapList, Slope, X),
|
|
||||||
query_probabilities( BDD, BDDProb),
|
|
||||||
assert( query_probability_intern(QueryID,BDDProb)),
|
|
||||||
fail.
|
|
||||||
save_state(_X, _Slope, _).
|
save_state(_X, _Slope, _).
|
||||||
|
|
||||||
%========================================================================
|
%========================================================================
|
||||||
|
@ -710,7 +710,7 @@ update_values :-
|
|||||||
%=
|
%=
|
||||||
%========================================================================
|
%========================================================================
|
||||||
|
|
||||||
listing(
|
update_query_cleanup(QueryID) :-
|
||||||
(
|
(
|
||||||
(query_is_similar(QueryID,_) ; query_is_similar(_,QueryID))
|
(query_is_similar(QueryID,_) ; query_is_similar(_,QueryID))
|
||||||
->
|
->
|
||||||
@ -893,7 +893,6 @@ ground_truth_difference :-
|
|||||||
%=
|
%=
|
||||||
%= -Float
|
%= -Float
|
||||||
%========================================================================
|
%========================================================================
|
||||||
|
|
||||||
mse_trainingset_only_for_linesearch(MSE) :-
|
mse_trainingset_only_for_linesearch(MSE) :-
|
||||||
update_values,
|
update_values,
|
||||||
|
|
||||||
|
@ -228,6 +228,7 @@
|
|||||||
:- use_module('problog/utils_lbdd').
|
:- use_module('problog/utils_lbdd').
|
||||||
:- use_module('problog/utils').
|
:- use_module('problog/utils').
|
||||||
:- use_module('problog/tabling').
|
:- use_module('problog/tabling').
|
||||||
|
:- use_module('problog/lbdd').
|
||||||
|
|
||||||
% used to indicate the state of the system
|
% used to indicate the state of the system
|
||||||
:- dynamic(values_correct/0).
|
:- dynamic(values_correct/0).
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
lbfgs_initialize/4,
|
lbfgs_initialize/4,
|
||||||
lbfgs_run/3,
|
lbfgs_run/3,
|
||||||
|
|
||||||
|
lbfgs_fx/1,
|
||||||
lbfgs_finalize/1,
|
lbfgs_finalize/1,
|
||||||
|
|
||||||
lbfgs_set_parameter/2,
|
lbfgs_set_parameter/2,
|
||||||
@ -180,7 +181,8 @@ lbfgs_finalize(_N).
|
|||||||
run the algorithm. output the final score of the function being optimised
|
run the algorithm. output the final score of the function being optimised
|
||||||
*/
|
*/
|
||||||
lbfgs_run(N,X,FX) :-
|
lbfgs_run(N,X,FX) :-
|
||||||
lbfgs(N,X, FX).
|
lbfgs(N,X),
|
||||||
|
lbfgs_fx(FX).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ 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;
|
||||||
|
|
||||||
lbfgsfloatval_t *x_p;
|
lbfgsfloatval_t *x_p, f_x;
|
||||||
|
|
||||||
static lbfgsfloatval_t evaluate(void *instance, const lbfgsfloatval_t *x,
|
static lbfgsfloatval_t evaluate(void *instance, const lbfgsfloatval_t *x,
|
||||||
lbfgsfloatval_t *g_tmp, const int n,
|
lbfgsfloatval_t *g_tmp, const int n,
|
||||||
@ -43,7 +43,7 @@ static lbfgsfloatval_t evaluate(void *instance, const lbfgsfloatval_t *x,
|
|||||||
YAP_Term call;
|
YAP_Term call;
|
||||||
YAP_Bool result;
|
YAP_Bool result;
|
||||||
lbfgsfloatval_t rc=0.0;
|
lbfgsfloatval_t rc=0.0;
|
||||||
YAP_Term v=YAP_MkVarTerm(), t1, t12;
|
YAP_Term t12;
|
||||||
YAP_Term t[6], t2[2];
|
YAP_Term t[6], t2[2];
|
||||||
|
|
||||||
YAP_Term t_0 = YAP_MkIntTerm((YAP_Int)&rc);
|
YAP_Term t_0 = YAP_MkIntTerm((YAP_Int)&rc);
|
||||||
@ -60,8 +60,6 @@ static lbfgsfloatval_t evaluate(void *instance, const lbfgsfloatval_t *x,
|
|||||||
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;
|
// lbfgs_status=LBFGS_STATUS_CB_EVAL;
|
||||||
result = YAP_RunGoalOnce(call);
|
result = YAP_RunGoalOnce(call);
|
||||||
// lbfgs_status=LBFGS_STATUS_RUNNING;
|
// lbfgs_status=LBFGS_STATUS_RUNNING;
|
||||||
@ -72,8 +70,6 @@ static lbfgsfloatval_t evaluate(void *instance, const lbfgsfloatval_t *x,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
YAP_ShutdownGoal(true);
|
YAP_ShutdownGoal(true);
|
||||||
YAP_RecoverSlots(1, sl);
|
|
||||||
fprintf(stderr,"%gxo\n",rc);
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,7 +179,7 @@ value will terminate the optimization process.
|
|||||||
*/
|
*/
|
||||||
static YAP_Bool p_lbfgs(void) {
|
static YAP_Bool p_lbfgs(void) {
|
||||||
YAP_Term t1 = YAP_ARG1, t;
|
YAP_Term t1 = YAP_ARG1, t;
|
||||||
int n, sl;
|
int n;
|
||||||
lbfgsfloatval_t *x;
|
lbfgsfloatval_t *x;
|
||||||
lbfgsfloatval_t fx;
|
lbfgsfloatval_t fx;
|
||||||
|
|
||||||
@ -196,7 +192,6 @@ static YAP_Bool p_lbfgs(void) {
|
|||||||
if (n < 1) {
|
if (n < 1) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
sl = YAP_InitSlot(YAP_ARG3);
|
|
||||||
|
|
||||||
if (!x_p)
|
if (!x_p)
|
||||||
x_p = lbfgs_malloc(n+1);
|
x_p = lbfgs_malloc(n+1);
|
||||||
@ -206,15 +201,17 @@ static YAP_Bool p_lbfgs(void) {
|
|||||||
lbfgs_parameter_t *param = &parms;
|
lbfgs_parameter_t *param = &parms;
|
||||||
void *ui = NULL; //(void *)YAP_IntOfTerm(YAP_ARG4);
|
void *ui = NULL; //(void *)YAP_IntOfTerm(YAP_ARG4);
|
||||||
int ret = lbfgs(n, x, &fx, evaluate, progress, ui, param);
|
int ret = lbfgs(n, x, &fx, evaluate, progress, ui, param);
|
||||||
t = YAP_GetFromSlot(sl);
|
f_x = fx;
|
||||||
YAP_Unify(t, YAP_MkFloatTerm(fx));
|
if (ret == 0)
|
||||||
YAP_RecoverSlots(1, sl);
|
|
||||||
if (ret == 0)
|
|
||||||
return true;
|
return true;
|
||||||
fprintf(stderr, "optimization terminated with code %d\n ",ret);
|
fprintf(stderr, "optimization terminated with code %d\n ",ret);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static YAP_Bool lbfgs_fx(void) {
|
||||||
|
return YAP_Unify(YAP_ARG1, YAP_MkFloatTerm(f_x));
|
||||||
|
}
|
||||||
|
|
||||||
static YAP_Bool lbfgs_grab(void) {
|
static YAP_Bool lbfgs_grab(void) {
|
||||||
int n = YAP_IntOfTerm(YAP_ARG1);
|
int n = YAP_IntOfTerm(YAP_ARG1);
|
||||||
|
|
||||||
@ -468,8 +465,9 @@ X_API void init_lbfgs_predicates(void) {
|
|||||||
lbfgs_parameter_init(&parms);
|
lbfgs_parameter_init(&parms);
|
||||||
|
|
||||||
YAP_UserCPredicate("lbfgs_grab", lbfgs_grab, 2);
|
YAP_UserCPredicate("lbfgs_grab", lbfgs_grab, 2);
|
||||||
YAP_UserCPredicate("lbfgs", p_lbfgs, 3);
|
YAP_UserCPredicate("lbfgs", p_lbfgs, 2);
|
||||||
YAP_UserCPredicate("lbfgs_release", lbfgs_release, 1);
|
YAP_UserCPredicate("lbfgs_release", lbfgs_release, 1);
|
||||||
|
YAP_UserCPredicate("lbfgs_fx", lbfgs_fx, 1);
|
||||||
|
|
||||||
YAP_UserCPredicate("lbfgs_defaults", lbfgs_defaults, 0);
|
YAP_UserCPredicate("lbfgs_defaults", lbfgs_defaults, 0);
|
||||||
|
|
||||||
|
@ -1011,7 +1011,7 @@ prolog_load_context(file, FileName) :-
|
|||||||
).
|
).
|
||||||
prolog_load_context(module, X) :-
|
prolog_load_context(module, X) :-
|
||||||
'__NB_getval__'('$consulting_file', _, fail),
|
'__NB_getval__'('$consulting_file', _, fail),
|
||||||
'current_module'(X).
|
current_source_module(X,X).
|
||||||
prolog_load_context(source, F0) :-
|
prolog_load_context(source, F0) :-
|
||||||
( source_location(F0, _) /*,
|
( source_location(F0, _) /*,
|
||||||
'$input_context'(Context),
|
'$input_context'(Context),
|
||||||
|
@ -35,20 +35,17 @@ fail.
|
|||||||
% parent module mechanism
|
% parent module mechanism
|
||||||
%% system has priority
|
%% system has priority
|
||||||
'$get_predicate_definition'(_ImportingMod:G,prolog:G) :-
|
'$get_predicate_definition'(_ImportingMod:G,prolog:G) :-
|
||||||
nonvar(G),
|
nonvar(G).
|
||||||
'$pred_exists'(G,prolog).
|
|
||||||
%% I am there, no need to import
|
%% I am there, no need to import
|
||||||
'$get_predicate_definition'(Mod:Pred,Mod:Pred) :-
|
'$get_predicate_definition'(Mod:Pred,Mod:Pred) :-
|
||||||
nonvar(Pred),
|
nonvar(Pred).
|
||||||
'$pred_exists'(Pred, Mod).
|
|
||||||
%% export table
|
%% export table
|
||||||
'$get_predicate_definition'(ImportingMod:G,ExportingMod:G0) :-
|
'$get_predicate_definition'(ImportingMod:G,ExportingMod:G0) :-
|
||||||
recorded('$import','$import'(ExportingMod,ImportingMod,G0,G,_,_),_).
|
recorded('$import','$import'(ExportingMod,ImportingMod,G0,G,_,_),_).
|
||||||
%% parent/user
|
%% parent/user
|
||||||
'$get_predicate_definition'(ImportingMod:G,ExportingMod:G0) :-
|
'$get_predicate_definition'(ImportingMod:G,PMod:G) :-
|
||||||
( '$parent_module'(ImportingMod, PMod) ; PMod = user ),
|
( '$parent_module'(ImportingMod, PMod) ; PMod = user ),
|
||||||
ImportingMod \= PMod,
|
ImportingMod \= PMod.
|
||||||
'$get_predicate_definition'(PMod:G, ExportingMod:G0).
|
|
||||||
%% autoload`
|
%% autoload`
|
||||||
%'$get_predicate_definition'(ImportingMod:G,ExportingMod:G) :-
|
%'$get_predicate_definition'(ImportingMod:G,ExportingMod:G) :-
|
||||||
% current_prolog_flag(autoload, true),
|
% current_prolog_flag(autoload, true),
|
||||||
@ -57,22 +54,25 @@ fail.
|
|||||||
|
|
||||||
'$predicate_definition'(Imp:Pred,Exp:NPred) :-
|
'$predicate_definition'(Imp:Pred,Exp:NPred) :-
|
||||||
'$predicate_definition'(Imp:Pred,[],Exp:NPred),
|
'$predicate_definition'(Imp:Pred,[],Exp:NPred),
|
||||||
|
'$pred_exists'(NPred,Exp),
|
||||||
%writeln((Imp:Pred -> Exp:NPred )).
|
%writeln((Imp:Pred -> Exp:NPred )).
|
||||||
!.
|
!.
|
||||||
|
|
||||||
'$one_predicate_definition'(Imp:Pred,Exp:NPred) :-
|
'$one_predicate_definition'(Imp:Pred,Exp:NPred) :-
|
||||||
'$predicate_definition'(Imp:Pred,[],Exp:NPred),
|
'$get_predicate_definition'(Imp:Pred,[],Exp:NPred),
|
||||||
|
'$pred_exists'(NPred,Exp),
|
||||||
%writeln((Imp:Pred -> Exp:NPred )).
|
%writeln((Imp:Pred -> Exp:NPred )).
|
||||||
!.
|
!.
|
||||||
'$one_predicate_definition'(Exp:Pred,Exp:Pred).
|
'$one_predicate_definition'(Exp:Pred,Exp:Pred).
|
||||||
|
|
||||||
'$predicate_definition'(M0:Pred0,Path,ModF:PredF) :-
|
'$predicate_definition'(M0:Pred0,Path,ModF:PredF) :-
|
||||||
'$get_predicate_definition'(M0:Pred0, Mod:Pred),
|
'$get_predicate_definition'(M0:Pred0, Mod:Pred),
|
||||||
\+ lists:member(Mod:Pred,Path),
|
|
||||||
(
|
(
|
||||||
'$predicate_definition'(Mod:Pred,[Mod:Pred|Path],ModF:PredF)
|
'$pred_exists'(Pred,Mod), Mod = ModF, Pred = PredF
|
||||||
;
|
;
|
||||||
Mod = ModF, Pred = PredF
|
\+ lists:member(Mod:Pred,Path),
|
||||||
|
'$predicate_definition'(Mod:Pred,[Mod:Pred|Path], ModF:PredF)
|
||||||
|
|
||||||
).
|
).
|
||||||
|
|
||||||
%
|
%
|
||||||
|
@ -405,6 +405,10 @@ meta_predicate(P) :-
|
|||||||
'$expand_goals'(B,B1,BO,HM,SM,BM,HVars),
|
'$expand_goals'(B,B1,BO,HM,SM,BM,HVars),
|
||||||
'$expand_goals'(C,C1,CO,HM,SM,BM,HVars),
|
'$expand_goals'(C,C1,CO,HM,SM,BM,HVars),
|
||||||
'$clean_cuts'(AO0, DCP, AO).
|
'$clean_cuts'(AO0, DCP, AO).
|
||||||
|
'$expand_goals'(forall(A,B), forall(A1,B1),
|
||||||
|
(A0 , ( B0 -> fail ; true ) -> fail; true ),HM,SM,BM,HVars) :- !,
|
||||||
|
'$expand_goals'(A,A1,AO,HM,SM,BM,HVars),
|
||||||
|
'$expand_goals'(B,B1,BO,HM,SM,BM,HVars).
|
||||||
'$expand_goals'((A*->B;C),(A1*->B1;C1),
|
'$expand_goals'((A*->B;C),(A1*->B1;C1),
|
||||||
('$current_choice_point'(DCP),AO,yap_hacks:cut_at(DCP),BO; CO),HM,SM,BM,HVars) :- !,
|
('$current_choice_point'(DCP),AO,yap_hacks:cut_at(DCP),BO; CO),HM,SM,BM,HVars) :- !,
|
||||||
'$expand_goals'(A,A1,AO0,HM,SM,BM,HVars),
|
'$expand_goals'(A,A1,AO0,HM,SM,BM,HVars),
|
||||||
|
@ -490,7 +490,7 @@ current_predicate(A0,T0) :-
|
|||||||
'$current_predicate'(A,M,T,_),
|
'$current_predicate'(A,M,T,_),
|
||||||
functor(T, A, _)
|
functor(T, A, _)
|
||||||
;
|
;
|
||||||
'$get_predicate_definition'(M:T,M1:_T1),
|
'$predicate_definition'(M:T,M1:_T1),
|
||||||
M\=M1,
|
M\=M1,
|
||||||
functor(T, A, _)
|
functor(T, A, _)
|
||||||
).
|
).
|
||||||
|
17
pl/top.yap
17
pl/top.yap
@ -602,7 +602,7 @@ write_query_answer( Bindings ) :-
|
|||||||
expand_goal(M:G, NG),
|
expand_goal(M:G, NG),
|
||||||
must_be_callable(NG),
|
must_be_callable(NG),
|
||||||
|
|
||||||
'$yap_strip_module'(NG,NM,NC),
|
'$yap_strip_module'(M:NG,NM,NC),
|
||||||
'$call'(NC,CP,G0,NM).
|
'$call'(NC,CP,G0,NM).
|
||||||
'$call'((X,Y),CP,G0,M) :- !,
|
'$call'((X,Y),CP,G0,M) :- !,
|
||||||
'$call'(X,CP,G0,M),
|
'$call'(X,CP,G0,M),
|
||||||
@ -614,8 +614,11 @@ write_query_answer( Bindings ) :-
|
|||||||
'$call'(Y,CP,G0,M)
|
'$call'(Y,CP,G0,M)
|
||||||
).
|
).
|
||||||
'$call'((X*->Y),CP,G0,M) :- !,
|
'$call'((X*->Y),CP,G0,M) :- !,
|
||||||
'$call'(X,CP,G0,M),
|
(
|
||||||
'$call'(Y,CP,G0,M).
|
'$call'(X,CP,G0,M)
|
||||||
|
*->
|
||||||
|
'$call'(Y,CP,G0,M)
|
||||||
|
).
|
||||||
'$call'((X->Y; Z),CP,G0,M) :- !,
|
'$call'((X->Y; Z),CP,G0,M) :- !,
|
||||||
(
|
(
|
||||||
'$call'(X,CP,G0,M)
|
'$call'(X,CP,G0,M)
|
||||||
@ -671,6 +674,13 @@ write_query_answer( Bindings ) :-
|
|||||||
'$call'(X,CP,G0,M) ).
|
'$call'(X,CP,G0,M) ).
|
||||||
'$call'(!, CP, _G0, _m) :- !,
|
'$call'(!, CP, _G0, _m) :- !,
|
||||||
'$$cut_by'(CP).
|
'$$cut_by'(CP).
|
||||||
|
'$call'(forall(X,Y), CP, _G0, _m) :- !,
|
||||||
|
\+ ('$call'(X, CP, G0, M),
|
||||||
|
\+ '$call'(Y, CP, G0, M) ).
|
||||||
|
'$call'(once(X), CP, G0, M) :- !,
|
||||||
|
( '$call'(X, CP, G0, M) -> true).
|
||||||
|
'$call'(!, CP, _G0, _m) :- !,
|
||||||
|
'$$cut_by'(CP).
|
||||||
'$call'([X|Y], _, _, M) :-
|
'$call'([X|Y], _, _, M) :-
|
||||||
(Y == [] ->
|
(Y == [] ->
|
||||||
consult(M:X)
|
consult(M:X)
|
||||||
@ -853,7 +863,6 @@ rules: first try term_expansion/2 in the current module, and then try to use th
|
|||||||
for DCG rules is applied, together with the arithmetic optimizer
|
for DCG rules is applied, together with the arithmetic optimizer
|
||||||
whenever the compilation of arithmetic expressions is in progress.
|
whenever the compilation of arithmetic expressions is in progress.
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
expand_term(Term,Expanded) :-
|
expand_term(Term,Expanded) :-
|
||||||
(
|
(
|
||||||
|
Reference in New Issue
Block a user