Comments (3)
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.
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.
Sounds like a plan! I'll look for the pull request. Thanks!
from powerlaw.
Related Issues (20)
- `estimate_discrete` should be False by default or raise a warning for x_min < 6 HOT 1
- p_value not computed from normalizes R HOT 6
- Issue with the x_min
- Curve fitted using power law is far from the data points
- Version label
- Added xmin computation does not work for distributions != power_law/truncated_power_law HOT 1
- power law plot showing fit and all data, not just data from xmin HOT 1
- New user: Why the curvature in power_law.plot_ccdf fit? HOT 14
- Defunct scipy import HOT 1
- threshold in powerlaw fit HOT 1
- Remove or make optional xmin fitting print
- Fitting a powerlaw with the xmax parameter HOT 17
- How to improve the efficiency of the fit.
- Get the estimates when i only have an probability distribution from empirical data
- Some issues in lognormal fit
- how to calculate the R value properly for discrete data
- Feature Request: Return the normalization constant HOT 9
- Please remove print statement on line 341 of powerlaw.py
- parameter1 attribute not set for fit.powerlaw HOT 1
- Can not pass 'bins' keyword to `plot_pdf` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from powerlaw.