Grid Search Method

Contents

Grid Search Method#

The simplest numerical approach to finding a minimum is to evaluate the function at many points and pick the point that gives the lowest value. This is called a grid search.

  1. Choose a range of \(r\) values to search over.

  2. Divide this range into a grid of points.

  3. Evalutate \(U(r)\) at each point.

  4. Find the point where \(U(r)\) is smallest.

While simple to understand and implement, this method has serious limitations:

  • The accuracy is limited by the grid spacing.

  • The number of function evaluations grows exponentially with the number of dimensions of our potential energy surface.

  • It provides no information about the shape of the function around the minimum.

Exercise#

  1. Write code to perform a grid search to find the minimum of your harmonic potential. Use numpy’s linspace() function to create your grid in the range \(0.38\leq r \leq 1.1\).

Hint: NumPy provides functions for finding the location of maximum or minimum values in an array, called argmax() and argmin():

import numpy as np

a = np.array([3,6,8,9,1])

print(f'Index of min value: {np.argmin(a)}')
print(f'Index of max value: {np.argmax(a)}')

loc = np.argmax(a)

print(f'The value at index {loc} is {a[loc]}')
Index of min value: 4
Index of max value: 3
The value at index 3 is 9