def _amIdoneIterating(self, f_k_new, relative_tolerance, iteration, maximum_iterations, print_warning, verbose):
        """
        Convenience function to test whether we are done iterating, same for all iteration types

        REQUIRED ARGUMENTS
          f_k_new (array): new free energies
          f_k (array) : older free energies
          relative_tolerance (float): the relative tolerance for terminating
          verbose (bool): verbose response
          iterations (int): current number of iterations
          print_warning (bool): sometimes, we want to surpress the warning.

        RETURN VALUES
           yesIam (bool): indicates that the iteration has converged.

        """
        yesIam = False

        # Compute change from old to new estimate.
        Delta_f_k = f_k_new - self.f_k[self.states_with_samples]

        # Check convergence criteria.
        # Terminate when max((f - fold) / f) < relative_tolerance for all
        # nonzero f.
        max_delta = np.max(
            np.abs(Delta_f_k) / np.max(np.abs(f_k_new)))

        # Update stored free energies.
        f_k = f_k_new.copy()
        self.f_k[self.states_with_samples] = f_k

        # write out current estimate
        if verbose:
            print("current f_k for states with samples =")
            print(f_k)
            print("relative max_delta = %e" % max_delta)

        # Check convergence criteria.
        # Terminate when max((f - fold) / f) < relative_tolerance for all
        # nonzero f.
        if np.isnan(max_delta) or (max_delta < relative_tolerance):
            yesIam = True

        if (yesIam):
            # Report convergence, or warn user if convergence was not achieved.
            if np.all(self.f_k == 0.0):
                # all f_k appear to be zero
                print('WARNING: All f_k appear to be zero.')
            elif (max_delta < relative_tolerance):
                # Convergence achieved.
                if verbose:
                    print('Converged to tolerance of %e in %d iterations.' % (max_delta, iteration + 1))
            elif (print_warning):
                # Warn that convergence was not achieved.
                # many times, self-consistent iteration is used in conjunction with another program.  In that case,
                # we don't really need to warn about anything, since we are not
                # running it to convergence.
                print('WARNING: Did not converge to within specified tolerance.')
                print('max_delta = %e, TOLERANCE = %e, MAX_ITS = %d, iterations completed = %d' % (max_delta, relative_tolerance, maximum_iterations, iteration))

        return yesIam
def _amIdoneIterating ( self , f_k_new , relative_tolerance , iteration , maximum_iterations , print_warning , verbose ) : yesIam = False Delta_f_k = f_k_new - self . f_k [ self . states_with_samples ] max_delta = np . max ( np . abs ( Delta_f_k ) / np . max ( np . abs ( f_k_new ) ) ) f_k = f_k_new . copy ( ) self . f_k [ self . states_with_samples ] = f_k if verbose : print ( "current f_k for states with samples =" ) print ( f_k ) print ( "relative max_delta = %e" % max_delta ) if np . isnan ( max_delta ) or ( max_delta < relative_tolerance ) : yesIam = True if ( yesIam ) : if np . all ( self . f_k == 0.0 ) : print ( 'WARNING: All f_k appear to be zero.' ) elif ( max_delta < relative_tolerance ) : if verbose : print ( 'Converged to tolerance of %e in %d iterations.' % ( max_delta , iteration + 1 ) ) elif ( print_warning ) : print ( 'WARNING: Did not converge to within specified tolerance.' ) print ( 'max_delta = %e, TOLERANCE = %e, MAX_ITS = %d, iterations completed = %d' % ( max_delta , relative_tolerance , maximum_iterations , iteration ) ) return yesIam
Convenience function to test whether we are done iterating, same for all iteration types

        REQUIRED ARGUMENTS
          f_k_new (array): new free energies
          f_k (array) : older free energies
          relative_tolerance (float): the relative tolerance for terminating
          verbose (bool): verbose response
          iterations (int): current number of iterations
          print_warning (bool): sometimes, we want to surpress the warning.

        RETURN VALUES
           yesIam (bool): indicates that the iteration has converged.