gluonts.torch.util 模块#
- gluonts.torch.util.copy_parameters(net_source: torch.nn.modules.module.Module, net_dest: torch.nn.modules.module.Module, strict: bool = True) None [source]#
将参数从一个网络复制到另一个网络。
- 参数
net_source – 输入网络。
net_dest – 输出网络。
strict – 是否严格要求
state_dict
中的键与此模块state_dict()
函数返回的键匹配。默认为:True
- gluonts.torch.util.lagged_sequence_values(indices: List[int], prior_sequence: torch.Tensor, sequence: torch.Tensor, dim: int) torch.Tensor [source]#
从给定序列构造滞后值数组。
- 参数
indices – 滞后观测值的索引。例如,
[0]
表示在任意时间t
,将只包含时间t
本身的观测值;而[0, 24]
表示输出将包含时间t
和t-24
的观测值。prior_sequence – 包含在需要输出的时间范围之前的输入序列的张量。
sequence – 包含在需要输出的时间范围内的输入序列的张量。
dim – 时间维度。
- 返回值
形状为 (*sequence.shape, len(indices)) 的张量。
- 返回类型
张量
- gluonts.torch.util.repeat_along_dim(a: torch.Tensor, dim: int, repeats: int) torch.Tensor [source]#
沿给定维度重复张量,内部使用
torch.repeat
。- 参数
a – 要重复的原始张量。
dim – 用于重复数据的维度。
repeats – 重复输入张量的次数。
- 返回值
一个张量,其大小与输入张量相同,除了维度
dim
的长度乘以repeats
。- 返回类型
torch.Tensor
- gluonts.torch.util.resolve_device(device: Union[str, torch.device]) Union[str, torch.device] [source]#
将 torch 设备解析为最合适的设备。
如果 CUDA 可用,
"auto"
设备将解析为"cuda"
,否则解析为"cpu"
。否则设备保持不变。
- gluonts.torch.util.slice_along_dim(a: torch.Tensor, dim: int, slice_: slice) torch.Tensor [source]#
沿给定维度对张量进行切片。
- 参数
a – 要切片的原始张量。
dim – 进行切片的维度。
slice – 要进行的切片。
- 返回值
一个张量,其大小与输入张量相同,除了维度
dim
的长度等于切片长度。- 返回类型
torch.Tensor
- gluonts.torch.util.take_last(a: torch.Tensor, dim: int, num: int) torch.Tensor [source]#
沿给定维度获取给定张量的最后几个元素。
- 参数
a – 要切片的原始张量。
dim – 进行切片的维度。
num – 要保留的尾部元素的数量(非负)。
- 返回值
一个张量,其大小与输入张量相同,除了维度
dim
的长度等于num
。- 返回类型
torch.Tensor