code: def cost_test(n=100, k=5):
      # check that cost.max() is equal to the data variance
      np.random.seed(0)
      x = np.random.randn(n, 2)
      G = knn(x, k)
      u, cost = ward_segment(G, x)
      assert np.abs(cost.max() / (n * np.var(x, 0).sum()) - 1) < 1e-6
  
file_path: nipy/nipy/algorithms/clustering/tests/test_hierarchical_clustering.py
imports: import math
  import numpy
  from numpy.random import randn
  from nipy.algorithms.graph.field import field_from_graph_and_data
  from nipy.algorithms.graph.graph import knn
  from ..hierarchical_clustering import average_link_graph, average_link_graph_segment, ward, ward_field_segment, ward_quick, ward_quick_segment, ward_segment
label_desc: Use image node_id 10 for calling a global function with example usage: cost_test(n, k) without return types