Feature Maps
Considering fitting cubic functions , we can view the cubic function as a linear function over a different set of feature variables. Concretely, let the function be defined as
Let be the vector containing as entries. Then we can rewrite the cubic function in as
Thus, a cubic function of the variable can be viewed as a linear function over the variables . To distinguish between these two sets of variables, in the context of kernel methods, we will call the “original” input value the input attributes of a problem. When the original input is mapped to some new set of quantities , we will call those new quantities the features variables. We will can a feature map, which maps the attributes to the features.
LMS with the kernel trick
The update rule of Least Squares Method in linear case is
If we use a feature map function
This update becomes computationally expensive when the features is high-dimensional. Let be the vector that contains all the monomials of with degree , then the dimension of would be on the order of .
It may appear at first that such runtime per update and memory usage are inevitable, because the vector itself is of dimension , and we may need to update every entry of and store it. However, we will introduce the kernel trick with which we will not need to store explicitly, and the runtime can be significantly improved.
For simplicity, we assume the initialize the value . At initialization, . Assume at some point, can be represented as
for some . Then we claim that in the next round, is still a linear combination of because
Our general strategy is to implicitly represent the -dimensional vector by a set of coefficients . Towards doing this, we derive the update rule of the coefficients . Using the equation above, we see that the new depends on the old one via
Here we still have the old on the RHS of the equation. Replacing by gives
We often rewrite as to emphasize that it's the inner product of the two feature vectors. It may appear that at every iteration, we still need to compute the values of for all pairs of , each of which may take roughly operation. However, two important properties come to rescue:
- We ca pre-compute the pairwise inner products for all pairs before the loop starts
- Compute the inner product can be efficient and does not necessarily require computing explicitly. This is because
Therefore, to compute , we can first compute with time and then take another constant number of operations to compute .
We define the Kernel corresponding to the feature map as a function that maps satisfying:
Now we can pre-compute the values , and define as , we have the new update rule
Properties of Kernels
AI Summary
这段文字的核心思想是介绍机器学习中的 核方法 (Kernel Methods), 特别是 核技巧 (Kernel Trick) 的概念和动机.
-
起点: 特征映射与核函数
- 我们通常从一个明确的 特征映射 (feature map) 开始. 这个函数将原始输入数据 转换到一个 (可能更高维度的) 特征空间 .
- 基于这个特征映射, 可以定义一个 核函数 (kernel function) , 它计算两个原始输入 和 在特征空间中的 内积 (inner product): . 在实数空间中, 这通常就是点积 .
-
核技巧 (Kernel Trick) 的关键
- 很多机器学习算法 (比如支持向量机SVM的训练和预测过程, 实际上只需要用到特征向量之间的 内积, 而不需要特征向量 本身.
- 这意味着, 只要我们能计算核函数 的值, 我们就可以完全用 来表达整个算法, 而 无需显式地计算或知道 特征映射 是什么.
-
动机: 直接定义核函数
- 既然算法只需要 , 那我们能不能反过来, 不先定义 , 而是直接 选择或设计 一个函数 来用呢?
- 这样做的好处是巨大的: 我们可能选择一些 , 它们对应的 非常复杂, 甚至是无限维的, 我们根本无法显式写出或计算 . 但只要我们能计算 , 算法依然可以运行.
- 但是, 有一个前提: 我们必须 确保 我们选择的这个 确实是 某个 特征映射 在特征空间中的内积. 也就是说, 必须 存在 这样一个 , 即使我们不知道它是什么.
-
问题: 什么样的函数K是有效的核函数?
- 核心问题来了: 什么样的函数 可以保证存在一个特征映射 使得 成立?
- 如果能回答这个问题, 我们就可以安全地选择一个满足条件的 , 然后直接在算法中使用它, 享受核技巧带来的便利 (比如计算效率, 处理非线性问题的能力) .
-
例子: 多项式核 (Polynomial Kernel)
- : 通过展开, 发现它等于 . 这明确展示了它对应一个特征映射 , 其分量是所有 的组合. 计算 只需要 时间, 而计算 需要 时间.
- : 类似地, 展开后发现它对应的 包含 项、 项和常数项 .
- : 推广到 次多项式核. 它对应的特征空间维度是 , 但计算 仍然只需要 时间. 这极大地体现了核技巧的 计算效率优势.
-
核函数的直观理解: 相似度度量
- 从直观上看, 可以被看作是衡量 和 之间相似度的一种方式 (内积越大, 向量越接近或方向越一致) . 因此, 也可以被看作是衡量原始输入 和 之间的一种 (通过 映射后的) 相似度.
- 这启发我们可以基于对问题 "相似性" 的理解来设计核函数.
-
例子: 高斯核 (Gaussian Kernel)
- . 当 和 距离近时, 接近 1; 当距离远时, 接近 0. 这符合相似度的直观概念.
- 文中提到, 高斯核 确实 是一个有效的核函数, 但它对应的特征映射 是 无限维 的. 这再次强调了我们无法显式使用 , 而必须依赖核函数 本身.
-
有效核函数的必要条件
-
假设 是一个有效的核函数, 即 . 它必须满足什么性质?
-
考虑任意 个数据点 , 构造一个 的 核矩阵 (Kernel Matrix) , 其中 .
-
对称性 (Symmetry): 因为内积是对称的 , 所以 . 因此, 核矩阵 必须是对称的.
-
半正定性 (Positive Semi-Definiteness, PSD): 对于任意向量 , 推导表明 . 这意味着核矩阵 必须是半正定的.
-
结论: 如果一个函数 是有效的核函数, 那么对于 任何 有限点集 , 由它生成的核矩阵 必须是 对称且半正定的. 这是成为有效核函数的 必要条件.
-
Mercer 定理 (Mercer's Theorem) 这段材料推导了有效核函数的必要条件 (对称性和半正定性) , 但没有说明这是否也是 充分条件. Mercer 定理正是回答了这个问题的关键定理.
简单来说, Mercer 定理陈述了:
设 是一个紧凑的度量空间 (例如 中的一个有界闭集) , 是一个连续的、对称的函数. 那么, 是一个 正定核 (positive definite kernel) (即对于任何有限点集 和任何非零实数 , 都有 , 注意这里用的是广义的半正定概念) 当且仅当 存在一个希尔伯特空间 (Hilbert Space) 和一个映射 , 使得对于所有的 , 都有: 并且 可以展开为一致收敛的级数: 其中 是 对应的积分算子的特征值, 是对应的特征函数.
Mercer 定理的关键意义:
- 充分性: 它告诉我们, 如果一个函数 (在适当的条件下, 如连续、对称) 能够确保对任何数据点集产生的核矩阵都是 半正定的, 那么这个函数就 一定 是一个有效的核函数. 即, 一定存在 一个特征空间和一个映射 , 使得 是该空间中的内积.
- 理论保证: 这为 "核技巧" 提供了坚实的数学基础. 只要我们选择或设计的函数 满足 Mercer 定理的条件 (主要是对称性和产生半正定核矩阵) , 我们就可以放心地在算法中使用它, 即使我们不知道 是什么.
- 连接: 材料中推导的是 "如果 是核函数 核矩阵 是对称半正定的" (必要性) . Mercer 定理说明了 "如果核矩阵 总是对称半正定的 是核函数" (充分性, 在一定条件下) .
总结: 材料解释了为什么我们想直接使用核函数 而不是特征映射 (核技巧) , 并推导了有效核函数必须满足的条件 (对称性和半正定性) . Mercer 定理则提供了判别一个函数是否为有效核函数的 充分条件, 即检查它生成的核矩阵是否总是半正定的. 这使得我们可以直接设计和使用满足条件的核函数, 极大地扩展了线性算法 (通过隐式映射到高维空间) 处理非线性问题的能力.