from pathlib import Path import json import numpy as np from infer import predict_linearised,predict_response R=Path(__file__).resolve().parent fits=json.loads((R/'fits.json').read_text());assert len(fits)==512 u=np.asarray([[0.,0.],[.25,-.5],[-.125,.75]]) for fit in fits: a=np.asarray(fit['A']);b=np.asarray(fit['b']);reference=u@a.T+b np.testing.assert_allclose(predict_linearised(fit,u),reference,rtol=0,atol=1e-12) want=np.tanh(reference) if fit['link_mode']=='tanh' else reference np.testing.assert_allclose(predict_response(fit,u),want,rtol=0,atol=1e-12) for bad in [np.zeros((1,3)),np.full((1,2),np.nan)]: try:predict_response(fits[0],bad) except ValueError:pass else:raise AssertionError('invalid input accepted') print(json.dumps({'status':'PASS','fits':len(fits),'interventions_per_fit':len(u),'scope':'saved coefficients; synthetic coordinate test, NOT new subject validation'},indent=2))