parameters: (self, trial, results, lower_is_better)
return_statement: return decision
docstring: Args:
              trial (sherpa.Trial): trial to be stopped.
              results (pandas.DataFrame): all results so far.
              lower_is_better (bool): whether lower objective values are better.
  
          Returns:
              bool: decision.
docstring_summary: Args:
              trial (sherpa.Trial): trial to be stopped.
              results (pandas.DataFrame): all results so far.
              lower_is_better (bool): whether lower objective values are better.
docstring_tokens: Args : trial ( sherpa . Trial ) : trial to be stopped . results ( pandas . DataFrame ) : all results so far . lower_is_better ( bool ) : whether lower objective values are better .
function: def should_trial_stop(self, trial, results, lower_is_better):
          """
          Args:
              trial (sherpa.Trial): trial to be stopped.
              results (pandas.DataFrame): all results so far.
              lower_is_better (bool): whether lower objective values are better.
  
          Returns:
              bool: decision.
          """
          if len(results) == 0:
              return False
          
          trial_rows = results.loc[results['Trial-ID'] == trial.id]
          
          max_iteration = trial_rows['Iteration'].max()
          if max_iteration < self.min_iterations:
              return False
          
          trial_obj_val = trial_rows['Objective'].min() if lower_is_better else trial_rows['Objective'].max()
  
          if numpy.isnan(trial_obj_val) and not trial_rows.empty:
              alglogger.debug("Value {} is NaN: {}, trial rows: {}".format(trial_obj_val, numpy.isnan(trial_obj_val), trial_rows))
              return True
  
          other_trial_ids = set(results['Trial-ID']) - {trial.id}
          comparison_vals = []
  
          for tid in other_trial_ids:
              trial_rows = results.loc[results['Trial-ID'] == tid]
              
              max_iteration = trial_rows['Iteration'].max()
              if max_iteration < self.min_iterations:
                  continue
  
              valid_rows = trial_rows.loc[trial_rows['Iteration'] <= max_iteration]
              obj_val = valid_rows['Objective'].min() if lower_is_better else valid_rows['Objective'].max()
              comparison_vals.append(obj_val)
  
          if len(comparison_vals) < self.min_trials:
              return False
  
          if lower_is_better:
              decision = trial_obj_val > numpy.nanmedian(comparison_vals)
          else:
              decision = trial_obj_val < numpy.nanmedian(comparison_vals)
  
          return decision
function_tokens: def should_trial_stop ( self , trial , results , lower_is_better ) : if len ( results ) == 0 : return False trial_rows = results . loc [ results [ 'Trial-ID' ] == trial . id ] max_iteration = trial_rows [ 'Iteration' ] . max ( ) if max_iteration < self . min_iterations : return False trial_obj_val = trial_rows [ 'Objective' ] . min ( ) if lower_is_better else trial_rows [ 'Objective' ] . max ( ) if numpy . isnan ( trial_obj_val ) and not trial_rows . empty : alglogger . debug ( "Value {} is NaN: {}, trial rows: {}" . format ( trial_obj_val , numpy . isnan ( trial_obj_val ) , trial_rows ) ) return True other_trial_ids = set ( results [ 'Trial-ID' ] ) - { trial . id } comparison_vals = [ ] for tid in other_trial_ids : trial_rows = results . loc [ results [ 'Trial-ID' ] == tid ] max_iteration = trial_rows [ 'Iteration' ] . max ( ) if max_iteration < self . min_iterations : continue valid_rows = trial_rows . loc [ trial_rows [ 'Iteration' ] <= max_iteration ] obj_val = valid_rows [ 'Objective' ] . min ( ) if lower_is_better else valid_rows [ 'Objective' ] . max ( ) comparison_vals . append ( obj_val ) if len ( comparison_vals ) < self . min_trials : return False if lower_is_better : decision = trial_obj_val > numpy . nanmedian ( comparison_vals ) else : decision = trial_obj_val < numpy . nanmedian ( comparison_vals ) return decision