Solving Power Law Distribution in Python

BullyWiiPlaza

I have data that closely resembles a power law distribution. Using Python, I want to approximate the data by solving two equations in the form:

y is the y axis data. In Python it would be data[i]. x would be i + 1. It follows that we get two equations with two unknown variables at the first data index and at a "random" 2nd one somewhere else in the data:


The problem comes down to solving just

due to mathematical simplification. I don't know how to solve an equation like this using libraries like numpy.linalg.solve. How do I find the value of a using Python?

BullyWiiPlaza

Alright, I got it.

import math

def get_power_law_variables(data):
    c = data[0]
    middle_index = len(data) / 2
    division = float(data[middle_index]) / c
    logarithm_base = middle_index + 1
    a = math.log(division, logarithm_base)
    return c, a

# Example usage
data = range(50, 150)
c, a = get_power_law_variables(data)
print c, a

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Python : generating random numbers from a power law distribution

From Dev

How can I find the power law parameter of a Student-t distribution in Python?

From Dev

Creating power law distribution chart based on raw data

From Dev

create random graph with "same" power-law degree distribution

From Dev

Sample a truncated integer power law in Python?

From Dev

Fit a power law to empirical data in Python

From Dev

Create directed random graph specifing alpha of power-law degree distribution

From Dev

Generating power-law distributed numbers from uniform distribution – found 2 approaches: which one is correct?

From Dev

Generating power-law distributed numbers from uniform distribution – found 2 approaches: which one is correct?

From Dev

Use function mle2() in bbmle package(R) to get parameters for exponential and power law distribution

From Dev

Fitting a power-law with powerlaw.py in Python 3

From Dev

Fitting a power-law with powerlaw.py in Python 3

From Dev

python nodal/piecewise-linear power-law generator

From Dev

How to find a fitting power law?

From Dev

SciPy Curve Fit Fails Power Law

From Dev

Min max optimizations for power law parameters in R

From Dev

Implementing a Broken Power Law as a fitting function in Origin

From Dev

Power Law in Excel works better than R?

From Dev

How to add power law likelihood to Netlogo Model

From Dev

Ergodic Markov chain stationary distribution: solving eqns

From Dev

De Morgan Law in Python 3

From Dev

Calculating vectors with the cosine law (Python)

From Dev

Fitting power-law distributions with poweRlaw package in R

From Dev

NLS And Log-Periodic Power Law (LPPL) in R

From Dev

R: fitting power law curve to data (starting value for c)

From Dev

NLS And Log-Periodic Power Law (LPPL) in R

From Dev

'Power of' in python

From Dev

Python : Apply distributive law to elements in list

From Dev

Benford's Law Plotting in Python 3.5.2

Related Related

  1. 1

    Python : generating random numbers from a power law distribution

  2. 2

    How can I find the power law parameter of a Student-t distribution in Python?

  3. 3

    Creating power law distribution chart based on raw data

  4. 4

    create random graph with "same" power-law degree distribution

  5. 5

    Sample a truncated integer power law in Python?

  6. 6

    Fit a power law to empirical data in Python

  7. 7

    Create directed random graph specifing alpha of power-law degree distribution

  8. 8

    Generating power-law distributed numbers from uniform distribution – found 2 approaches: which one is correct?

  9. 9

    Generating power-law distributed numbers from uniform distribution – found 2 approaches: which one is correct?

  10. 10

    Use function mle2() in bbmle package(R) to get parameters for exponential and power law distribution

  11. 11

    Fitting a power-law with powerlaw.py in Python 3

  12. 12

    Fitting a power-law with powerlaw.py in Python 3

  13. 13

    python nodal/piecewise-linear power-law generator

  14. 14

    How to find a fitting power law?

  15. 15

    SciPy Curve Fit Fails Power Law

  16. 16

    Min max optimizations for power law parameters in R

  17. 17

    Implementing a Broken Power Law as a fitting function in Origin

  18. 18

    Power Law in Excel works better than R?

  19. 19

    How to add power law likelihood to Netlogo Model

  20. 20

    Ergodic Markov chain stationary distribution: solving eqns

  21. 21

    De Morgan Law in Python 3

  22. 22

    Calculating vectors with the cosine law (Python)

  23. 23

    Fitting power-law distributions with poweRlaw package in R

  24. 24

    NLS And Log-Periodic Power Law (LPPL) in R

  25. 25

    R: fitting power law curve to data (starting value for c)

  26. 26

    NLS And Log-Periodic Power Law (LPPL) in R

  27. 27

    'Power of' in python

  28. 28

    Python : Apply distributive law to elements in list

  29. 29

    Benford's Law Plotting in Python 3.5.2

HotTag

Archive