KNOWLEDGE
The knowledge module covers Chapter 19: Knowledge in Learning from Stuart Russel's and Peter Norvig's book Artificial Intelligence: A Modern Approach.
Execute the cell below to get started.
CONTENTS
Overview
Inductive Logic Programming (FOIL)
OVERVIEW
Like the learning module, this chapter focuses on methods for generating a model/hypothesis for a domain; however, unlike the learning chapter, here we use prior knowledge to help us learn from new experiences and to find a proper hypothesis.
First-Order Logic
Usually knowledge in this field is represented as first-order logic, a type of logic that uses variables and quantifiers in logical sentences. Hypotheses are represented by logical sentences with variables, while examples are logical sentences with set values instead of variables. The goal is to assign a value to a special first-order logic predicate, called goal predicate, for new examples given a hypothesis. We learn this hypothesis by infering knowledge from some given examples.
Representation
In this module, we use dictionaries to represent examples, with keys being the attribute names and values being the corresponding example values. Examples also have an extra boolean field, 'GOAL', for the goal predicate. A hypothesis is represented as a list of dictionaries. Each dictionary in that list represents a disjunction. Inside these dictionaries/disjunctions we have conjunctions.
For example, say we want to predict if an animal (cat or dog) will take an umbrella given whether or not it rains or the animal wears a coat. The goal value is 'take an umbrella' and is denoted by the key 'GOAL'. An example:
{'Species': 'Cat', 'Coat': 'Yes', 'Rain': 'Yes', 'GOAL': True}
A hypothesis can be the following:
[{'Species': 'Cat'}]
which means an animal will take an umbrella if and only if it is a cat.
Consistency
We say that an example e
is consistent with an hypothesis h
if the assignment from the hypothesis for e
is the same as e['GOAL']
. If the above example and hypothesis are e
and h
respectively, then e
is consistent with h
since e['Species'] == 'Cat'
. For e = {'Species': 'Dog', 'Coat': 'Yes', 'Rain': 'Yes', 'GOAL': True}
, the example is no longer consistent with h
, since the value assigned to e
is False while e['GOAL']
is True.
Inductive Logic Programming (FOIL)
Inductive logic programming (ILP) combines inductive methods with the power of first-order representations, concentrating in particular on the representation of hypotheses as logic programs. The general knowledge-based induction problem is to solve the entailment constraint:
for the unknown , given the knowledge described by and .
The first approach to ILP works by starting with a very general rule and gradually specializing it so that it fits the data.
This is essentially what happens in decision-tree learning, where a decision tree is gradually grown until it is consistent with the observations.
To do ILP we use first-order literals instead of attributes, and the is a set of clauses (set of first order rules, where each rule is similar to a Horn clause) instead of a decision tree.
The FOIL algorithm learns new rules, one at a time, in order to cover all given positive and negative examples.
More precicely, FOIL contains an inner and an outer while loop.
outer loop: (function foil()) add rules until all positive examples are covered.
(each rule is a conjuction of literals, which are chosen inside the inner loop)inner loop: (function new_clause()) add new literals until all negative examples are covered, and some positive examples are covered.
In each iteration, we select/add the most promising literal, according to an estimate of its utility. (function new_literal())
The evaluation function to estimate utility of adding literal to a set of rules is (function gain()) :
where:
Calculate the extended examples for the chosen literal (function extend_example())
(the set of examples created by extending example with each possible constant value for each new variable in literal)
Finally, the algorithm returns a disjunction of first order rules (= conjuction of literals)
Example Family
Suppose we have the following family relations:
Given some positive and negative examples of the relation 'Parent(x,y)', we want to find a set of rules that satisfies all the examples.
A definition of Parent is , which is the result that we expect from the algorithm.
Indeed the algorithm returned the rule:
Suppose that we have some positive and negative results for the relation 'GrandParent(x,y)' and we want to find a set of rules that satisfies the examples.
One possible set of rules for the relation could be:
Or, if included the sentence then:
Indeed the algorithm returned the rule:
Example Network
Suppose that we have the following directed graph and we want to find a rule that describes the reachability between two nodes (Reach(x,y)).
Such a rule could be recursive, since y can be reached from x if and only if there is a sequence of adjacent nodes from x to y:
The algorithm produced something close to the recursive rule:
This happened because the size of the example is small.