in reply to A better way of lookup?

I would go for parallel arrays and binary search or leave it as is. If you do not depend on the discrete values (piecewise constant function), a log-log-linear fit would work very well: $lookup=exp(-2.276+0.997*log($v));. If you want to be fancy you could add some rounding.

Replies are listed 'Best First'.
Re^2: A better way of lookup?
by BrowserUk (Patriarch) on Apr 26, 2015 at 13:15 UTC
    $lookup = exp( -2.276 + 0.997 * log( $v ) );

    That's a pretty good fit(*) -- a lot closer than I got -- but, this is intended to replace the Mysterious Function, and on balance, I think those constants make it even more mysterious.

    I'm not particularly happy with my mysterious lookup table either, but every other attempt I've had screws up the results to a greater or lesser extent, whereas this works. I just need to come up with some documentation to explain it. (Not easy!).

    (* However, I would be very interested to know how you derived that equation?)


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
    In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

      Paste the data into Excel as two columns, apply LN to the data, use SLOPE and INTERCEPT to get the constants. That gives you have a linear formula to predict the log of the desired value as a funtion of the log of the input, therefore take EXP on the result. If you want to do it in Perl, have a look at this: Re^5: Data range detection?. There is a coefficients function in that module.

      Update: On documentation, I remember that all these numbers are milliseconds, so translating into seconds, minutes, hours, days, and years should be helpful.