Comments (6)
from powerlaw.
When I run the example in a while loop, like this:
import powerlaw
xmax=100
exponent=1.1
dist=powerlaw.Power_Law(xmin=1,xmax=xmax,discrete=True,parameters=[exponent],discrete_approximation="xmax")
while True:
print(dist.generate_random(n=1,estimate_discrete=False))
it crashes after a while. Alternatively, more samples also (almost always) cause the problem:
print(dist.generate_random(n=100,estimate_discrete=False))
from powerlaw.
I don't have a computer at the moment with powerlaw
installed/installable, but reading through the code it looks like the doc string for .generate_random
states "If xmax is present, it is currently ignored." So, in principle this function shouldn't even generate the thing that you want, anyway. I would just generate data from a Power_Law
instance without an xmax
, then cut out all the data above your desired xmax
.
It appears the bug is that .generate_random
calls on _double_search_discrete
, which does binary search across values of x
to match a random number in [0,1] with the CCDF of the Power_Law
instance (thus producing x
proportional to its probability in the Power_Law
). My guess is that the problem arises when there's xmax
and the binary search overshoots past xmax
, yielding a candidate x
value the cdf
function can't handle; it trims out everything that's outside of xmax
and xmin
with trim_to_range
, yielding an empty list and later producing the error you see.
So, the problem is that we don't actually know how to directly generate synthetic data from a discrete power law with an xmax
. If there's an elegant solution, I'll happily implement it. In the meantime, please confirm that my suggestion above actually works for you. Thanks!
from powerlaw.
If I understood correctly, it is not possible to use this library to sample the distribution with given xmax?
Thank you for your help.
from powerlaw.
I would just generate data from a Power_Law
instance without an xmax
, then cut out all the data above your desired xmax
.
That'll get you what you want.
from powerlaw.
Okay, thank you very much.
from powerlaw.
Related Issues (20)
- `estimate_discrete` should be False by default or raise a warning for x_min < 6 HOT 1
- Finding xmin for a truncated power law HOT 3
- Alpha exponent less than 1? HOT 4
- python 3.7 HOT 1
- 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.