LEC 02: Probability

COMP 540 Intro to A.I. - 图1

Probability basis

Cumulative Distribution Func. (CDF) 累计分布函数

image.png

Independence

image.png

Conditional Probability

image.png
leads to conditional independence
image.png

Chain rule

image.png

Bayes’ Rule

image.png
idea of Bayes’s rule: update probabilities from evidence
image.png
Prior: P(H) - estimate of the probability without evidence
Likelihood: P(E|H) - probability of evidence given a hypothesis
Posterior: P(H|E) - probability of hypothesis given evidence

Conditional Prob. & Bayes
image.png


LEC 03

COMP 540 Intro to A.I. - 图10

Linear Basis

vector products

image.png
Inner product defines “orthogonality” : 正交性, if = 0

vector norms - size

image.png

dentity matrix

  • like “1”
  • multiplying by it gets back the same matrix or vector
  • row & columns are the standard basis vectors

    Inverses

    image.png

    Eigenvalues & Eigenvectors

    image.png

    Dimensionality Reduction

    Why - 1) lots of features redundant 2) storage & computation costs
    image.png

    PCA

    image.png
    为什么样本在“协方差矩阵C的最大K个特征值所对应的特征向量”上的投影就是k维理想特征?
    其中一种解释是: 最大方差理论:方差越大,信息量就越大。协方差矩阵的每一个特征向量就是一个投影面,每一个特征向量所对应的特征值就是原始特征投影到这个投影面之后的方差。由于投影过去之后,我们要尽可能保证信息不丢失,所以要选择具有较大方差的投影面对原始特征进行投影,也就是选择具有较大特征值的特征向量。然后将原始特征投影在这些特征向量上,投影后的值就是新的特征值。每一个投影面生成一个新的特征,k个投影面就生成k个新特征。

LEC 04 - Stats Math

Sample and Estimation

image.png

estimate mean with sample mean

image.png

estimate error

image.png


LEC 05 - Logic

Conjuctive Normal Form - CNF 合取范式

QUIZ:
image.png
use equivbalences for connectives: p V (-q ^ q))


LEC 06 - NLP

COMP 540 Intro to A.I. - 图21

Language models

basic idea - using probalilistic models to assign a probability to a sentence
image.png
chain rule:
image.png

Training: Make Assumptions

Markov-type assumptions:
image.png
1) when k = 0: unigram model -

  • full independece assumtion, present doesn’t depend on teh past :
    • P(w1,w2, w3,…,wn) = P(w1)P(w2)…P(wn)

2) when k = n-1: n-gram model -

  • for bigmra: image.png
  1. multiply tiny numbers? - use logs; add instead of multiply
  2. n-grams with zero probability? - smoothing, 分母+V, 分子+1
  3. Smoothing is increasingly useful for n-grams when n gets larger

    Perplexity

    Perplexity is a measure of uncertainty
    image.png

LEC 07 - Machine Learning Overview

COMP 540 Intro to A.I. - 图27

Supervised learning

  • Classification: the label is a discrete variable, y∈{1,2,3,…,K}
  • Regression: the label is continuous variable, y∈R

Training data is teh “experience“ given to a learning algorithm, learning a function mapping f: X -> Y, such that f(x) predicts the label y on future data x (not in traing data)

error

image.png

Unsupervised learning

given: dataset contains no label x1, x2,… xn
goal: discover new patterns and structures in the data

Clusters

  • K-means clustering (do not confuse it with k-NN classifier)
    • input a dataset x1, x2, …, xn, and assume the number of clusters k is given
    • image.pngimage.png
    • image.pngimage.png
  • Hierarchical Clustering

    Reinforcement learning

  • learn from reward

  • given: an agent that can take actions and a reward function specifiying how good an action is.
  • Data: (x0,a0,r0), (x1,a1,r1) … (xn,an,rn)
  • Goal: learn to choose actions that maximize future reward total

image.png

A* algorithm

For normal BFS:

  1. frontier = Quene()
  2. frontier.put(start)
  3. reached = set()
  4. reached.add(start)
  5. while not frontiner.empty():
  6. current = frontiner.get()
  7. for next in graph.neighbours(current):
  8. if next no in reached:
  9. frontier.put(next)
  10. reached.add(next)

For normal BFS with back track:

  1. frontier = Queue()
  2. frontier.put(start)
  3. came_from = dict{}
  4. came_from[start] = None
  5. while not frontier.empty():
  6. current = frontier.get()
  7. for next in graph.neighbors(current):
  8. if next not in came_from:
  9. frontier.put(next)
  10. came_from[next] = current
  1. # initialize
  2. frontier = Queue()
  3. frontier.put(start)
  4. reached = set()
  5. reached.add(start)
  6. while not frontier.empty():
  7. current = frontier.get()
  8. for next in graph.neighbors(current):
  9. if next not in reached:
  10. frontier.put(next)
  11. reached.add(next)
  12. # BFS with track
  13. frontier = Queue()
  14. frontier.put(start)
  15. came_from = dict()
  16. came_from[start] = None
  17. while not frontier.empty():
  18. current = frontier.get()
  19. for next in graph.neighbors(current):
  20. if next not in came_from:
  21. frontier.put(next)
  22. came_from[next] = current
  23. current = goal
  24. path = []
  25. while current != start:
  26. path.append(current)
  27. current = came_from[current]
  28. path.append(start)
  29. path.reverse()
  30. frontier = Queue()
  31. frontier.put(start)
  32. came_from = dict()
  33. came_from[start] = None
  34. while not frontier.empty():
  35. current = frontier.get()
  36. if current == goal:
  37. break
  38. for next in graph.neighbors(current):
  39. if next not in came_from:
  40. frontier.put(next)
  41. came_from[next] = current
  42. ---
  43. # Dijkstra
  44. frontier = PriorityQueue()
  45. frontier.put(start, 0)
  46. came_from = dict()
  47. cost_so_far = dict()
  48. came_from[start] = None
  49. cost_so_far[start] = 0
  50. while not frontier.empty():
  51. current = frontier.get()
  52. if current == goal:
  53. break
  54. for next in graph.neighbors(current):
  55. new_cost = cost_so_far[current] + graph.cost(current, next)
  56. if next not in cost_so_far or new_cost < cost_so_far[next]:
  57. cost_so_far[next] = new_cost
  58. priority = new_cost
  59. frontier.put(next, priority)
  60. came_from[next] = current
  61. ---
  62. # greedy
  63. frontier = PriorityQueue()
  64. frontier.put(start, 0)
  65. came_from = dict()
  66. came_from[start] = None
  67. while not frontier.empty():
  68. current = frontier.get()
  69. if current == goal:
  70. break
  71. for next in graph.neighbors(current):
  72. if next not in came_from:
  73. priority = heuristic(goal, next)
  74. frontier.put(next, priority)
  75. came_from[next] = current
  76. ---
  77. # A*
  78. frontier = PriorityQueue()
  79. frontier.put(start, 0)
  80. came_from = dict()
  81. cost_so_far = dict()
  82. came_from[start] = None
  83. cost_so_far[start] = 0
  84. while not frontier.empty():
  85. current = frontier.get()
  86. if current == goal:
  87. break
  88. for next in graph.neighbors(current):
  89. next_cost = cost_so_far[current] + graph.cost(current,next)
  90. if next not in cost_so_far or new_cost < cost_so_far[next]:
  91. cost_so_far[next] = new_cost
  92. priority = new_cost + heuristic(goal, next)
  93. frontier.put(next, priority)
  94. came_from[next] = current