GithubHelp home page GithubHelp logo

Comments (3)

jeffalstott avatar jeffalstott commented on July 22, 2024

Thanks @mountaindust for the great analysis.

bins = range(int(xmin2), int(xmax2)) is already wacky because xmax is not required to be an integer, and so int()ing it has potential for problems around the edges. Can you think of a more general solution to this problem, which would also address your issue?

There are similarly other issues with edge cases with logarithmic bins, which will leave your single outlier still unincorporated. Consider xmax2=999.1 and xmin=1:

xmax2=999.1
xmin2=1

log_min_size = log10(xmin2+.0001)
log_max_size = log10(xmax2+.0001)
number_of_bins = ceil((log_max_size-log_min_size)*10)
bins=unique(
        floor(
            logspace(
                log_min_size, log_max_size, num=number_of_bins)))
print(bins)
[   1.    2.    3.    4.    5.    6.    8.   10.   13.   17.   22.   28.
   35.   45.   57.   72.   92.  117.  148.  188.  239.  303.  385.  489.
  620.  787.  999.]

Can you think of a more comprehensive solution?

Pull requests are welcome!

from powerlaw.

mountaindust avatar mountaindust commented on July 22, 2024

I wasn't thinking about non-integers before.

The bins = range(int(xmin2), int(xmax2)) solution suggested to me integer bins were desirable for linear binning, which would make sense from a plotting point of view (otherwise, why not use linspace?). If that is indeed the case, it doesn't matter if the last bin overshoots the data a bit (a bit being <1) - I think it's more important to include all data points. A more general solution than I had before is bins = range(int(xmin2), ceil(xmax2)+1), where the ceil comes from math so it returns an int? That is guaranteed to include the last point in all cases.

Certainly this does not add any more error than the current code (consider for example a case where xmax2 = 999.9), and is an improvement in that xmax will be included.

The logarithmic issue is more subtle, but I think can be similarly dealt with by taking the ceil of the last entry rather than the floor. So how about:

log_min_size = log10(xmin2)
log_max_size = log10(xmax2)
number_of_bins = ceil((log_max_size-log_min_size)*10)
bins = logspace(log_min_size, log_max_size, num=number_of_bins)
bins[:-1] = floor(bins[:-1])
bins[-1] = ceil(bins[-1])
bins = unique(bins)

The same ceil can be used; even though it returns an int, it will get converted to float to match the dtype of bins (if that matters). If you agree I can open a pull request, and I'll also throw in an edit for #66.

from powerlaw.

jeffalstott avatar jeffalstott commented on July 22, 2024

Sounds like a plan! I'll look for the pull request. Thanks!

from powerlaw.

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.