Check gradients with finite differences
Check a claimed gradient using centered finite differences.
What’s going wrong
Original LLM Architecture lab. Implement the missing behavior in solve(data) and keep the supplied JSON interface. Use Python’s standard library.
Input params is a vector and terms are [coefficient, powers] giving a multivariate polynomial sum of coefficient times product(params[j]**powers[j]). Powers are nonnegative. epsilon > 0 and tolerance ≥ 0. Approximate each partial using two perturbations on one coordinate. Return numerical, absolute_errors and passed based on unrounded errors. An empty vector passes.
Small, well-formed JSON inputs and standard-library Python arithmetic. Keep full precision during computation. The supplied output wrapper rounds results to six decimal places.
Expected behavior
Check a claimed gradient using centered finite differences.
Reproduction
{"params":[2,3],"terms":[[1,[1,1]]],"claimed":[2,3],"epsilon":0.0001,"tolerance":1e-06}{"numerical":[3,2],"absolute_errors":[1,1],"passed":false}{"params":[1],"terms":[[4,[0]]],"claimed":[0],"epsilon":0.0001,"tolerance":1e-06}{"numerical":[0],"absolute_errors":[0],"passed":true}{"params":[2,3],"terms":[[1,[1,1]]],"claimed":[3,2],"epsilon":0.0001,"tolerance":1e-06}{"numerical":[3,2],"absolute_errors":[0,0],"passed":true}Before you begin
- Python functions, lists and dictionaries
Need a nudge?
Reveal one investigation hint at a time. Try each clue before opening the next.
Read the report, then sign in to start your investigation.