Distr(3pm)
π Distr(3pm) π β the user-contributed Perl docs, but make it cute
okay bestie, welcome to Distr(3pm), aka PDL::Stats::Distr, and honestly? she's a whole vibe. it's giving "I do statistics and I look good doing it" β¨
πΈ NAME πΈ
PDL::Stats::Distr β parameter estimations and probability density functions for distributions. yes. all the distributions. π
π¦ DESCRIPTION π¦
So here's the tea on how the parameter estimates work, and it's actually super simple:
- if there's a closed form estimate, you get the maximum likelihood estimate π
- otherwise? it's the method of moments estimate π«Ά
periodt. that's the rule. β¨
π SYNOPSIS π
like, let's actually do something. here's you making a frequency (probability) plot with a fitted normal curve:
use PDL::LiteF;
use PDL::Stats::Distr;
# do a frequency (probability) plot with fitted normal curve
my $data = grandom(100)->abs;
my ($xvals, $hist) = $data->hist;
# turn frequency into probability
$hist /= $data->nelem;
# get maximum likelihood estimates of normal curve parameters
my ($m, $v) = $data->mle_gaussian();
# fitted normal curve probabilities
my $p = $xvals->pdf_gaussian($m, $v);
use PDL::Graphics::PGPLOT::Window;
my $win = pgwin( Dev=>"/xs" );
$win->bin( $hist );
$win->hold;
$win->line( $p, {COLOR=>2} );
$win->close;
orrr, if you're feeling β¨adventurousβ¨ and wanna play with different distributions, there's plot_distr :)
$data->plot_distr( 'gaussian', 'lognormal' );
β¨ FUNCTIONS β¨
okay this is the main event. every single one, no skips, we're not doing that. π«Ά
π mme_beta
Signature: (a(n); float+ [o]alpha(); float+ [o]beta())
my ($a, $b) = $data->mme_beta();
beta distribution, bestie. pdf: f(x; a,b) = 1/B(a,b) x^(a-1) (1-x)^(b-1)
mme_beta processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. (this lil disclaimer shows up literally everywhere and yes I'm telling you every time, no cap π)
π pdf_beta
Signature: (x(); a(); b(); float+ [o]p())
probability density function for beta distribution. x defined on [0,1]. π
pdf_beta processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π mme_binomial
Signature: (a(n); int [o]n_(); float+ [o]p())
my ($n, $p) = $data->mme_binomial;
binomial distribution. pmf: f(k; n,p) = (n k) p^k (1-p)^(n-k) for k = 0,1,2..n
mme_binomial processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π pmf_binomial
Signature: (ushort x(); ushort n(); p(); float+ [o]out())
probability mass function for binomial distribution.
pmf_binomial processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π mle_exp
Signature: (a(n); float+ [o]l())
my $lamda = $data->mle_exp;
exponential distribution. mle same as method of moments estimate. (they agree, iconic behavior honestly π)
mle_exp processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π pdf_exp
Signature: (x(); l(); float+ [o]p())
probability density function for exponential distribution.
pdf_exp processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π mme_gamma
Signature: (a(n); float+ [o]shape(); float+ [o]scale())
my ($shape, $scale) = $data->mme_gamma();
two-parameter gamma distribution. π
mme_gamma processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π pdf_gamma
Signature: (x(); a(); t(); float+ [o]p())
probability density function for two-parameter gamma distribution.
pdf_gamma processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π mle_gaussian
Signature: (a(n); float+ [o]m(); float+ [o]v())
my ($m, $v) = $data->mle_gaussian();
gaussian aka normal distribution. same results as $data->average and $data->var. mle same as method of moments estimate. the classic. the main character. π
mle_gaussian processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π pdf_gaussian
Signature: (x(); m(); v(); float+ [o]p())
probability density function for gaussian distribution.
pdf_gaussian processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π mle_geo
Signature: (a(n); float+ [o]p())
geometric distribution. mle same as method of moments estimate.
mle_geo processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π pmf_geo
Signature: (ushort x(); p(); float+ [o]out())
probability mass function for geometric distribution. x >= 0.
pmf_geo processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π mle_geosh
Signature: (a(n); float+ [o]p())
shifted geometric distribution. mle same as method of moments estimate. (the shifted one. she's different. π )
mle_geosh processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π pmf_geosh
Signature: (ushort x(); p(); float+ [o]out())
probability mass function for shifted geometric distribution. x >= 1.
pmf_geosh processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π mle_lognormal
Signature: (a(n); float+ [o]m(); float+ [o]v())
my ($m, $v) = $data->mle_lognormal();
lognormal distribution. maximum likelihood estimation.
mle_lognormal processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π mme_lognormal
Signature: (a(n); float+ [o]m(); float+ [o]v())
my ($m, $v) = $data->mme_lognormal();
lognormal distribution. method of moments estimation.
mme_lognormal processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π pdf_lognormal
Signature: (x(); m(); v(); float+ [o]p())
probability density function for lognormal distribution. x > 0. v > 0. (both of those constraints are non-negotiable bestie π«Ά)
pdf_lognormal processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π mme_nbd
Signature: (a(n); float+ [o]r(); float+ [o]p())
my ($r, $p) = $data->mme_nbd();
negative binomial distribution. pmf: f(x; r,p) = (x+r-1 r-1) p^r (1-p)^x for x=0,1,2...
mme_nbd processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π pmf_nbd
Signature: (ushort x(); r(); p(); float+ [o]out())
probability mass function for negative binomial distribution.
pmf_nbd processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π mme_pareto
Signature: (a(n); float+ [o]k(); float+ [o]xm())
my ($k, $xm) = $data->mme_pareto();
pareto distribution. pdf: f(x; k,xm) = k xm^k / x^(k+1) for x >= xm > 0.
mme_pareto processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π pdf_pareto
Signature: (x(); k(); xm(); float+ [o]p())
probability density function for pareto distribution. x >= xm > 0.
pdf_pareto processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π mle_poisson
Signature: (a(n); float+ [o]l())
my $lamda = $data->mle_poisson();
poisson distribution. pmf: f(x;l) = e^(-l) * l^x / x!
mle_poisson processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π pmf_poisson
Signature: (x(); l(); float+ [o]p())
Probability mass function for poisson distribution. Uses Stirling's formula for x > 85.
pmf_poisson processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π pmf_poisson_stirling
Signature: (x(); l(); [o]p())
Probability mass function for poisson distribution. Uses Stirling's formula for all values of the input. See http://en.wikipedia.org/wiki/Stirling's_approximation for more info. (yes the whole thing is stirling'd. she committed. π₯)
pmf_poisson_stirling processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
π pmf_poisson_factorial
Signature: ushort x(); l(); float+ [o]p()
Probability mass function for poisson distribution. Input is limited to x < 170 to avoid gsl_sf_fact() overflow.
β οΈ bestie listen β stay underx < 170orgsl_sf_fact()overflows and everything falls apart. the limit is there for a reason. π
π plot_distr
Plots data distribution. When given specific distribution(s) to fit, returns % ref to sum log likelihood and parameter values under fitted distribution(s). See FUNCTIONS above for available distributions. π
Default options (case insensitive):
MAXBN => 20,
# see PDL::Graphics::PGPLOT::Window for next options
WIN => undef, # pgwin object. not closed here if passed
# allows comparing multiple distr in same plot
# set env before passing WIN
DEV => '/xs' , # open and close dev for plotting if no WIN
# defaults to '/png' in Windows
COLOR => 1, # color for data distr
Usage:
# yes it threads :)
my $data = grandom( 500, 3 )->abs;
# ll on plot is sum across 3 data curves
my ($ll, $pars)
= $data->plot_distr( 'gaussian', 'lognormal', {DEV=>'/png'} );
# pars are from normalized data (ie data / bin_size)
print "$_\t@{$pars->{$_}}\n" for (sort keys %$pars);
print "$_\t$ll->{$_}\n" for (sort keys %$ll);
π DEPENDENCIES π
- GSL β GNU Scientific Library. yeah you need it, no cap. π
π¦ SEE ALSO π¦
go read these too bestie, iykyk:
- PDL::Graphics::PGPLOT
- PDL::GSL::CDF
π AUTHOR π
Copyright (C) 2009 Maggie J. Xiong <maggiexyz users.sourceforge.net>, David Mertens
All rights reserved. There is no warranty. You are allowed to redistribute this software / documentation as described in the file COPYING in the PDL distribution.
and that's the whole page, bestie!! π«Άβ¨ this was Distr(3pm) from the User Contributed Perl Documentation, running on perl v5.38.2, dated 2024-03-31 β slay, ate, no crumbs, periodt. π
ππ
π¦ where this page comes from
- ubuntu noble: libpdl-stats-perl 0.83-1build3 Β· PDL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms