docstr: Update the global best using a star topology
  
  This method takes the current pbest_pos and pbest_cost, then returns
  the minimum cost and position from the matrix.
  
  .. code-block:: python
  
      import pyswarms.backend as P
      from pyswarms.backend.swarms import Swarm
      from pyswarm.backend.topology import Star
  
      my_swarm = P.create_swarm(n_particles, dimensions)
      my_topology = Star()
  
      # Update best_cost and position
      swarm.best_pos, swarm.best_cost = my_topology.compute_gbest(my_swarm)
  
  Parameters
  ----------
  swarm : pyswarms.backend.swarm.Swarm
      a Swarm instance
  
  Returns
  -------
  numpy.ndarray
      Best position of shape :code:`(n_dimensions, )`
  float
      Best cost
code: def compute_gbest(self, swarm, **kwargs):
      """Update the global best using a star topology
  
      This method takes the current pbest_pos and pbest_cost, then returns
      the minimum cost and position from the matrix.
  
      .. code-block:: python
  
          import pyswarms.backend as P
          from pyswarms.backend.swarms import Swarm
          from pyswarm.backend.topology import Star
  
          my_swarm = P.create_swarm(n_particles, dimensions)
          my_topology = Star()
  
          # Update best_cost and position
          swarm.best_pos, swarm.best_cost = my_topology.compute_gbest(my_swarm)
  
      Parameters
      ----------
      swarm : pyswarms.backend.swarm.Swarm
          a Swarm instance
  
      Returns
      -------
      numpy.ndarray
          Best position of shape :code:`(n_dimensions, )`
      float
          Best cost
      """
      try:
          if self.neighbor_idx is None:
              self.neighbor_idx = np.tile(
                  np.arange(swarm.n_particles), (swarm.n_particles, 1)
              )
          if np.min(swarm.pbest_cost) < swarm.best_cost:
              # Get the particle position with the lowest pbest_cost
              # and assign it to be the best_pos
              best_pos = swarm.pbest_pos[np.argmin(swarm.pbest_cost)]
              best_cost = np.min(swarm.pbest_cost)
          else:
              # Just get the previous best_pos and best_cost
              best_pos, best_cost = swarm.best_pos, swarm.best_cost
      except AttributeError:
          self.rep.logger.exception(
              "Please pass a Swarm class. You passed {}".format(
                  type(swarm)
              )
          )
          raise
      else:
          return (best_pos, best_cost)
  
file_path: pyswarms/pyswarms/backend/topology/star.py
imports: import logging
  import numpy
  from ..None import operators
  from ..handlers import BoundaryHandler, VelocityHandler
  from ...utils.reporter import Reporter
  from .base import Topology
label_desc: Use image node_id 2 for calling the Star obj's underlying member method code with example usage: obj.compute_gbest(swarm) and returns: best_pos,  best_cost