1. 程式人生 > >核函式詳解

核函式詳解

這篇博文開始的例子就很好地揭示了核函式的簡單原理,寫得很好!

原地址:https://blog.csdn.net/zkq_1986/article/details/52448238

1 核函式K(kernel function)定義

核函式K(kernel function)就是指K(x, y) = <f(x), f(y)>,其中x和y是n維的輸入值,f(·) 是從n維到m維的對映(通常,m>>n)。<x, y>是x和y的內積(inner product)(也稱點積(dot product))。

舉個小小栗子。
令 x = (x1, x2, x3, x4); y = (y1, y2, y3, y4);
令 f(x) = (x1x1, x1x2, x1x3, x1x4, x2x1, x2x2, x2x3, x2x4, x3x1, x3x2, x3x3, x3x4, x4x1, x4x2, x4x3, x4x4); f(y)亦然;
令核函式 K(x, y) = (<x, y>)^2.
接下來,讓我們帶幾個簡單的數字進去看看是個什麼效果:x = (1, 2, 3, 4); y = (5, 6, 7, 8). 那麼:
f(x) = ( 1, 2, 3, 4, 2, 4, 6, 8, 3, 6, 9, 12, 4, 8, 12, 16) ;
f(y) = (25, 30, 35, 40, 30, 36, 42, 48, 35, 42, 49, 56, 40, 48, 56, 64) ;
<f(x), f(y)> = 25+60+105+160+60+144+252+384+105+252+441+672+160+384+672+1024
= 4900. 
如果我們用核函式呢?
K(x, y) = (5+12+21+32)^2 = 70^2 = 4900.
就是這樣!

所以現在你看出來了吧,kernel其實就是幫我們省去在高維空間裡進行繁瑣計算的“簡便運演算法”。甚至,它能解決無限維空間無法計算的問題!因為有時f(·)會把n維空間對映到無限維空間去。

那麼kernel在SVM究竟扮演著什麼角色?
初學SVM時常常可能對kernel有一個誤讀,那就是誤以為是kernel使得低維空間的點投射到高位空間後實現了線性可分。其實不然。這是把kernel和feature space transformation混為了一談。(這個錯誤其實很蠢,只要你把SVM從頭到尾認真推導一遍就不會犯我這個錯。)

這裡寫圖片描述

這裡寫圖片描述 
我們成功地找到了那個分界線,這就是最直觀的kernel啦! 
可能不太嚴謹,但是kernel大概就是這個意思,詳細的數學定義樓上說的很好,就不贅述了。 
引用一句這門課的教授的話: 
“你在你的一生中可能會經歷很多變故,可能會變成完全不同的另一個人,但是這個世界上只有一個你,我要怎樣才能把不同的“你”分開呢?最直觀的方法就是增加“時間”這個維度,雖然這個地球上只有一個你,這個你是不可分割的,但是“昨天在中國的你”和“今天在美國的你”在時間+空間這個維度卻是可以被分割的。”

We know that everything in the world can be decomposed into the combination of the basic elements. For example, water is the combination of hydrogen and oxygen. Similarly, in mathematics, basis is used to represent various things in a simple and unified way.

In RnRn space, we can use n independent vectors to represent any vector by linear combination. The n independent vectors can be viewed as a set of basis. There are infinite basis sets in R

nRn space. Among them, basis vectors that are orthogonal to each other are of special interests. For example, {ei}ni=1{ei}i=1n is a special basis set with mutually orthogonal basis vectors in the same length, where eiei is a vector that has all zero entries except the iith entry which equals 1. 
The inner product operator measures the similarity between vectors. For two vectors x and y , the inner product is the projection of one vector to the other.

這裡寫圖片描述

3. Kernel Function

A function f(x)f(x) can be viewed as an infinite vector, then for a function with two independent variables K(x,y)K(x,y), we can view it as an infinite matrix. Among them, if K(x,y)=K(y,x)K(x,y)=K(y,x) and

f(x)K(x,y)f(y)dxdy0∫∫f(x)K(x,y)f(y)dxdy≥0for any function ff, then K(x,y)K(x,y) is symmetric and positive definite, in which case K(x,y)K(x,y) is a kernel function.

這裡寫圖片描述 
這裡寫圖片描述 
Here are some commonly used kernels:

  • Polynomial kernel K(x,y)=(γxTy+C)dK(x,y)=(γxTy+C)d
  • Gaussian radial basis kernel K(x,y)=exp(γxy2)K(x,y)=exp⁡(−γ‖x−y‖2)
  • Sigmoid kernel K(x,y)=tanh(γxTy+C)K(x,y)=tanh⁡(γxTy+C)

3.1 補充知識

The hyperbolic functions are: 

Hyperbolic sine: 
sinhx=exex2=e2x12ex=1e2x2ex.sinh⁡x=ex−e−x2=e2x−12ex=1−e−2x2e−x.
Hyperbolic cosine: 
coshx=ex+ex2=

相關推薦

函式

這篇博文開始的例子就很好地揭示了核函式的簡單原理,寫得很好!原地址:https://blog.csdn.net/zkq_1986/article/details/524482381 核函式K(kernel function)定義核函式K(kernel function)就是指

機器學習--支援向量機(五)函式

前面我們曾經引入二維資料的非線性的情況,但是那種非線性(並不是真正意義上的非線性)是通過鬆弛因子進行優化的,如果資料比之前還複雜怎麼辦呢? 複雜到即使你怎麼調節C你都無法進行分類,這個時候怎麼辦?如下例子: 這個無論你怎麼調節引數都無法在二維平面內進行線性分離了,但是

#26 Linux kernel(內與uname、lsmod、modinfo、depmod、insmod、rmmod、modprobe...命令用法

linux kernel(內核)詳解與uname、lsmod、modinfo、depmod、insmod、rmmod、modprobe...命令用法Linux kernel: 內核設計流派: 單內核設計,但是充分借鑒了微內核體系設計的優點,為內核引入了模塊化機制,內核高度模塊化; 內核被模塊化之

MySQL 的函式

完整性約束 什麼是資料完整性 資料的準確性和可靠性。 分類 實體完整性 記錄準確的。(記錄不能重複) 主鍵約束: 不能重複,不能為空。  Primary key 欄位唯一的。 不能使用業務欄位。 無意義的

Vue生命週期函式

 vue例項的生命週期 1 什麼是生命週期(每個例項的一輩子) 概念:每一個Vue例項建立、執行、銷燬的過程,就是生命週期;在例項的生命週期中,總是伴隨著各種事件,這些事件就是生命週期函式; 生命週期:例項的生命週期,就是一個階段,從建立到執行,再到銷燬的階段; 生命週期函式:在例項的生命週

goinit函式

init()函式會在每個包完成初始化後自動執行,並且執行優先順序比main函式高。init 函式通常被用來: 對變數進行初始化 檢查/修復程式的狀態 註冊 執行一次計算   包的初始化        為

linux 核心 - ioctl 函式

1. 概念 ioctl 是裝置驅動程式中裝置控制介面函式,一個字元裝置驅動通常會實現裝置開啟、關閉、讀、寫等功能,在一些需要細分的情境下,如果需要擴充套件新的功能,通常以增設 ioctl() 命令的方式實現。 在檔案 I/O 中,ioctl 扮演著重要角色,本文將以驅動開發為側重

assert.ifError()函式

assert.ifError(value) 如果 value 為真值時,丟擲 value。當測試在回撥函式裡的引數 error 時非常有用。 const assert = require('assert'); assert.ifError(0); // OK assert.ifError(1); //

assert.throws()函式

assert.throws(block[, error][, message]) 期望 block 函式丟擲一個錯誤。 如果指定 error,它可以是一個建構函式、正則表示式或驗證函式。 如果指定 message,如果 block 因為失敗而丟擲錯誤,message 會是由 AssertionError 提

Swoole Echo伺服器隨意搭建 及set函式

<?php //Server Class Server { private $serv; /** * 連結swoole伺服器 * Server constructor. */ public function __construct()

深入理解計算機系統配套實驗(一) data lab 函式

/* 135. * bitAnd - x&y using only ~ and | 136. * Example: bitAnd(6, 5) = 4 137. * Legal ops: ~ | 138. * Max ops: 8 139. *

fcntl函式

功能描述:根據檔案描述詞來操作檔案的特性。 #include <unistd.h> #include <fcntl.h>  int fcntl(int fd, int cmd);  int fcntl(i

Mysql 字元函式

MySql 所有字串函式函式詳解 ASCII(str) 返回str最左邊第一位字元的ASCII編碼,如果str為空,則返回 0 。如果str為NULL,則返回NULL -- 只返回a的ASCII編碼 SELECT ASCII('ab') - 97 SELECT ASCII('a') - 97

C++建構函式及顯示呼叫建構函式

                         

單鏈表,頭插法,尾插法各種函式

一:LinkList.cpp檔案 #include <stdio.h> #include <malloc.h> //malloc函式 用了<stdlib.h>中的 <malloc.h>標頭檔案 typedef int ElemT

Opencv基礎: Mat類裡setTo函式

https://blog.csdn.net/oMoDao1/article/details/80324360 函式原型:   /** @brief Sets all or some of the array elements to the specified value. &n

keras:4)LSTM函式

LSTM層 keras.layers.recurrent.LSTM(units, activation='tanh', recurrent_activation='hard_sigmoid', use_bias=True, kernel_initializer='glorot_uni

Socket通訊過程和函式

from:http://blog.csdn.net/tianmo2010/article/details/6542063 ①什麼是Socket    Socket介面是TCP/IP網路的API,Socket介面定義了許多函式或例程,程式設計師可以用它們來開發TCP/IP網路上的應用程式。要學

malloc和free函式(轉載只是為了查閱方便,若侵權立刪)

malloc和free函式詳解   本文介紹malloc和free函式的內容。   在C中,對記憶體的管理是相當重要。下面開始介紹這兩個函式:     一、malloc()和free()的基本概念以及基本用法: 1、函式原型及說明: void *malloc(lon

【深度學習】Tensorflow函式

  目錄 tf.truncated_normal tf.random_normal tf.nn.conv2d tf.nn.max_pool tf.reshape tf.nn.softmax tf.reduce_sum tf.reduce_max,tf.r