Is there a way to convert numbers to 8-bit and 12-bit floating point representation?
15 ビュー (過去 30 日間)
古いコメントを表示
By representation i mean, similar to the IEEE 754 single precision representation but instead of 32 bits we use only 8 or 12 bits to represent the number.
0 件のコメント
採用された回答
John D'Errico
2016 年 8 月 20 日
Simple answer in MATLAB - No. MATLAB does not provide floating point numbers with a generally user specified number of bits. Unless a single or double applies, then you are out of luck. So your choices are 52 bits or 23 bits.
Nothing stops you from creating a class of objects that contain numbers of your own creation, as long as you also provide tools to compute all operations on those numbers. That can take some serious work though.
3 件のコメント
John D'Errico
2016 年 8 月 21 日
Short bit floating point numbers are a REALLY bad thing to work with. A REALLY bad idea.
If you are working in floating point, it is the least significant bits that lose a bit here, a bit there. On every computation, you have some significant chance of introducing an error in that LSB. These errors accumulate after many computations. But if you are only working in 8 bits of precision, can you really afford to lose anything at all? NOOOOO!!!!!!!!
Anyway, when you say 8 bit floats, how many bits will you put into the exponent? Shiver.
So what do you gain? Ok, a wee bit in terms of memory, that is, IF you can actually store those numbers efficiently. RAM IS CHEAP.
What else? speed? Again, you will see little in terms of a speed boost. Processors are designed to work with 32 bit buses and registers at least, usually now more than that. So you won't gain much by going to 8 or 12 bits in terms of speed.
Worse, if you think you can do linear algebra using 8 or 12 bit floats, you will need to write EVERYTHING yourself. Can you write faster code than the blas? Than tools like LAPACK?
So you gain little here, for a serious risk in terms of precision loss.
Do I know of anyone who has done this? No. OK, you could, in theory use my HPF toolbox to do short float computations. It will be slow of course, compared to compiled code. And HPF works in decimal. Finally, HPF will take more memory to store one number than you could achieve with a double. HPF is a fun tool to use, but far better to use it as it is targeted, to work in high precision - NOT low.
James Tursa
2016 年 8 月 22 日
16-bit "Half Precision" floating point format is a relatively new but I think now common format used in graphics processors (e.g., the Nvidia Ge-Force processors). Since that is implemented in silicon, you could potentially do something with this format on the GPU that is fast and has h/w support. But once you got it on the MATLAB side of things, you couldn't really do much except to convert it to/from single or double for working with it. Some conversion code can be found here:
But 12-bits is really pushing it, and 8-bits sounds absurd. Other than writing converters to/from single and double to deal with h/w that works in these formats I see no compelling reason to try to work with these formats.
https://en.wikipedia.org/wiki/Half-precision_floating-point_format
その他の回答 (2 件)
Walter Roberson
2016 年 8 月 21 日
You might be able to do something useful with the Fixed Point Toolbox.
2 件のコメント
Walter Roberson
2016 年 8 月 21 日
Which formats are you trying to support? See http://www.mrob.com/pub/math/floatformats.html#minifloat
Are you just looking for conversion routines, or are you also looking for operations (e.g., sum, product, log, gamma) ?
Erendiz Tarakci
2017 年 11 月 25 日
Were you ever able to figure this out? And if so, do you mind sharing how you did it? I'm having a similar problem where I'm decreasing the bit depth of my matrix from 16 bits to 8 bits in 2 bit increments.
1 件のコメント
Walter Roberson
2017 年 11 月 25 日
Which formats are you trying to support? See http://www.mrob.com/pub/math/floatformats.html#minifloat
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!