Personal Notes of the CS50 AI course
Search
Agent: entity perceives its environment and acts upon that environment
State: config of the agent and its environment
Actions: choices that can be made in a state
ACTIONS(s) returns the set of actions that can be executed in state s
transition model: description of what state results from performing any applicable action in any state
RESULT(s, a) returns the state resulting from performing action a in state s
state space: the set of all states reachable from the inital state by any sequence of actions (sometimes we use a Graph to represent the state space)
goal test: way to determine whether a given state is a goal state
path cost: numerical cost associated with a given path
Search Problems: init state, actions, transition model, goal test, path cost function
Solution: sequence of actions that leads to the goal state
Optimal Solution: the solution with the lowest path cost
Node: data structure that keeps track of: a state, a parent, an action, a path cost (from init to node).
Normal/Classic Search
Search ALGOS: (most examples are in traversing a maze)
- Frontier:
- Depth-First Search (uses a stack) DFS
- Breadth-First Search (uses a queue) BFS
Informed search: search startegy that uses problem-specific knowledge to find solutions more efficiently
Greedy Best-First search: search algo that expands the node is closest to the goal, esitmated by a heuristic function h(n)
A* Search: search algo that expands the node with lowest value of g(n) + h(n)
g(n) = cost to reach node
h(n) = estimated cost to goal
this algo is the optimal under these conditions:
- h(n) is admissible (never overestimates the true cost) and
- h(n) is consistent (for every node n and successor n’ with step cost c, h(n) <= h(n’) + c)
Adversarial Search:
like playing a game against opponent (tic tac toe, )
Minimax:
- MAX: (X) aims to maximize score
- MIN: (O) aims to minimize score
S0: init state
Player/s: returns which player to move in state s
ACTIONS(s) returns the set of actions that can be executed in state s
RESULT(s, a) returns the state resulting from performing action a in state s
TERMINAL(s): checks if state s is a terminal state (game over)
UTILITY(s): final numerical value for the terminal state s (score of the state)
The algo process: Given a state s:
- MAX picks action a in ACTIONS(s) that produces the highest value of MIN-VALUE(RESULT(s, a))
- MIN picks action a in ACTIONS(s) that produces the lowest value of MAX-VALUE(RESULT(s, a))
1function MAX-VALUE(state):2 if TERMINAL(state):3 return UTILITY(state)4 v = -∞5 for action in ACTIONS(state):6 v = MAX(v, MIN-VALUE(RESULT(state, action)))7 return v1function MIN-VALUE(state):2 if TERMINAL(state):3 return UTILITY(state)4 v = ∞5 for action in ACTIONS(state):6 v = MIN(v, MAX-VALUE(RESULT(state, action)))7 return vAlpha-Beta Pruning: I can ignore the rest of the nodes of already there is a choice for the other player that is less than we have already to optimize the minimax algo
Depth-Limited Minimax: after certain number of moves I won’t consider extra ones, this algo is important for complex games like Chess that got billions of possibilites that cannot be calculated in a reasonable time
evaluation function: function that estimates the expected utility of the game from a given state (the better this function is in estimating, the more intelligent the AI is)
Knowledge
knowledge-based agents: agents that reason by operating on internal representations of knowledge
Sentence: an assertion about the world in a knowledge representation language
Propositional Logic, Proposition Symbols: P & Q, Truth Tables are the essential way to represent logic and deductions for AI
Model: assignment of truth value to every propositional symbol (a “possible world”)
Knowledge base: a set of sentences known by a knowledge-based agent
Entailment: α⊢β in every model in which sentence α is true, sentence β is also true
Inference: the process of deriving new sentences from old ones
KB is knowledge base Inference Algo: does KB⊢α ?
Model Checking:
- To Determine if KB⊢α:
- Enumerate all possible models.
- if in every model where KB is true, α is true, then KB entails α
Inference rules:
Modus Ponens, De Morgan’s Law, And elimination, implication elimination, Double Negation elimination, bi-conditional elimination, Distributive Property
Theorem Proving
works a bit like search problems
State: config of the agent and its knowledge base
Actions: inference rules
ACTIONS(s) returns the set of actions that can be executed in state s
transition model: new knowledge base after inference
RESULT(s, a) returns the state resulting from performing action a in state s
state space: the set of all states reachable from the inital state by any sequence of actions (sometimes we use a Graph to represent the state space)
goal test: way to determine whether a given state is a goal state (check statement we are trying to prove)
path cost: number of steps in proof
Theorem Proving: init state, actions, transition model, goal test, path cost function
Conversion To CNF (Conjuctive Normal Form)
disjunction: literals connected with ∨ conjunction: literals connected with ∧
clause: a disjunction of literals
Conjuctive Normal Form: logical sentence that is a conjuction of clauses e.g. (A∨B∨C)∧(D∨¬E)∧(F∨G)
Steps to Convert to CNF
- Eliminate biconditonals
- turn (α↔β) into (α→β)∧(β→α)
- Eliminate implications
- turn (α→β) into ¬α∨β
- Move ¬ inwards using De Morgan’s Laws
- e.g. turn ¬(α∧β) into ¬α∨¬β
- Use distributive law to distribute ∨ wherever possible
Inference by Resolution
-
To Determine if KB⊢α:
- Check if (KB∧¬α) is a contradiction
- if so, then KB⊢α
- Otherwise, no entailment
- Check if (KB∧¬α) is a contradiction
-
To Determine if KB⊢α:
- Convert (KB∧¬α) to CNF (Conjuctive Normal Form)
- Keep checking to see if we can use resolution to produce a new clause
- if ever we produce the empty clause (contradiction in computer represented as false), then we have a contradiction, and KB⊢α
- Otherwise, if we can’t add new clauses, no entailment.
First-Order Logic
Constant Symbols (Names, Objects, etc), Predicate Symbols (Classes) (Person, House, BelongsTo)
Universal Quantification: ∀x Existential Quantification: ∃x and so on of Quantifications
Probability
Possible World: ω Probability of a possible world: P(ω)
1 = Certain 0 = Impossible
0≤P(ω)≤1
The sum of all possible worlds ω in the set of all worlds Ω is 1 ∑ω∈ΩP(ω)=1
unconditional probability
degree of belief in a proposition in the absence of any other evidence.
conditional probability
degree of belief in a proposition given some evidence that has already been revealed
the probability of “a” given “b” P(a∣b)
to know the probability of a given b, we take the probability of both and divide it by the probability of the second (b) to get rid of its own probability that happens when (a) doesn’t
P(a∣b)=P(b)P(a∧b)
random variable
a variable in probability theory with a domain of possible values it can take on can be encoded as an array to distribute the probabilities
Probability Distribution
P(Flight=ontime)=0.6
P(Flight=delayed)=0.3
P(Flight=cancelled)=0.1
or as a vector/array
P(Flight)=<0.6,0.3,0.1>
independence
the knowledge that one event occurs doesn’t affect the probability of the other event
then P(b∣a)=P(b) because (b) is independent of (a) anyways
P(a∧b)=P(a)P(b∣a)=P(a)P(b)
dependence
the knowledge that one event occurs affects the probability of the other event
Bayes’ Rule
Note∵ P(a∧b)=P(b)P(a∣b)
P(a∧b)=P(a)P(b∣a)
∴ P(b)P(a∣b)=P(a)P(b∣a)
∴
P(b∣a)=P(a)P(b)P(a∣b)
knowing P(a | b) we can calculate P(b | a)
knowing P(visible effect | unknown cause) we can calculate P(unknown cause | visible effect)
knowing P(medical test result | disease) we can calculate P(disease | medical test result)
Joint Probability
P(a∣b)=P(b)P(a∧b)=αP(a∧b)
α=P(b)1
the conditional probability of (a) given (b) is proportional to a factor α multiplied by the joint probability of (a) and (b) P(a∧b)
Probability Rules
Negation
P(¬a)=1−P(a)
Inclusion-Exclusion
P(a∨b)=P(a)+P(b)−P(a∧b)
Marginalization
P(a)=P(a∧b)+P(a∧¬b)
P(X=xi)=∑jP(X=xi∧Y=yj)
Conditioning
P(a)=P(a∣b)P(b)+P(a∣¬b)P(¬b)
P(X=xi)=∑jP(X=xi∣Y=yj)P(Y=yj)
Probability Models
Bayesian Network
data structure that represents the dependencies among random variables.
- Directed Graph
- Each node represents a random variable
- arrow from X to Y means X is a parent of Y
- each node X has probability distribution P(X∣Parents(X))
Some information may be outdated