CUHK CSCI5030
instructor: XU Lei
来自 交大 的大佬教授。
大佬就是大佬,直接用中文。
四年来第一次上中问的专业课,感觉exciting。
CUHK CSCI5030
instructor: XU Lei
来自 交大 的大佬教授。
大佬就是大佬,直接用中文。
四年来第一次上中问的专业课,感觉exciting。
$P(d) = log_{10}(d+1)-log_{10}(d)$, where d is the case that the first digit of the data is d
Sample space: $S$
event:
$P(A|B) = \frac{P(A\cap B)}{P(B)}$
$P(A) = \sum{P(A\cap B_i)}$
Now: We want to know: if A happened, what are the p of different B?
$P(B_j|A) = \frac{P(A\cap B_j)}{P(A)}$
$P(A\cap B_j) = P(A|B_j)P(B_j)$
Consider a partition $B_j$ of $S$ and event $A$:
$P(B_j|A) = \frac{P(A\cap B_j)}{P(A)}= \frac{P(A|B_j)P(B_j)}{\sum{P(A|B_i)P(B_i)}}$
$B_j = C_2|X_1, A = H_3|X_1$
Mean is the quantity a that minimizes $min_aE(X-a)^2$
Variance $(x-E(x))^2$
Moment generating function = mgf = summary of the overall random behavior
median $min_b |x-b|$
新的一年
惟愿此心无怨尤。
In Tensorflow, kernel (tf.Variable) can be easily accessed by slim.get_model_variables() (return a list of tf.Variable)if using slim package. Also, if we want to access corresponding
.namesess.run1 | weights = slim.get_model_variables() |
Extracted numpy array is usually multi-dimentional, therefore numpy.savetxt is not applicable, because it requires a 1-d or 2-d array.
pretty easy to use, but only applicable when we only need to load the file using Python, but we need to implement a C code in our project
numpy to .mat file, need a dic to generate the file, therefore we need the name of tf.variable above.
1 | import numpy as np |
We need to consider more about transformation rather than information.
eg. Expect top3, but 8th.
除去多余石头,变成大卫
Two keys to be extraordinary successful
1.Believe in yourself.
2.Keep asking questions.Not satisfied with an offer.
Most papers, researchers focus on negative such as depression,
few is working on what works, such as positive feelings.
Analogy: Using multiple layers of neurons (logic gates) to represent some functions are much simpler
deeper layer ->Modularization (More kinds of module with less training data)
low layer = basic module = enough training data
choosing proper loss
softmax output layer -> cross entropy
And its partial derivation by W is:
$\begin{eqnarray} \frac{\partial C}{\partial w_j} & = & \frac{1}{n} \sum_x \frac{\sigma’(z) x_j}{\sigma(z) (1-\sigma(z))} (\sigma(z)-y). \tag{60}\end{eqnarray}$
Because the final activation function is usually softmax, therefore,
$\begin{eqnarray} \frac{\partial C}{\partial w_j} = \frac{1}{n} \sum_x x_j(\sigma(z)-y). \tag{61}\end{eqnarray}$
mini-batch
Vanishing Gradient Problem
lower layer = smaller gradients = slow learning = almost random
deeper layer = larger gradients = fast learning = already converge
ReLU
$\dfrac{\partial{C}}{\partial{b_{1}}}=\sigma^{\prime}(z_{1})\omega_{2}\sigma^{\prime}(z_{2})\omega_{3}\sigma^{\prime}(z_{3})\omega_{4}\sigma^{\prime}(z_{4})\dfrac{\partial{C}}{\partial{a_{4}}}$
where $\sigma^{\prime}(z)$ is the activation function respectively. Therefore, ReLU = 1
Adaptive Learning Rate
If learning rate is too large, Total loss may not decrease after each update
If learning rate is too small, Training would be too slow
Reduce the learning rate by some factor every few epochs:
Adagrad
Learning rate is smaller and smaller for all parameters
Smaller derivatives, larger learning rate, and vice versa
Momentum
Early Stopping
L2 regu
我们拿 L2正则化来探讨一下, 机器学习的过程是一个 通过修改参数 theta 来减小误差的过程, 可是在减小误差的时候非线性越强的参数, 比如在 x^3 旁边的 theta 4 就会被修改得越多, 因为如果使用非线性强的参数就能使方程更加曲折, 也就能更好的拟合上那些分布的数据点. Theta 4 说, 瞧我本事多大, 就让我来改变模型, 来拟合所有的数据吧, 可是它这种态度招到了误差方程的强烈反击, 误差方程就说: no no no no, 我们是一个团队, 虽然你厉害, 但也不能仅仅靠你一个人, 万一你错了, 我们整个团队的效率就突然降低了, 我得 hold 住那些在 team 里独出风头的人. 这就是整套正规化算法的核心思想. 那 L1, L2 正则化又有什么不同呢?
l1:
尽量稀疏 和dropout 类似
Weight Decay
$w = 0.99 w - learning~rate * gradient$
Dropout
Each time before updating the parameters: Each neuron has p% to dropout
The structure of the network is changed
Using the new network for training
For each mini-batch, we resample the dropout neurons
If the dropout rate at training is p%, all the weights when testing times (1-p)%
Reason
When teams up, if everyone expect the partner will do the work, nothing will be done finally
However, if you know your partner will dropout, you will do better.
When testing, no one dropout actually, so obtaining good results eventually.
Dropout is a kind of ensemble
Train a bunch of networks with different structures
CSCI3230 HW3 Li Wei 1155062148
test!
define $P_{front}$ and $P_{back}$ as the possibilities of front and back respectively. And we have:
$P_{front}+P_{back} = 1$
$I(V) = 0$: The coin flipping result must be front/ back, which means its possibility is 1. $P_{front} \ or \ P_{back} =1$ so that $I(V) = - 0\times log_2 0 - 1\times log_21 = 0$
$I(V) = log_2n$: The possibility of front and back are same, which is 0.5 respectively. $P_{front} =P_{back} =0.5$ so that $I(V) = - 0.5\times log_2 0.5 - 0.5\times log_20.5 = log_22=1$
R1:
$Pass(x,computer) \wedge Win(x,prize)\rightarrow Happy(x)\Rightarrow $
$\neg(Pass(x,computer) \wedge Win(x,prize)) \vee Happy(x) \Rightarrow$
$\neg Pass(x,computer) \vee \neg Win(x,prize) \vee Happy(x) $
R2:
$Study(y) \vee Lucky(y) \rightarrow Pass(y,z) \Rightarrow$
$\neg(Study(y) \vee Lucky(y)) \vee Pass(y,z) \Rightarrow$
$(\neg Study(y) \wedge \neg Lucky(y)) \vee Pass(y,z) \Rightarrow$
$(\neg Study(y) \vee Pass(y,z)) \wedge(\neg Lucky(y)\vee Pass(y,z))$
R3:
$Lucky(w) \rightarrow Win(w,prize) \Rightarrow$
$\neg Lucky(w) \vee Win(w,prize) $

$O = f(\sum_{j=1}^{n} (w_jI_j)+ w_o)$
$h_{i,k} = f(\sum_{j = 1}^{H_{i-1}}(w_{i-1,j,k}h_{i-1,j}))$
$O_m =f(\sum_{j = 1}^{H_{K}}(w_{K,j,m}h_{K,j})) $
$f’(z) = (\frac{1}{1+e^{-z}})’ = \frac{e^{-z}}{(1+e^{-z})^2} = \frac{1}{1+e^{-z}}\times \frac{e^{-z}}{1+e^{-z}}= f(z)(1-f(z))$
Learning rate represents the impact of the correction applied following a training step. The bigger the learning rate, the more drastic the changes at each step. And if we set learning rate as 1, which means no learning rate, we’ll mostly likely start diverging away from the minimum. Therefore, we need a learning rate to control the changing velocity of weights and it is better to use a smaller learning rate.
$\frac{\delta E}{\delta w_{K,j,k}} = \frac{\delta E}{\delta O_k}\cdot \frac{\delta O_k}{\delta w_{K,j,k}}= (O_k - T_k)\cdot O_k\cdot(1-O_k)\cdot h_{K,j}$ (because $E = 0.5\sum_{m=1}^{H_{K+1}}(O_m - T_m)^2 \ and\ O_ k=f(\sum_{j = 1}^{H_{K}}(w_{K,j,k}h_{K,j}) ) $)
considering $E=F(h_{i+2,1}+ …+ h_{i+2,H_{i-2}})$ and $h_{i+2,j} = G(h_{i+1,k})$, according to the multivariate chain rule:
$\frac{\delta E}{\delta h_{i+1,k}} = \sum_{j=1}^{H_{i+2}}(\frac{\delta E}{\delta h_{i+2,j}} \cdot \frac{\delta h_{i+2,j}}{\delta h_{i+1},k})$
$=\sum_{j=1}^{H_{i+2}}(\frac{\delta E}{\delta h_{i+2,j}}\cdot h_{i+2,k}\cdot (1-h_{i+2,k})\cdot w_{i+1,k,j}) = \sum_{j=1}^{H_{i+2}}\Delta_{i+2,j} \cdot w_{i+1,k,j}$
According to chain rule, we have
$\frac{\delta E}{\delta w_{i,j,k}} = \frac{\delta E}{\delta h_{i+1},k} \cdot \frac{\delta h_{i+1},k}{w_{i,j,k}}$
And $\frac{\delta h_{i+1,k}}{w_{i,j,k}} = f’(\sum_{j = 1}^{H_{i}}(w_{i,j,k}h_{i,j}))\cdot h_{i,j}= h_{i+1,k}\cdot (1-h_{i+1,k})\cdot h_{i,j}$
Therefore, the result is:
$\frac{\delta E}{\delta w_{i,j,k}} = (\sum_{j=1}^{H_{i+2}}\Delta_{i+2,j} \cdot w_{i+1,k,j})\cdot h_{i+1,k}\cdot (1-h_{i+1,k})\cdot h_{i,j} $
def BP(network,examples,a) return a modified network:
INPUTS:
network, a multilayer network
examples, a set of data/label pairs
a, learning rate
Repeat:
for each e in examples:
$O \leftarrow Run(Network, e)$
for each neuron in network:
$\Delta_{K+1,k} \leftarrow (O_k - T_k)\cdot O_k\cdot(1-O_k)\cdot h_{K,j}$
for each weight connected to corresponding neuron:
$W_{K,j,k} \leftarrow W_{K,j,k} - a\cdot \Delta_{K+1,k} \cdot h_{K,j}$
for each sub-layer except the first layer:
**for each ** neuron in sub layer:
$\Delta_{i,k}= (\sum_{j=1}^{H_{i+1}}\Delta_{i+1,j} \cdot w_{i,k,j})\cdot h_{i,k}\cdot (1-h_{i,k})\cdot $
for each weight connected to corresponding neuron in current sublayer:
$W_{i,j,k} \leftarrow W_{i,j,k} - a\cdot \Delta_{i+1,k} \cdot h_{i,j}$
Until network has converged
return network
Agents include humans,robots, softbots, thermostats, etc.
The agent function maps from percept histories(sequences) to actions $P->A$
agent program runs on the physical architecture to produce f. (prescode)
Rational agent: For each possible percept sequence, a rational agent should choose an action
that is expected to maximize its performance measure, given the evidence provided by the percept sequence and whatever built-in knowledge (environment) (capabilities(actions)) it has
Basic types of agents in order of increasing generality:
Agents with condition-action rules
Simple agents that maintain some sort of internal state(arg: state,action,percept,model) of the world (and a model) in order to choose an action.
Knowing about the current state of the environment is not always enough to decide what to do.The agent need a GOAL describing the desirable situations.
Goals alone are not really enough to generate high-quality behavior. (eg: quicker? safer? cheaper?) }We
can only achieve some utilities, or have a compromise action.
The learning element responsible for making improvements to the performance element.
The performance element = previously entire agent: it takes in percepts and decides on actions.
The critic tells the learning element how well the agent is doing w.r.t. a fixed standard of performance. Necessary because the percepts themselves provide no indication of agent’s success.
The problem generator - responsible for suggesting problems & actions for new and informative experiences.
deterministic, fully observable: consider a single state at a time
non-observable: reason about sets of states that it might get to.
nondeterministic and/or partially observable: calculates a whole tree of actions rather than a single action sequence
unknown state space: agent must experiment, discovering the actions and states.
state space : The set of all states reachable from the initial state by any sequence of actions
Basic idea:
Current state - generate a new set of states (expanding the state) - choose one (expanding state) by a search strategy to expand - search tree with search nodes
depth first search with depth limit L
iterate limit L from 0 to infinite
Nodes are ordered so that the best evaluation is expanded first.
if h2 > h1 for all n, then h2 dominates h1 and is better
$N = 1 + b^1 + b^2 + … + b^d $
N:total number of expanded nodes, b: effective branching factor d: solution depth. use b to determine the h’s overall usefulness.
1.Deterministic2.Stochastic
Single point Hill-climbing Simulator A
Multiple poi Multi-start GA
Mul: Send whole class to search
如果邻居最大值 < current -> return
else current = 邻居最大值
problem: stuck on local max
选择初始生命种群(initial population)
评价种群中的个体适应度(fitness function)
以比例原则(分数高的挑中机率也较高)选择产生下一个种群。不仅仅挑分数最高的的原因是这么做可能收敛到局部的最佳点,而非整体的。
改变该种群(交叉和变异)(crossover mutation)
直到停止循环的条件满足
Resource limits: cutoff test: depth limit ; evaluation function:= estimated desirability of position
Expand non-quiescent(静) positions until quiescent positions are reached.
compute the correct minimax decision without looking at every node in the search tree.
perfect order: time = $O(b^{m/2})$
Syntax defines the sentences in the language
Semantics define the meaning of sentences
m is a model of a sentence s if s in true in m
M(s) = set of all models of s
KB entails s iff M(KB) belongs to M(s)
Valid: true in all models
Satisfiable: true in some models
Unsatisfiable: true in no models
conjunction of Horn clauses
Horn clauses
proposition symbol || conjucton of symbols -> symbol
1.check if q is known already
2.prove by BC all premises of some rules concluding q
conjunction of “disjunctions of literals”
sound and complete
To proof Kb entails a , by contradiction, show that Kb and not a unsatisfiable
well formed formula/wff: for sentences that have all their variables properly introduced.
FOL: one can quantify over objects but not over relations or functions on these object
Higher order logic : quantify over relations and functions
$(\lambda x,y\ x^2-y^2)(25,24) = 25^2 - 24^2 = 49$
E! = unique
UI can be applied several times to add new sentences, the new KB is logically equivalent
to the old
EI can be applied once to replace the existential sentence, the new KB is not equivalent to the old.
UNIFY(p,q) = theta where SUBST(theta,p) = SUBST(theta, q)
Decision Tree not a good way to represent the function because the truth table is exponentially large in the number of attributes
**Ockham’s razor.**The most likely hypothesis is the simplest one that is consistent with all observations.
Information content I
$I(P(v_1),…,P(v_n)) = \sum-P(v_i)log_2P(v_i)$
P is smaller, then -log P is bigger
$Gain(A) = I(p/(p+n), n/(n+p)) - Reminder(A)$
$Reminder(A) = \sum\frac{p_i+n_i}{p+n}I(p_i/{p_i+n_i},n_i/p_i+n_i)$
We select features with largest Gain.
Sample Size: $m >= 1/e ( ln 1/o + ln|H|)$
e = max error o = error’s probablity H= number of possible hypothesis