# 基于Numpy构建RNN **Repository Path**: Zen07/Building_RNN_based_on_Numpy ## Basic Information - **Project Name**: 基于Numpy构建RNN - **Description**: 本项目使用NumPy从零实现循环神经网络(RNN),包含基础模型实现和实例应用。 - **Primary Language**: Python - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-03-11 - **Last Updated**: 2025-03-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: 论文代码实现 ## README # 基于NumPy构建RNN 本项目使用NumPy从零实现循环神经网络(RNN),包含基础模型实现和实例应用。 ## 项目介绍 循环神经网络(RNN)是一种特殊的神经网络结构,能够处理序列数据,捕捉时间序列中的依赖关系。本项目使用NumPy实现了RNN的核心算法,包括前向传播和反向传播过程,并通过实例展示了如何应用RNN进行时间序列预测。 ## 项目结构 ``` 基于Numpy构建RNN/ ├── README.md # 项目介绍文档 ├── rnn_model.py # RNN模型核心实现 ├── example.py # 示例应用 ├── utils.py # 工具函数 ├── requirements.txt # 项目依赖 └── docs/ # 文档目录 └── model_intro.md # 模型原理介绍 ``` ## 环境要求 - Python 3.6+ - NumPy - Matplotlib 可以通过以下命令安装依赖: ```bash pip install -r requirements.txt ``` ## 使用方法 ### 训练和测试RNN模型 ```python from rnn_model import RNN import numpy as np # 创建RNN模型 rnn = RNN(input_dim=1, hidden_dim=16, output_dim=1, lr=0.01) # 准备数据 x_train = [...] # 输入序列 y_train = [...] # 目标序列 # 训练模型 loss_history = rnn.train(x_train, y_train, epochs=100) # 预测 x_test = [...] # 测试输入序列 predictions = rnn.predict(x_test) ``` ### 运行示例 ```bash python example.py ``` ## 原理简介 RNN通过在隐藏层引入循环连接,使网络具有"记忆"能力。在每个时间步,RNN不仅接收当前的输入,还接收上一时间步的隐藏状态。 ### 前向传播 在时间步t,RNN的隐藏状态计算如下: h_t = tanh(W_x·x_t + W_h·h_{t-1} + b_h) 输出计算: y_t = W_y·h_t + b_y 其中: - x_t 是时间步t的输入 - h_t 是时间步t的隐藏状态 - h_{t-1} 是时间步t-1的隐藏状态 - y_t 是时间步t的输出 - W_x, W_h, W_y 是权重矩阵 - b_h, b_y 是偏置向量 详细原理请查看 [docs/model_intro.md](docs/model_intro.md) ## 许可证 MIT