class_docstr: Default gradient descent.
class_docstr_tok: ["Default","gradient","descent","."]
docstr: Perform default gradient descent.
code: def minimize(self, space, points, weights=None):
      """Perform default gradient descent."""
      n_points = gs.shape(points)[0]
      if weights is None:
          weights = gs.ones((n_points,))
  
      mean = points[0] if self.init_point is None else self.init_point
  
      if n_points == 1:
          return mean
  
      sum_weights = gs.sum(weights)
      iteration = 0
      sq_dist = 0.0
      var = 0.0
  
      norm_old = gs.linalg.norm(points)
      step_size = self.init_step_size
  
      while iteration < self.max_iter:
          logs = space.metric.log(point=points, base_point=mean)
  
          var = (
              gs.sum(space.metric.squared_norm(logs, mean) * weights)
              / sum_weights
          )
  
          tangent_mean = _scalarmulsum(weights, logs)
          tangent_mean /= sum_weights
          norm = gs.linalg.norm(tangent_mean)
  
          sq_dist = space.metric.squared_norm(tangent_mean, mean)
  
          var_is_0 = gs.isclose(var, 0.0)
  
          sq_dist_is_small = gs.less_equal(
              sq_dist, self.epsilon * space.dim
          )
  
          condition = ~gs.logical_or(var_is_0, sq_dist_is_small)
          if not (condition or iteration == 0):
              break
  
          estimate_next = space.metric.exp(
              step_size * tangent_mean, mean
          )
          mean = estimate_next
          iteration += 1
  
          if norm < norm_old:
              norm_old = norm
          elif norm > norm_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: {}, final variance: {}, final dist: {}".format(
                  iteration, var, sq_dist
              )
          )
  
      return mean
  
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 GradientDescent obj's underlying member method code with example usage: obj.minimize(space, points, weights) and returns: mean, mean