Git Product home page Git Product logo

Comments (6)

eyeonus avatar eyeonus commented on July 4, 2024

That's odd, because that should always result in a number between 0 and -0.5.

Hmmm. Maybe it's the "x^(x/4)' bit that's overflowing?

I'll look into it.

from trade-dangerous.

eyeonus avatar eyeonus commented on July 4, 2024

So, I did this:

                    try:
                        penalty = (-1 + 1 / (cruiseKls + 1) ** ((cruiseKls + 1) / 4)) / 2
                    except OverflowError as e:
                        print(str(e) + "cKls: " + str(cruiseKls))

and got this:

[                         ] (34, 'Result too large')cKls: 4218.0
[==                       ] (34, 'Result too large')cKls: 4218.0
[====                     ] (34, 'Result too large')cKls: 4218.0
[=============            ] (34, 'Result too large')cKls: 4218.0
[=========================] (34, 'Result too large')cKls: 514.4

First of all, what damned system has a station 4.2 MILLION ls away from the entry point?

Secondly, now I need to decide which of two options to use, those being:

  1. Use "sys.float_info.max" instead of "(cruiseKls + 1) ** ((cruiseKls + 1) / 4)" when an overflow occurs.
  2. Use the decimal module to do this math, which doesn't overflow until 9E+999999999999999999.
    (Which might still overflow if any stations are far enough away, but in that case I can easily get away with assuming "1/(cruiseKls + 1) ** ((cruiseKls + 1) / 4)" == 0.)

Thoughts?

from trade-dangerous.

aadler avatar aadler commented on July 4, 2024

4.2m ls, pshaw, that's nothing. Hutton Orbital in Proxima Centaurii is 6,784,404 ls! Over a 40 minute trip (I've yet to do it).

Converting the penalty into logs would look like:

penalty = (1 / exp(0.25 * (cruiseKls + 1) * log(cruiseKls + 1)) - 1) * 0.5

However, in this case, using logs doesn't really help, since log(Max(Double) is a hair over 709.78 and Hutton orbital would require exp(0.25 * 6201 * log(6201)) which becomes exp(13537.51) which overflows like mad. Actually, you have a form of Lambert W function here since you have a*Xe^X whew a is 0.25 and X is cruiseKls + 1. The largest Lambert W able to be calculated using double precision is a bit over 703.22. So, I'm not at home so I cannot try it, but perhaps the following will work:

cappeddist = min(0.25 * (cruiseKls + 1) * log(cruiseKls + 1), 709.78)
penalty = (1/exp(cappeddist) - 1) * 0.5

This should work and return the -0.5 for large numbers like Hutton Orbital without overflowing, If you haven't tried it by tonight, I will. Thanks!

from trade-dangerous.

aadler avatar aadler commented on July 4, 2024

Changed cap to 709.78 since we're not actually calculating Lambert W_0 but the exponentiation of capped dist. Not tghat it really matters, that's all going to be -0.5 anyway, we just need to make sure Python doesn't see a number it doesn't like.

if you wanted to use try, you'd probably want:

 try:
    penalty = (-1 + 1 / (cruiseKls + 1) ** ((cruiseKls + 1) / 4)) / 2
 except OverflowError:
    penalty = -0.5

Which is faster, try:except or the min?

from trade-dangerous.

eyeonus avatar eyeonus commented on July 4, 2024

Your math is off.

https://goo.gl/nPgbth

(-1 + 1 / (x + 1) ** ((x + 1) / 4)) / 2 != (1 / exp(0.25 * (x + 1) * log(x + 1)) - 1) * 0.5

from trade-dangerous.

aadler avatar aadler commented on July 4, 2024

My math is correct when you take into account that the FooPlot website has an ln operator so log is base 10, where R and Python both assume log to be natural :)

http://bit.ly/2MpyRDt

from trade-dangerous.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.