TopcoderArchive
Archive
Algorithm problem

PowerLaw

Problem statement, definition, constraints, and public examples.

Problem Statement

A power law distribution is one where the probability density of a value X >= 1 being observed in a trial is proportional to X-a where a is some constant.

We have collected some data from the real world, and we suspect that it comes from a power law distribution as described above. We would like to find the most likely value of a for this data. That is, what value of a in the range above would generate the observed data with the highest probability density.

Definition

Class:
PowerLaw
Method:
fit
Parameters:
double[]
Returns:
double
Method signature:
double fit(double[] x)
(be sure your method is public)

Constraints

  • The answer will be greater than 1 and at most 1000.
  • x will contain between 1 and 50 elements, inclusive.
  • Each element of x will be at least 1 and non-infinite.

Examples

  1. {1,1,1,1,2}
    Returns: 8.213475204444817
    When a=8.213475204444817 the probability density at 1 is 7.21348 and the probability density at 2 is 0.024302. The overall probability density of observing this data from a=8.213475204444817 is 65.7992. It turns out that any other value of a would result in a lower probability density.
  2. {1,1,1,1,2,2,2,3,3,4}
    Returns: 2.765860813452108
  3. {1,2,3,4,5,6,7,8,9,10}
    Returns: 1.6620581867464064
  4. {1,1000}
    Returns: 1.289529654602168
Back to all problems