generate functionFri, 17 Mar 2023

def numerical_derivative_2d(func, epsilon): """ Function for approximate calculation of the gradient of a function of two variables. :param func: np.array[2] -> float - arbitrary differentiable function :param epsilon: float - the maximum amount of increment along the axes :return: another function that approximates the gradient at a point """ def grad_func(x): """ :param x: np.array[2] - the point at which you want to calculate the gradient :return: np.array[2] - approximate value of the gradient at this point """ <YOUR CODE> return <YOUR CODE> return grad_func def grad_descent_2d(func, low, high, start=None, callback=None): """ Gradient Descent Implementation for Functions of Two Variables with few local minima but known square neighborhood global minimum. All tests will be of this nature. Note that the function gradient is not given here. It must be calculated approximately. :param func: np.ndarray -> float - function :param low: the left margin of the interval along each of the axes :param high: the right limit of the interval along each of the axes """ eps=1e-10 df = numerical_derivative_2d(func, eps) <YOUR CODE> return <YOUR CODE>

def grad_descent_2d(func, low, high, start=None, callback=None): """ Gradient Descent Implementation for Functions of Two Variables with few local minima but known square neighborhood global minimum. All tests will be of this nature. Note that the function gradient is not given here. It must be calculated approximately. :param func: np.ndarray -> float - function :param low: the left margin of the interval along each of the axes :param high: the right limit of the interval along each of the axes """ eps=1e-10 df = numerical_derivative_2d(func, eps) <YOUR CODE> return <YOUR CODE>

Questions about programming?Chat with your personal AI assistant