class_docstr: Metropolis acceptance criterion.
  
  Parameters
  ----------
  T : float
      The "temperature" parameter for the accept or reject criterion.
  random_gen : {None, int, `numpy.random.Generator`,
                `numpy.random.RandomState`}, optional
  
      If `seed` is None (or `np.random`), the `numpy.random.RandomState`
      singleton is used.
      If `seed` is an int, a new ``RandomState`` instance is used,
      seeded with `seed`.
      If `seed` is already a ``Generator`` or ``RandomState`` instance then
      that instance is used.
      Random number generator used for acceptance test.
class_docstr_tok: ["Metropolis","acceptance","criterion",".","Parameters","--","--","--","--","--","T",":","float","The","``","temperature","''","parameter","for","the","accept","or","reject","criterion",".","random_gen",":","{","None",",","int",",","`","numpy.random.Generator","`",",","`","numpy.random.RandomState","`","}",",","optional","If","`","seed","`","is","None","(","or","`","np.random","`",")",",","the","`","numpy.random.RandomState","`","singleton","is","used",".","If","`","seed","`","is","an","int",",","a","new","``","RandomState","``","instance","is","used",",","seeded","with","`","seed","`",".","If","`","seed","`","is","already","a","``","Generator","``","or","``","RandomState","``","instance","then","that","instance","is","used",".","Random","number","generator","used","for","acceptance","test","."]
docstr: If new energy is lower than old, it will always be accepted.
  If new is higher than old, there is a chance it will be accepted,
  less likely for larger differences.
docstr_tok: ["If","new","energy","is","lower","than","old",",","it","will","always","be","accepted",".","If","new","is","higher","than","old",",","there","is","a","chance","it","will","be","accepted",",","less","likely","for","larger","differences","."]
code: def accept_reject(self, energy_new, energy_old):
      """
      If new energy is lower than old, it will always be accepted.
      If new is higher than old, there is a chance it will be accepted,
      less likely for larger differences.
      """
      with np.errstate(invalid="ignore"):
          # The energy values being fed to Metropolis are 1-length arrays, and if
          # they are equal, their difference is 0, which gets multiplied by beta,
          # which is inf, and array([0]) * float('inf') causes
          #
          # RuntimeWarning: invalid value encountered in multiply
          #
          # Ignore this warning so so when the algorithm is on a flat plane, it always
          # accepts the step, to try to move off the plane.
          prod = -(energy_new - energy_old) * self.beta
          w = math.exp(min(0, prod))
  
      rand = self.random_gen.uniform()
      return w >= rand
  
imports: import numpy
  import math
  from numpy import cos, sin
  import scipy.optimize
  from scipy._lib._util import check_random_state
label_desc: Use image node_id 2 for calling the Metropolis obj's underlying member method code with example usage: obj.accept_reject(energy_new, energy_old) and returns: unknown