Numerical Gradient Checking
Calculus & Optimization DS practice problem on Onlearn.
Difficulty: medium.
Topics: Numerical Gradient Checking, Two-sided difference quotient, Relative error calculation, Vector perturbation, Partial derivative approximation, Tolerance thresholds, Calculus, Numerical Analysis, Optimization, Machine Learning Theory, Computational Linear Algebra, Finite Difference Approximation, Backpropagation Verification, Floating Point Precision, Sensitivity Analysis, Gradient Descent Validation.
Implement a function 'numerical gradient(f, x, h=1e 5)' that estimates the gradient of a scalar valued function 'f' at a vector point 'x' using the two sided finite difference method. Then, write a function 'is gradient correct(f, grad func, x, epsilon=1e 7)' that compares the analytic gradient provided by 'grad func' with the numerical estimation, returning True if the relative error is within the specified epsilon.