# 学习向量量化LVQ

前提：假设样本带有标记类型（也可事先通过聚类等算法学到类型）$$D={(x1,y1),(x2,y2),...(xm,ym)}$$

\> >

> 1）选择k个不同类样的x值本作为k个初始向量$${p\_1,p\_2,...,p\_k }$$，向量的类标记为初始样本的y
>
> 2）直到 k个向量更新很小才停止、或满足迭代次数：
>
> > D中随机选择(xi,yi)
> >
> > 计算(xi,yi)和k个向量$${p\_1,p\_2,...,p\_k }$$的距离，假设最近的距离是第j个向量pj
> >
> > if yi 和 向量pj 的类标记一致：$$p\_j=p\_j+\gamma(x\_i-p\_j),\gamma \in (0,1)$$ //也就是，pj向xi靠
> >
> > else：$$p\_j=p\_j-\gamma(x\_i-p\_j),\gamma \in (0,1)$$ //也就是，pi远离xi

学好模型向量$${{p\_1,p\_2,...,p\_k }}$$后，可定义一个样本空间X：pi对应其中一个区域Ri，这个区域内的点离pi最近

$$
R\_i={x \in X ||x-p\_i|\_2 \le |x-p\_j|\_2,i \ne j }
$$

![img](https://img-blog.csdnimg.cn/20190227000652544.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2ppYW5nNDI1Nzc2MDI0,size_16,color_FFFFFF,t_70)

扩展：提高收敛速度的改进LVQ2、LVQ3

这个LVQ算法没有库，需要自己手动实现，看上面的伪代码，不难吧？


---

# 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/cluster/lvq.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.
