nodes: 0, module; 1, function_definition; 2, function_name:optimize_batch; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, if_statement; 11, expression_statement; 12, if_statement; 13, expression_statement; 14, return_statement; 15, identifier:batchsize; 16, integer:10; 17, identifier:returns; 18, string; 19, identifier:paralell; 20, True; 21, comment:"""
          Run multiple optimizations using different starting coordinates.
  
          Args:
              batchsize (`int`): Number of optimizations to run.
              returns (`str`): If ``'all'``, return results of all optimizations,
                  ordered by stress, ascending. If ``'best'`` return the
                  projection with the lowest stress.
              parallel (`bool`): If ``True``, run optimizations in parallel.
  
          Examples:
  
              .. doctest::
  
                 >>> import pandas as pd
                 >>> from pymds import DistanceMatrix
                 >>> dist = pd.DataFrame({
                 ...    'a': [0.0, 1.0, 2.0],
                 ...    'b': [1.0, 0.0, 3 ** 0.5],
                 ...    'c': [2.0, 3 ** 0.5, 0.0]} , index=['a', 'b', 'c'])
                 >>> dm = DistanceMatrix(dist)
                 >>> batch = dm.optimize_batch(batchsize=3, returns='all')
                 >>> len(batch)
                 3
                 >>> type(batch[0])
                 <class 'pymds.mds.Projection'>
  
          Returns:
              `list` or :py:class:`pymds.Projection`:
  
                  `list`: Length batchsize, containing instances of
                  :py:class:`pymds.Projection`. Sorted by stress, ascending.
  
                  or
  
                  :py:class:`pymds.Projection`: Projection with the lowest
                  stress.
          """; 22, comparison_operator:returns not in ('best', 'all'); 23, block; 24, assignment; 25, identifier:paralell; 26, block; 27, else_clause; 28, assignment; 29, conditional_expression:results if returns == 'all' else results[0]; 30, string_content:best; 31, identifier:returns; 32, tuple; 33, raise_statement; 34, identifier:starts; 35, list_comprehension; 36, with_statement; 37, block; 38, identifier:results; 39, call; 40, identifier:results; 41, comparison_operator:returns == 'all'; 42, subscript; 43, string; 44, string; 45, call; 46, binary_operator:np.random.rand(self.m * 2) * 10; 47, for_in_clause; 48, with_clause; 49, block; 50, expression_statement; 51, identifier:sorted; 52, argument_list; 53, identifier:returns; 54, string; 55, identifier:results; 56, integer:0; 57, string_content:best; 58, string_content:all; 59, identifier:ValueError; 60, argument_list; 61, call; 62, integer:10; 63, identifier:i; 64, call; 65, with_item; 66, expression_statement; 67, assignment; 68, identifier:results; 69, keyword_argument; 70, string_content:all; 71, string:'returns must be either "best" or "all"'; 72, attribute; 73, argument_list; 74, identifier:range; 75, argument_list; 76, as_pattern; 77, assignment; 78, identifier:results; 79, call; 80, identifier:key; 81, lambda; 82, attribute; 83, identifier:rand; 84, binary_operator:self.m * 2; 85, identifier:batchsize; 86, call; 87, as_pattern_target; 88, identifier:results; 89, call; 90, identifier:map; 91, argument_list; 92, lambda_parameters; 93, attribute; 94, identifier:np; 95, identifier:random; 96, attribute; 97, integer:2; 98, identifier:Pool; 99, argument_list; 100, identifier:p; 101, attribute; 102, argument_list; 103, attribute; 104, identifier:starts; 105, identifier:x; 106, identifier:x; 107, identifier:stress; 108, identifier:self; 109, identifier:m; 110, identifier:p; 111, identifier:map; 112, attribute; 113, identifier:starts; 114, identifier:self; 115, identifier:optimize; 116, identifier:self; 117, identifier:optimize
code: def optimize_batch(self, batchsize=10, returns='best', paralell=True):
          """
          Run multiple optimizations using different starting coordinates.
  
          Args:
              batchsize (`int`): Number of optimizations to run.
              returns (`str`): If ``'all'``, return results of all optimizations,
                  ordered by stress, ascending. If ``'best'`` return the
                  projection with the lowest stress.
              parallel (`bool`): If ``True``, run optimizations in parallel.
  
          Examples:
  
              .. doctest::
  
                 >>> import pandas as pd
                 >>> from pymds import DistanceMatrix
                 >>> dist = pd.DataFrame({
                 ...    'a': [0.0, 1.0, 2.0],
                 ...    'b': [1.0, 0.0, 3 ** 0.5],
                 ...    'c': [2.0, 3 ** 0.5, 0.0]} , index=['a', 'b', 'c'])
                 >>> dm = DistanceMatrix(dist)
                 >>> batch = dm.optimize_batch(batchsize=3, returns='all')
                 >>> len(batch)
                 3
                 >>> type(batch[0])
                 <class 'pymds.mds.Projection'>
  
          Returns:
              `list` or :py:class:`pymds.Projection`:
  
                  `list`: Length batchsize, containing instances of
                  :py:class:`pymds.Projection`. Sorted by stress, ascending.
  
                  or
  
                  :py:class:`pymds.Projection`: Projection with the lowest
                  stress.
          """
          if returns not in ('best', 'all'):
              raise ValueError('returns must be either "best" or "all"')
  
          starts = [np.random.rand(self.m * 2) * 10 for i in range(batchsize)]
  
          if paralell:
              with Pool() as p:
                  results = p.map(self.optimize, starts)
          else:
              results = map(self.optimize, starts)
  
          results = sorted(results, key=lambda x: x.stress)
  
          return results if returns == 'all' else results[0]