code: def confidence_based_inlier_selection(
      residuals: Tensor,
      ransidx: Tensor,
      rdims: Tensor,
      idxoffsets: Tensor,
      dv: torch.device,
      min_confidence: Tensor,
  ) -> Tuple[Tensor, Tensor, Tensor, Tensor, Tensor]:
      numransacs = rdims.shape[0]
      numiters = residuals.shape[0]
  
      sorted_res, sorting_idxes = stable_sort_residuals(
          residuals, ransidx
      )
      sorted_res_sqr = sorted_res**2
  
      too_perfect_fits = sorted_res_sqr <= 1e-8
      end_rans_indexing = torch.cumsum(rdims, dim=0) - 1
  
      _, inv_indices, res_dup_counts = torch.unique_consecutive(
          sorted_res_sqr.half().float(),
          dim=1,
          return_counts=True,
          return_inverse=True,
      )
  
      duplicates_per_sample = res_dup_counts[inv_indices]
      inlier_weights = (1.0 / duplicates_per_sample).repeat(numiters, 1)
      inlier_weights[too_perfect_fits] = 0.0
  
      balanced_rdims, weights_cumsums = group_sum_and_cumsum(
          inlier_weights, end_rans_indexing, ransidx
      )
      if not isinstance(weights_cumsums, Tensor):
          raise TypeError(
              "Expected the `weights_cumsums` to be a Tensor!"
          )
  
      progressive_inl_rates = (
          weights_cumsums.float()
          / (balanced_rdims.repeat_interleave(rdims, dim=1)).float()
      )
  
      good_inl_mask = (
          sorted_res_sqr * min_confidence <= progressive_inl_rates
      ) | too_perfect_fits
  
      inlier_weights[~good_inl_mask] = 0.0
      inlier_counts_matrix, _ = group_sum_and_cumsum(
          inlier_weights, end_rans_indexing
      )
  
      inl_counts, inl_iters = torch.max(
          inlier_counts_matrix.long(), dim=0
      )
  
      relative_inl_idxes = arange_sequence(inl_counts)
      inl_ransidx = torch.arange(
          numransacs, device=dv
      ).repeat_interleave(inl_counts)
      inl_sampleidx = sorting_idxes[
          inl_iters.repeat_interleave(inl_counts),
          idxoffsets[inl_ransidx] + relative_inl_idxes,
      ]
      highest_accepted_sqr_residuals = sorted_res_sqr[
          inl_iters, idxoffsets + inl_counts - 1
      ]
      expected_extra_inl = (
          balanced_rdims[
              inl_iters, torch.arange(numransacs, device=dv)
          ].float()
          * highest_accepted_sqr_residuals
      )
      return (
          inl_ransidx,
          inl_sampleidx,
          inl_counts,
          inl_iters,
          inl_counts.float() / expected_extra_inl,
      )
  
file_path: kornia/kornia/feature/adalam/ransac.py
imports: from typing import Any, Dict, Tuple, Union
  import torch
  from kornia.core import Tensor
  from .utils import arange_sequence, batch_2x2_ellipse, batch_2x2_inv, draw_first_k_couples, piecewise_arange
label_desc: Use image node_id 3 for calling a global function with example usage: confidence_based_inlier_selection(residuals, ransidx, rdims, idxoffsets, dv, min_confidence) and returns: inl_ransidx,  inl_sampleidx,  inl_counts,  inl_iters,  unknown