code: def confidences(
      cluster: Sequence[int],
      squared_distances: numpy.typing.NDArray[numpy.float_],
      d: int,
  ) -> numpy.typing.NDArray[numpy.float_]:
      """
      We calculate a per record score that is similar to a standard
      deviation.  The main reason is that these record scores can be
      used to calculate the standard deviation of an entire cluster,
      which is a reasonable metric for clusters.
      """
      scores: numpy.typing.NDArray[numpy.float_]
      scores_d = dict.fromkeys(cluster, 0.0)
      C = 2 * d - 3
      for i, j in itertools.combinations(cluster, 2):
          index = i * (C - i) // 2 + j - 1
          squared_dist = squared_distances[index]
          scores_d[i] += squared_dist
          scores_d[j] += squared_dist
      scores = numpy.array(
          [score for _, score in sorted(scores_d.items())]
      )
      scores /= len(cluster) - 1
      scores = numpy.sqrt(scores)
      scores = 1 - scores
      return scores
  
imports: from __future__ import annotations
  import array
  import itertools
  import logging
  import tempfile
  from collections import defaultdict
  from typing import Generator, Iterable, Sequence, cast
  import numpy
  import numpy.typing
  import scipy.cluster.hierarchy
  from dedupe._typing import ArrayLinks, Clusters, RecordID, Scores, TupleLinks
label_desc: Use image node_id 6 for calling a global function with example usage: confidences(cluster, squared_distances, d) and returns: scores