Can Popper use constants?
Closed this issue · 6 comments
Simple question as the header says.
I would like to learn rules that have constants in them.
No, the only way to learn rules with constants is to create a monadic relation for each possible constant symbol, like so:
constant(agent_white, agent).
constant(agent_black, agent).
constant(int_0, int).
constant(int_1, int).
constant(int_2, int).
body_pred(P,1):-
constant(P,_).
type(P,(T,)):-
constant(P,T).
This bias file shows a full example: https://github.com/logic-and-learning-lab/Popper/blob/c1935cfa98112debe91ef9295c3d260f229a22d0/examples/iggp-gt-chicken-goal/bias.pl
There is a version of Popper, called MagicPopper, that can learn rules with constants (including from infinite domains) but I have still not merged it into the main repository: https://github.com/celinehocquette/magicpopper?tab=readme-ov-file
Thank you! magicpopper worked right away :)
I will try to use popper as well.
The performance should be similar?
Thank you for the prompt reply.
I am having trouble running it on Popper.
############# bias ##############
head_pred(hard, 1).
body_pred(contains, 2).
body_pred(direction, 2).
body_pred(shape, 2).
body_pred(size, 2).
constant(small, szid).
constant(large, szid).
constant(airliner, shid).
constant(biplane, shid).
constant(jet, shid).
constant(fighter, shid).
constant(utility, shid).
constant(tandem, shid).
constant(road, shid).
constant(mountain, shid).
constant(articulated, shid).
constant(double, shid).
constant(regular, shid).
constant(school, shid).
constant(truck, shid).
constant(suv, shid).
constant(minivan, shid).
constant(sedan, shid).
constant(wagon, shid).
constant(chopper, shid).
constant(scooter, shid).
constant(cruiser, shid).
constant(dirtbike, shid).
constant(south, did).
constant(southwest, did).
constant(west, did).
constant(northeast, did).
constant(north, did).
constant(northwest, did).
constant(west, did).
constant(southeast, did).
type(hard, (sid,)).
type(contains, (sid, oid)).
type(direction, (oid, did)).
type(shape, (oid, shid)).
type(size, (oid, szid)).
body_pred(P,1):-
constant(P,_).
type(P,(T,)):-
constant(P,T).
####### bk ##############
:-style_check(-discontiguous).
contains(s1, o1_0).
direction(o1_0, southeast).
shape(o1_0, double).
size(o1_0, small).
...
examples
pos(hard(s1)).
pos(hard(s2)).
neg(hard(s4)).
neg(hard(s8)).
...
It throws the error:
hard(V0):- small(V2),size(V1,V2),contains(V0,V1).
Traceback (most recent call last):
File "/home/nelson/Research/ILP4SD/Popper/popper.py", line 8, in
prog, score, stats = learn_solution(settings)
File "/home/nelson/Research/ILP4SD/Popper/popper/loop.py", line 1729, in learn_solution
timeout(settings, popper, (settings, tester, bkcons), timeout_duration=int(settings.timeout-time_so_far),)
File "/home/nelson/Research/ILP4SD/Popper/popper/util.py", line 81, in timeout
result = func(*args, **kwargs)
File "/home/nelson/Research/ILP4SD/Popper/popper/loop.py", line 1658, in popper
Popper(settings, tester, bkcons).run()
File "/home/nelson/Research/ILP4SD/Popper/popper/loop.py", line 247, in run
pos_covered = tester.test_prog_pos(prog)
File "/home/nelson/Research/ILP4SD/Popper/popper/tester.py", line 113, in test_prog_pos
return frozenset(query_once(q)['S'])
File "/home/nelson/miniconda3/lib/python3.10/site-packages/janus_swi/janus.py", line 243, in query_once
return _swipl.call(query, inputs, keep)
janus.PrologError: ''/1: Unknown procedure: small/1
If possible could you help me spot the error?
Thank you again.
For each constant, you need to define the corresponding relation in the BK file, such as:
airliner(airliner).
small(small).
It is silly, but I have not yet implemented the code to automatically add them to the BK (I will move it up my TODO list),
It worked!
Thank you so much for your help!