ZipfianDistribution Class

Represents a Zipfian distribution.

Definition

Namespace: Numerics.NET.Statistics.Distributions
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 9.1.2
C#
public class ZipfianDistribution : DiscreteDistribution
Inheritance
Object  →  Distribution  →  DiscreteDistribution  →  ZipfianDistribution

Remarks

The Zipfian distribution is a discrete probability distribution commonly used to model the frequency of events in a large dataset, where the frequency of an event is inversely proportional to its rank.

The distribution is characterized by two parameters: a shape parameter s > 0 which controls the skewness of the distribution, and a parameter N > 0 which represents the number of elements in the distribution. The probability mass function is given by p(k) = k^(-s) / H(N,s), where H(N,s) is the Nth generalized harmonic number of order s.

When the shape parameter s is high, the distribution is heavily skewed toward the lower ranks. As s approaches 0, the distribution becomes more uniform. When the second (integer) parameter N approaches infinity, the Zipfian distribution approaches a ZipfDistribution.

The Zipfian distribution has applications in many fields including linguistics (modeling word frequencies in natural languages), information retrieval, population distributions in cities, income distributions, and web traffic modeling. It is commonly used in performance testing to generate realistic access patterns for caches, databases, and other systems where some items are accessed much more frequently than others.

Example

This example demonstrates how to create and use a Zipfian distribution:
C#
using Numerics.NET.Statistics.Distributions;
using System;

// Create a Zipfian distribution with shape parameter s=1.5 and N=100 elements
var zipf = new ZipfianDistribution(1.5, 100);

// Distribution parameters
Console.WriteLine("Distribution Parameters:");
Console.WriteLine($"Shape parameter (s): 1.5");
Console.WriteLine($"Number of elements (N): 100");

// Distribution functions
Console.WriteLine("\nDistribution Functions:");
Console.WriteLine($"Probability of rank 1: {zipf.Probability(1):F6}");
Console.WriteLine($"Probability of rank 2: {zipf.Probability(2):F6}");
Console.WriteLine($"Probability of rank 10: {zipf.Probability(10):F6}");
Console.WriteLine($"Log probability of rank 1: {zipf.LogProbability(1):F6}");
Console.WriteLine($"CDF at rank 5: {zipf.DistributionFunction(5):F6}");
Console.WriteLine($"CDF at rank 20: {zipf.DistributionFunction(20):F6}");

// Moments
Console.WriteLine("\nDistribution Moments:");
Console.WriteLine($"Mean: {zipf.Mean:F6}");
Console.WriteLine($"Variance: {zipf.Variance:F6}");
This example creates a Zipfian distribution with a shape parameter of 1.5 and 100 elements, then calculates various probabilities and distribution characteristics. The output shows how probability decreases as rank increases, demonstrating the power-law relationship characteristic of the Zipfian distribution.

Constructors

ZipfianDistribution Constructs a new Zipfian distribution.

Properties

Capabilities Gets a value that indicates the capabilities of the distribution class.
(Inherited from Distribution)
Entropy Gets the entropy of the distribution.
(Inherited from Distribution)
Exponent Gets the value of the exponent.
IsUnimodal Gets whether the distribution has one or more modes.
(Inherited from DiscreteDistribution)
Kurtosis Gets the kurtosis of the distribution.
(Overrides Distribution.Kurtosis)
Mean Gets the mean or expectation value of the distribution.
(Overrides Distribution.Mean)
Mode Gets the mode of the distribution.
(Inherited from DiscreteDistribution)
NumberOfModes Gets the number of modes of the distribution.
(Inherited from DiscreteDistribution)
Size Gets the population size of the distribution.
Skewness Gets the skewness of the distribution.
(Overrides Distribution.Skewness)
StandardDeviation Gets the standard deviation of the distribution.
(Inherited from Distribution)
StatisticSymbol Gets the common symbol to describe a statistic from the distribution.
(Inherited from Distribution)
Variance Gets the variance of the distribution.
(Overrides Distribution.Variance)

Methods

DistributionFunction Gets the probability of obtaining an outcome less than or equal to a specified value.
(Overrides DiscreteDistribution.DistributionFunction(Int32))
EqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
GetAllModes Returns an array that contains all the modes of the distribution.
(Inherited from DiscreteDistribution)
GetExpectedHistogram(Index<Interval<Int32>>, Double) Returns a histogram whose bins contain the expected number of samples from the distribution for a given total number of samples.
(Inherited from DiscreteDistribution)
GetExpectedHistogram(Index<Int32>, Double) Returns a histogram whose bins contain the expected number of samples from the distribution for a given total number of samples.
(Inherited from DiscreteDistribution)
GetExpectedHistogram(Int32, Int32, Double) Returns a histogram whose bins contain the expected number of samples from the distribution for a given total number of samples.
(Inherited from DiscreteDistribution)
GetHashCodeServes as the default hash function.
(Inherited from Object)
GetRandomSequence() Returns a sequence of random samples from the distribution.
(Inherited from DiscreteDistribution)
GetRandomSequence(Random) Returns a sequence of random samples from the distribution.
(Inherited from DiscreteDistribution)
GetRandomSequence(Random, Int32) Returns a sequence of random samples of the specified length from the distribution.
(Inherited from DiscreteDistribution)
GetTypeGets the Type of the current instance.
(Inherited from Object)
InverseDistributionFunction Returns the inverse of the distribution function.
(Inherited from DiscreteDistribution)
LeftTailProbability Gets the probability of obtaining a sample that is less than or less than or equal to the specified upper bound.
(Inherited from DiscreteDistribution)
LogProbability Returns the logarithm of the probability of obtaining a specific integer value in the distribution.
(Overrides DiscreteDistribution.LogProbability(Int32))
MemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
Probability(Int32) Returns the probability of obtaining a specific integer value in the distribution.
(Overrides DiscreteDistribution.Probability(Int32))
Probability(Int32, Int32) Gets the probability of obtaining a sample that falls within the specified interval from the distribution.
(Inherited from DiscreteDistribution)
RightTailProbability Gets the probability of obtaining a sample that is less than or less than or equal to the specified upper bound.
(Inherited from DiscreteDistribution)
Sample() Returns a random sample from the distribution.
(Inherited from DiscreteDistribution)
Sample(Int32) Returns a vector of random samples from the distribution.
(Inherited from DiscreteDistribution)
Sample(Random) Returns a random sample from the distribution.
(Overrides DiscreteDistribution.Sample(Random))
Sample(Int32, Random) Returns a vector of random samples from the distribution.
(Inherited from DiscreteDistribution)
Sample(Random, Int32[]) Fills an Int32 array with random numbers.
(Inherited from DiscreteDistribution)
Sample(Random, Int32[], Int32, Int32) Fills an Int32 array with random numbers from this DiscreteDistribution.
(Inherited from DiscreteDistribution)
ToStringReturns a string that represents the current object.
(Inherited from Object)
TwoTailProbability Gets the probability of obtaining a sample that is less than or less than or equal to the specified upper bound.
(Inherited from DiscreteDistribution)

See Also