1/23
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What is the “objective function” in an optimization problem?
The function that you are trying to maximize or minimize.
What is argmin?
The x value at which the minimum occurs.
What is minimum?
THe minimum value of the output of the function.
What is argmax?
The x value at which the maximum occurs.
What is maximum?
The maximum value of the output of the function.
Solve maximization problems by recasting as a minimization problem and using a minimization technique.
max(g(x))=−min(−h(x))
What is the FIRST step to minimize functions using scipy.optimize.fsolve to find the root of the derivative of the function.
Take the derivative of the function analytically.
What is the SECOND step to minimize functions using scipy.optimize.fsolve to find the root of the derivative of the function.
Find the root numerically using scipy.optimize.fsolve .
What is the FINAL step to minimize functions using scipy.optimize.fsolve to find the root of the derivative of the function.
Check to see if it’s a max or min by checking a nearby point or looking at a graph.
Show an example of minimizing functions using scipy.optimize.fsolve to find the root of the derivative of the function.
import numpy as np
import matplotlib.pyplot as plt
f = lambda x: x**2*np.sin(x)
f_prime_factor = lambda x: x*np.cos(x) + 2*np.sin(x)
from scipy.optimize import fsolve
crit_point = fsolve(f_prime_factor, -2)[0]
print("Minimizer = ", crit_point)
print("Minimum =", f(crit_point))What is the syntax for fminbound?
scipy.optimize.fminbound(function, a, b)
Give an example of scipy.optimize.fminbound being used.
import numpy as np
import matplotlib.pyplot as plt
f = lambda x: x**2*np.sin(x)
xplot = np.linspace(-5, 5, 200)
fig, ax = plt.subplots()
ax.plot(xplot, f(xplot), linewidth=3, label=r"$f(x)$")
ax.legend()
plt.xlim([-3, -1]) # Restrict the x range for the plot
plt.ylim([-5, 0]) # Restrict the y range for the plot
from scipy.optimize import fminbound
argmin = fminbound(f, -3, -1) # Syntax is fminbound(function, left_bound, right_bound)
print("Minimizer = ", argmin)
print("Minimum =", f(argmin))
plt.show()What is the FIRST step to recognize and explain the steps of the gradient descent algorithm.
Calculate the gradient, Δf(p0).
What is the SECOND step to recognize and explain the steps of the gradient descent algorithm.
Define the line in the negative direction of the gradient, Φ(t)=p0−t⋅Δf(p0).
What is the THIRD step to recognize and explain the steps of the gradient descent algorithm.
Define the function of heights along the line, f(Φ(t)).
What is the FOURTH step to recognize and explain the steps of the gradient descent algorithm.
Use fminbound to find t*, the minimizer of the heights along the line f(Φ(t)).
What is the FINAL step to recognize and explain the steps of the gradient descent algorithm.
Define p1=f(Φ(t∗)).
Give an example of meshes being created from two arrays using np.meshgrid .
import numpy as np
x = np.linspace(-2, 1, 4)
y = np.linspace(-4, 4, 3)
X_grid, Y_grid = np.meshgrid(x,y)Give an example of a contour plot of 2-dimensional functions being created.
# Create our function
f = lambda x, y: (x-2)**2 + (y+1)**2 + 5*np.sin(x)*np.sin(y) + 100
fig, ax = plt.subplots()
# 🚨 Create the contour plot
ax.contour(X_grid, Y_grid, f(X_grid, Y_grid))Give an example of a surface plot of 2-dimensional functions being created.
# Create our function
f = lambda x, y: (x-2)**2 + (y+1)**2 + 5*np.sin(x)*np.sin(y) + 100
# 🚨 Tell matplotlib we are making a 3D plot
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
# 🚨 Plot the surface by evaluating f on the grid.
ax.plot_surface(X_grid, Y_grid, f(X_grid, Y_grid))What is the standard format for the while function?
while condition:
# some actionWhat does numpy.linalg.norm do?
Calculates vector and matrix norms.
What is the standard format for linalg.norm ?
numpy.linalg.norm(x)
What is the standard format for optimize.fmin ?
argmin = scipy.optimize.fmin(function, [0, 0])