class_docstr: Batch gradient descent.
class_docstr_tok: ["Batch","gradient","descent","."]
docstr: Perform batch gradient descent.
code: def minimize(self, space, points, weights=None):
      """Perform batch gradient descent."""
      shape = points.shape
      n_points, n_batch = shape[:2]
      point_shape = shape[2:]
  
      if n_points == 1:
          return points[0]
  
      if weights is None:
          weights = gs.ones((n_points, n_batch))
  
      flat_shape = (n_batch * n_points,) + point_shape
      estimates = (
          points[0] if self.init_point is None else self.init_point
      )
      points_flattened = gs.reshape(
          points, (n_points * n_batch,) + point_shape
      )
      convergence = math.inf
      iteration = 0
      convergence_old = convergence
  
      step_size = self.init_step_size
  
      while convergence > self.epsilon and self.max_iter > iteration:
          iteration += 1
          estimates_broadcast, _ = gs.broadcast_arrays(
              estimates, points
          )
          estimates_flattened = gs.reshape(
              estimates_broadcast, flat_shape
          )
  
          tangent_grad = space.metric.log(
              points_flattened, estimates_flattened
          )
          tangent_grad = gs.reshape(tangent_grad, shape)
  
          tangent_mean = (
              _batchscalarmulsum(weights, tangent_grad) / n_points
          )
  
          next_estimates = space.metric.exp(
              step_size * tangent_mean, estimates
          )
          convergence = gs.sum(
              space.metric.squared_norm(tangent_mean, estimates)
          )
          estimates = next_estimates
  
          if convergence < convergence_old:
              convergence_old = convergence
          elif convergence > convergence_old:
              step_size = step_size / 2.0
  
      if iteration == self.max_iter:
          logging.warning(
              "Maximum number of iterations %d reached. The mean may be inaccurate",
              self.max_iter,
          )
  
      if self.verbose:
          logging.info(
              "n_iter: %d, final dist: %e, final step size: %e",
              iteration,
              convergence,
              step_size,
          )
  
      return estimates
  
imports: import abc
  import logging
  import math
  from sklearn.base import BaseEstimator
  import geomstats.backend
  import geomstats.errors
  from geomstats.geometry.discrete_curves import ElasticTranslationMetric, SRVTranslationMetric
  from geomstats.geometry.euclidean import EuclideanMetric
  from geomstats.geometry.hypersphere import HypersphereMetric
  from geomstats.geometry.matrices import MatricesMetric
  from geomstats.geometry.minkowski import MinkowskiMetric
label_desc: Use image node_id 1 for calling the BatchGradientDescent obj's underlying member method code with example usage: obj.minimize(space, points, weights) and returns: estimates, points