概率逻辑规则学习器
probfoil的Python项目详细描述
probfoil是foil的概率扩展,它能够从 概率数据。
probfoil 2.1是对https://lirias.kuleuven.be/handle/123456789/499989中引入的prob2foil算法的重新设计。 它在problog 2.1之上工作。
如果您正在查找论文中使用的版本,则应签出标记paper_version。
安装
ProbFoil 2.1需要ProbLog 2.1。 您可以使用以下命令安装problog:
pipinstallproblog
Probfoil不需要进一步安装。
用法
probfoil的输入包括两部分:设置和数据。 它们都在prolog(或problog)文件中指定,并且可以组合成一个。
数据由(概率)事实组成。 设置定义
- target:我们要学习的谓词
- 模式:哪些谓词可以添加到规则中
- 类型:谓词的类型信息
- 与数据相关的其他设置
使用:
probfoil data.pl
或者,在存储库版本中
python probfoil/probfoil.py data.pl
可以指定多个文件并将其中的信息连接起来。 (例如,建议将设置与数据分开)。
有几个命令行参数可用。使用--help获取更多信息。
设置格式
目标
应该通过添加事实learn(predicate/arity)来指定目标。
模式
模式应该通过添加mode(predicate(mode1, mode2, ...)形式的事实来指定, 其中modeX是参数x的模式说明符。 可能的模式说明符是:
- ^{tt6}$: the variable at this position must already exist when the literal is added
- ^{tt7}$: the variable at this position does not exist yet in the rule (note that this is stricter than usual)
- ^{tt8}$: a constant should be introduced here; possible value are derived automatically from the data
类型
对于每个相关谓词(目标和模式),应该有一个类型说明符。 此说明符的格式为base(predicate(type1, type2, ...),其中typeX是类型标识符。 类型可以由任意prolog原子(例如person、a等)标识
示例生成
默认情况下,示例是通过查询目标谓词的数据生成的。 可以通过添加零概率事实来指定反例,例如:
0.0::grandmother(john,mary).
或者,probfoil可以通过采用 目标参数的值。注意,这可能导致组合爆炸。 要启用此行为,可以指定事实
example_mode(auto).
示例
% Modesmode(male(+)).mode(parent(+,+)).mode(parent(+,-)).mode(parent(-,+)).% Type definitionsbase(parent(person,person)).base(male(person)).base(female(person)).base(mother(person,person)).base(grandmother(person,person)).base(father(person,person)).base(male_ancestor(person,person)).base(female_ancestor(person,person)).% Targetlearn(grandmother/2).% How to generate negative examplesexample_mode(auto).
更多示例可以在目录examples中找到。