

from typing import Dict, Optional, Tuple

import torch



def   UpperCamelCase(   lowercase_				)      ->							torch.Tensor:





  '''simple docstring'''





  snake_case_					= boundaries[1] - boundaries[0]
  snake_case_					= boundaries + step / 2
  snake_case_					= torch.cat([bin_centers, (bin_centers[-1] + step).unsqueeze(-1				)]     ,   dim=0				)
  return bin_centers



def   UpperCamelCase(   lowercase_     ,   lowercase_     ,   )      ->							Tuple[torch.Tensor, torch.Tensor]:





  '''simple docstring'''





  snake_case_					= _calculate_bin_centers(lowercase_				)
  return (
      torch.sum(aligned_distance_error_probs * bin_centers     ,   dim=-1				),
      bin_centers[-1],
  )



def   UpperCamelCase(   lowercase_     ,   lowercase_ = 31     ,   lowercase_ = 64     ,   **lowercase_     ,   )      ->							Dict[str, torch.Tensor]:





  '''simple docstring'''





  snake_case_					= torch.linspace(0     ,   lowercase_     ,   steps=(no_bins - 1)     ,   device=logits.device				)

  snake_case_					= torch.nn.functional.softmax(lowercase_     ,   dim=-1				)
  snake_case_		,							snake_case_					= _calculate_expected_aligned_error(
      alignment_confidence_breaks=lowercase_     ,   aligned_distance_error_probs=lowercase_     ,   )

  return {
      "aligned_confidence_probs": aligned_confidence_probs,
      "predicted_aligned_error": predicted_aligned_error,
      "max_predicted_aligned_error": max_predicted_aligned_error,
  }



def   UpperCamelCase(   lowercase_     ,   lowercase_ = None     ,   lowercase_ = 31     ,   lowercase_ = 64     ,   lowercase_ = 1e-8     ,   **lowercase_     ,   )      ->							torch.Tensor:





  '''simple docstring'''





  if residue_weights is None:
    snake_case_					= logits.new_ones(logits.shape[-2]				)

  snake_case_					= torch.linspace(0     ,   lowercase_     ,   steps=(no_bins - 1)     ,   device=logits.device				)

  snake_case_					= _calculate_bin_centers(lowercase_				)
  torch.sum(lowercase_				)
  snake_case_					= logits.shape[-2]
  snake_case_					= max(lowercase_     ,   19				)

  snake_case_					= 1.24 * (clipped_n - 15) ** (1.0 / 3) - 1.8

  snake_case_					= torch.nn.functional.softmax(lowercase_     ,   dim=-1				)

  snake_case_					= 1.0 / (1 + (bin_centers**2) / (da**2))
  snake_case_					= torch.sum(probs * tm_per_bin     ,   dim=-1				)

  snake_case_					= residue_weights / (eps + residue_weights.sum())
  snake_case_					= torch.sum(predicted_tm_term * normed_residue_mask     ,   dim=-1				)

  snake_case_					= per_alignment * residue_weights

  snake_case_					= (weighted == torch.max(lowercase_				)).nonzero()[0]
  return per_alignment[tuple(lowercase_				)]


def   UpperCamelCase(   lowercase_				)      ->							str:





  '''simple docstring'''





  return "".join(chr(ord(lowercase_				) + 32				) if """A""" <= char <= """Z""" else char for char in word				)


if __name__ == "__main__":
    from doctest import testmod

    testmod()