Datasets:
Download models/predict.py from PureOne/Iyeumaring-AION-LATCH-VI: direct link, hf CLI and curl.
- Browser
- Download file 1.16 kB
-
https://huggingface.co/datasets/PureOne/Iyeumaring-AION-LATCH-VI/resolve/main/models/predict.py
- Command line
-
hf download hf://datasets/PureOne/Iyeumaring-AION-LATCH-VI/models/predict.py
-
curl -L -o predict.py https://huggingface.co/datasets/PureOne/Iyeumaring-AION-LATCH-VI/resolve/main/models/predict.py
1.16 kB
| """Standard-library inference for the exported protected ReLU head. | |
| Run: python predict.py -0.8 -0.2 0 0.2 0.8 | |
| The reported error bound is conditional on the stored finite-data contract. | |
| The batch-throughput study used NumPy; its timings do not describe this CLI. | |
| """ | |
| from pathlib import Path | |
| import json,sys | |
| from fractions import Fraction | |
| def load_model(path=None): | |
| path=Path(path) if path else Path(__file__).with_name('relu_head_example.json') | |
| return json.loads(path.read_text()) | |
| def predict(x,model): | |
| # Exact rational evaluation preserves the exported mathematical model. | |
| z=Fraction(x) | |
| head=Fraction(model['exact_head_bias'])+sum( | |
| Fraction(w)*max(Fraction(0),z-Fraction(k)) | |
| for k,w in zip(model['exact_hinge_knots'],model['exact_hinge_weights'])) | |
| return float(abs(z)*head) | |
| if __name__=='__main__': | |
| model=load_model();points=[float(x) for x in sys.argv[1:]] or [-.8,-.2,0.,.2,.8] | |
| print(json.dumps([{'x':x,'residual':predict(x,model), | |
| 'conditional_error_bound':model['conditional_uniform_error_bound'] if -1<=x<=1 else None} | |
| for x in points],indent=2)) | |