Search
Prune on insert/remove if the end node has been expanded.
A*:
-
Admissible: estimate is always an underestimate
-
Monotone/consistent:
for all neighbors of - That is, the estimate is always less than estimate from a neighbor plus the cost to go to the neighbor
-
Fails if pruning + heuristic not monotone
Bidirectional search (BFS, LCFS, A*):
Iterative deepening: max depth incremented until solution found. DFS is
Propositions and Inference
-
: if is true, must be true. is an atom, the body -
KB: set of definite clauses
-
Interpretation: assignment of truth value to each atom
-
Model: interpretation where all clauses are true
-
Logical consequence: atoms that are true in every model of the KB
Soundness and Completeness
-
means can be derived (is a consequence) from the given proof procedure - Sound if every consequence derived is true (if
, ) - Complete if all consequences are derived (if
, )
Bottom-up/forward-chaining
- Initialize the set of consequences to be the set of atomic clauses
- Find an atom
that is not yet a consequence where and all ’s are consequences; add it to the set - Repeat until no more clauses can be selected
Fixed point: set of consequences generated.
If
Top-down procedure
Answer clause:
Until the answer clause is an answer (
- Pick an atom
- Choose a clause
- Replace
with its body - If it is just a definition (atomic clause like
), the answer clause will shrink
- If it is just a definition (atomic clause like
Prolog
-
consult(filename).loads all knowledge bases -
make.re-consults all knowledge bases -
,is AND,;is OR -
predicate(args) :- definition. -
Search uses DFS: place non-recursive term first
-
List is
[]or[Head_Element|Rest_Of_List] -
_is anonymous variable -
% append(list, list_to_append, result) append([], L, L). append([H|L1], L2, [H|L3]) :- append(L1, L2, L3). % accReverse(original, accumulator, reversed) accReverse([], L, L). accReverse([Head|Tail], Acc, Rev) :- accReverse(Tail, [Head|Acc], Rev). -
!suppresses backtailing;failalways fail; can be combined to invert result. Can also use\+to do the same
Constraint Satisfaction Problems
A set of variables with domains for each, and set of constraints; a solution is an assignment that satisfies the constraints.
Constraint Network:
- Oval for variable; has associated domain
- Rectangle for constraint
- Arc from each variable to each constraint
Arc Consistency
For a given constraint and variable
Elements may need to be removed from the domain of
Algorithm:
- Get all pairings of constraints and variables in their scope
- For each pairing and element, find values in the domain that allow for valid assignments
- If the domain has changed, need to recheck all variables involved with any constraints involving the variable
Empty domains: no solution; multiple values in domains: may or may not have a solution.
Domain Splitting
Halve the domain for some variable, create two instances of the problem with the new domain, and solve both, revisiting only constraints involving the split variable.
Variable Elimination
Eliminate variables by passing constraints on to their neighbors.
- Select a variable
- For each constraint involving
, find all assignments that satisfy that constraint - If a variable is not involved in any of the constraints, it does not need to be assigned
- Join all constraints, then remove
with a project operation - Repeat
Local and Global Search
-
Optimization problem: finding the assignment that optimizes (min/max) the value of an objective function
-
Local search
- Each iteration, move to one of its neighbors
- Use random restarts/steps (moving to random neighbors) to prevent getting stuck in local optima
-
Constrained satisfaction problem
- The objective function is the number of unsatisfied constraints
-
Global search with parallel search
- Get
individuals/total assignments - At each iteration update all individuals - if any individual is a solution the search can stop
- Get
-
Simulated Annealing
- Pick a random variable and value, adopting it if it is an improvement
- If it is not an improvement, adopt it with probability
- Decrease temperature over time
-
Gradient descent
- Walk along the gradient of the objective function to find a minima
Roulette wheel: return the first individual whose fitness added to the running total is larger than a random number between 1 and sum of the fitnesses.
Probabilistic Inference and Belief Networks
For a full assignment:
If it is the probability over all variables, it is called the joint probability distribution.
Basic Machine Learning
- Error = num incorrect / total
- Naïve Bayes model: assume features only dependent on class variable (thing being predicted)
- Laplace smoothing: add pseudo-count to reduce confidence
- Add pseudo-count to counts for every tuple
- K-nearest neighbors
- Non-parametric, instance-based learning: needs to store all examples
- Uses k examples closest to one being retrieved and method to merge them
Artificial Neural Networks
Prediction:
Activation function:
Learning: