Snippet Compress Number

Nestharus

o-o
Reaction score
84
After much effort, I've come up with this for lossy compression in save/load ; ).


Lossy compression is commonly used on hero experience, hero x,y coordinates, and player gold. The most common equation for gold is R2I(gold/100), which cuts off the last 2 digits. The problem with this is that it fails with smaller values.


The equation I present will still get the max of 10,000 for gold like the above but with better results ; ).

JASS:

library CompressInt
//performs lossy compression on integers
//compressed number = number^(2/3)

//decompressed number = roundDown(number^1.5+.5)

function CompressInt takes integer n returns integer
    return R2I(Pow(n,2/3.))
endfunction
function DecompressInt takes integer n returns integer
    return R2I(Pow(n,1.5)+.5)
endfunction

endlibrary



This does lose accuracy, but it's extremely good and works on any size numbers.


You can also compress multiple times.


The current exponents I have set up seem to be the magic numbers ; ).



Demonstration:

995995 -> 9973
9973 -> 995952


As can be seen, rather than getting 995000, 995952 was retrieved, which is quite a bit closer to the real value.


123456 -> 2479
2479 -> 123428


357832393 -> 504026
504026 -> 357832192


Side by side
357832393
357832192


Yes, the retrieved value is only 201 off from the actual number while storing a 9 digit number as a 6 digit number.
 

Switch33

New Member
Reaction score
12
This is neat. But instead of just getting a wacky closer digit number couldn't they just round the number saved? I mean like save the first 1-3 digits in front then count the number of zeroes afterward to store instead.

Because that would be roughly the same concept of storing a large digit number like a 9 digit number as a 3-4 digit number.

I think it at least makes more sense to save numbers as rounded down/up after the 100's(or 1000's) place anyway. I mean no one will fret too much of a loss of 49 gold at least(or 499 in some other maps). And when people load this they see this weird number that is really not looking like what they saved they might get kind of confused at first.

Although this is really so accurate that it doesn't matter too much. I just find it'd be annoying to try to tell people that the gold they got back is the correct amount it's just rounded arbitrarily to an close number.
 

Nestharus

o-o
Reaction score
84
That wouldn't be good because you'd have to round with a constant... if you round to 100, which is the norm, then if they have 50 gold that they worked hard to get, it drops to 0. If they have something like 3589459935 of something, then that only drops to 3589459900, whereas it would drop more and be stored smaller if it were running off of this compression.


Think of this as rounding based on how big the data is ; ).
 

tooltiperror

Super Moderator
Reaction score
231
This is pretty nice. I kind of want something like this from time to time.

Would it be too much to ask for it in a library? As someone like you who loves modularity, I would think you would be horrified of somebody duplicating this function :p

Also, documentation. I know you have some irrational fear of it, but I just ask for a quick header like Bribe's. Mention the functions, their return and input, then add a note on how it rounds and you can lose accuracy (pros and cons) the usual stuff.
 

Nestharus

o-o
Reaction score
84
I can put it in a library sure.


As for the description of it, the first post already does that no?
 

tooltiperror

Super Moderator
Reaction score
231
It's sort of a de facto standard to keep that information in the header in the world of Jass.
 

Nestharus

o-o
Reaction score
84
The most I'm putting in the header is that this does Lossy Compression ; ).

Take it or leave it : p.
 

Bribe

vJass errors are legion
Reaction score
67
Actually the documentation would make more sense as: round(number ^ 1.5) because that implies adding the 0.5 itself, and rounding down implies not adding the 0.5.
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
thats pretty cool, to improve acuracy couldnt you do a little more to the function and maybe add a digit or convert it to a real with a .last_exact_digit00 ?
like:
JASS:
library CompressInt
//performs lossy compression on integers
//compressed number = number^(2/3)

//decompressed number = roundDown(number^1.5+.5)

function CompressInt takes integer n returns real
    local real i = (n - (R2I(n/10))*10)/10
    return Pow(n,2/3.) + i
endfunction
function DecompressInt takes integer n, integer y returns integer
    return R2I(Pow(n,1.5)+.5)/10)*10 + y//where y would be the end digit of the real it returned, that way they could just convert the first return to an integer if they just want the compressed integer, or save the real end to make it exact
endfunction

endlibrary
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    So what it really is me trying to implement some kind of better site navigation not change the whole theme of the site
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top