| Author |
Need help using Arithmetic Code
|
|
| Tjackson.1982@gmail.com 2006-04-10, 9:55 pm |
| I am trying to learn arithmetic coding, but the code I am using which
prolly works, but when I use it with some modification now doesn't :(.
The code is well known I believe, Mark Nelson's Arithmetic code in C -
previously a remake of some CACM article (?). The changes I made are
basically :
1) change the shorts to unsigned longs to accomdate values larger then
65k.
2) Instead of reading from a file it reads from an array of bytes.
The error I get is that in the function get_count the range varible
manages to be 0. meaning "High" is one less then "Low". My
understanding of the implementation of AC is bad. I understand the
concept but not the bit shifting and all that good stuff. Anybody think
they can help me?
Thanks agian
T. Jackson
| |
| Tjackson.1982@gmail.com 2006-04-11, 3:55 am |
| Good news, I am continuely working on this so any suggestions are
welcome. I got it to go "further" but still end up with the same error.
Simply by removing some casting that effected the numbers. Also another
question, since the global "high" goes below the "low" is that a safe
time to "reset" them?
Well like I said any suggestions are appreciated, I gotta put it away
and do more work in the morning with some freash eyes.
Thanks again,
T. Jackson
| |
| Sachin Garg 2006-04-11, 3:55 am |
|
Tjackson.1982@gmail.com wrote:
> Good news, I am continuely working on this so any suggestions are
> welcome. I got it to go "further" but still end up with the same error.
> Simply by removing some casting that effected the numbers. Also another
> question, since the global "high" goes below the "low" is that a safe
> time to "reset" them?
>
> Well like I said any suggestions are appreciated, I gotta put it away
> and do more work in the morning with some freash eyes.
You might want to take a look at
http://www.sachingarg.com/compressi...y_coding/64bit/
I have modified that same code to use 64-bit variables. You are
planning to use 32-bit variables, I think it will be easy to see
correlations between what all needs to be edited.
Link to download the code is near the bottom of the page.
Best of luck
Sachin Garg [India]
http://www.sachingarg.com
| |
| Randy McNabb 2006-04-11, 3:55 am |
|
<Tjackson.1982@gmail.com> wrote in message
news:1144722622.763225.114000@j33g2000cwa.googlegroups.com...
> The error I get is that in the function get_count the range varible
> manages to be 0. meaning "High" is one less then "Low". My
> understanding of the implementation of AC is bad. I understand the
> concept but not the bit shifting and all that good stuff. Anybody think
> they can help me?
>
It sounds like when you are calculating the range that the variable is
rolling over to zero again. If you are using the full 32 bits where low =
0x0 and high = 0xFFFFFFFF , high - low = 0xFFFFFFFF. When you add 1 a 32
bit value will equal .
Randy McNabb
| |
| Randy McNabb 2006-04-11, 3:55 am |
|
"Randy McNabb" <the_frog_man@hotmail.com> wrote in message
news:123msnpb93u9eac@corp.supernews.com...
>
> <Tjackson.1982@gmail.com> wrote in message
> news:1144722622.763225.114000@j33g2000cwa.googlegroups.com...
> It sounds like when you are calculating the range that the variable is
> rolling over to zero again. If you are using the full 32 bits where low =
> 0x0 and high = 0xFFFFFFFF , high - low = 0xFFFFFFFF. When you add 1 a 32
> bit value will equal .
correction:
will equal 0.
>
> Randy McNabb
>
>
| |
| Sachin Garg 2006-04-11, 7:56 am |
|
Randy McNabb wrote:
> "Randy McNabb" <the_frog_man@hotmail.com> wrote in message
> news:123msnpb93u9eac@corp.supernews.com...
> correction:
> will equal 0.
My guess on what he has done is that he has only changed data type of
count variables from short to long and had expected that now he can use
larger range.
To use larger range, precision of arithmetic coder needs to be
increased too.
Sachin Garg [India]
http://www.sachingarg.com
| |
| Tjackson.1982@gmail.com 2006-04-11, 7:56 am |
| Hey thanks everyone.
Sachin- I actually saw your code, and tried to "merge" the two. I
suppose I did a half ass job of it. lol I gotta keep hacking away at it
I suppose.
Randy - I think that is what happens, but what do I do when that
happens? Its funny I was thinking it was -1 but since they are unsigned
long I suppose it would be 0xFFFFFFFF. I will review code and keep
trying.
Thanks again.
| |
| Randy McNabb 2006-04-11, 6:55 pm |
|
<Tjackson.1982@gmail.com> wrote in message
news:1144758803.187519.200350@t31g2000cwb.googlegroups.com...
> Hey thanks everyone.
>
> Sachin- I actually saw your code, and tried to "merge" the two. I
> suppose I did a half ass job of it. lol I gotta keep hacking away at it
> I suppose.
>
> Randy - I think that is what happens, but what do I do when that
> happens? Its funny I was thinking it was -1 but since they are unsigned
> long I suppose it would be 0xFFFFFFFF. I will review code and keep
> trying.
>
> Thanks again.
>
The easiest solution would be to use 64 bit unsigned integers for range. I
used inline assembly to handle the 32 bit values directly which is a lot
faster. You must also take care when calculating the new high and low
values.
Randy McNabb
| |
| Tjackson.1982@gmail.com 2006-04-11, 6:55 pm |
| Hey yes, Good news. what I did was I divided all occurence by 2, thus
making the scale half. I was then able to retrive some but not all the
original data. I think after my class ( Master student) I will upgrade
to 64 integers. I think that will fix the accuracy problems. see the
scale sometimes is 100k but some ranges are only by 1 so I think
somtimes the wrong symbol are found.
Thanks again guys.
TJackson
|
|
|
|