class_docstr: Bundle-based Minimum Distance for joint optimization.
  
  This cost function is used by the StreamlineLinearRegistration class when
  running halfway streamline linear registration for unbiased groupwise
  bundle registration and atlasing.
  
  It computes the BMD distance after moving both static and moving bundles to
  a halfway space in between both.
  
  Methods
  -------
  setup(static, moving)
  distance(xopt)
  
  Notes
  -----
  In this metric both static and moving bundles are treated equally (i.e.,
  there is no static reference bundle as both are intended to move). The
  naming convention is kept for consistency.
class_docstr_tok: ["Bundle-based","Minimum","Distance","for","joint","optimization",".","This","cost","function","is","used","by","the","StreamlineLinearRegistration","class","when","running","halfway","streamline","linear","registration","for","unbiased","groupwise","bundle","registration","and","atlasing",".","It","computes","the","BMD","distance","after","moving","both","static","and","moving","bundles","to","a","halfway","space","in","between","both",".","Methods","--","--","--","-","setup","(","static",",","moving",")","distance","(","xopt",")","Notes","--","--","-","In","this","metric","both","static","and","moving","bundles","are","treated","equally","(","i.e.",",","there","is","no","static","reference","bundle","as","both","are","intended","to","move",")",".","The","naming","convention","is","kept","for","consistency","."]
docstr: Distance calculated from this Metric.
  
  Parameters
  ----------
  xopt : sequence
      List of affine parameters as an 1D vector. These affine parameters
      are used to derive the corresponding halfway transformation
      parameters for each bundle.
docstr_tok: ["Distance","calculated","from","this","Metric",".","Parameters","--","--","--","--","--","xopt",":","sequence","List","of","affine","parameters","as","an","1D","vector",".","These","affine","parameters","are","used","to","derive","the","corresponding","halfway","transformation","parameters","for","each","bundle","."]
code: def distance(self, xopt):
      """Distance calculated from this Metric.
  
      Parameters
      ----------
      xopt : sequence
          List of affine parameters as an 1D vector. These affine parameters
          are used to derive the corresponding halfway transformation
          parameters for each bundle.
      """
      # Define halfway space transformations
      x_static = np.concatenate(
          (xopt[0:6] / 2, (1 + xopt[6:9]) / 2, xopt[9:12] / 2)
      )
      x_moving = np.concatenate(
          (-xopt[0:6] / 2, 2 / (1 + xopt[6:9]), -xopt[9:12] / 2)
      )
  
      # Move static bundle to the halfway space
      aff_static = compose_matrix44(x_static)
      static = transform_streamlines(self.static, aff_static)
  
      # Move moving bundle to halfway space and compute distance
      return bundle_min_distance(x_moving, static, self.moving)
  
imports: import logging
  import abc
  from itertools import combinations
  import numpy
  from dipy.core.optimize import Optimizer
  from dipy.align.bundlemin import _bundle_minimum_distance, _bundle_minimum_distance_asymmetric, distance_matrix_mdf
  from dipy.tracking.streamline import transform_streamlines, unlist_streamlines, center_streamlines, set_number_of_points, select_random_set_of_streamlines, length, Streamlines
  from dipy.segment.clustering import qbx_and_merge
  from dipy.core.geometry import compose_transformations, compose_matrix, decompose_matrix
  from time import time
label_desc: Use image node_id 2 for calling the JointBundleMinDistanceMetric obj's underlying member method code with example usage: obj.distance(xopt) and returns: bundle_min_distance