时序预测模型 ============ VQNetTimeSeries 提供了多种时序预测模型,包括量子-经典混合模型和经典模型。 .. toctree:: :maxdepth: 2 DLinear ------- DLinear(Decomposition-Linear)模型,核心思想是将时间序列进行分解,然后分别用线性层进行建模,属于一种轻量级、解释性强的模型。 论文链接: https://arxiv.org/pdf/2205.13504.pdf .. class:: DLinear(seq_len, pred_len, enc_in, moving_avg=25, individual=False) :module: vqnetts.models.DLinear_model 先用滑动平均将序列分解为趋势项与季节项,再分别用线性层建模并求和得到预测结果。 :param seq_len: 输入序列长度。 :type seq_len: int :param pred_len: 预测序列长度。 :type pred_len: int :param enc_in: 输入变量(通道)数。 :type enc_in: int :param moving_avg: 滑动平均窗口大小,默认为 25。 :type moving_avg: int :param individual: 为 ``True`` 时每个变量使用独立的线性层,``False`` 时所有变量共享,默认为 ``False``。 :type individual: bool .. method:: forward(x_enc, x_mark_enc=None, x_dec=None, x_mark_dec=None, mask=None) 前向传播。仅使用 ``x_enc``,其余参数为与其他模型保持接口一致的占位参数。 :param x_enc: 输入序列,形状 ``[batch, seq_len, enc_in]``。 :returns: 预测序列,形状 ``[batch, pred_len, enc_in]``。 **使用示例**:: from vqnetts.models.DLinear_model import DLinear import pyvqnet.tensor as tensor # 创建模型 model = DLinear( seq_len=96, pred_len=96, moving_avg=3, enc_in=7, individual=False ) # 输入数据 x = tensor.randn([32, 96, 7]) # 前向传播 output = model(x) print(output.shape) # [32, 96, 7] QDLinear -------- 基于量子参数生成的 DLinear 模型。与 DLinear 采用相同的序列分解 + 线性建模框架, 但线性层权重由量子参数生成线路(QPG)动态生成。 .. class:: QDLinear(seq_len, pred_len, enc_in, moving_avg=25, individual=False) :module: vqnetts.models.DLinear_model :param seq_len: 输入序列长度。 :type seq_len: int :param pred_len: 预测序列长度。 :type pred_len: int :param enc_in: 输入变量(通道)数。 :type enc_in: int :param moving_avg: 滑动平均窗口大小,默认为 25。 :type moving_avg: int :param individual: 为 ``True`` 时每个变量使用独立的线性层,``False`` 时所有变量共享,默认为 ``False``。 :type individual: bool .. method:: forward(x_enc, x_mark_enc=None, x_dec=None, x_mark_dec=None, mask=None) 前向传播。仅使用 ``x_enc``,其余参数为与其他模型保持接口一致的占位参数。 :param x_enc: 输入序列,形状 ``[batch, seq_len, enc_in]``。 :returns: 预测序列,形状 ``[batch, pred_len, enc_in]``。 **使用示例**:: from vqnetts.models.DLinear_model import QDLinear import pyvqnet.tensor as tensor # 创建模型 model = QDLinear( seq_len=96, pred_len=96, moving_avg=3, enc_in=7, individual=False ) # 输入数据 x = tensor.randn([32, 96, 7]) # 前向传播 output = model(x) print(output.shape) # [32, 96, 7] HQCLSTM ------- 混合量子经典长短期记忆网络 (Hybrid Quantum Classical LSTM),结合量子计算和经典 LSTM 的优势。 .. class:: HQCLSTM(seq_len, pred_len, enc_in, hidden_size, n_qubits, c_out, num_lstm_layers=1, n_vqc_qlayers=4) :module: vqnetts.models.HQCLSTM_model 混合量子-经典集成模型,用于时间序列预测。 :param seq_len: 输入序列长度。 :type seq_len: int :param pred_len: 预测序列长度。 :type pred_len: int :param enc_in: 输入特征维度。 :type enc_in: int :param hidden_size: LSTM 隐藏层维度。 :type hidden_size: int :param n_qubits: 量子比特数量。 :type n_qubits: int :param c_out: 输出维度。 :type c_out: int :param num_lstm_layers: LSTM 层数,默认为 1。 :type num_lstm_layers: int :param n_vqc_qlayers: 量子线路层数,默认为 4。 :type n_vqc_qlayers: int .. method:: forward(x, x_mark_enc=None, x_dec=None, x_mark_dec=None, mask=None) 前向传播。 :param x: 输入序列,形状 ``[batch, seq_len, enc_in]``。 :returns: 预测序列,形状 ``[batch, pred_len, c_out]``。 **使用示例**:: from vqnetts.models.HQCLSTM_model import HQCLSTM import pyvqnet.tensor as tensor # 创建模型 model = HQCLSTM( seq_len=96, pred_len=96, enc_in=7, hidden_size=64, n_qubits=4, c_out=7, num_lstm_layers=2, n_vqc_qlayers=4 ) # 输入数据 x = tensor.randn([32, 96, 7]) # 前向传播 output = model(x) # 反向传播 output.backward() print(output.shape) # [32, 96, 7] QRegLSTM -------- 量子回归长短期记忆网络(Quantum Regression LSTM)。在 RegLSTM 框架基础上,将 LSTM 的输入门、遗忘门、更新门与输出门替换为量子变分电路(QLSTM),并配合时间-特征双重 SE 注意力与回归头完成时序回归预测。设置 ``quantum=False`` 时退化为经典 LSTM 版本。 .. class:: QRegLSTM(input_sz, hidden_sz, inputLen, quantum, vqc, para_num) :module: vqnetts.models.QRegLSTM_model :param input_sz: 输入特征数。 :type input_sz: int :param hidden_sz: 隐藏维度,同时是量子比特数。 :type hidden_sz: int :param inputLen: 输入序列长度。 :type inputLen: int :param quantum: 为 ``True`` 时使用 QLSTM,为 ``False`` 时使用经典 LSTM。 :type quantum: bool :param vqc: 变分量子线路构造函数,``quantum=True`` 时必需,采用 pyQPanda 风格签名 ``vqc(input, param, qubits, cubits, m_machine)``,返回长度为 ``hidden_sz`` 的测量值列表。 :type vqc: callable :param para_num: 量子线路可训练参数数量。 :type para_num: int .. method:: forward(x) 前向传播,完成序列建模、双重 SE 注意力加权与回归输出。 :param x: 输入序列,形状 ``[batch, inputLen, input_sz]``。 :returns: 回归预测值,形状 ``[batch, 1]``。 **使用示例**:: from vqnetts.models.QRegLSTM_model import QRegLSTM import pyvqnet.tensor as tensor # 创建模型 model = QRegLSTM( input_sz=7, hidden_sz=4, inputLen=96, quantum=True, para_num=16 ) # 输入数据: [batch, seq_len, features] x = tensor.randn([32, 96, 7]) # 前向传播 output = model(x) print(output.shape) # [32, 1] SegRNN ------ 分段递归神经网络。论文链接: https://arxiv.org/abs/2308.11200.pdf .. class:: SegRNN(seq_len, pred_len, seg_len, enc_in, d_model=512, dropout=0.1) :module: vqnetts.models.SegRNN_model :param seq_len: 输入序列长度。 :type seq_len: int :param pred_len: 预测序列长度。 :type pred_len: int :param seg_len: 分段迭代的长度。 :type seg_len: int :param enc_in: 输入变量(通道)数。 :type enc_in: int :param d_model: 模型隐藏维度,默认为 512。 :type d_model: int :param dropout: Dropout 比例,默认为 0.1。 :type dropout: float .. method:: forward(x_enc, x_mark_enc=None, x_dec=None, x_mark_dec=None, mask=None) 前向传播。 :param x_enc: 输入序列,形状 ``[batch, seq_len, enc_in]``。 :returns: 预测序列,形状 ``[batch, pred_len, enc_in]``。 **使用示例**:: from vqnetts.models.SegRNN_model import SegRNN import pyvqnet.tensor as tensor # 创建模型 model = SegRNN( seq_len=96, pred_len=96, seg_len=24, enc_in=7, d_model=512, dropout=0.1 ) # 输入数据 x = tensor.randn([32, 96, 7]) # 前向传播 output = model(x) print(output.shape) # [32, 96, 7] Transformer ----------- 基于自注意力机制的编码器-解码器架构,通过多头注意力捕获序列中的长程依赖关系,适用于多变量时间序列预测任务。 论文链接: https://arxiv.org/pdf/1706.03762 .. class:: Transformer(pred_len, enc_in, dec_in, c_out, d_model, e_layers, d_layers, embed, n_heads, d_ff, freq='h', activation='relu', factor=1, dropout=0.1) :module: vqnetts.models.Transformer_model :param pred_len: 预测序列长度。 :type pred_len: int :param enc_in: 编码器输入特征数(源序列维度)。 :type enc_in: int :param dec_in: 解码器输入特征数(目标序列维度)。 :type dec_in: int :param c_out: 输出特征数。 :type c_out: int :param d_model: 模型嵌入维度(Transformer 层隐藏维度)。 :type d_model: int :param e_layers: 编码器层数。 :type e_layers: int :param d_layers: 解码器层数。 :type d_layers: int :param embed: 时间特征嵌入策略,可选 ``'timeF'`` / ``'fixed'`` / ``'learned'``。 :type embed: str :param n_heads: 多头注意力的头数。 :type n_heads: int :param d_ff: 前馈网络维度。 :type d_ff: int :param freq: 时间特征编码频率,可选 ``'s'`` 秒 / ``'t'`` 分 / ``'h'`` 时 / ``'d'`` 日 / ``'b'`` 工作日 / ``'w'`` 周 / ``'m'`` 月,默认为 ``'h'``。 :type freq: str :param activation: 激活函数,默认为 ``'relu'``。 :type activation: str :param factor: 注意力因子(稀疏注意力的超参数),默认为 1。 :type factor: int :param dropout: Dropout 比例,默认为 0.1。 :type dropout: float .. method:: forward(x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None) 前向传播。 :param x_enc: 编码器输入序列,形状 ``[batch, seq_len, enc_in]``。 :param x_mark_enc: 编码器时间特征,形状 ``[batch, seq_len, n_time]``,``n_time`` 由 ``freq`` 决定。 :param x_dec: 解码器输入序列,形状 ``[batch, dec_len, dec_in]``。 :param x_mark_dec: 解码器时间特征,形状 ``[batch, dec_len, n_time]``。 :returns: 预测序列,形状 ``[batch, pred_len, c_out]``。 **使用示例**:: from vqnetts.models.Transformer_model import Transformer import pyvqnet.tensor as tensor # 创建模型 model = Transformer( pred_len=96, enc_in=7, dec_in=7, c_out=7, d_model=128, e_layers=2, d_layers=2, embed='timeF', n_heads=4, d_ff=256, freq='h', activation='relu', factor=1, dropout=0.1 ) # 输入数据 x_enc = tensor.randn([2, 96, 7]) x_mark_enc = tensor.randn([2, 96, 4]) x_dec = tensor.randn([2, 96, 7]) x_mark_dec = tensor.randn([2, 96, 4]) # 前向传播 output = model(x_enc, x_mark_enc, x_dec, x_mark_dec) print(output.shape) # (2, 96, 7) QTransformer ------------ 量子增强的 Transformer 模型,在保持原始 Transformer 架构的基础上引入量子参数生成策略,提升时序特征建模能力。 .. class:: QTransformer(pred_len, enc_in, dec_in, c_out, d_model, e_layers, d_layers, embed, n_heads, d_ff, freq='h', activation='relu', factor=1, dropout=0.1) :module: vqnetts.models.Transformer_model 参数含义与 :class:`vqnetts.models.Transformer_model.Transformer` 一致。 .. method:: forward(x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None) 前向传播,参数含义与 :meth:`vqnetts.models.Transformer_model.Transformer.forward` 一致。 :param x_enc: 编码器输入序列,形状 ``[batch, seq_len, enc_in]``。 :param x_mark_enc: 编码器时间特征,形状 ``[batch, seq_len, n_time]``。 :param x_dec: 解码器输入序列,形状 ``[batch, dec_len, dec_in]``。 :param x_mark_dec: 解码器时间特征,形状 ``[batch, dec_len, n_time]``。 :returns: 预测序列,形状 ``[batch, pred_len, c_out]``。 **使用示例**:: from vqnetts.models.Transformer_model import QTransformer import pyvqnet.tensor as tensor # 创建模型 model = QTransformer( pred_len=96, enc_in=7, dec_in=7, c_out=7, d_model=128, e_layers=2, d_layers=2, embed='timeF', n_heads=4, d_ff=256, freq='h', activation='relu', factor=1, dropout=0.1 ) # 输入数据 x_enc = tensor.randn([2, 96, 7]) x_mark_enc = tensor.randn([2, 96, 4]) x_dec = tensor.randn([2, 96, 7]) x_mark_dec = tensor.randn([2, 96, 4]) # 前向传播 output = model(x_enc, x_mark_enc, x_dec, x_mark_dec) print(output.shape) # (2, 96, 7) iTransformer ------------ 改进的 Transformer 模型,专为时间序列预测优化。采用倒置架构,将每个变量整体作为一个 token, 通过注意力建模变量之间的关联。论文链接: https://arxiv.org/abs/2310.06625 .. class:: iTransformer(seq_len, pred_len, e_layers=2, d_model=128, d_ff=32, embed='timeF', freq='h', n_heads=8, factor=1, activation='gelu', dropout=0.1, output_attention=False) :module: vqnetts.models.iTransformer_model :param seq_len: 输入序列长度。 :type seq_len: int :param pred_len: 预测序列长度。 :type pred_len: int :param e_layers: 编码器层数,默认为 2。 :type e_layers: int :param d_model: 模型隐藏维度,默认为 128。 :type d_model: int :param d_ff: 前馈网络维度,默认为 32。 :type d_ff: int :param embed: 时间特征编码方式,可选 ``'timeF'`` / ``'fixed'`` / ``'learned'``,默认为 ``'timeF'``。 :type embed: str :param freq: 时间特征编码频率,可选 ``'s'`` / ``'t'`` / ``'h'`` / ``'d'`` / ``'b'`` / ``'w'`` / ``'m'``,默认为 ``'h'``。 :type freq: str :param n_heads: 多头注意力的头数,默认为 8。 :type n_heads: int :param factor: 注意力因子,默认为 1。 :type factor: int :param activation: 激活函数,默认为 ``'gelu'``。 :type activation: str :param dropout: Dropout 比例,默认为 0.1。 :type dropout: float :param output_attention: 是否返回注意力权重,默认为 ``False``。 :type output_attention: bool .. method:: forward(x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None) 前向传播。 :param x_enc: 输入序列,形状 ``[batch, seq_len, enc_in]``。 :param x_mark_enc: 编码器时间特征,形状 ``[batch, seq_len, n_time]``。 :param x_dec: 解码器输入序列,形状 ``[batch, dec_len, dec_in]``。 :param x_mark_dec: 解码器时间特征,形状 ``[batch, dec_len, n_time]``。 :returns: 预测序列,形状 ``[batch, pred_len, enc_in]``。 **使用示例**:: from vqnetts.models.iTransformer_model import iTransformer import pyvqnet.tensor as tensor # 创建模型 model = iTransformer( seq_len=96, pred_len=96, d_model=128, n_heads=8, e_layers=2, d_ff=32, dropout=0.1, embed='timeF', freq='h', factor=1, activation='gelu', output_attention=False ) # 输入数据 x = tensor.randn([32, 96, 7]) x_mark_enc = tensor.randn([32, 96, 4]) x_dec = tensor.randn([32, 96, 7]) x_mark_dec = tensor.randn([32, 96, 4]) # 前向传播 output = model(x, x_mark_enc, x_dec, x_mark_dec) print(output.shape) # [32, 96, 7] Informer -------- 高效 Transformer 模型,专为长序列时间序列预测设计,采用概率稀疏注意力(ProbAttention)降低长序列的计算复杂度。 .. class:: Informer(pred_len, label_len, enc_in, dec_in, c_out, d_model, n_heads, e_layers, d_layers, d_ff, factor, embed, freq, activation='gelu', dropout=0.1) :module: vqnetts.models.Informer_model :param pred_len: 预测序列长度。 :type pred_len: int :param label_len: 解码器起始 token(已知序列片段)长度。 :type label_len: int :param enc_in: 编码器输入特征数。 :type enc_in: int :param dec_in: 解码器输入特征数。 :type dec_in: int :param c_out: 输出特征数。 :type c_out: int :param d_model: 模型嵌入维度。 :type d_model: int :param n_heads: 多头注意力的头数。 :type n_heads: int :param e_layers: 编码器层数。 :type e_layers: int :param d_layers: 解码器层数。 :type d_layers: int :param d_ff: 前馈网络维度。 :type d_ff: int :param factor: 注意力因子(稀疏注意力的超参数)。 :type factor: int :param embed: 时间特征编码方式,可选 ``'timeF'`` / ``'fixed'`` / ``'learned'``。 :type embed: str :param freq: 时间特征编码频率,可选 ``'s'`` / ``'t'`` / ``'h'`` / ``'d'`` / ``'b'`` / ``'w'`` / ``'m'``。 :type freq: str :param activation: 激活函数,默认为 ``'gelu'``。 :type activation: str :param dropout: Dropout 比例,默认为 0.1。 :type dropout: float .. method:: forward(x_enc, x_mark_enc, x_dec, x_mark_dec, mask=None) 前向传播。 :param x_enc: 编码器输入序列,形状 ``[batch, seq_len, enc_in]``。 :param x_mark_enc: 编码器时间特征,形状 ``[batch, seq_len, n_time]``。 :param x_dec: 解码器输入序列,形状 ``[batch, label_len + pred_len, dec_in]``。 :param x_mark_dec: 解码器时间特征,形状 ``[batch, label_len + pred_len, n_time]``。 :returns: 预测序列,形状 ``[batch, pred_len, c_out]``。 **使用示例**:: from vqnetts.models.Informer_model import Informer import pyvqnet.tensor as tensor # 创建模型 model = Informer( pred_len=96, label_len=48, enc_in=7, dec_in=7, c_out=7, d_model=128, n_heads=8, e_layers=2, d_layers=1, d_ff=32, factor=5, embed='timeF', freq='h', activation='gelu', dropout=0.1 ) # 输入数据 x_enc = tensor.randn([32, 96, 7]) x_mark_enc = tensor.randn([32, 96, 4]) x_dec = tensor.randn([32, 96, 7]) x_mark_dec = tensor.randn([32, 96, 4]) # 前向传播 output = model(x_enc, x_mark_enc, x_dec, x_mark_dec) print(output.shape) # [32, 96, 7] ConvLSTM -------- 卷积长短期记忆网络,结合卷积和 LSTM 的优势,用于时空序列预测。 .. class:: ConvLSTM(in_shape, total_length, input_length, num_layers=4, num_hidden=64) :module: vqnetts.models.ConvLSTM_model :param in_shape: 输入的空间与通道维度,格式 ``[序列长度, 通道数, 高度, 宽度]``。 :type in_shape: list 或 tuple :param total_length: 用于预测的总序列长度。 :type total_length: int :param input_length: 用于预测的输入序列长度。 :type input_length: int :param num_layers: 堆叠的 ConvLSTM 层数,默认为 4。 :type num_layers: int :param num_hidden: 每层 ConvLSTM 的隐藏通道数,默认为 64。 :type num_hidden: int .. method:: forward(frames_tensor, mask_true) 前向传播。 :param frames_tensor: 输入帧序列,形状 ``[batch, total_length, C, H, W]``。 :param mask_true: 计划采样(scheduled sampling)掩码,形状 ``[batch, total_length - input_length - 1, C, H, W]``。 :returns: 预测帧序列,形状 ``[batch, total_length - 1, C, H, W]``。 **使用示例**:: from vqnetts.models.ConvLSTM_model import ConvLSTM import pyvqnet.tensor as tensor # 创建模型 model = ConvLSTM( in_shape=[10, 1, 64, 64], total_length=20, input_length=10, num_layers=4, num_hidden=64 ) # 输入数据 x = tensor.randn([2, 20, 1, 64, 64]) mask_true = tensor.randn([2, 9, 1, 64, 64]) # 前向传播 output = model(x, mask_true) print(output.shape) # [2, 19, 1, 64, 64] PredRNN ------- 预测递归神经网络,在 ConvLSTM 记忆单元的基础上引入时空记忆(spatio-temporal memory)流动,用于时空序列预测。 .. class:: PredRNN(in_shape, total_length, input_length, num_layers=4, stride=1, patch_size=1, num_hidden=64, filter_size=5) :module: vqnetts.models.PredRNN_model :param in_shape: 输入形状,格式 ``[序列长度, 通道数, 高度, 宽度]``。 :type in_shape: list :param total_length: 输入序列的总长度。 :type total_length: int :param input_length: 输入序列的长度。 :type input_length: int :param num_layers: 堆叠层数,默认为 4。 :type num_layers: int :param stride: 卷积步长,默认为 1。 :type stride: int :param patch_size: 块大小,默认为 1。 :type patch_size: int :param num_hidden: 隐藏单元数量,默认为 64。 :type num_hidden: int :param filter_size: 卷积核大小,默认为 5。 :type filter_size: int .. method:: forward(frames_tensor, mask_true=None) 前向传播。 :param frames_tensor: 输入帧序列,形状 ``[batch, total_length, C, H, W]``。 :param mask_true: 计划采样掩码,形状 ``[batch, total_length - input_length - 1, C, H, W]``,可为 ``None``。 :returns: 预测帧序列,形状 ``[batch, total_length - 1, C, H, W]``。 **使用示例**:: from vqnetts.models.PredRNN_model import PredRNN import pyvqnet.tensor as tensor # 创建模型 model = PredRNN( in_shape=[10, 1, 64, 64], total_length=20, input_length=10, num_layers=4, num_hidden=64 ) # 输入数据 x = tensor.randn([2, 20, 1, 64, 64]) mask_true = tensor.randn([2, 9, 1, 64, 64]) # 前向传播 output = model(x, mask_true) print(output.shape) # [2, 19, 1, 64, 64] HQSTM ----- 混合量子时空模型 (Hybird Quantum Spatial-Temporal module),在时空预测框架中以量子参数生成模块构建隐藏网络。 .. class:: HQSTM(in_shape, enc_out=16, hid_out=256, hidden_layers=[3, 4, 2, 2], out_channel=[128, 64, 32, 16], group=8) :module: vqnetts.models.HQSTM_model :param in_shape: 输入形状,格式 ``[T, C, H, W]``。 :type in_shape: list 或 tuple :param enc_out: 编码器的输出维度,默认为 16。 :type enc_out: int :param hid_out: 隐藏模块的输出维度,默认为 256。 :type hid_out: int :param hidden_layers: 隐藏模块各阶段的层数列表,默认为 ``[3, 4, 2, 2]``。 :type hidden_layers: list :param out_channel: 隐藏模块各阶段的输出通道列表,默认为 ``[128, 64, 32, 16]``。 :type out_channel: list :param group: 组归一化的组大小,默认为 8。 :type group: int .. method:: forward(x_raw) 前向传播。 :param x_raw: 输入张量,形状 ``[batch, T, C, H, W]``。 :returns: 预测张量,形状 ``[batch, T, C, H, W]``。 **使用示例**:: from vqnetts.models.HQSTM_model import HQSTM import pyvqnet.tensor as tensor # 创建模型 model = HQSTM( in_shape=[10, 1, 64, 64], enc_out=16, hid_out=256, hidden_layers=[2, 2, 2, 2], out_channel=[64, 64, 64, 64], group=8 ) # 输入数据 x = tensor.randn([2, 10, 1, 64, 64]) # 前向传播 output = model(x) print(output.shape) # [2, 10, 1, 64, 64] SimVP ----- 简单视频预测模型,采用「空间编码 - 时间隐藏 - 空间解码」结构,时间隐藏模块由 Inception 结构堆叠而成。 .. class:: SimVP(in_shape, hid_S=16, hid_T=256, N_S=4, N_T=8, incep_ker=[3, 5, 7, 11], groups=8) :module: vqnetts.models.SimVP_model :param in_shape: 输入张量形状,格式 ``[T, C, H, W]``。 :type in_shape: tuple :param hid_S: 空间编码器/解码器的隐藏通道数,默认为 16。 :type hid_S: int :param hid_T: 时间隐藏模块的隐藏通道数,默认为 256。 :type hid_T: int :param N_S: 空间编码器/解码器的层数,默认为 4。 :type N_S: int :param N_T: 时间隐藏模块的层数,默认为 8。 :type N_T: int :param incep_ker: Inception 块的卷积核大小列表,默认为 ``[3, 5, 7, 11]``。 :type incep_ker: list :param groups: 分组卷积的组数,默认为 8。 :type groups: int .. method:: forward(x_raw) 前向传播。 :param x_raw: 输入张量,形状 ``[batch, T, C, H, W]``。 :returns: 预测张量,形状 ``[batch, T, C, H, W]``。 **使用示例**:: from vqnetts.models.SimVP_model import SimVP import pyvqnet.tensor as tensor # 创建模型 model = SimVP( in_shape=[10, 1, 64, 64], hid_S=16, hid_T=256, N_S=4, N_T=8, incep_ker=[3,5,7,11], groups=8 ) # 输入数据 x = tensor.randn([2, 10, 1, 64, 64]) # 前向传播 output = model(x) print(output.shape) # [2, 10, 1, 64, 64] TAU --- 时间注意力单元 (Temporal Attention Unit),以时间注意力替代离散堆叠的时序卷积,用于时空序列预测。 .. class:: TAU(in_shape, hid_S=32, hid_T=128, N_S=4, N_T=8, mlp_ratio=8.0, drop=0.0, drop_path=0.1, spatio_kernel_enc=3, spatio_kernel_dec=3, act_inplace=True) :module: vqnetts.models.TAU_model :param in_shape: 输入张量形状,格式 ``[T, C, H, W]``。 :type in_shape: tuple :param hid_S: 空间编码分支的隐藏维度,控制空间特征图的通道数,默认为 32。 :type hid_S: int :param hid_T: 时间注意力分支的隐藏维度,默认为 128。 :type hid_T: int :param N_S: 空间模块中堆叠的层数,默认为 4。 :type N_S: int :param N_T: 时间模块中堆叠的层数,默认为 8。 :type N_T: int :param mlp_ratio: Transformer 块中 MLP 层的扩展比例,MLP 隐藏维度为 ``mlp_ratio * 输入维度``,默认为 8.0。 :type mlp_ratio: float :param drop: 特征图 Dropout 概率,默认为 0.0。 :type drop: float :param drop_path: 残差连接的 drop path(随机深度)概率,用于缓解深度网络的过拟合,默认为 0.1。 :type drop_path: float :param spatio_kernel_enc: 空间编码器的方形卷积核大小,如 3 表示 3×3 卷积,默认为 3。 :type spatio_kernel_enc: int :param spatio_kernel_dec: 空间解码器的方形卷积核大小,默认为 3。 :type spatio_kernel_dec: int :param act_inplace: 是否就地执行激活以减少内存占用,默认为 ``True``。 :type act_inplace: bool .. method:: forward(x_raw) 前向传播。 :param x_raw: 输入张量,形状 ``[batch, T, C, H, W]``。 :returns: 预测张量,形状 ``[batch, T, C, H, W]``。 **使用示例**:: from vqnetts.models.TAU_model import TAU import pyvqnet.tensor as tensor # 创建模型 model = TAU( in_shape=[10, 1, 64, 64], hid_S=32, hid_T=128, N_S=4, N_T=8, mlp_ratio=8., drop=0.0, drop_path=0.1, spatio_kernel_enc=3, spatio_kernel_dec=3, act_inplace=True ) # 输入数据 x = tensor.randn([2, 10, 1, 64, 64]) # 前向传播 output = model(x) print(output.shape) # [2, 10, 1, 64, 64] ResQPG ------ 基于量子参数生成(QPG)的残差卷积时空预测模型。在「空间编码-时间隐藏-空间解码」框架上,中间隐藏网络模块采用多尺度分组卷积分支加权融合和通道注意力,实现量子-经典混合的时空序列预测。 .. class:: ResQPG(in_shape, hid_S=16, hid_T=256, N_S=4, N_T=8, block_ker=[3, 5, 7, 11], groups=8, reduction=8, is_quantum=False, qpg_V='1') :module: vqnetts.models.ResQPG_model :param in_shape: 输入张量形状,格式 ``[T, C, H, W]``。 :type in_shape: tuple :param hid_S: 空间编码器/解码器的隐藏通道数,默认为 16。 :type hid_S: int :param hid_T: 时间隐藏网络的隐藏通道数,默认为 256。 :type hid_T: int :param N_S: 空间下采样层数,默认为 4。 :type N_S: int :param N_T: 时间隐藏网络的层数,默认为 8。 :type N_T: int :param block_ker: ResQPGBlock 多尺度分组卷积核大小列表,默认为 ``[3, 5, 7, 11]``。 :type block_ker: list :param groups: 分组卷积的组数,默认为 8。 :type groups: int :param reduction: SE 通道注意力的通道缩减比,默认为 8。 :type reduction: int :param is_quantum: 是否启用量子参数生成层,默认为 ``False``,即纯经典模式: * ``True`` —— 所有 ResQPGBlock 启用量子层; * ``'min'`` —— 仅在最小通道数的层启用; * 正整数 —— 在前 N 层启用。 :type is_quantum: bool、str 或 int :param qpg_V: 量子态输出编码版本,默认为 ``'1'``: * ``'1'`` —— 取量子态实部; * ``'2'`` —— 测量概率 ``|ψ|²`` 并经 MLP 解码; * ``'3'`` —— 测量概率线性映射到角度区间。 :type qpg_V: str .. method:: forward(x_raw) 前向传播。 :param x_raw: 输入张量,形状 ``[batch, T, C, H, W]``。 :returns: 预测张量,形状 ``[batch, T, C, H, W]``。 **使用示例**:: from vqnetts.models.ResQPG_model import ResQPG import pyvqnet.tensor as tensor # 创建模型 model = ResQPG( in_shape=[10, 1, 64, 64], hid_S=16, hid_T=128, N_S=4, N_T=4 ) # 输入数据: [batch, T, C, H, W] x = tensor.randn([2, 10, 1, 64, 64]) # 前向传播 output = model(x) print(output.shape) # [2, 10, 1, 64, 64]