Datasets:
Download code/evaluation-code/v0.2-0c2690ae/tools/release/numeric_choice.py from VEHwang/cocogni4d: direct link, hf CLI and curl.
- Browser
- Download file 1.61 kB
-
https://huggingface.co/datasets/VEHwang/cocogni4d/resolve/main/code/evaluation-code/v0.2-0c2690ae/tools/release/numeric_choice.py
- Command line
-
hf download hf://datasets/VEHwang/cocogni4d/code/evaluation-code/v0.2-0c2690ae/tools/release/numeric_choice.py
-
curl -L -o numeric_choice.py https://huggingface.co/datasets/VEHwang/cocogni4d/resolve/main/code/evaluation-code/v0.2-0c2690ae/tools/release/numeric_choice.py
1.61 kB
| """Tolerance-derived quantizer; all four numeric options display with one decimal place.""" | |
| import math | |
| from dataclasses import dataclass | |
| from tools.evaluation import np_answers | |
| class Format: | |
| digits: int | |
| def value(self, value): | |
| """Quantize before candidate spacing, normalizing signed zero.""" | |
| if isinstance(value, list): | |
| return [self.value(x) for x in value] | |
| rounded = float(f'{value:.{self.digits-1}e}') | |
| return 0. if rounded == 0 else rounded | |
| def text(self, value): | |
| """Plain decimal with one digit after the point (options are already quantized), also per vector component.""" | |
| if isinstance(value, list): | |
| return '[' + ', '.join(self.text(x) for x in value) + ']' | |
| text = f"{value:.1f}" | |
| return '0.0' if text == '-0.0' else text | |
| def formatter(truth, rule): | |
| """Use the least precision whose worst rounding error fits half a tolerance. | |
| The logarithmic rule needs a relative bound; other rules use their original | |
| truth's radius. Planar components share the same precision and error budget. | |
| """ | |
| if rule['kind'] == 'log_ratio': | |
| digits = max(1, math.ceil(1-math.log10(2*(1-1/rule['factor'])))) | |
| else: | |
| vector = isinstance(truth, list) | |
| magnitude = max(map(abs, truth)) if vector else abs(truth) | |
| tau = np_answers.radius(truth, rule)[0] | |
| budget = tau / (2*math.sqrt(2) if vector else 2) | |
| digits = max(1, math.ceil(math.floor(math.log10(magnitude)) - math.log10(2*budget) + 1)) if magnitude else 1 | |
| return Format(digits) | |