113職前Deeplearning
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # 機器學習/深度學習百科 > [!Warning] 部分定義使用 ChatGPT 生成,但經過人工改寫。 :::spoiler 目錄 [TOC] ::: ## A ### Activation function **啟動函數**(activation function)是在[神經網路](#Neural-network)中的一種非線性函數(nonlinear function),位於每一層神經元的輸出端。它的作用是將輸入映射到某個範圍,並引入非線性(nonlinearity),使得神經網路能夠學習和表示複雜的非線性關係,從而提升模型在分類、迴歸等複雜任務中的表現。 常見的啟動函數包括 [Logistic 函數](#Logistic-function)、[ReLU](#ReLU)、[tanh](#Tanh)、[Leaky ReLU](#Leaky-ReLU) 等等。 ### Adam optimizer ## B ### Bias 在機器學習模型中,**偏差**(bias)是一個加到加權和(weighted sum)中的額外參數,用於調整模型輸出的偏移量。 偏差與[權重](#Weight)合稱[模型參數](#Model-parameters),它們共同決定特徵對最終輸出的影響。 偏差允許模型擬合更複雜的資料模式。例如在應對非線性問題情況時能夠保持靈活性。或是幫助模型在沒有輸入的情況下也能產生有意義的輸出。 ### Binary classification **二元分類**(binary classification)是機器學習中一種[分類問題](#Classification),目標是將輸入的資料分成兩個類別之一。 - 二元分類模型的輸出通常是 0 或 1,對應於兩個可能的結果。例如,在垃圾郵件過濾中,二元分類問題就是判斷一封郵件是垃圾郵件(1)還是非垃圾郵件(0)。 - 二元分類模型的預測結果通常是一個機率值 $p$,表示資料屬於某一類別的可能性,並從閾值(通常為 0.5)來判斷最終的分類結果。如果 $p > 0.5$,則預測為類別 1;否則,預測為類別 0。 - 二元分類問題常用的損失函數是[二元交叉熵](#Binary-cross-entropy)。 ### Binary cross entropy **二元交叉熵**(binary cross-entropy,BCE)是專門用於[二元分類](#Binary-classification)問題的[損失函數](#Loss-function),衡量模型預測的機率分佈與實際標籤之間的差異。它是[交叉熵損失](#Cross-entropy-loss)在二元分類上的專用版本。 其數學表達式為: $$ L = - \big[ y \log(p) + (1 - y) \log(1 - p) \big] $$ 其中: - $y$ 是真實標籤,取值為 0 或 1。 - $p$ 是模型預測輸出為類別 1 的機率。 - $\log$ 是自然對數函數。 **二元交叉熵**損失越小,模型的預測結果與實際標籤越接近。這個損失函數通常用在如垃圾郵件檢測、疾病診斷等二元分類問題中。 - 在 [TensorFlow Keras](#Tensorflow-keras) 中的對應函式為 [`BinaryCrossentropy`][tf-bce]。 - 在 [PyTorch](#PyTorch) 中的對應函式為 [`BCELoss`][torch-bce]。 [tf-bce]: <https://www.tensorflow.org/api_docs/python/tf/keras/losses/BinaryCrossentropy> 'tf.keras.losses.BinaryCrossentropy' [torch-bce]: <https://pytorch.org/docs/stable/generated/torch.nn.BCELoss.html> 'torch.nn.BCELoss' ## C ### Classification **分類問題**(classification problem)是機器學習中一種常見的任務,目的是將輸入的資料分配到不同的類別中。分類問題的輸出是離散的,也就是模型要從一組有限的標籤中選擇一個作為輸出的結果。 分類問題的例子包括: - [二元分類](#Binary-classification):只有兩個類別,例如垃圾郵件分類(垃圾郵件或非垃圾郵件)。 - [多元分類](#Multiclass-classification):有多於兩個類別,例如手寫數字識別(0 到 9 共 10 個類別)。 在處理分類問題時,常見的演算法有: - [Logistic 迴歸](#Logistic-regression) - 支持向量機(Support Vector Machine, SVM) - 決策樹(Decision Tree) - 隨機森林(Random Forest) - 神經網路(Neural Networks) 分類問題的損失函數通常使用[交叉熵損失](#Cross-entropy-loss)來度量預測結果和真實標籤之間的差異,並透過最佳化演算法來最小化這個損失。 ### Cross-entropy loss **交叉熵損失**(cross-entropy loss)是機器學習中常用於[分類問題](#Classification)的一種[損失函數](#Loss-function),特別是二元或多元分類問題。==它衡量模型預測的機率分佈與實際分佈之間的差異==。 - [二元交叉熵](#Binary-cross-entropy) - [多元交叉熵](#Multiclass-cross-entropy) 交叉熵損失越小,表示模型預測的機率分佈與真實標籤的分佈越接近,因此交叉熵損失被最小化時,模型性能通常會更好。 ## D ### Decision tree ## E ### Elastic net ## F ## G ### Gradient **梯度**(gradient)是向量微積分中的一個概念,表示一個多變數函數在每個變數上的[偏導數](#Partial-derivative)。對於一個函數 $f(x_1, x_2, \dots, x_n)$,其梯度是一個向量,其分量是該函數對每個變數的偏導數。具體的數學表達式為: $$ \nabla f(x_1, x_2, \dots, x_n) = \left( \frac{\partial f}{\partial x_1}, \frac{\partial f}{\partial x_2}, \dots, \frac{\partial f}{\partial x_n} \right) $$ 其中 $\nabla f$ 是函數 $f$ 的梯度,$\frac{\partial f}{\partial x_i}$ 是函數 $f$ 對變數 $x_i$ 的偏導數。 就幾何意義來說,梯度指向函數值增長最快的方向,且向量的長度表示增長的速率。 在機器學習中,梯度通常是指[目標函數](#Objective-function)(如[損失函數](#Loss-function))相對於[模型參數](#Model-parameters)的梯度。在[最佳化演算法](#Optimization-algorithm)(如[梯度下降法](#Gradient-descent))中,梯度用來告訴我們應該如何更新模型的參數,使損失函數減少。 ### Gradient descent **梯度下降法**(gradient descent)是機器學習中一種常用的[最佳化演算法](#Optimization-algorithm),用來最小化[損失函數](#Loss-function)。它透過計算損失函數對模型參數的[梯度](#Gradient)來更新參數,使損失函數逐步減小。 以下是梯度下降法的過程概說: 1. **初始化**:隨機初始化[模型參數](#Model-parameters)。 2. **計算梯度**:對損失函數計算相對於每個模型參數的梯度。 3. **更新參數**:根據梯度的方向和[學習率](#Learning-rate) $\eta$ 更新參數: $$ \theta := \theta - \eta \cdot \nabla L(\theta) $$ 其中,$\theta$ 表示模型參數,$\nabla L(\theta)$ 是損失函數 $L$ 的梯度,$\eta$ 是學習率。 4. **迭代**:重複步驟 2 和 3,直到損失函數收斂到某個最小值,或者達到指定的迭代次數。 關於更淺白的解釋,可以參考[^tommy-huang-gradient]。 梯度下降法有多種變體,如[**批次梯度下降法**](#batch-gradient-descent)、[**隨機梯度下降法**](#stochastic-gradient-descent)、[**小批次梯度下降法**](#mini-batch-gradient-descent),它們在計算梯度時使用的資料量不同。 ## H ### Hyperparameter **超參數**(hyperparameter)是在機器學習中由開發者或使用者事先設定的參數,這些參數在模型訓練過程中保持不變。與模型中的「參數」不同,參數是由訓練資料自動學習而來,而超參數需要手動調整。 常見的超參數包括: - [學習率](#Learning-rate):控制模型更新參數的速度。 - [批次大小](#Batch-size):一次訓練所使用的資料量。 - [隱藏層](#Hidden-layer)的數量(在神經網路中)。 - [正則化](#Regularization)參數:防止過度擬合。 調整這些超參數對模型性能有很大影響,通常需要透過實驗來找到最佳設定。 ## L ### L1 norm **L1 範數**(L1-norm)是 [L1 正則化](#L1-regularization)使用的[範數](#Norm),定義為==所有參數的絕對值之和==,即 $$ \|\theta\|_1 = \sum_{j=1}^{p} |\theta_j| $$ ### L1 regularization **L1 正則化**(L1 regularization)是一種[正則化](#Regularization)技術。它在[損失函數](#Loss-function)中加入模型參數的 [L1 範數](#L1-norm)作為[懲罰項](#Penalty-term),也就是 $$ \lambda \|\theta_j\|_1 = \lambda \sum^p_{j=1} |\theta_j| $$ 使用 L1 正則化的線性迴歸,稱為 [Lasso 迴歸](#Lasso-regression)。 ### L2 norm **L2 範數**(L2-norm)是 [L2 正則化](#L2-regularization)使用的[範數](#Norm),定義為==所有參數平方和的平方根==,即 $$ \| \theta \|_2 = \sqrt{\small \sum_{j=1}^{p} (\theta_j)^2} $$ ### L2 regularization **L2 正則化**(L2 regularization)是一種[正則化](#Regularization)技術。它在[損失函數](#Loss-function)中加入模型參數的 [L2 範數](#L2-norm)作為[懲罰項](#Penalty-term),也就是 $$ \lambda \|\theta_j\|_2 = \lambda \sqrt{\small \sum^p_{j=1} (\theta_j)^2} $$ 使用 L2 正則化的線性迴歸,稱為 [Ridge 迴歸](#Ridge-regression)。 ### Lasso regression **Lasso 迴歸**(Lasso regression)是使用 [L1 正則化](#L1-regularization)的[線性迴歸](#Linear-regression)模型,它的[損失函數](#Loss-function)可以表示成 $$ \begin{aligned} \text{Loss} &= \text{MSE} + \lambda \|\theta_1\|_1 \\ &= \frac{1}{2n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2 + \lambda \sum_{j=1}^{p} |\theta_j| \end{aligned} $$ 其中: - $\text{MSE} = \frac{1}{2n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2$ 是[均方誤差](#Mean-square-error)(mean square error),是線性迴歸模型常用的損失函數。 - $y_i$ 是實際值,$\hat{y}_i$ 是模型預測值; - $i$ 是資料集索引,$n$ 是資料集的樣本數。 - $\lambda \|\theta_j\|_1$ 是包含 [L1 範數](#L-norm)的[懲罰項](#Penalty-term)。 - $\theta_j$ 是模型參數;$j$ 是特徵和參數的索引,$p$ 是特徵和參數的數量。 - $\|\theta_j\|_1 = \sum_{j=1}^{p} |\theta_j|$ 是 $\theta_j$ 的 L1 範數,即所有參數的絕對值之和。 - $\lambda$ 是正則化係數,控制正則化的強度。 因為 L1 正則化會讓一些參數的值收縮到零,Lasso 回歸可以同時進行[特徵選擇](#Feature-selection),這在有大量冗餘特徵的情況下非常有用。 Lasso 迴歸的「Lasso」來自 Least Absolute Shrinkage and Selection Operator 的縮寫。 ### Leaky ReLU Leaky ReLU 是基於 [ReLU](#ReLU) 的變體[^pwc-leaky-relu],是一種分段線性函數(piecewise linear function),也是神經網路中常見的[啟動函數](#Activation-function)之一。它的定義是 $$ \text{Leaky ReLU}(x) = \max(\alpha x, x) = \begin{cases} x, & \text{if } x \geq 0 \\ \alpha x, & \text{if } x < 0 \end{cases} $$ 其中 $\alpha > 0$。由上式可看出,當輸入小於 0 時,Leaky-ReLU 有一個微小的斜率 $\alpha$,這可避免 ReLU 的「[神經元死亡問題](#Dying-ReLU-problem)」。 [^pwc-leaky-relu]: https://paperswithcode.com/method/leaky-relu ### Learning rate **學習率**(learning rate)是機器學習中的一種[超參數](#Hyperparameter),用來控制模型在每次更新時調整參數的步伐大小。它決定了模型在優化過程中學習的速度。 學習率通常需要調整,以找到「能平衡模型訓練速度和穩定性」的最佳值。 - 學習率過大,模型可能會跳過最佳解,導致訓練不穩定; - 學習率過小,模型學習速度會很慢,甚至無法收斂到最佳解。 學習率的符號通常用希臘字母 $\eta$(eta)來表示,有時也會用 $\alpha$(alpha)表示。 ### Logistic regression **Logistic 迴歸**(logistic regression,可譯作**邏輯斯迴歸**)是一種常用於[分類問題](#Classification)的統計模型。它透過一個線性方程式計算輸入變數的加權總和,然後使用 [sigmoid 函數](#Sigmoid-function)將結果轉換成介於 0 和 1 之間的機率值。這樣,模型可以預測某個觀察值屬於某一類別的機率,當機率超過某個閾值(通常為 0.5)時,就將其分類到某一類。 簡單來說,邏輯斯迴歸就是用來預測輸出為兩個可能值(例如,真或假、是或否)的分類模型。 ### Loss function **損失函數**(loss function)是機器學習中用來衡量模型預測結果與實際標籤之間差異的一個函數。它的目的是量化模型預測的「錯誤」,以便在模型訓練過程中通過最小化這個錯誤來優化模型的性能。 常見的損失函數包括: - **[均方誤差](#mean-squared-error)**:常用於[迴歸問題](#regression),計算預測值與真實值之間誤差的平方平均。 - **[交叉熵損失](#cross-entropy-loss)**:常用於[分類問題](#classification),特別是二元分類或多類分類,衡量預測的機率分佈與實際分佈之間的差異。 損失函數越小,表示模型預測的準確性越高,因此優化的目標通常是最小化損失函數的值。 ## M ### MNIST **MNIST**(Modified National Institute of Standards and Technology)是機器學習和深度學習領域中最常用的圖像資料集之一,主要用來進行手寫數字的識別任務。 MNIST 資料集包含 70,000 張 $28\times28$ 像素的灰階手寫數字圖像,其中訓練集有 60,000 張圖像,測試集有 10,000 張圖像。 每張圖像都代表 0 到 9 的手寫數字,這是一個典型的[多元分類問題](#Multiclass-classification),共有 10 個類別。由於其簡單且易於上手的特性,MNIST 數據集經常被用作測試機器學習演算法和深度神經網路的入門範例。此外,MNIST 資料集也經常用來進行模型性能的比較,像是比較各種不同的[卷積神經網路](#Convolutional-neural-network)。 在 Python 中,可以透過 Tensorflow Keras 或 PyTorch 的 API 來載入 MNIST 資料集。以下是 Keras 的載入範例: ```python= from tensorflow.keras.datasets import mnist # 載入資料集 (x_train, y_train), (x_test, y_test) = mnist.load_data() # 資料預處理 x_train = x_train.reshape(-1, 28, 28, 1).astype('float32') / 255 x_test = x_test.reshape(-1, 28, 28, 1).astype('float32') / 255 ``` ### Model parameters 對於機器學習模型來說,**模型參數**(model parameters)通常指的是模型的[權重](#Weight)和[偏差](#Bias)。這些參數透過模型訓練過程自動更新,以最小化[損失函數](#Loss-function),從而提高模型的準確性,使模型學習到資料中潛在的規律,並應用於未來的預測或分類等機器學習任務。 模型參數和**可學習參數**(learnable parameters)基本上是同義的。後者強調了模型參數有「透過訓練來學習和最佳化」的特性。 ### Momentum **動量**(momentum)是一種[優化器](#Optimizer)技術,它在[梯度下降法](#Gradient-descent)的基礎之上額外引入「動量項」,讓參數更新時不僅考慮「當前」的梯度,還考慮到「過去」的梯度,從而能夠減少振盪並加快收斂速度。 動量的數學表達式為: $$ \begin{aligned} v_t &= \gamma v_{t-1} + \eta \nabla L(\theta_t)\\ \theta_{t+1} &= \theta_t - v_t \end{aligned} $$ 其中: - $v$ 是動量,$\theta$ 是[模型參數](#Model-parameters),下標 $t$ 是迭代次數的索引,所以: - $v_t$ 是本次迭代的動量, - $v_{t-1}$ 是上次迭代的動量, - $\theta_{t+1}$ 是下次迭代的模型參數, - 以此類推。 - $\gamma$ 是動量係數(通常設定在 0.9 左右),它控制過去梯度對當前更新的影響。 - $\eta$ 是[學習率](#Learning-rate)。 - $\nabla L(\theta_t)$ 是本次迭代的[梯度](#Gradient)。 動量可以幫助模型更快穿過扁平的區域(即梯度變化小的區域),並減少在損失函數谷底附近的振盪,使優化過程更為穩定。 ### Multiclass classification ### Multiclass cross entropy 對於[多元分類](#Multiclass-classification)問題(使用 [one-hot 編碼](#One-hot-encoding)標籤),交叉熵損失的數學表達式為: $$ L = - \sum_{i=1}^{C} y_i \log(p_i) $$ 其中: - $C$ 是類別的數量。 - $y_i$ 是實際標籤,值為 0 或 1,表示樣本屬於類別 $i$。 - $p_i$ 是模型對類別 $i$ 預測的機率。 - $\log$ 是自然對數函數。 ## N ### Neutal network **神經網路**(neural network),或稱**人工神經網路**(artificial neural network,ANN),是機器學習的一種模型,受到人腦結構和功能的啟發。它由多層節點(node,或稱為神經元 [neuron]、單元 [unit])組成,這些節點以特定的方式相互連接,模擬大腦神經元之間的連結。神經網路主要用於處理複雜的非線性問題,例如影像辨識、語音識別、自然語言處理等。 典型的神經網路由以下幾個部分組成: 1. **輸入層**:負責接收輸入資料,每個節點代表一個特徵。例如,在影像識別中,輸入層的每個節點可以代表一個像素值。 2. **隱藏層**:位於輸入層和輸出層之間,負責進行資料的非線性轉換。隱藏層中的每個節點通過權重與前一層和後一層的節點相連,並應用啟動函數來處理數據。 3. **輸出層**:負責產生模型的最終預測結果。對於分類問題,輸出層的每個節點對應於一個類別。 神經網路的訓練過程通常包括以下步驟: 1. **[前向傳播](#Forward-propagation)**:資料從輸入層開始,經過隱藏層的運算傳遞到輸出層,計算預測結果。 2. **損失計算**:使用[損失函數](#Loss-function)(如交叉熵損失)來衡量模型預測值與實際值之間的差異。 3. **[反向傳播](#Backpropagation)**:通過計算損失相對於每個權重的梯度,使用梯度下降等優化演算法來更新權重,從而最小化損失。 4. **更新權重**:使用優化器(如 SGD、Adam 等)根據梯度更新神經網路的[權重](#Weight)。 常見的神經網路類型包括: - **前饋神經網路**(Feedforward Neural Network, FNN):資料僅從前向後傳遞,沒有循環或回饋,適用於一般的分類與迴歸問題。 - **卷積神經網路**(Convolutional Neural Network, CNN):專門用於處理影像資料的神經網路,能夠有效擷取空間特徵。 - **遞歸神經網路**(Recurrent Neural Network, RNN):適用於序列資料(如語音、文字等)的神經網路,能夠處理時間相關性。 神經網路的強大之處在於它們能夠自動從資料中學習特徵,尤其在深度學習的應用中,能夠處理大量資料並表現出色。 ### Norm ## O ### Objective function 在最佳化問題中,**目標函數**(objective function)是[最佳化演算法](#Optimization-algorithm)需要最小化或最大化的函數。 在機器學習任務中,目標函數通常是指[損失函數](#Loss-function),因為損失函數代表「模型預測與實際結果之間的差異」,而縮小此差異相當於讓「模型預測更加準確」,這正是模型訓練的目標。 ### One-hot encoding **One-hot 編碼**(one-hot encoding)是將分類資料轉換為二進制向量的編碼方式。每個類別對應一個唯一的二進制向量,向量中只有一個位置為 1,其餘為 0。 例如,對於 3 個類別 `["A", "B", "C"]`,編碼結果為: - `A` $\to$ `[1, 0, 0]` - `B` $\to$ `[0, 1, 0]` - `C` $\to$ `[0, 0, 1]` 這種編碼方式適合用於機器學習中的[分類問題](#Classification)。 ### Optimizer **優化器**(optimizer)是[最佳化演算法](#Optimization-algorithm)在機器學習中的實作(implementation)。它根據模型的[損失函數](#Loss-function),計算出每次[模型參數](#Model-paramters)更新的方向和步伐,目標是使損失函數找到最小值。 常見的優化器有: - [梯度下降法](#Gradient-descent):基於損失函數的梯度來更新模型參數。 - [隨機梯度下降法](#Stochastic-gradient-descent)(SGD):每次更新只使用一個或少量樣本計算梯度,速度快但收斂不穩定。 - [Adam 演算法](#Adam-optimizer):基於一階和二階[動量](#Momentum)的改進梯度下降法,具備較好的收斂性。 - [RMSProp](#RMSProp):通過調整每個參數的學習率來加速收斂,避免振盪。 ### Optimization algorithm **最佳化演算法**(optimization algorithm)是在最佳化問題中用來尋找[目標函數](#Objective-function)最大值或最小值的程序。這些演算法透過迭代調整變數值,使目標函數的結果逐漸逼近最佳解。 在機器學習領域中,最佳化演算法的實作(implementation)稱為[**優化器**](#Optimizer)(optimizer)。 ### Overfitting ## P ### PyTorch **PyTorch** 是一個開源的深度學習框架,主要由 Facebook 開發和維護。PyTorch 提供了靈活且易於使用的動態計算圖,這讓它特別適合研究和實驗性質的深度學習模型。它的主要特點包括: 1. **動態計算圖**:與 [TensorFlow](#TensorFlow) 的靜態計算圖不同,PyTorch 使用動態計算圖,這讓模型的建構和修改更加靈活,特別適合需要頻繁變動的研究性工作。 2. **自動微分**:PyTorch 提供了自動微分功能,允許用戶輕鬆計算梯度,這對於反向傳播和優化參數非常重要。 3. **Tensor 運算**:PyTorch 支援高效的數值運算,並能夠利用 GPU 進行加速。其 `torch.Tensor` 是類似於 NumPy 的多維數組,但能在 GPU 上運行。 4. **支援深度學習模型**:PyTorch 提供了高度模組化的神經網路建構工具(如 `torch.nn` 和 `torch.optim`),讓使用者可以輕鬆構建和訓練深度神經網路。 PyTorch 因其靈活性和友好的使用體驗,成為了深度學習研究和開發中的主流框架之一。 ## R ### Regularization **正則化**(regularization)是在機器學習中用來防止模型[過度擬合](#Overfitting)(overfitting)的一種技術。 正則化是透過在[損失函數](#Loss-function)中加入一個[懲罰項](#Penalty-term),來限制模型的複雜度,從而減少過度擬合的風險。 常見的正則化方法有: - [**L1 正則化**](#L1-regularization)的懲罰項包含 [L1 範數](#L1-norm),亦即 $$ \lambda\|\theta\|_1 = \lambda \cdot \sum_{j=1}^{p} |\theta_j| $$ - [**L2 正則化**](#L2-regularization)的懲罰項包含 [L2 範數](#L2-norm),亦即 $$ \lambda\|\theta\|_2 = \lambda \cdot \sqrt{\small \sum_{j=1}^{p} (\theta_j)^2} $$ - [**Elastic net**](#Elastic-net) 結合了 L1 和 L2 正則化,兼具兩者的特點。 在以上公式中, - $\lambda$ 是正則化係數,它是一種[超參數](#Hyperparameter),代表正則化的強度。$\lambda$ 的值越大,則特徵越容易縮減。 - $\theta_j$ 是對應第 $j$ 個特徵的[模型參數](#Model-parameter),$j$ 是特徵和參數的索引,$p$ 是特徵和參數的數量。 正則化的目的在於簡化模型結構,使其更具[泛化](#Generalization)能力,不會過度依賴訓練資料的[特異性](#Specificity)。 ### ReLU **ReLU**,全稱 Rectified Linear Unit,是一種分段線性函數(piecewise linear function),也是神經網路中常用的[啟動函數](#Activation-function)。它的定義是 $$ \text{ReLU}(x) = \max(0, x) = \begin{cases} x, & \text{if } x \geq 0 \\ 0, & \text{if } x < 0 \end{cases} $$ - 常用於隱藏層,具有計算簡單且能有效避免[梯度消失](#Vanishing-gradient-problem)問題。 - 有一個稱為 [Leaky ReLU](#Leaky-ReLU) 的變體。 ### RMSProp **RMSProp**,全稱 Root Mean Square Propagation(均方根傳遞),是一種具有[自適應學習率](#Adaptive-learning-rate)的[優化器](#Optimizer),專門用來解決[梯度下降](#Gradient-descent)過程中學習率調整的問題。RMSProp 針對每個參數使用不同的學習率,根據歷史梯度的平方平均值來動態調整,使最佳化過程更加穩定。 RMSProp 的主要特點是,它可以有效地解決由於梯度差異過大而導致的振盪問題,特別是對於深度神經網路來說,它可以加速收斂並防止學習率過大造成的優化失敗。 RMSProp 的更新規則如下: $$ v_t = \beta v_{t-1} + (1 - \beta) \nabla \theta_t^2 $$ $$ \theta_{t+1} = \theta_t - \frac{\eta}{\sqrt{v_t + \epsilon}} \nabla \theta_t $$ 其中: - $\nabla \theta_t$ 是當前參數的梯度。 - $v_t$ 是梯度的平方移動平均。 - $\beta$ 是衰減率,一般取 0.9,控制過去梯度對當前更新的影響。 - $\eta$ 是學習率。 - $\epsilon$ 是一個很小的數,通常取 $10^{-8}$,用來防止除以 0 的錯誤。 RMSProp 通過平滑化梯度的影響,能夠穩定更新步伐,特別適合處理噪音大的梯度或在 RNN 等模型中常見的長期依賴問題。 在 PyTorch 和 TensorFlow 中,RMSProp 可以這樣使用: - **PyTorch**: ```python optimizer = torch.optim.RMSprop(model.parameters(), lr=0.001) ``` - **TensorFlow/Keras**: ```python optimizer = tf.keras.optimizers.RMSprop(learning_rate=0.001) ``` RMSProp 是一種強大的優化器,尤其適合在訓練深度學習模型時處理較為複雜和不穩定的梯度問題。 ## S ### Sigmoid function **Sigmoid 函數**(sigmoid function,或譯為 **S 型函數**)是一類數學函數。 - 實際上包含很多種函數,例如 [logistic 函數](#Logistic-function)、[tanh 函數](#Tanh)、[arctan 函數](#Arctan)等等,參見下圖。 - 它們的共同特色是定義域為 $\mathbb{R}$,值域為 $(0,1)$,且在 $\mathbb{R}$ 上處處可微。 - 在機器學習與深度學習領域中,sigmoid 函數通常是指 logistic 函數,尤其是標準 logistic 函數 $\sigma(x) = \dfrac{1}{1 + e^{-x}}$。 - Sigmoid 函數可以作為類神經網路中的[啟動函數](#Activation-function)。 > ![sigmoids](https://upload.wikimedia.org/wikipedia/commons/6/6f/Gjl-t%28x%29.svg =600x) > 一些 sigmoid 函數的比較。圖片來源:[Wikimedia](https://commons.wikimedia.org/wiki/File:Gjl-t(x).svg) ## T ### Tanh **Tanh** (發音為 [tæntʃ][^wiktionary-tanh]),即**雙曲正切函數**(hyperbolic tangent),是一種雙曲函數,也常在深度學習中作為神經元的[啟動函數](#Activation-function)。 Tanh 函數可以定義為 $$ \tanh(x) = \frac{e^x - e^{-x}}{e^x + e^{-x}} $$ 它的值域在 $[-1, 1]$ 之間,常用於需要對稱輸出的情況。 [^wiktionary-tanh]: https://en.wiktionary.org/wiki/tanh#Pronunciation ## W ### Weight 在機器學習模型中,**權重**(weight)是與每個輸入[特徵](#Feature)相乘的係數。在神經網絡中,每個神經元的輸出都是其輸入特徵與權重的加權和(weighted sum)。 權重與[偏差](#Bias)合稱[模型參數](#Model-parameters),它們共同決定特徵對最終輸出的影響。 ## Appendix - [Deflist 的 Markdown 語法](https://hackmd.io/c/codimd-documentation/%2F%40codimd%2Fmarkdown-syntax#markdown-it-deflist) [^tommy-huang-gradient]: Tommy Huang. [機器/深度學習-基礎數學(二):梯度下降法(gradient descent)](https://chih-sheng-huang821.medium.com/406e1fd001f). Medium. 2018-07-25.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully