基础插值器
插值器
基类:ABC
表示插值器的抽象基类。
此类作为创建可用于各种应用中的插值器的基础,为插值相关操作提供基本结构和接口。
源代码位于 bionemo/moco/interpolants/base_interpolant.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
|
__init__(time_distribution, prior_distribution, device='cpu', rng_generator=None)
初始化 Interpolant 类。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
time_distribution
|
TimeDistribution
|
时间步长的分布。 |
必需 |
prior_distribution
|
PriorDistribution
|
变量的先验分布。 |
必需 |
device
|
Union[str, device]
|
在其上操作的设备。默认为 "cpu"。 |
'cpu'
|
rng_generator
|
Optional[Generator]
|
用于可重现采样的可选 :class: |
None
|
源代码位于 bionemo/moco/interpolants/base_interpolant.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
clean_mask_center(data, mask=None, center=False)
返回一个干净的张量,该张量已根据函数参数进行掩码和/或居中。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
data
|
Tensor
|
形状为 (..., 节点, 特征) 的输入数据。 |
必需 |
mask
|
Optional[Tensor]
|
可选的掩码,用于应用于形状为 (..., 节点) 的数据。如果提供,则用于计算 CoM。默认为 None。 |
None
|
center
|
Bool
|
一个布尔值,指示是否将数据围绕计算出的 CoM 居中。默认为 False。 |
False
|
返回值
类型 | 描述 |
---|---|
Tensor
|
形状为 (..., 节点, 特征) 的数据,如果 |
源代码位于 bionemo/moco/interpolants/base_interpolant.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
|
general_step(method_name, kwargs)
通过名称调用类的 step 方法,并传递提供的关键字参数。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
method_name
|
str
|
要调用的 step 方法的名称。 |
必需 |
kwargs
|
dict
|
要传递给 step 方法的关键字参数。 |
必需 |
返回值
类型 | 描述 |
---|---|
step 方法调用的结果。 |
Raises
类型 | 描述 |
---|---|
ValueError
|
如果提供的方法名称不以 'step' 开头。 |
Exception
|
如果 step 方法调用失败。错误消息包括可用 step 方法的列表。 |
Note
此方法允许动态调用 step 方法,从而在类的使用中提供灵活性。
源代码位于 bionemo/moco/interpolants/base_interpolant.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
|
interpolate(*args, **kwargs)
abstractmethod
从噪声和数据中获取给定时间 t 的 x(t)。
在给定时间 t 时在 x0 和 x1 之间插值。
源代码位于 bionemo/moco/interpolants/base_interpolant.py
134 135 136 137 138 139 140 |
|
sample_prior(*args, **kwargs)
从先验分布中采样。
此方法从 prior_distribution
属性指定的先验分布生成一个样本。
返回值
名称 | 类型 | 描述 |
---|---|---|
Tensor |
Tensor
|
从先验分布生成的样本。 |
源代码位于 bionemo/moco/interpolants/base_interpolant.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
|
sample_time(*args, **kwargs)
从时间分布中采样。
源代码位于 bionemo/moco/interpolants/base_interpolant.py
196 197 198 199 200 201 202 203 |
|
step(*args, **kwargs)
abstractmethod
执行一步积分。
源代码位于 bionemo/moco/interpolants/base_interpolant.py
142 143 144 145 |
|
to_device(device)
将所有内部张量移动到指定的设备,并更新 self.device
属性。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
device
|
str
|
要将张量移动到的设备(例如 "cpu", "cuda:0")。 |
必需 |
Note
此方法用于将 DDPM 插值器的内部状态传输到不同的设备。它更新 self.device
属性以反映新设备,并将所有内部张量移动到指定的设备。
源代码位于 bionemo/moco/interpolants/base_interpolant.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
|
PredictionType
基类:Enum
一个枚举,表示降噪扩散概率模型 (DDPM) 可以用于的预测类型。
DDPM 是多功能模型,可用于各种预测任务,包括
- 数据:从噪声输入预测原始数据分布。
- 噪声:预测添加到原始数据以获得输入的噪声。
- 速度:预测数据的速度或变化率,特别适用于建模时间动态。
这些预测类型可用于训练神经网络以执行特定任务,例如降噪、图像合成或时间序列预测。
源代码位于 bionemo/moco/interpolants/base_interpolant.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
pad_like(source, target)
填充源张量的维度以匹配目标张量的维度。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
source
|
Tensor
|
要填充的张量。 |
必需 |
target
|
Tensor
|
源张量应在维度上匹配的张量。 |
必需 |
返回值
名称 | 类型 | 描述 |
---|---|---|
Tensor |
Tensor
|
填充后的源张量。 |
Raises
类型 | 描述 |
---|---|
ValueError
|
如果源张量的维度多于目标张量。 |
示例
source = torch.tensor([1, 2, 3]) # 形状: (3,) target = torch.tensor([[1, 2], [4, 5], [7, 8]]) # 形状: (3, 2) padded_source = pad_like(source, target) # 形状: (3, 1)
源代码位于 bionemo/moco/interpolants/base_interpolant.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
|
string_to_enum(value, enum_type)
将字符串转换为指定类型的枚举值。如果输入已经是枚举实例,则按原样返回。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
value
|
Union[str, E]
|
要转换的字符串或现有枚举实例。 |
必需 |
enum_type
|
Type[E]
|
要转换为的枚举类型。 |
必需 |
返回值
名称 | 类型 | 描述 |
---|---|---|
E |
AnyEnum
|
对应的枚举值。 |
Raises
类型 | 描述 |
---|---|
ValueError
|
如果字符串与任何枚举成员都不对应。 |
源代码位于 bionemo/moco/interpolants/base_interpolant.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|