# 感知机

**感知机是：**

> 二分类线性分类模型
>
> 输入：特征向量
>
> 输出：+1、-1
>
> 属于：判别模型，是神经网络、支持向量机的基础

**定义：**

输入特征空间中的特征向量，输出y={+1,-1}，期望的是找到一个不错的映射：

$$f(x)=sign(w\.x+b)= \begin{cases}+1, & x>=0 \ -1, & x<0\end{cases}$$

w、b为需要学习的参数叫做权值

**目的：**

学到超平$$w\.x+b=0$$面把正负样本分开。

**定义推导：**

输入空间任一点$$x\_0$$到超平面（$$w\.x+b=0$$）的距离：$$d=\frac{1}{||w||}|w\.x\_0+b|$$ 因为：对于误分的点$$(x\_i,y\_i)$$有关系：$$-y\_i(w\.x+b)>0$$，（因为误分的点不同号，分对的点同号） 因此，误分点$$(x\_i,y\_i)$$到超平面的距离为：$$-\frac{1}{||w||}y\_i(w\.x\_i+b)$$ 因此，所有误分点集合M，距离总和为： $$\frac{1}{||w||}\sum\_{ x\_i \in M } y\_i(w\.x\_i+b)$$ 对于固定数 $$\frac{1}{||w||}$$ 在损失函数求导梯度优化中没有意义，因此可以省略，得到损失函数，即经验风险函数： $$-\sum\_{x\_i\in M}y\_i(w\.x\_i+b)$$ 这个损失函数，误分点虽然都是误分，但是离超平面越近损失约小

**优化求解：**

根据上面，不误分的点损失是0，希望所有误分点距离和越小越好，既目标为：

$$min\_{w,b}L(w,b)=-\sum\_{x\_i\in M}y\_i(w\.x\_i+b)$$

通常用随机梯度下降求解出参数w、b：

$$\nabla *wL(w,b)=-\sum*{x\_i\in M}y\_ix\_i$$

$$\nabla\_bL(w,b)=-\sum\_{x\_i \in M}{y\_i}$$

策略：随机选一个误分类点$$(x\_i,y\_i)$$进行权值更新：

$$w \leftarrow w+r y\_ix\_i$$

$$b \leftarrow b+ry\_i$$

其中$$r \in (0,1])$$为步长，有很多策略（随机、线性搜索、不断缩小）


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://im-qianuxn.gitbook.io/pytorch/ji-suan-ji/ml/2-gan-zhi-ji.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
