Implement a damped multivariate Newton step with minimum-eigenvalue and condition-number control
Role: Machine Learning Engineer
Category: Machine Learning
Difficulty: medium
Interview Round: Other
Implement `newton_step(params, grad, hessian, min_eig=1e-6, max_cond=1e8)` returning `(new_params, damping)`. Symmetrise the Hessian as `H = 0.5 * (hessian + hessian.T)`, choose the smallest damping `λ ≥ 0` so that `H + λI` has minimum eigenvalue ≥ `min_eig` and condition number ≤ `max_cond`, then solve with `np.linalg.solve`.
Requirements:
- With eigenvalues `lam_min ≤ lam_max` of `H`: `λ = max(0, min_eig - lam_min, (lam_max - max_cond*lam_min) / (max_cond - 1))`.
- `new_params = params - solve(H + λI, grad)`. Return `damping` as a Python `float`.
- Raise `ValueError` if `params` is not 1-D, `grad` is not `(n,)`, or `hessian` is not `(n, n)`.
- Raise `ValueError` if `max_cond <= 1`.
- Do not modify the input arrays.
Example:
```python
newton_step(np.zeros(2), np.array([1.0, 1.0]), np.diag([-2.0, 3.0]), max_cond=10.0)
# damping = max(0, 1e-6 + 2, (3 + 20) / 9) = 23/9 ≈ 2.5556
# returns (array([-1.8, -0.18]), 2.5555...)
```
```hint How a shift moves the spectrum
Adding a multiple of the identity to a symmetric matrix adds the same amount to every eigenvalue and leaves the eigenvectors alone. Write both requirements in terms of the shifted smallest and largest eigenvalues.
```
```hint Order of the checks
Look at how many dimensions `params` has before you read its length. Otherwise a scalar input fails with the wrong exception type.
```
### Constraints & Assumptions
- Inputs are array-likes of finite floats.
- `hessian` may be indefinite, ill-conditioned or asymmetric.
### What a Strong Answer Covers
- Derives the condition-number bound from the ratio of the shifted extreme eigenvalues and explains why the largest of the lower bounds is the smallest feasible damping.
- Uses the symmetrised matrix for both the eigenvalues and the solve, and solves the linear system instead of forming an inverse.
- Validates shapes and `max_cond` with `ValueError` in an order that cannot raise a different exception first, and leaves the inputs unmodified.
- Traces the example to the expected step and damping, and states the time and space cost.
### Follow-up Questions
- Why does the damped step guarantee a descent direction?
- How would you combine this with a line search or trust region?
- When a full eigendecomposition is too expensive for large `n`, how would you choose the damping instead?
Overview: Implement one damped Newton step in NumPy: symmetrise the Hessian, pick the smallest identity shift that bounds its minimum eigenvalue and condition number, and solve for the update. Tests eigenvalue reasoning, numerical linear algebra and careful input validation.