# 自动编码器

## 自动编码器的基本思想

直接用一个单层或者多层神经网络对输入数据进行映射，得到输出向量，作为从输入数据提取出的特征。

## 网络结构

> 编码器：将输入数据映射为特征向量.下图6 -> 3,x -> y
>
> 解码器：将特征向量映射回输入向量，重构. 3 -> 6,y -> x

也就是：把输入向量x经过编码器编码压缩，然后又假设被解码器解码还原，希望这么个过程尽可能完美还原，然后就训练完了，把解码器拿掉，也就是右边的拿掉，只保留编码器部分，这样，就可以训练出一个把长向量压缩为短向量的一个机器啦！

![](/files/-LpsmagOszIvjPhn6yWt)

## 损失函数与训练算法

损失函数定义为重构误差：也就是重构的和原来的越近越好，怎么说？

里面的$$h\_{\theta}(x\_i)$$就是把向量压缩（编码器），再外面那个$$g\_{\theta}$$呢自然就是解码编码器的结果了，然后$$||x\_i-g\_{\theta}(h\_{\theta}(x\_i))||\_2^2$$就是简单的平方差，最后除以$$l$$就是均方差，$$\frac{1}{2}$$就是为了求导约去凑的

$$
\begin{aligned}
min\frac{1}{2l}\sum\_{i=1}^{l}||x\_i-g\_{\theta}(h\_{\theta}(x\_i))||\_2^2
\end{aligned}
$$

## 实际使用/得到特征向量

实际使用时，只需要编码器网络，解码器只用于训练阶段 输入一个数据向量，即可得到特征向量


---

# 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/shen-du-xue-xi-li-lun/01.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.
