自己產生資料,比如從輸出產生輸入,把完整的拼圖打亂,叫Machine把它拼回去。
自監督式學習 Self-Supervised Learning for Computer Vision 之概述
Where does the error come from?
Unseen cases可能與seen cases差異甚大
Test set太小則有可能與真實的正確率有偏差
:真實誤差
:根據seen cases得到的誤差
用Hoeffding’s Inequality bound兩者的誤差。
的大小:
太大:bound太大,和可能差很大
太小:找不到好的使得很小但是PLA的怎麼辦?
abbr: PAC=probably approximately correct
bound the distance between and by the number of hypotheses. but for infinite hypotheses? Classify them into dichotomies(from parameters to the classification results of samples). In a binary classification problem, the number of dichotomies is upper bound by where N is the number of samples. growth function: the maximum number of dichotomies among possible inputs(to make it independent of inputs), denoted as . But for some tasks, the number of dichotomies may be lower,
is a breakpoint if , property: all minimum break point are break points.
For some N, k inputs can be shattered by
For a set of hypotheses for a task, VC dimension=breakpoint-1, VC dimension means the last s.t. the hypotheses can shatter any possible N inputs. VC dimension can be view as the strength of a set of hypotheses.
It's proven that for ,
Example:
linear classification: h(x)=sign(s), error: 0/1
linear regression: h(x)=s, error: mse
logistic regression: h(x)=, error: cross-entropy
non-linear transform + linear model => non-linear model
low , high
Maybe automatically detect outliers, and
Example: slightly shift/rotate images to generate more data.
Aka data augmentation
validation set:作弊,從training data分個出來當作選擇hypothesis的標準。
practical:
When choose n-th data as validation set,
Hope
It takes a lot of time. Not practical.
把資料切成V份,輪流把其中一份當作validation。
practical:
Report test result instead of best validation result.
越簡單越好。
只加入必要的東西。
Machine learning may cause harm.
Match test scenario as much as possible
One possible solution: emphasize later samples
If designing the model while snooping(偷看) data, it may overfit.
If a data set has affected any step in the learning process, its ability to assess the outcome has been compromised.
carefully balance between data-driven modeling(snooping) and validation (no-snooping)
If many hypotheses can perfectly solve this, choose the one with the largest "Robustness"(can classify even if some test data is affected by noise.)
Robustness = Fatness of saparating hyperplane = the distance to the nearest (margin).
Choose the one with the largest margin and can perfectly separate data.
Shorten x and w first. Make -> , and -> and .
So ->
Want to know the distance(x,b,w) = the distance between x and hyperplane
distance=project some to orthogonal of the hyperplane(the normal vector )=
Goal: Find subject to
If , say , we can let so that is larger.
Origin of name: The optimal boundary only depends on the nearest points(support vectors(candidates)).
It's equivalent to finding the minimum of . And minimum of subject to for ,
where
easy with QP solver
可以像Linear model一樣直接把transform後的資料作為輸入跑Linear SVM,但因為有些transform後的維度()非常大,像是d維資料的Q-order polynomial transform 的,就會爆炸,因此depend on 不利於使用更複雜的transform,要使用對偶來消除
如上所述,(Non-)Linear SVM要optimize 個variables(和b),且符合個條件(,即每一筆資料都正確分類)。
We want to construct an equivalent SVM with variables and constraints. 細節需要太多的數學過程,因此只介紹必要部分。
以regularization舉例
s.t.
如果想要讓weight length ,相當於給定另一個參數。
用Lagrange Multipliers把原本 s.t. 變成
其中,KKT會用到。
violate, feasible: Does satisfy constraints?
For any fixed with all ,
Because max any , and this still holds after .
For the best , the above also holds, so
LHS is equivalent to the original SVM, called primal. RHS is called Lagrange dual.
In the Lagrange dual problem,
Strong duality means there exists a primal-dual optimal solution for both sides.
Since inner has no constraints on (unconstrained), we can simply take a partial derivative on .
If we want to maximize , we can set(without loss of optimality) the constraint
Therefore, we can remove b:
Under a constraint outside , .
Since the last term is .
Similarly, we can simply take a partial derivative on .
We then have
Then substitute it into the expression:
Under addtional constraints for : and .
If is a optimal solution for Lagrange dual, and
Called Karush-Kuhn-Tucker (KKT) conditions
根據以上結論,我們可以用QP解
得出 ,再用以上條件得出
optimal optimal
optimal optimal ?
根據primal feasible,,給出了 的範圍(大部分(non-support vector)都大於1)。
進一步,根據primal-inner optimal,
由於non-SV後面都是non-zero,因此 。因此若 ,可以得出:
SVM | PLA |
---|---|
從 dual solution。 | # of mistake corrections on |
is linear combination of . This is also true for GD/SGD-based Logistic regression/Linear regression when .
is represented by data.
SVM: represented by SVs only.
目標:解決上述暴力計算 時需要 的問題。
=Transform+Inner Product
用有效的Kernel function快速計算
Example for (poly transform)
考慮計算
Note: 是原本資料的維度,而 是轉換後的維度,如果在 時間算完是可接受的。
aggregation for binary classification
假設有 個朋友,每個人對一個股票的預測為 函數,對於股票 ,代表漲跌。而根據這些朋友的結果做綜合的預測有哪些方法?
以uniform blending舉例
的平均,也就是
Therefore, the uniform blending is better than the average of .
This can also be interpreted as:
(expected performance of randomly choosing one hypothesis)
= (expected deviation to consensus)
+ (performance of consensus).
Uniform blending reduces variance for more stable performance.
Known , and each is given ballots.
Compute good :
For linear regression(+transform), it looks alike.
有些 hypothesis 可能是反指標,所以 可以是負的,因此不一定需要 的 constraints。
Blending 相當於把 變換為 ,其中 。
之後 Linear blending 相當於做 linear regression。
事實上也可以用其他模型,也就是 Any blending ,相當於 Stacking(blending 權重與資料有關)。
雖然很 powerful,但一樣會 overfitting。
如果能找出多樣化的 hypothesis,效果會更好。
可能方法:
而實際上可以用同一份資料利用資 料隨機性製造出不同的 。
:
This simulates the real aggregation:
因為我們沒有辦法真的每次得到不同的 筆資料,所以重複取樣是一個近似的方法。
又稱為 Bagging,把資料打包。
如果 hypothesis 對隨機資料很敏感(指產生多樣化的結果),很有可能平均後的效果會很好。(像是沒教的 pocket algorithm)
叫一堆小孩講出可能的判斷方法:
過程中會得出一個班級的共識,老師再把錯誤的分類結果提出來讓小孩再想一想。
對應到 ML
Bootstrapping 相當於把N筆資料重新給予權重,有些可能是 0,有些可能是很多次。
每個 相當於在 minimize bootstrap-weighted error。
可以重複某些資料,但也可以用演算法來達成,像是
重複 T 次,第 t 次使用 作為權重,我們希望每次結果會非常不同:
具體作法就是讓 在以 作為權重時的準確率為 0.5。
我們想要:
因此我們可以把 設為:
或是交叉相乘:把正確的乘上錯誤率(次數),錯誤的乘上正確率(次數)
若 在 的錯誤率是 。前一部分的方法相當於把正確的乘以 ,錯誤的乘以 。
因此可以取他們的中間值
正確時除以 ,錯誤時乘以 。
這會在之後用到。
Best for ,則用 (相當於沒有 reweighting)。
不太可能用 uniform,因為 是在正常的 表現很差的資料訓練,這個資料會與原本的資料偏差很大,很有可能結果會很差,其他結果也是差不多。
Linear 或 Non-linear 都行
使用特殊 blending 方法:
,因為 Scaling Factor 與正確率正相關,所以相當於給越正確的 hypothesis 越多的權重。
AdaBoost = 弱的 hypothesis(學生) + reweighting(老師) + blending(整個班)
If , after iterations.
在某一維度上,用一個 threshold 來分類。非常弱,但很有效率。
筆 維資料可以在 的時間完成。
用 Decision Stump 作為 hypothesis,用 AdaBoost 來訓練。
第一個實時辨認人臉的系統就是用這個方法,把圖片切成很多塊,並且用 Decision Stump 來判斷是否有人臉。
Decision Tree 可以達到 conditional aggregation,也就是 stacking。
aggregation | blending | learning example |
---|---|---|
uniform | voting | bagging |
weighted | linear | boosting |
conditional | stacking | Desicion Tree |
Decision tree 就是一堆 if-else 的組合,每個 if-else 就是一個 node。
是個很接近人類邏輯的模型,也很容易解釋、很簡單(很多財經分析也許會用)、很有效率。但是沒有理論保證,不知道該怎麼選擇參數、沒有代表性的演算法。
可以簡單的用 decision stump 來當作節點分枝條件的 hypothesis set,相對應的小孩數量就是 2(binary tree)。
節點分枝條件的決定:盡量找出分群後的結果能讓不純程度(用 Impurity Function 決定)最小的 hypothesis。差不多相當於 error function。
具體就是把不同群的 impurity function 以群的大小加權平均。
分類通常用 Gini index,回歸用第一種。
CART 是 fully-grown tree,因此會分到不能分為止,具體有這些條件:
因為結果會是不能繼續分的,可以直接用 optimal constant hypothesis。
One regularizer:
變成對於所有的 decision tree ,找到
但當然無法找到所有的 decision tree,所以通常只會考慮:
找到 的方法:validation
對應到 decision stump,會用 decision subset。
,其中
一樣是個二元樹,所以就是一個包含於 、一個不包含於 。
用其他類似的特徵來取代缺失的特徵。
但實際上不一定能找到全部都沒有缺失的特徵,比如在 final project 大概就用不到。
用 bagging 的方法把 個 Fully-grown Decision Tree 的輸出結合起來
假設 bagging 每次抽 個,那每個 沒抽到 的機率是 ,當 大了的話:
每次大約會有 個沒抽到,比想像中還多。
用處: 可以對於每個 剛好可以用它的 OOB examples 當作 validation。剛好就不用重新訓練。
在複雜的資料上,也能得到很好的結果,這就是投票的力量。
越多越好,實際上大概需要幾千幾萬這個量級。
壞處就是要算很多次 Decision Tree。
(Ada)Boost + Decision Tree
Intuition: 多個 perceptrons,加上 activation (模仿神經,用簡單的門檻,過某個值才是 1,否則是 0,相當於一個 perceptron 得到其他 perceptrons 的輸出作為輸入),可以造出 AND OR NOT 等等的邏輯閘。多層的話就更強。
為了簡化,用 MSE error。
如果只是加起來,整個還是 Linear Model,所以沒差,提到 sigmoid、tanh,會提到為何 現在比較少用。
For a Neural Network:
raw output
transformed output
universal approximator:
Neural Network 能夠模仿任何函數,實際上就算只有一層,只要 neuron 夠多也可以達到。像是 Gaussian Kernel 很強的概念一樣。
adaboost 難以與 perceptron 並用。
可以用(stochastic)gradient descent來minimize loss(error)
簡單暴力的把error對w取偏微分,會得到de/dw=de/ds*ds/dw,但除了輸出層的s直接與e關連,其他需要用 backward propagation 算。
直接真的用很少的偏移看看結果差多少作為微分結果。
如果只用 gradient descent,只會得到 local minimum,因此 init weights 很重要,像是太大的話梯度很小,會「飽和」,可以試試看小又隨機的 weight。
但後來發現其實不太會跑到 bad local minimum,只要用經驗法則選好的 weights 就好了。或是pre-training
因此需要 small and random
Early Stopping: 因為 gradient descent 類型的 model 在步驟多了之後會探索更多區域,相當於 漸漸增大,因此可以用 validation error 早點停下來。但有可能 validation error, 會在之後再次下降。
這是早期流行的方法,現在會用 double descent,