def METHOD_NAME(params, *args):
  """ This is the function to be minimized by graph processing.
  It returns the total residual given params, which is a tuple containing the parameters to refine for one image. Formated for use with the scipy minimization routines. There are thus between 5 and 12,
  :param params: a list of the parameters for the minimisation as a tuple, only including vertices that have edges. See ImageNode.get_x0() for details of parameters.
  :param *args:  a 2-tuple of the vertex to be minimised, cross_val. cross_val is a list of edge to leave out of the optimisation for cross-validation purposes.
  :return: the total squared residual of the graph minimisation
  """
  from xfel.graph_proc.components import Edge
  vertex = args[0]
  cross_val = args[1]
  assert vertex.partialities != vertex.calc_partiality(params), "params have not changed the partialities"
  pa = vertex.calc_partiality(params)
  sa = vertex.calc_scales(params)
  # 2. Calculate all new residuals
  total_sum = 0
  for edge in vertex.edges:
    if edge not in cross_val:
      other_v = edge.other_vertex(vertex)
      residuals = Edge._calc_residuals(vertex, other_v,
                  pa, other_v.partialities,
                  sa, other_v.scales)
      total_sum += np.sum([loss_func(res) for res in residuals])
  logging.debug("Total Score: {}".format(total_sum))
  return total_sum