Skip to content

Commit 70ab3d6

Browse files
committed
updated version and readme
1 parent 45ef24b commit 70ab3d6

File tree

2 files changed

+60
-48
lines changed

2 files changed

+60
-48
lines changed

README.md

Lines changed: 55 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Popper is an [inductive logic programming](https://arxiv.org/pdf/2008.07912.pdf) (ILP) system.
44
Popper is still a **major** work-in-progress, so please notify us of bugs or usability issues.
55

6-
If you use Popper for research, please cite the paper: Andrew Cropper and Rolf Morel. [Learning programs by learning from failures](https://arxiv.org/abs/2005.02259). Mach. Learn. 110(4): 801-856 (2021)
6+
If you use Popper, please cite the paper: Andrew Cropper and Rolf Morel. [Learning programs by learning from failures](https://arxiv.org/abs/2005.02259). Mach. Learn. 110(4): 801-856 (2021)
77

88

99
## Requirements
@@ -15,9 +15,9 @@ If you use Popper for research, please cite the paper: Andrew Cropper and Rolf M
1515
[pyswip](https://pypi.org/project/pyswip/)
1616

1717

18-
# Usage
18+
# Command line usage
1919

20-
You can run Popper with the command `python popper.py <input dir>`
20+
You can run Popper with the command `python popper.py <input dir>`.
2121
For instance, running the command `python popper.py examples/dropk` produces the output:
2222

2323
```prolog
@@ -35,17 +35,26 @@ f(A):-long(B),roof_closed(B),has_car(A,B),three_wheels(C),has_car(A,C).
3535

3636
Take a look at the examples folder for examples.
3737

38+
# Library usage
3839

39-
# Example problem
40+
You can import Popper and use it in your Python code like so:
41+
42+
```python
43+
from popper.util import Settings
44+
from popper.loop import learn_solution
45+
prog, stats_ = learn_solution(Settings('bias.pl', 'exs.pl', 'bk.pl'))
46+
print(prog)
47+
```
4048

49+
# Example problem
4150

4251
Popper requires three files:
4352

4453
- an examples file
4554
- a background knowledge (BK) file
4655
- a bias file
4756

48-
An examples file simply contains positive and negative examples of the relation you wish to learn:
57+
An examples file contains positive and negative examples of the relation you want to learn:
4958

5059
```prolog
5160
pos(grandparent(ann,amelia)).
@@ -56,7 +65,7 @@ pos(grandparent(linda,amelia)).
5665
neg(grandparent(amy,amelia)).
5766
```
5867

59-
Likewise, a BK file contains helpful information about the relation you are trying to learn:
68+
A BK file contains other information about the problem:
6069

6170
```prolog
6271
mother(ann,amy).
@@ -69,26 +78,25 @@ father(gavin,amelia).
6978
father(andy,spongebob).
7079
```
7180

72-
The bias file contains all the information necessary to restrict the search space of Popper.
73-
74-
There two main things to add to this file are predicate declarations. These simply inform Popper whether it can use a predicate symbol in the head or body of a rule in a solution, such as:
81+
A bias file contains information necessary to restrict the search space of Popper.
82+
The first key thing thing to add to this file are *predicate declarations*.
83+
These tell Popper which predicate symbols it can use in the head or body of a rule, such as:
7584

7685
```prolog
7786
head_pred(grandparent,2).
7887
body_pred(mother,2).
7988
body_pred(father,2).
8089
```
8190

82-
In other words, the above says each role in a program must have the symbol grandparent with arity two in the head and mother and/or father in the body, also with arity two.
83-
84-
Popper needs three parameters to restrict the search space:
91+
These declarations say that each rule in a program must have the symbol *grandparent* with arity two in the head and *mother* and/or *father* in the body, also with arity two.
8592

86-
- `max_vars(N).` sets the maximum number of variables allowed in a rule to be `N`
87-
- `max_body(N).` sets the maximum number of body literals in a rule to be `N`
88-
- `max_clauses(N).` sets the maximum number of rules/clause to be `N`
93+
Popper also needs three parameters to restrict the search space:
8994

90-
These parameters are important as they greatly influence the search space. If they are way too high then Popper will likely take a long time to learn a solution. If the settings are way too low then the search space might be too small to contain a good solution. We are currently working on techniques to automatically deduce these settings. But in the meantime finding the correct values can often be process of trial and error.
95+
- `max_vars(N).` sets the maximum number of variables in a rule to `N`
96+
- `max_body(N).` sets the maximum number of body literals in a rule to `N`
97+
- `max_clauses(N).` sets the maximum number of rules/clauses to `N`
9198

99+
These parameters are very important as they greatly influence the search space. If the values are too high then Popper will might struggle to learn a solution. If the settings are too low then the search space might be too small to contain a good solution. We are currently working on method to automatically set these settings, but in the meantime finding the correct values can often be a process of trial and error.
92100

93101
In our running example, we will add these three lines to our bias file:
94102
```prolog
@@ -97,7 +105,7 @@ max_vars(4).
97105
max_body(3).
98106
```
99107

100-
If we call Popper with these three files, then it will produce the output:
108+
If we call Popper with these three files it will produce the output:
101109

102110
```prolog
103111
grandparent(A,B):-mother(A,C),father(C,B).
@@ -107,29 +115,9 @@ grandparent(A,B):-mother(A,C),mother(C,B).
107115
% Precision:1.00, Recall:1.00, TP:5, FN:0, TN:1, FP:0
108116
```
109117

110-
# Predicate invention
118+
# Anytime
111119

112-
Popper supports [automatic predicate invention](https://arxiv.org/pdf/2104.14426.pdf) (PI). To enable PI, add the setting `enable_pi.` to the bias file.
113-
With PI enabled, Popper (`python popper.py examples/kinship-pi`) learns the following program:
114-
115-
```prolog
116-
grandparent(A,B):-inv1(C,B),inv1(A,C).
117-
inv1(A,B):-mother(A,B).
118-
inv1(A,B):-father(A,B).
119-
% Precision:1.00, Recall:1.00, TP:5, FN:0, TN:1, FP:0
120-
```
121-
122-
<!-- Popper can invent multiple levels of predicates. For instance, running `python popper.py examples/robots-pi` produces the output:
123-
124-
```prolog
125-
126-
``` -->
127-
128-
Predicate invention is currently very expensive so it is best to avoid it if possible.
129-
130-
# Anytime
131-
132-
Popper is an anytime algorithm. To see the intermediate solutions use the `--info` flag. For instance, running the command `python popper.py examples/trains2 --info` produces the output:
120+
Popper is an anytime algorithm. To see intermediate solutions use the `--info` flag (or `settings.info = True`). For instance, running the command `python popper.py examples/trains2 --info` produces the output:
133121

134122
```prolog
135123
% NEW BEST PROG 1:
@@ -163,7 +151,7 @@ f(A):-rectangle(B),has_load(E,B),has_car(A,E),has_car(A,D),has_load(D,C),triangl
163151

164152
# Recursion
165153
To enable recursion add `enable_recursion.` to the bias file.
166-
This allows Popper to learn programs where a predicate symbol appears both in the head and body of a rule, such as to find a duplicate element (`python popper.py examples/find-dupl`) in a list:
154+
This flag allows Popper to learn programs where a predicate symbol appears in both the head and body of a rule, such as to find a duplicate element (`python popper.py examples/find-dupl`) in a list:
167155

168156
```prolog
169157
f(A,B):-head(A,B),tail(A,C),element(C,B).
@@ -194,7 +182,7 @@ type(prepend,(element,list,list)).
194182
```
195183

196184
# Directions
197-
Prolog often require arguments to be ground.
185+
Prolog often requires arguments to be ground.
198186
For instance, when asking Prolog to answer the query:
199187
```prolog
200188
X is 3+K.
@@ -220,6 +208,32 @@ direction(prepend,(in,int,out)).
220208
direction(geq,(in,in)).
221209
```
222210

211+
# Predicate invention
212+
213+
Popper supports [automatic predicate invention](https://arxiv.org/pdf/2104.14426.pdf) (PI). To enable PI, add the setting `enable_pi.` to the bias file.
214+
With PI enabled, Popper (`python popper.py examples/kinship-pi`) learns the following program:
215+
216+
```prolog
217+
grandparent(A,B):-inv1(C,B),inv1(A,C).
218+
inv1(A,B):-mother(A,B).
219+
inv1(A,B):-father(A,B).
220+
% Precision:1.00, Recall:1.00, TP:5, FN:0, TN:1, FP:0
221+
```
222+
223+
<!-- Popper can invent multiple levels of predicates. For instance, running `python popper.py examples/robots-pi` produces the output:
224+
225+
```prolog
226+
227+
``` -->
228+
229+
Predicate invention is currently very expensive so it is best to avoid it if possible.
230+
231+
232+
# Non-observational predicate learning
233+
234+
Popper supports non-observational predicate learning, where it must learn definitions for relations not given as examples.
235+
See the example 'non-OPL'.
236+
223237
# Parallelisation
224238
[Coming soon](https://arxiv.org/pdf/2109.07132.pdf)
225239

setup.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,20 @@
77

88
setuptools.setup(
99
name="Popper",
10-
version="1.0.2", # Update this for every new version
10+
version="1.1.0", # Update this for every new version
1111
author="Andrew Cropper",
1212
author_email="[email protected]",
1313
description="Popper",
1414
include_package_data=True,
15-
package_data={'pl': ['popper/pl/alan.pl', 'popper/pl/test.pl']},
16-
1715
long_description=long_description,
1816
long_description_content_type="text/markdown",
1917
install_requires=[
2018
'clingo',
2119
"PySwip>=0.2.10"
2220
],
2321
url="https://github.com/logic-and-learning-lab/Popper",
24-
packages=setuptools.find_packages(),
25-
classifiers=( # Classifiers help people find your
26-
"Programming Language :: Python :: 3" # projects. See all possible classifiers
27-
),
22+
packages=setuptools.find_packages()
23+
# classifiers=( # Classifiers help people find your
24+
# "Programming Language :: Python :: 3" # projects. See all possible classifiers
25+
# ),
2826
)

0 commit comments

Comments
 (0)