Transfer Learning / Domain Adaptation 筆記
===
# Content
[TOC]
# I. Basic Concept
### Negative Transfer
指的是:在 source domain 上學到的 knowledge,對 target domain 產生 negative effect
#### 該方向的研究
- Transitive transfer learning, 2015, SIGKDD
- 傳統 transfer learning 踩一個石頭過河,他們踩很多個
- Distant domain transfer learning, 2017, AAAI
- 領域不相似時,仍然可以 transfer learning,踩一連串石頭過河
# II. Transfer Learning 研究領域
## 以 target domain 的 label 分類
1. Supervised Transfer Learning
2. Semi-Supervised Transfer Learning
3. Unsupervised Transfer Learning
## 以 學習方法 分類
1. Instance based
- reuse weight ?
- 相似的 instance,給他高權重
- 簡單直接
2. Feature based
- 想辦法把 source 和 target 的 feature 變換到同個 space
- 應該是最熱門的研究方向
3. Model based
- 建立 share parameter 的模型,在NN系列用得特別多,例如 finetune
4. Relation based
- 0.0
## 以 feature 分類
1. Homogeneous (同構) Transfer Learning
- 例如 image 之間的 transfer
2. Heterogeneous (異構) Transfer Learning
- 例如 image 到 text 的 transfer
## 以 online 或 offline 分類
1. Offline Transfer Learning
- 目前大多數研究屬於此類
2. Online Transfer Learning
# IV. Basic Knowledge
## Formatting the Problem
- $\mathcal D$: domain
- $P$: 機率分布
- $x$: data
- $X$: 某 domain 的 data
- $\mathcal X$: feature space
## Metrics
### Distance
1. Euclidean Distance
2. Minkowski Distance
3. Mahalanobis Distance
### Similarity
1. cosine similarity
2. mutual information
3. Pearson correlation
4. Jaccard correlation
- $J = \dfrac{X\cap Y}{X\cup Y}$
# V. Basic Method of Transfer Learning
## Instance-based
本類方法通常假定 $P(x_s)\neq P(x_t)$,而 CV 領域的 dimension 都很大,因此直接對 $P(x_s)$ 或 $P(X_t)$ 做估計並不可行。故許多 work 是對 source 及 domain 機率分布的比值進行估計。估計得出的比值即為樣本的權重。例如:
- Adapting instance weights for unsupervised domain adaptation using quadratic mutual information and subspace learning. ICPR 2016
-
而這些方法通常假設 $P(x_t)/P(x_s)<\infty$ 且條件機率相同 $P(y|x_s)=P(y|x_t)$
### methods
- TrAdaboost
- 提高有利於 target task 的權重,降低不利於 target task 的權重
- Kernal Mean Matching (KMM)
- 目標是使得加權後的 source domain 和 target domain 的 distribution 盡可能相近
- Transitive Transfer Learning
- Distant Domain Transfer Learning
只在 domain 間差異較小時有效 ***(last2???)*** ,對 CV 領域不甚理想。
## Feature-based
這類的方法通常假設 source domain 及 target domain 有一些交叉的 feature
典型方法
- (Transfer Component Analysis, TCA) Domain adaptation via transfer component analysis. 2011
對於 source 和 target domain 各自訓練不同的變換矩陣,以 transfer learning
- Joint geometrical and statistical alignment for visual domain adaptation. CVPR 2017
以下研究同時學習 feature 和 model 的 transfer learning (和 NN 結合)
- Learning transferable features with deep adaptation networks. 2015, ICML
- Deep learning of transferable representation for scalable domain adaptation. 2016
- Deep transfer learning with joint adaptation networks. 2017, ICML
- Learning transferrable representations for unsupervised domain adaptation. 2016
## Parameter/Model-based
這類方法假設某些參數可以共享
Cross-people mobile-phone based activity recognition. IJCAI 2011
- 提出了 TransEMDT 方法。先針對 labeled data 利用 decision tree 構建 robust 的 action recognition 模型,然後對 unlabeled data 利用 K-means clustering 尋找 optimized 標定參數。
Instilling social to physical: Co-regularized heterogeneous transfer learning. AAAI 2016
- 將社交訊息加入 transfer learning 方法的 regularization term,對方法進行了改良
在 NN 中加入機率分布適配層
- Learning transferable features with deep adaptation networks. ICML 2015
- Deep learning of transferable representation for scalable domain adaptation. 2016 IEEE Transaction on Knowledge and Engineering
- Deep transfer learning with joint adaptation networks. ICML 2017
以下研究同時學習 feature 和 model 的 transfer learning
- Learning transferable features with deep adaptation networks. 2015, ICML
- Deep learning of transferable representation for scalable domain adaptation. 2016
- Deep transfer learning with joint adaptation networks. 2017, ICML
## Relation-based
0.0
# V. method 1: Distribution Adaptation
主要分三類:
1. Marginal Distribution Adaptation
2. Conditional Distribution Adaptation
3. Joint Distribution Adaptation
## Marginal Distribution Adaptation
目標為減小 source 和 target domain 的 marginal distribution $P(x)$,以 $P(x_s)$ 和 $P(x_t)$ 之間的距離來近似兩個 domain 的差異
核心方法 Transfer Component Analysis (TCA)
TCA 的假設:
- 存在一個 feature mapping $\phi$ 使得 mapping 後的 distribution $P(\phi(x_s))\approx P(\phi(x_t))$
- 若 marginal distribution 接近,則 conditional distribution ($P(y_s|\phi(x_s))\approx P(y_t|\phi(x_t))$) 也會接近
因此目標是:找到一個合適的 $\phi$ 使得 feature transform 之後的 marginal distribution 最接近
- 使用 maximum mean discrepancy (MMD) 來衡量 domain 之間的距離
- $DISTANCE(x_s, x_t) = ||\frac{1}{n_1}\sum_\limits{i=1}^{n_1}\phi(x_i) - \frac{1}{n_2}\sum_\limits{j=1}^{n_2}\phi(x_j)||_{\mathcal H}$
- $\phi(\cdot)$ 是將 variable 映射到 Reproducing Kernel Hilbert Space, RKHS
- 引入了 kernel matrix $K$
- TCA 最後的優化目標:
## Conditional Distribution Adaptation
用 $P(y_s|x_s)$ 和 $P(y_t|x_t)$ 的距離來近似兩個 domain 之間的差異
$DISTANCE(D_s, D_t)\approx ||P(y_s|x_s) - P(y_t|x_t)||$
不過單純用這類的方法不多,主要可以在以下 paper 找到
- Asymmetric tri-training for unsupervised domain adaptation. ICML 2017
Stratified Transfer Learning 提出了 Intra-class Transfer 的思想,指出大多數方法只是學習一個 Global Domain Shift,而忽略了 intra-class 的相似性
- Stratified transfer learning for cross-domain activity recognition. 2018
- 計算每個 class 的 MMD distance
## Joint Distribution Adaptation
JDA 方法:Transfer feature learning with joint distribution adaptation. 2013, ICCV
$DISTANCE(D_s, D_t)\approx ||P(x_s)-P(x_t)|| + ||P(y_s|x_s)-P(y_t|x_t)||$
然而 Marginal Distribution Adaptation 和 Conditional Distribution Adaptation 並不是同樣重要,depends on domain distribution 的差異,因此
Balanced distribution adaptation for transfer learning. 2017, ICDM
提出了 BDA,採用 balance factor $\mu$ 來動態調整兩個 distribution 的距離。
## 小結
1. 精度比較:BDA > JDA > TCA > Conditional Distribution Adaptation
2. 某圖顯示,將 prob distr 加入 DNN 中,往往取得比 非deep方法 更好的結果
# VII. method 2. Feature Selection
---
# VIII. method 3. Subspace Learning
---
# IX. method 4. Deep Transfer Learning
該如何決定 transfer 哪些 layer,固定哪些 layer?
- How transferable are features in deep neural networks? 2014, NIPS
- 前三層基本 general feature
## 3 Deep Network Adaptation
finetune 的基本假設是 training data 和 testing data 服從相同的 distribution,然而這在 transfer learning (domain adaptation) 中不成立,**fine tune 無法處理 training data 和 testing data 的 distribution 不同的情況。** 因此需要更進一步開發出更好的方法。
絕大多數 Deep Transfer Learning 方法都採用了以下的 loss definition
- $l = l_c(D_s, y_s) + \lambda l_A(D_s, D_t)$
- $l_c(D_s, y_s)$ 表示 labeled data (通常是 source domain) 上的 loss
- $l_A(D_s, D_t)$ 表示 network 的 adaptation loss,這裡與之前提到的 distribution 差異,道理相同
以下方法開發出了 **Adaptation Layer**
- (**DDC**) Deep domain confusion: Maximizing for domain invariance. 2014
- 圖為 DDC 方法示意圖 
- 為何選倒數第二層? 實驗表明,在 classifier 前一層加入 adaptation 可以達到最好的效果
- loss function: $l = l_c(D_s, y_s) + \lambda MMD^2(D_s, D_t)$ 使用 MMD 作為衡量標準
- (**DAN**) Learning transferable features with deep adaptation networks. 2015 ICML
- 相較於 DDC 只加入一層 Adaptation Layer,DAN 同時加入了三個 Adaptation Layer (classifier 前三層)
- 相較於 DDC 使用 MMD,DAN 使用 Multi-Kernel MMD (MK-MMD)
- 比 DDC 更強
- network 結構如下圖 
### 3. 同時 transfer domain & task 的方法
- Simultaneous deep transfer across domains and tasks. 2015, ICCV
- 針對的情況:target domain 的部分 class 有少量 label,剩下 class 無 label
- 作者提出方法名為 joint CNN architecture for domain and task transfer
- 現有方法都只做 domain confusion,而這樣不夠,因為忽略了 class 之間的聯繫,因此提出了要再加 soft label loss
- 
- 如下圖 
- $L_C$ 是普通的 loss
- $L_{conf}$ 是一般的 domain adaptation
- $L_{soft}$ 是 soft label 的 loss,只作用於 target 上
- ***什麼是 soft label loss? 在 network 對 source 訓練時,把 source 每個 sample 的每個 class 機率都記下來,(???)***
- soft label 示意圖 
### 4. Deep Joint Distribution Adaptation
- (**JAN**) Deep transfer learning with joint adaptation networks. ICML 2017
- 提出了 Joint MMD (JMMD)
- JAN 示意圖 
### 5. AdaBN (Adaptive Batch Normalization)
- Adaptive batch normalization for practical domain adaptation. 2018
- 在 normalization layer 加入統計 feature 的 adaptation
- 實現簡單、方法本身不帶有任何額外 parameter
- AdaBN 示意圖 
#### 小結
Deep Transfer Learning 的研究
- Deep learning of transferable representation for scalable domain adaptation. 2016
- Deep unsupervised convolutional domain adaptation. 2017
- Supervised representation learning: Transfer learning with deep autoencoders. 2015, IJCAI
- Deep coral: Correlation alignment for deep domain adaptation. 2016, ECCV
- Deep nonlinear feature coding for unsupervised domain adaptation. 2016, IJCAI
- Label efficient learning of transferable representations acrosss domains and tasks. 2017, NIPS
- Autodial: Automatic domain alignment layers. 2017, ICCV
- 這方法很容易被加入現有的 DNN 中,使 deep transfer learning 更方便
## 9.4 Deep Adversaial Network Transfer
### 1. DANN (Domain-Adversarial Neural Network)
Domain-adversarial training of neural networks. 2016, JMLR

- $l = l_c(D_s, y_s) + \lambda l_d(D_s, D_t)$
- $l_c$ 是 NN 的 loss;$l_d$ 是 domain 的 loss
- **domain loss:** $l_d = \max [-\frac{1}{n}\sum_\limits{i=1}^n \mathcal L_d^i(W, b, u, z) - \frac{1}{n'}\sum_\limits{i= n+1}^N \mathcal L_d^i(W, b, u, z)]$
- $u, z$ ***是???***
- ***不懂這個式子在幹嘛***
- $\mathcal L_d(G_d(G_f(x_i)), d_i) = d_i\log\dfrac{1}{G_d(G_f(x_i))} + (1-d_i)\log\dfrac{1}{G_d(G_f(x_i))}$
- $G_d$ 是 discriminator;$G_f$ 是 feature extractor
### 2. DSN (Domain Separation Networks)
Domain Separation Networks. 2016, NIPS
DSN 認為,source 和 target domain 都由兩部分組成:shared & private,對 DANN 進行了擴展。

- loss function: $l = l_{task} + \alpha l_{recon} + \beta l_{difference} + \gamma l_{similarity}$
- $l_{recon}$: reconstruction loss,確保 private 部分仍然對 learning 的目標有用
- **為什麼 reconstruction loss 會對 learning 目標有用?** 個人理解為:能夠將 feature 給 reconstruct 回來就代表這個 feature 幾乎保留了 data 的所有訊息
- $l_{difference}$: shared & private 部分的 difference loss
- 應該是希望兩個 feature 差越多越好
- $l_{similarity}$: source & target domain 在 shared 部分的 similarity loss
- 應該是希望兩個 feature 越相似越好
#### ADDA, Adversarial Discriminative Domain Adaptation (不知為何被寫在 DSN 下面
- Adversarial discriminative domain adaptation. 2017, CVPR
- 可視為一個通用的框架,現有的很多方法都可被看做 ADDA 的特例
- 以下 work 似乎都照之前思路進行
- 利用 WGAN 進行 transfer learning
- Wasserstein distance guided representation learning for domain adaptation. 2018, AAAI
- Coupled GAN 用於 transfer learning
- Coupled generative adversarial networks. 2016, NIPS
### 3. SAN
**Partial Transfer Learning**
動機:source domain 通常非常豐富,常常會出現 target domain 的 class 只是 source domain 的一小部分 class。這樣會有一個問題:只存在於 source domain 的 class 在 transfer 時,會對結果產生 **negative transfer** 的影響。
這種情況非常普遍,因此就要求 transfer learning 方法能對 target domain 選擇相似的 source domain sample(class),**然而實際使用的時候,target domain 通常沒有 label,不知道 (target domain 的某個 instance?) 和 source domain 的什麼 class 更相似**。作者指出這個問題叫 partial transfer learning,也就是 「只 transfer source domain 中某部分和 target domain 相關的 sample」。

Partial Transfer Learning 的 idea 示意圖如上
Selective Adversarial Networks (SAN)
- Partial transfer learning with selective adversarial networks. 2017
- 在 partial problem 中,傳統的 adversarial network 不再適用,因此需要修改使之適用於 partial problem
- ***下面這裡沒懂***
- instance level 的 loss $L_d' = \dfrac{1}{n_s+n_t}\sum_\limits{k=1}^{|C_s|}\sum_\limits{x_i\in D_s+D_t} \hat y_i^kL_d^k(G_d^k(G_f(x_i)), d_i)$
- 或者 class level 的 loss 
- 為了消除 過於依賴每個 instance 的 prediction probability 的影響,作者又在 target domain 上加了一項 minimize entropy
- $E = \frac{1}{n_t}\sum_\limits{x_i\in D_t}H(G_y(G_f(x_i)))$
### Deep Adversarial Network Transfer 小結
使用 adversarial network 進行 transfer learning 是近年熱門的研究方向。
## Cutting Edge of Transfer Learning
### TL with Human Knowledge
- 不需要 label,取而代之的是將 knowledge 教給 network
- Label-free supervision of neural networks with physics and domain knowledge. 2017, AAAI
- task: 預測枕頭落下軌跡
- 不需要 label,給予 knowledge: 拋出的物體通常會沿著拋物線的軌跡運動
### Transitive Transfer Learning
兩個看起來不相似的 domain A & B,是否能找到中間的 domain C,和 A&B 都有一定程度的相似,使得 A 可以先 transfer 到 C 再到 B。
- Transitive transfer learning. 2015, SIGKDD
- 在 A 與 B 中間 transfer 一個 domain
- Distant domain transfer learning. 2017, AAAI
- 在 A 與 B 中間 transfer 多個 domain
### Life-long Learning System
- (L2T) Learning to Transfer. 2017
### Online Transfer Learning
- 第一篇 OTL(Online Transfer Learning) 的 paper
- Otl: A framework of online transfer learning. ICML 2010
- 在多個 source domain 和 target domain 上的 OTL
- Online transfer learning by leveraging multiple source domains. 2017
- Online heterogeneous transfer by hedge ensemble of offline and online decisions. 2017
- Online Feature Selection
- Online feature selection and its applications. 2014
- Online feature transformation learning for cross-domain object category recognition.
- Online Transfer Ensemble
- Online transfer boosting for object tracking.
- Knowledge transfer using cost sensitive online learning classification.
- Application
- Online bayesian transfer learning for sequential data modeling. ICLR 2017
### Transfer Reinforcement Learning
- Transfer learning for reinforcement learning domains: A survey.
發展空間還很大
### Explainable Transfer Learning
為什麼 domain A 和 domain B 更相似,而不是 domain C?
- 只有經驗,缺乏理論
- **Understanding how feature structure transfers in transfer learning. 2017, IJCAI**
- **本篇 paper 有助於理解 feature 如何 transfer**
### Understanding how features structure transfers in transfer learning. 2017, IJCAI
這篇 paper 定義某個 domain 的 **feature structure** 為一個 bases 的 set,這個 set 可以重構該 domain 的所有 observation,並且定義 source domain 到 target domain 的 **feature structure**轉換 為 **feature structure transfer learning**
- 例如 self-taught learning algorithm 就是一種 feature structure transfer learning algorithm
# Others
## Journals and Conferences about Transfer Learning
### Journals

### Conferences

<!--
## Transfer Learning 很猛的學者
- [Qiang Yang @ HKUST](https://scholar.google.com.tw/citations?user=1LxWZLQAAAAJ&hl=zh-TW&oi=ao)
- [Sinno J. Pan @ NTU](https://scholar.google.com.tw/citations?user=P6WcnfkAAAAJ&hl=zh-TW&oi=ao)
- [Ben Tan @ 騰訊](https://scholar.google.com.tw/citations?user=aBOqAicAAAAJ&hl=zh-TW&oi=sra)
- Transitive Transfer Learning
- Distant Domain Transfer Learning
等等
-->
# 參考資料
- [《迁移学习简明手册》](http://jd92.wang/assets/files/transfer_learning_tutorial_wjd.pdf)
###### tags: `transfer learning` `domain adaptation`