MCPcopy Create free account
hub / github.com/DeepGraphLearning/DiffPack / step_correct

Method step_correct

diffpack/schedule.py:244–279  ·  view source on GitHub ↗

Correct step for the input tensor (torsion angles). Args: x (Tensor): Torsion angles of shape :math:`(num_res, 4)` x_score (Tensor): Score of shape :math:`(num_res, 4)` x_batch (Tensor): Batch of shape :math:`(num_res)` x_mask (Tensor): Mask o

(self, x, x_score, x_batch, x_mask=None, snr=0.16)

Source from the content-addressed store, hash-verified

242
243 @torch.no_grad()
244 def step_correct(self, x, x_score, x_batch, x_mask=None, snr=0.16):
245 """Correct step for the input tensor (torsion angles).
246
247 Args:
248 x (Tensor): Torsion angles of shape :math:`(num_res, 4)`
249 x_score (Tensor): Score of shape :math:`(num_res, 4)`
250 x_batch (Tensor): Batch of shape :math:`(num_res)`
251 x_mask (Tensor): Mask of shape :math:`(num_res, 4)`
252 snr (float): Signal to noise ratio
253
254 Returns:
255 Tensor: Corrected torsion angles of shape :math:`(num_res, 4)`
256 """
257 x_batch = x_batch.reshape(-1, 4)
258
259 # Calculate Score Norm
260 x_score_2 = x_score ** 2
261 score_norm = torch.sqrt(scatter_add(x_score_2[x_mask], x_batch[x_mask], dim=0)).mean()
262
263 # Calculate Noise Norm
264 noise = torch.randn_like(x_score)
265 noise_2 = noise ** 2
266 noise_norm = torch.sqrt(scatter_add(noise_2[x_mask], x_batch[x_mask], dim=0)).mean()
267
268 # Step Size
269 step_size = (snr * noise_norm / score_norm) ** 2 * 2
270
271 # Correct Step
272 x_prev = x.clone()
273 x_prev += step_size * x_score
274 x_prev += ((step_size * 2) ** 0.5) * noise
275
276 if x_mask is not None:
277 x_prev[~x_mask] = x[~x_mask]
278
279 return x_prev
280
281 def sample_train_t(self, shape):
282 """Sample timesteps from uniform distribution.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected