本项目演示如何使用 PyTorch 构建并训练一个多层感知机,来学习参数积分 (\int_0^1 x^{\alpha} dx) 的解析结果。
- 安装依赖:
py -m pip install -r requirements.txt- 运行训练脚本(示例命令会保存模型、日志和图像):
py scripts/integral_nn.py --epochs 200 --train-size 2048 --val-size 512 --test-size 512 \
--batch-size 128 --save-model outputs/model/integral_mlp.pt \
--log-file outputs/logs/training_log.csv \
--plot-path outputs/figures/pred_vs_true.png \
--residual-plot-path outputs/figures/residual_hist.png生成的文件:
outputs/logs/training_log.csv:每个 epoch 的训练与验证损失。outputs/model/integral_mlp.pt:训练好的模型参数。outputs/figures/pred_vs_true.png:预测值与真实值的散点对比图。outputs/figures/residual_hist.png:预测残差的直方图分布。
运行 py scripts/integral_nn.py --help 可以查看所有可用参数,常用选项包括:
--alpha-min/--alpha-max:积分参数的采样范围。--hidden-dim/--hidden-layers:网络隐藏层宽度与层数。--lr:学习率。--device:训练使用的设备(如cpu或cuda)。
scripts/ # Python 训练脚本
outputs/ # 默认的模型、日志与图像输出目录
md文档/ # 其他文档
requirements.txt # Python 依赖列表
README.md # 当前说明文档