Bioinformatics Tutorial
Files Needed
  • Getting Started
    • Setup
    • Run jobs in a Docker
    • Run jobs in a cluster [Advanced]
  • Part I. Programming Skills
    • 1.Linux
      • 1.1.Basic Command
      • 1.2.Practice Guide
      • 1.3.Linux Bash
    • 2.R
      • 2.1.R Basics
      • 2.2.Plot with R
    • 3.Python
  • PART II. BASIC ANALYSES
    • 1.Blast
    • 2.Conservation Analysis
    • 3.Function Analysis
      • 3.1.GO
      • 3.2.KEGG
      • 3.3.GSEA
    • 4.Clinical Analyses
      • 4.1.Survival Analysis
  • Part III. NGS DATA ANALYSES
    • 1.Mapping
      • 1.1 Genome Browser
      • 1.2 bedtools and samtools
    • 2.RNA-seq
      • 2.1.Expression Matrix
      • 2.2.Differential Expression with Cufflinks
      • 2.3.Differential Expression with DEseq2 and edgeR
    • 3.ChIP-seq
    • 4.Motif
      • 4.1.Sequence Motif
      • 4.2.Structure Motif
    • 5.RNA Network
      • 5.1.Co-expression Network
      • 5.2.miRNA Targets
      • 5.3. CLIP-seq (RNA-Protein Interaction)
    • 6.RNA Regulation - I
      • 6.1.Alternative Splicing
      • 6.2.APA (Alternative Polyadenylation)
      • 6.3.Chimeric RNA
      • 6.4.RNA Editing
      • 6.5.SNV/INDEL
    • 7.RNA Regulation - II
      • 7.1.Translation: Ribo-seq
      • 7.2.RNA Structure
    • 8.cfDNA
      • 8.1.Basic cfDNA-seq Analyses
  • Part IV. MACHINE LEARNING
    • 1.Machine Learning Basics
      • 1.1 Data Pre-processing
      • 1.2 Data Visualization & Dimension Reduction
      • 1.3 Feature Extraction and Selection
      • 1.4 Machine Learning Classifiers/Models
      • 1.5 Performance Evaluation
    • 2.Machine Learning with R
    • 3.Machine Learning with Python
  • Part V. Assignments
    • 1.Precision Medicine - exSEEK
      • Help
      • Archive: Version 2018
        • 1.1.Data Introduction
        • 1.2.Requirement
        • 1.3.Helps
    • 2.RNA Regulation - RiboShape
      • 2.0.Programming Tools
      • 2.1.RNA-seq Analysis
      • 2.2.Ribo-seq Analysis
      • 2.3.SHAPE Data Analysis
      • 2.4.Integration
    • 3.RNA Regulation - dsRNA Code
    • 4.Single Cell Data Analysis
      • Help
  • 5.Model Programming
  • Appendix
    • Appendix I. Keep Learning
    • Appendix II. Databases & Servers
    • Appendix III. How to Backup
    • Appendix IV. Teaching Materials
    • Appendix V. Software and Tools
    • Appendix VI. Genome Annotations
Powered by GitBook
On this page
  • 1) 背景与原理
  • 1. 单层感知机
  • 2. 多层感知机(MLP)
  • 3. 训练与评估
  • 2) 步骤式指南
  • 1. 数据准备
  • 2. 选择网络结构
  • 3. 数据预处理
  • 4. 构建网络
  • 5. 训练网络
  • 6. 评估和测试
  • 7. 使用网络进行预测
  • 8. 预期结果
  • 3) 报告要求

Was this helpful?

Edit on GitHub

5.Model Programming

PreviousHelpNextAppendix I. Keep Learning

Last updated 7 days ago

Was this helpful?

神经网络(Neural Networks)在机器学习领域中是一种强大的工具,例如,可以用NN拟合复杂的数学公式和模式。以下是如何使用神经网络拟合数学公式的基本步骤:

1) 背景与原理

1. 单层感知机

对于输入 x∈Rx \in Rx∈R ,感知机首先将其映射到一个标量 z=w⊤x+b,z= w^{\top} x+b,z=w⊤x+b, 再通过激活函数(阶跃、sigmoid 等)得到输出 y^=σ(z)\hat y=\sigma(z)y^​=σ(z)。感知机能拟合所有线性可分布尔函数(AND、OR、NOT 等)——权重与阈值示例如下:

逻辑函数

AND

((1,1))

(-2)

OR

((1,1))

(-1)

NOT

((-1))

(0)

感知机无法表示XOR,1969 年的《Perceptrons》对此给出经典反例。

2. 多层感知机(MLP)

通过在输入与输出之间加入隐藏层(非线性激活),MLP 可以逼近任意连续函数。含一层隐藏层的表达式

h=ϕ ⁣(W(1)x+b(1)),y^ =ψ ⁣(W(2)h+b(2)).\begin{aligned}\mathbf h &=\phi\!\bigl(W^{(1)}\mathbf x+\mathbf b^{(1)}\bigr), \\ \hat y   &=\psi\!\bigl(W^{(2)}\mathbf h+b^{(2)}\bigr).\end{aligned}hy^​ ​=ϕ(W(1)x+b(1)),=ψ(W(2)h+b(2)).​

XOR 示例 PPT 给出的两隐层神经元权重可实现

h1=AND(x1,¬x2),h2=AND(¬x1,x2),y^=h1∨h2,h_1=\text{AND}(x_1,\lnot x_2),\quad h_2=\text{AND}(\lnot x_1,x_2),\quad \hat y=h_1\lor h_2,h1​=AND(x1​,¬x2​),h2​=AND(¬x1​,x2​),y^​=h1​∨h2​,

从而精确复现 XOR 函数。

3. 训练与评估

PPT 采用 均方误差 (MSE) 作为损失:

L=1N∑i=1N(y^(i)−y(i))2,\mathcal L=\frac1N\sum_{i=1}^{N}\bigl(\hat y^{(i)}-y^{(i)}\bigr)^2,L=N1​i=1∑N​(y^​(i)−y(i))2,

并将数据随机切分为 Training / Test,在 512 个隐藏神经元的 MLP 上训练至收敛,再用测试集评估预测误差——同样适用于一般数学公式拟合任务。

2) 步骤式指南

1. 数据准备

首先,你需要准备用于训练神经网络的数据集。这些数据应包含输入值和对应的输出值,这些输出值由你想要拟合的数学公式计算得出。

2. 选择网络结构

选择一个适合你问题的神经网络结构。对于大多数数学公式拟合问题,一个前馈神经网络(Feedforward Neural Network)就足够了。你需要决定网络的层数、每层的神经元数量以及激活函数。

3. 数据预处理

对输入数据进行预处理,如归一化或标准化,以确保神经网络能够更有效地学习。

4. 构建网络

使用深度学习框架(如TensorFlow、PyTorch等)构建神经网络。以下是一个使用PyTorch的简单示例:

import torch
import torch.nn as nn
import torch.optim as optim
# 定义网络结构
class Net(nn.Module):
    def __init__(self):
        super(Net, self).__init__()
        self.fc1 = nn.Linear(n_inputs, 128)  # 输入层到隐藏层
        self.relu = nn.ReLU()
        self.fc2 = nn.Linear(128, 128)       # 隐藏层到隐藏层
        self.fc3 = nn.Linear(128, n_outputs) # 隐藏层到输出层
    def forward(self, x):
        x = self.fc1(x)
        x = self.relu(x)
        x = self.fc2(x)
        x = self.relu(x)
        x = self.fc3(x)
        return x
# 实例化网络
net = Net()

5. 训练网络

使用训练数据来训练神经网络。这通常涉及前向传播、计算损失、反向传播和更新权重。

criterion = nn.MSELoss()  # 使用均方误差作为损失函数
optimizer = optim.Adam(net.parameters(), lr=0.001)  # 使用Adam优化器
# 训练循环
for epoch in range(n_epochs):
    for inputs, labels in train_loader:
        optimizer.zero_grad()   # 清空梯度
        outputs = net(inputs)   # 前向传播
        loss = criterion(outputs, labels)  # 计算损失
        loss.backward()         # 反向传播
        optimizer.step()        # 更新权重

6. 评估和测试

使用测试数据集评估神经网络的性能。如果网络能够很好地拟合测试数据,那么它很可能也能够很好地拟合未知的数学公式。

7. 使用网络进行预测

一旦网络训练完成,你就可以使用它来预测新的输入值对应的输出值。

# 使用训练好的网络进行预测
with torch.no_grad():
    predictions = net(test_inputs)

8. 预期结果

3) 报告要求

  • 提交一份完整的工作报告 (中英文不限),需要提供主要的代码

报告模板可以参考如下文章:

  • 注意事项

  • 确保你的数据集足够大且具有代表性,以便神经网络能够学习到数学公式的真实模式。

  • 调整网络结构和超参数(如学习率、层数、神经元数量等)可能会影响网络的学习能力和最终性能。

  • 过拟合是一个常见问题,可以通过正则化、提前停止或使用更多的训练数据来缓解。 通过以上步骤,你可以使用神经网络来拟合复杂的数学公式。

www
bbb
2017 Attention is all you need