Skip to main content

PowerLawFit

Struct PowerLawFit 

Source
pub struct PowerLawFit<'a> {
    pub continuous: bool,
    pub alpha: f64,
    pub xmin: f64,
    pub log_likelihood: f64,
    pub ks_statistic: f64,
    pub data: &'a [f64],
}
Expand description

A power-law distribution fitted to a sample by power_law_fit (the Rust counterpart of igraph_plfit_result_t).

The fitted model is P(X = x) ∝ x^(-alpha) for x >= xmin. The struct borrows the fitted sample, which is needed to compute the p-value of the fit.

Fields§

§continuous: bool

Whether a continuous (true) or a discrete (false) power law was fitted.

§alpha: f64

The fitted exponent alpha (larger than 1 for a normalizable law).

§xmin: f64

The threshold above which the power-law behavior holds (given, or estimated by minimizing the Kolmogorov–Smirnov statistic).

§log_likelihood: f64

The log-likelihood of the fitted parameters (L in igraph).

§ks_statistic: f64

The Kolmogorov–Smirnov test statistic between the fitted distribution and the sample (D in igraph); the smaller, the better.

§data: &'a [f64]

The sample the model was fitted to.

Implementations§

Source§

impl PowerLawFit<'_>

Source

pub fn p_value(&self, precision: f64) -> Result<f64>

Computes the p-value of the fit by a (slow) resampling procedure.

Many synthetic datasets are drawn: the part of the sample below xmin is resampled from the data itself, the part above xmin from the fitted power law. A power law is fitted to each of them, and the p-value is the fraction of synthetic datasets whose Kolmogorov–Smirnov statistic is larger than the observed one. Small p-values (e.g. below 0.1) mean that the power-law hypothesis can be rejected.

The number of resampling rounds is 0.25 / precision²: a precision of 0.01 means 2500 rounds. Results depend on the thread’s default random number generator (seed it with rng::seed); if igraph was built with OpenMP, the rounds run in parallel and the results are not reproducible unless OpenMP is limited to one thread.

Binds igraph_plfit_result_calculate_p_value.

The fields of the struct are public, so the model is checked before calling igraph (whose resampling code crashes or loops forever on some invalid models): it must have a non-empty, finite sample, a finite alpha > 1 (degenerate fits with alpha = inf are rejected), and a finite xmin, positive for a continuous law and in [1, 4e18) for a discrete one. The samples of a discrete model must also be below 2^62.

Known upstream issue. For discrete models, plfit draws from the fitted law with (long) floor(pow(1 - u, -1 / (alpha - 1)) * xmin), relying on the conversion of too large values to a C long to “handle overflow” (vendor/plfit/sampling.c). Such a conversion is undefined behavior in C; on x86-64 it yields a negative number and the draw is retried. This cannot be ruled out from Rust without constraining alpha: it only happens for extremely heavy tails (alpha close to 1), which huge samples produce most readily, hence the 2^62 bound above.

§Errors

ErrorKind::InvalidValue if precision is not a positive number, is so small that the number of rounds would not fit in a 64-bit integer (below about 2.5e-10), or so large that there would be no round at all (above 0.5); if the model is invalid (see above); and the errors of power_law_fit.

Trait Implementations§

Source§

impl<'a> Clone for PowerLawFit<'a>

Source§

fn clone(&self) -> PowerLawFit<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for PowerLawFit<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> PartialEq for PowerLawFit<'a>

Source§

fn eq(&self, other: &PowerLawFit<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> StructuralPartialEq for PowerLawFit<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for PowerLawFit<'a>

§

impl<'a> RefUnwindSafe for PowerLawFit<'a>

§

impl<'a> Send for PowerLawFit<'a>

§

impl<'a> Sync for PowerLawFit<'a>

§

impl<'a> Unpin for PowerLawFit<'a>

§

impl<'a> UnsafeUnpin for PowerLawFit<'a>

§

impl<'a> UnwindSafe for PowerLawFit<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.