In order to keep error the same in all range, we need a function that will keep a relative
The solution is
We need only integer values, but
The next idea to use
The final idea is next: we need to use
where
-
$a$ is the point where we switch functions -
$b$ is the max value of source function (given) -
$s$ is the max value of target function (given)
The solution is:
- Purple-blue graph is perfect approach
- Red graph is naive and another approach
Error for PIQ is
Error for Naive approach is
For
The next step is to quantize the uintX
into uintY
using PIQ and Naive approach.
See Excel file for all results and details
Some results:
source | destination | PIQ error | Naive error | Improvement |
---|---|---|---|---|
16 | 8 | 1.74% | 2.22% | 21.79% |
32 | 8 | 4.22% | 4.54% | 7.10% |
64 | 8 | 9.32% | 9.50% | 1.87% |
32 | 16 | 0.01% | 0.02% | 33.35% |
64 | 16 | 0.03% | 0.03% | 14.56% |
128 | 16 | 0.06% | 0.07% | 6.40% |
256 | 16 | 0.13% | 0.14% | 2.79% |
64 | 32 | 0.0000003% | 0.0000005% | 40.36% |
128 | 32 | 0.0000008% | 0.0000010% | 19.06% |
256 | 32 | 0.0000019% | 0.0000021% | 9.07% |
Use main.py to generate this values.
Note that 16 bit and 32 bit values need np.longdouble
for calculations