Next: , Previous: , Up: Directory Index   [Contents][Index]


2.19 statistics

Function File: [ fLower, fUpper ] = binomialConfidenceInterval ( N, K, confidence )

Compute the posterior confidence interval [fLower, fUpper] for the true rate f given a drawing experiment with K "successful" results out of N trials. The confidence interval satisfies confidence = int_{fLower}^{fUpper} pdf(f|N,K) df, where pdf(f|N,K) is the posterior pdf for the rate f, which is computed using the function binomialRatePDF(f,N,K).

The confidence-interval is constructed with iso-probability endpoints (if possible), namely P(fLower) = P(fUpper), which is guaranteed to bracket the maximum of the pdf. In the special cases where K = 0 or K = N, we return the "single-sided" intervals [0,fUpper] or [fLower,1], respectively.

Note

all inputs must be scalars! confidence must be in (0,1)

Examples

binomialConfidenceInterval(10, 0, 0.9545);
mo if 1
function plot_this ( N, K )
  conf2sigma = 0.9545;
  [fLower, fUpper] = binomialConfidenceInterval ( N, K, conf2sigma );
  fMPE = K / N;
  fE = (K+1)/(N+2);
  sigf = sqrt ( fE * ( 1 - fE ) / (N+3) );
  fMin = max(0, fMPE - 3.5 * sigf );
  fMax = min(1, fMPE + 3.5 * sigf );
  fLowerGauss = fE - 2*sigf;
  fUpperGauss = fE + 2*sigf;
  fi = linspace ( fMin, fMax, 100);
  pdf_f = binomialRatePDF ( fi, N, K );
  PMax = max ( pdf_f );
  ylim([0,1.05 * PMax]);
  set ( 0, "defaultlinemarkersize", 10 );
  plot ( fi, pdf_f, fMPE, PMax, "rx", [fLower, fUpper], [PMax,PMax], "r+-",
        fLower*[1,1], ylim(), "color", "black", "linestyle", "--", fUpper*[1,1], ylim(), "color", "black", "linestyle", "--",
        fMPE*[1,1], ylim(), "color", "black", "linestyle", ":",
        [fLowerGauss, fUpperGauss], 1.02*[PMax,PMax], "m+-"
        );
  xlabel("f"); ylabel("pdf(f|N,K)");
  tstr = sprintf ("N=%d, K=%d, confidence=%.2f%%", N, K, conf2sigma * 100.0 );
  title ( tstr );
endfunction
figure(1); clf;
subplot(2,3,1); plot_this ( 10, 0 );
subplot(2,3,2); plot_this ( 10, 1 );
subplot(2,3,3); plot_this ( 500, 300 );
subplot(2,3,4); plot_this ( 5000, 4999 );
subplot(2,3,5); plot_this ( 50000, 25000 );
subplot(2,3,6); plot_this ( 50000, 10000 );
## red shows the exact posterior 95.45% confidence intervals
## magenta shows the Gaussian +-2sigma intervals centered on the expectation value of f
endif
Function File: pdf = binomialRatePDF ( f, N, K )

Return the posterior pdf(f|N,K) for the true ’rate’ f given a drawing experiment with K "successful" results out of N trials, assuming a uniform prior on f in [0,1], which yields

pdf(f|N,K) = (N+1)!/(K! (N-K)!) * f^K * (1-f)^(N-K)

This expression would be numerically overflowing very easily when N,K>>1, and so we use the fact that

K!(N-K)!/(N+1)! = beta(K+1,N-K+1)

and the numerically robust octave-function betaln()=ln(beta()):

ln pdf(f|N,K) = -betaln(K+1,N-K+1) + K ln(f) + (N-K) ln(1-f)

Some useful properties of this posterior PDF are:

Examples

assert(binomialRatePDF(0:0.1:1, 10, 7), [0.000 0.000 0.009 0.099 0.467 1.289 2.365 2.935 2.215 0.631 0.000], 1e-3)
Function File: p = ChiSquare_cdf ( x, k, lambda )

Compute the cumulative density function of the non-central chi^2 distribution.

Arguments

x

value of the non-central chi^2 variable

k

number of degrees of freedom

lambda

non-centrality parameter

Function File: p = ChiSquare_pdf ( x, k, lambda )

Compute the probability density function of the non-central chi^2 distribution.

Arguments

x

value of the non-central chi^2 variable

k

number of degrees of freedom

lambda

non-centrality parameter

Examples

assert(ChiSquare_pdf(10^-2, 10^-2, 1), 0.44224, 1e-3)
assert(ChiSquare_pdf(10^+2, 10^+2, 2), 0.027895, 1e-3)
assert(ChiSquare_pdf(10^10, 10^10, 3), 2.8209e-06, 1e-3)
assert(ChiSquare_pdf(10^30, 10^30, 4), 2.8209e-16, 1e-3)
Function File: y = erfcinv_asym ( X )

Compute the inverse complementary error function, i.e., Y such that

erfc(y) == x

An asymptotic expression is used for small X.

Examples

assert(erfcinv_asym(logspace(-4, -20, 17)), [2.751 3.123 3.459 3.767 4.052 4.320 4.573 4.813 5.042 5.261 5.473 5.676 5.872 6.063 6.247 6.427 6.602], 1e-3)
Function File: [ threshold, pFA_MPE, pFA_Lower, pFA_Upper, threshold_Lower, threshold_Upper ] = estimateFAThreshold ( DATA, pFA, confidence=0.95 )

Compute threshold for desired false-alarm probablity on samples DATA, returns the resulting maximum-posterior estimate pFA_MPE, and confidence interval [pFA_Lower, pFA_Upper]. Also returns the corresponding confidence interval in thresholds [threshold_Lower, threshold_Upper], obtained by simply re-computing threshold on [pFA_Lower, pFA_Upper].

Note

the input pFA is allowed to be a vector, returns corresponding vectors

Examples

assert(estimateFAThreshold(0:1000, 0.1), 900)
assert(estimateFAThreshold(0:1000, 0.5), 500)
assert(estimateFAThreshold(0:1000, 0.9), 100)
Function File: [ fMPE, fE, fLower, fUpper ] = estimateRateFromSamples ( DATA, threshold, confidence )

Compute maximum-posterior rate estimate fMPE and confidence-interval [fLower, fUpper].

This is a simple helper function: estimate the ’rate’ f of threshold-crossings from the samples DATA, namely via K = length( DATA > threshold ), N = length(DATA) The maximum-posteror estimate is fMPE = K/N, and the confidence interval [fLower, fUpper] is given by binomialConfidenceInterval(N,K,confidence)

Note

threshold is allowed to be a vector, returns corresponding rate vectors

Examples

Ntrials = 100;
DATA = octforge_normrnd ( 0, 1, 1, Ntrials );
threshold = linspace ( 0, 1, 10 );
[fMPE0, fLower0, fUpper0] = estimateRateFromSamples ( DATA, threshold, confidence=0.95 );
for i = 1:length(threshold)
   [fMPE1(i), fLower1(i), fUpper1(i)] = estimateRateFromSamples ( DATA, threshold(i), confidence=0.95 );
endfor
assert ( fMPE0 = fMPE1 );
assert ( fLower0 = fLower1 );
assert ( fUpper0 = fUpper1 );
Function File: [ pDet_MPE, pDet_Lower, pDet_Upper, pFA_MPE, pFA_Lower, pFA_Upper ] = estimateROC ( DATA_noise, DATA_signal, pFA, confidence = 0.95 )

Compute the Receiver Operator Characteristic (ROC) function pDet(pFA) on given samples drawn under the noise hypothesis, DATA_noise, and under the signal hypothesis, DATA_signal. Returns estimates for the detection-probability and false-alarm probability for the given DATA samples and a vector of desired false-alarm probabilities pFA.

Note

this function replaces the deprecated estimateFalseDismissal()

Examples

Ntrials_N = 600; Ntrials_S = 300;
stat_S = octforge_normrnd ( 1, 1, 1, Ntrials_S );
stat_N = octforge_normrnd ( 0, 1, 1, Ntrials_N );
pFA = linspace ( 0, 1, 15 );
[pDet_MPE, pDet_Lower, pDet_Upper, pFA_MPE, pFA_Lower, pFA_Upper] = estimateROC ( stat_N, stat_S, pFA, confidence=0.9545 );
mo
Ntrials_N = 600; Ntrials_S = 300;
stat_S = octforge_normrnd ( 1, 1, 1, Ntrials_S );
stat_N = octforge_normrnd ( 0, 1, 1, Ntrials_N );
pFA = linspace ( 0, 1, 15 );
[pFD0, dpDet0] = estimateFalseDismissal ( pFA, stat_N, stat_S );
[pDet_MPE, pDet_Lower, pDet_Upper, pFA_MPE, pFA_Lower, pFA_Upper] = estimateROC ( stat_N, stat_S, pFA, confidence=0.9545 );
figure(1);
set ( 0, "defaultlinemarkersize", 5 );
set ( 0, "defaultaxesfontsize", 15 );
clf; hold on;
hax = errorbar ( pFA, 1 - pFD0, 2*dpDet0, "~x;estimateFalseDismissal();",
                 pFA_MPE, pDet_MPE, (pFA_MPE - pFA_Lower), (pFA_Upper-pFA_MPE), (pDet_MPE - pDet_Lower), (pDet_Upper-pDet_MPE), "#~>or;estimateROC();" );
line ( [0, 1, 1, 0, 0 ], [ 0, 0, 1, 1, 0 ], "linestyle", ":" );
hold off;
set ( hax, "markersize", 10 );
xlim([-0.05, 1.05]); ylim([-0.1, 1.15]);
legend ("location", "northwest" ); legend("boxoff");
xlabel("pFA"); ylabel("pDet");
Function File: fA = falseAlarm_chi2 ( thresh, dof )

compute the false-alarm probability for given threshold thresh’ for a (central) chi-squared distribution with dof degrees-of-freedom

Examples

assert(falseAlarm_chi2([23.513 28.473 33.377 38.442 43.258 48.051 52.827 57.590 62.341 67.082 71.816 76.539 81.257 85.968 90.675 95.376 100.074], 4), logspace(-4, -20, 17), 1e-3)
Function File: fAH = falseAlarm_HoughF ( nth, Nseg, Fth )

compute Hough-on-Fstat false-alarm probability fAH for given number of segments Nseg, a threshold on segment-crossings nth, and an F-statistic threshold per segment Fth. A false-alarm is defined as n >= nth segments crossing the threshold Fth in the absence of a signal

Note

all arguments need to be scalars, use arrayfun() or cellfun() to iterate thisover vectors of arguments

Examples

assert(falseAlarm_HoughF(11, 100, 5.5), 7.5e-05, 1e-3)
assert(falseAlarm_HoughF(18, 100, 5.5), 1.7e-10, 1e-3)
Function File: fDH = falseDismissal_HoughF ( nth, Nseg, Fth, SNR0sq )

compute Hough-on-Fstat false-dismissal probability fDH for given number of segments Nseg, a threshold on segment-crossings nth, an F-statistic threshold per segment Fth, and the optimal signal SNR^2 per segment SNR0sq, which is assumed constant across all segments.

A false-dismissal is defined as n < nth segments crossing the threshold Fth in the presence of a signal

Note

all arguments need to be scalars, use arrayfun() or cellfun() to iterate thisover vectors of arguments

Examples

assert(falseDismissal_HoughF(11, 100, 5.5, 2.2), 0.303, 1e-3)
assert(falseDismissal_HoughF(18, 100, 5.5, 2.2), 0.939, 1e-3)
Function File: thresh = invFalseAlarm_chi2 ( fA, dof )

compute the threshold on a central chi^2 distribution with dof degrees of freedom, corresponding to a false-alarm probability of fA

Examples

assert(invFalseAlarm_chi2(logspace(-4, -20, 17), 4), [23.513 28.473 33.377 38.442 43.258 48.051 52.827 57.590 62.341 67.082 71.816 76.539 81.257 85.968 90.675 95.376 100.074], 1e-3)
Function File: sa = invFalseAlarm_chi2_asym ( pa, k )

Calculate the threshold of a central chi^2 distribution which gives a certain false alarm probability. Uses an analytic, asymptotic inversion of the chi^2 CDF that is accurate for very small false alarm probabilities and very large degrees of freedom.

Arguments

sa

threshold

pa

false alarm probability

k

degrees of freedom of the chi^2 distribution

Examples

assert(invFalseAlarm_chi2_asym(logspace(-4, -20, 17), 4), [23.467 28.411 33.557 38.442 43.258 48.051 52.827 57.590 62.341 67.082 71.816 76.539 81.257 85.968 90.675 95.376 100.074], 1e-3)
Function File: [ nth, fAH ] = invFalseAlarm_HoughF ( fAH, Nseg, Fth )

’invert’ false-alarm function to obtain discrete numer-count threshold nth which comes closest to the desired false-alarm probability fAH0 for Hough-on-Fstat, for given number of segments Nseg, and an F-statistic threshold per segment Fth. A false-alarm is defined as n >= nth segments crossing the threshold Fth in the absence of a signal

returns nth and corresponding actual false-alarm probability fAH

Note

all arguments need to be scalars, use arrayfun() or cellfun() to iterate thisover vectors of arguments

Examples

assert(invFalseAlarm_HoughF(1e-4, 100, 5.5), 11)
assert(invFalseAlarm_HoughF(1e-10, 100, 5.5), 18)
Function File: [ bandwidth, density, xmesh ] = kde ( data, n, MIN, MAX )

Reliable and extremely fast kernel density estimator for one-dimensional data; Gaussian kernel is assumed and the bandwidth is chosen automatically; Unlike many other implementations, this one is immune to problems caused by multimodal densities with widely separated modes (see example). The estimation does not deteriorate for multimodal densities, because we never assume a parametric model for the data.

Inputs

data

a vector of data from which the density estimate is constructed;

n

the number of mesh points used in the uniform discretization of the interval [MIN, MAX]; n has to be a power of two; if n is not a power of two, then n is rounded up to the next power of two, i.e., n is set to n = 2^ceil(log2(n)); the default value of n is n = 2^12;

MIN
MAX

defines the interval [MIN,MAX] on which the density estimate is constructed; the default values of MIN and MAX are: MIN = min(data)-Range/10 and MAX = max(data)+Range/10, where Range=max(data)-min(data);

Outputs

bandwidth

the optimal bandwidth (Gaussian kernel assumed);

density

column vector of length n with the values of the density estimate at the grid points;

xmesh

the grid over which the density estimate is computed; if no output is requested, then the code automatically plots a graph of the density estimate.

Reference

Please cite in your work:

Z. I. Botev, J. F. Grotowski and D. P. Kroese "Kernel Density Estimation Via Diffusion", Annals of Statistics, 2010, to appear [Download from: http://www.maths.uq.edu.au/~kroese/ps/AOS799.pdf]

Example

data=[randn(100,1);randn(100,1)*2+35 ;randn(100,1)+55];
kde(data,2^14,min(data)-5,max(data)+5);
Function File: function p ( x ) = maxChi2FromNdraws_pdf ( x, Ndraws, dof = 4 )

Probability density (pdf) for the maximum out of Ndraws independent draws from a (central) chi2 distribution with dof degrees of freedom.

Return p(x): pdf over (vector of) maxChi2 statistics values x

Examples

max2F = linspace ( 30, 60, 100 );
p = maxChi2FromNdraws_pdf ( max2F, 2e7, dof=4 );
dFmax = mean(diff(max2F));
Emax2F = sum ( max2F .* p ) * dFmax;
assert ( Emax2F, 40.901, -1e-3 );    ## 1e-3 relative tolerance
Function File: p = maxStatFromNdraws_pdf ( x, Ndraws, statHgrm )

Probability density (pdf) for the maximum out of Ndraws independent draws from an arbitrary statistic, defined via its empirical probability density statHgrm as a histogram object.

Return p(x): pdf over (vector of) max(Statistic) statistics values x

Examples

Ndraws = 1e3;
twoF = linspace ( 10, 40, 100 );
pdf0 = maxChi2FromNdraws_pdf ( twoF, Ndraws, dof=4 );
hgrm = Hist ( 1, {"lin", "dbin", 0.05, "bin0", 0 } );
F = @(x) octforge_chi2pdf(x, 4);
hgrm = initHistFromFunc(hgrm, F, [0, 50] );
pdf1 = maxStatFromNdraws_pdf ( twoF, Ndraws, hgrm );
relerr = max ( abs ( pdf0 - pdf1 ) ./ pdf0 );
assert ( relerr < 2e-3 );
Function File: y = meanNaN ( x, dim )

Compute the mean of x over the dimension dim, ignoring NaNs.

Examples

assert(meanNaN([1:5, NaN, 6:10]), mean(1:10))
Function File: [ NN, XX ] = normHist ( data, bins )

compute a pdf-normalized histogram (i.e. the *integral* is 1)

With one vector input argument, plot a histogram of the values with 10 bins. The range of the histogram bins is determined by the range of the data. With one matrix input argument, plot a histogram where each bin contains a bar per input column.

Given a second scalar argument, use that as the number of bins.

Given a second vector argument, use that as the centers of the bins, with the width of the bins determined from the adjacent values in the vector.

Examples

assert(normHist(0:0.001:100), 0.011 * ones(1, 10), 1e-3)
: octforge_chi2cdf (x, n)

For each element of x, compute the cumulative distribution function (CDF) at x of the chi-square distribution with n degrees of freedom.

Examples

x = [-1 0 0.5 1 2];
y = [0, 1 - exp(-x(2:end)/2)];
ssert (octforge_chi2cdf (x, 2*ones (1,5)), y, eps)
ssert (octforge_chi2cdf (x, 2), y, eps)
ssert (octforge_chi2cdf (x, 2*[1 0 NaN 1 1]), [y(1) NaN NaN y(4:5)], eps)
ssert (octforge_chi2cdf ([x(1:2) NaN x(4:5)], 2), [y(1:2) NaN y(4:5)], eps)
assert (octforge_chi2cdf ([x, NaN], 2), [y, NaN], eps)
assert (octforge_chi2cdf (single ([x, NaN]), 2), single ([y, NaN]), eps ("single"))
assert (octforge_chi2cdf ([x, NaN], single (2)), single ([y, NaN]), eps ("single"))
: octforge_chi2inv (x, n)

For each element of x, compute the quantile (the inverse of the CDF) at x of the chi-square distribution with n degrees of freedom.

Examples

x = [-1 0 0.3934693402873666 1 2];
ssert (octforge_chi2inv (x, 2*ones (1,5)), [NaN 0 1 Inf NaN], 5*eps)
ssert (octforge_chi2inv (x, 2), [NaN 0 1 Inf NaN], 5*eps)
ssert (octforge_chi2inv (x, 2*[0 1 NaN 1 1]), [NaN 0 NaN Inf NaN], 5*eps)
ssert (octforge_chi2inv ([x(1:2) NaN x(4:5)], 2), [NaN 0 NaN Inf NaN], 5*eps)
assert (octforge_chi2inv ([x, NaN], 2), [NaN 0 1 Inf NaN NaN], 5*eps)
assert (octforge_chi2inv (single ([x, NaN]), 2), single ([NaN 0 1 Inf NaN NaN]), 5*eps ("single"))
assert (octforge_chi2inv ([x, NaN], single (2)), single ([NaN 0 1 Inf NaN NaN]), 5*eps ("single"))
: octforge_chi2pdf (x, n)

For each element of x, compute the probability density function (PDF) at x of the chi-square distribution with n degrees of freedom.

Examples

x = [-1 0 0.5 1 Inf];
y = [0, 1/2 * exp(-x(2:5)/2)];
ssert (octforge_chi2pdf (x, 2*ones (1,5)), y)
ssert (octforge_chi2pdf (x, 2), y)
ssert (octforge_chi2pdf (x, 2*[1 0 NaN 1 1]), [y(1) NaN NaN y(4:5)])
ssert (octforge_chi2pdf ([x, NaN], 2), [y, NaN])
assert (octforge_chi2pdf (single ([x, NaN]), 2), single ([y, NaN]))
assert (octforge_chi2pdf ([x, NaN], single (2)), single ([y, NaN]))
: octforge_chi2rnd (n)
: octforge_chi2rnd (n, r)
: octforge_chi2rnd (n, r, c, …)
: octforge_chi2rnd (n, [sz])

Return a matrix of random samples from the chi-square distribution with n degrees of freedom.

When called with a single size argument, return a square matrix with the dimension specified. When called with more than one scalar argument the first two arguments are taken as the number of rows and columns and any further arguments specify additional matrix dimensions. The size may also be specified with a vector of dimensions sz.

If no size arguments are given then the result matrix is the size of n.

Examples

assert (size (octforge_chi2rnd (2)), [1, 1])
assert (size (octforge_chi2rnd (ones (2,1))), [2, 1])
assert (size (octforge_chi2rnd (ones (2,2))), [2, 2])
assert (size (octforge_chi2rnd (1, 3)), [3, 3])
assert (size (octforge_chi2rnd (1, [4 1])), [4, 1])
assert (size (octforge_chi2rnd (1, 4, 1)), [4, 1])
assert (class (octforge_chi2rnd (2)), "double")
assert (class (octforge_chi2rnd (single (2))), "single")
assert (class (octforge_chi2rnd (single ([2 2]))), "single")
: octforge_gamcdf (x, a, b)

For each element of x, compute the cumulative distribution function (CDF) at x of the Gamma distribution with shape parameter a and scale b.

Examples

x = [-1 0 0.5 1 2 Inf];
y = [0, gammainc(x(2:end), 1)];
ssert (octforge_gamcdf (x, ones (1,6), ones (1,6)), y)
ssert (octforge_gamcdf (x, 1, ones (1,6)), y)
ssert (octforge_gamcdf (x, ones (1,6), 1), y)
ssert (octforge_gamcdf (x, [0 -Inf NaN Inf 1 1], 1), [NaN NaN NaN NaN y(5:6)])
ssert (octforge_gamcdf (x, 1, [0 -Inf NaN Inf 1 1]), [NaN NaN NaN NaN y(5:6)])
ssert (octforge_gamcdf ([x(1:2) NaN x(4:6)], 1, 1), [y(1:2) NaN y(4:6)])
assert (octforge_gamcdf ([x, NaN], 1, 1), [y, NaN])
assert (octforge_gamcdf (single ([x, NaN]), 1, 1), single ([y, NaN]), eps ("single"))
: octforge_gaminv (x, a, b)

For each element of x, compute the quantile (the inverse of the CDF) at x of the Gamma distribution with shape parameter a and scale b.

Examples

x = [-1 0 0.63212055882855778 1 2];
ssert (octforge_gaminv (x, ones (1,5), ones (1,5)), [NaN 0 1 Inf NaN], eps)
ssert (octforge_gaminv (x, 1, ones (1,5)), [NaN 0 1 Inf NaN], eps)
ssert (octforge_gaminv (x, ones (1,5), 1), [NaN 0 1 Inf NaN], eps)
ssert (octforge_gaminv (x, [1 -Inf NaN Inf 1], 1), [NaN NaN NaN NaN NaN])
ssert (octforge_gaminv (x, 1, [1 -Inf NaN Inf 1]), [NaN NaN NaN NaN NaN])
ssert (octforge_gaminv ([x(1:2) NaN x(4:5)], 1, 1), [NaN 0 NaN Inf NaN])
assert (octforge_gaminv ([x, NaN], 1, 1), [NaN 0 1 Inf NaN NaN], eps)
assert (octforge_gaminv (single ([x, NaN]), 1, 1), single ([NaN 0 1 Inf NaN NaN]), eps ("single"))
assert (octforge_gaminv ([x, NaN], single (1), 1), single ([NaN 0 1 Inf NaN NaN]), eps ("single"))
assert (octforge_gaminv ([x, NaN], 1, single (1)), single ([NaN 0 1 Inf NaN NaN]), eps ("single"))
: octforge_gampdf (x, a, b)

For each element of x, return the probability density function (PDF) at x of the Gamma distribution with shape parameter a and scale b.

Examples

x = [-1 0 0.5 1 Inf];
y = [0 exp(-x(2:end))];
ssert (octforge_gampdf (x, ones (1,5), ones (1,5)), y)
ssert (octforge_gampdf (x, 1, ones (1,5)), y)
ssert (octforge_gampdf (x, ones (1,5), 1), y)
ssert (octforge_gampdf (x, [0 -Inf NaN Inf 1], 1), [NaN NaN NaN NaN y(5)])
ssert (octforge_gampdf (x, 1, [0 -Inf NaN Inf 1]), [NaN NaN NaN 0 y(5)])
ssert (octforge_gampdf ([x, NaN], 1, 1), [y, NaN])
assert (octforge_gampdf (single ([x, NaN]), 1, 1), single ([y, NaN]))
assert (octforge_gampdf ([x, NaN], single (1), 1), single ([y, NaN]))
assert (octforge_gampdf ([x, NaN], 1, single (1)), single ([y, NaN]))
: octforge_gamrnd (a, b)
: octforge_gamrnd (a, b, r)
: octforge_gamrnd (a, b, r, c, …)
: octforge_gamrnd (a, b, [sz])

Return a matrix of random samples from the Gamma distribution with shape parameter a and scale b.

When called with a single size argument, return a square matrix with the dimension specified. When called with more than one scalar argument the first two arguments are taken as the number of rows and columns and any further arguments specify additional matrix dimensions. The size may also be specified with a vector of dimensions sz.

If no size arguments are given then the result matrix is the common size of a and b.

Examples

assert (size (octforge_gamrnd (1,2)), [1, 1])
assert (size (octforge_gamrnd (ones (2,1), 2)), [2, 1])
assert (size (octforge_gamrnd (ones (2,2), 2)), [2, 2])
assert (size (octforge_gamrnd (1, 2*ones (2,1))), [2, 1])
assert (size (octforge_gamrnd (1, 2*ones (2,2))), [2, 2])
assert (size (octforge_gamrnd (1, 2, 3)), [3, 3])
assert (size (octforge_gamrnd (1, 2, [4 1])), [4, 1])
assert (size (octforge_gamrnd (1, 2, 4, 1)), [4, 1])
assert (class (octforge_gamrnd (1, 2)), "double")
assert (class (octforge_gamrnd (single (1), 2)), "single")
assert (class (octforge_gamrnd (single ([1 1]), 2)), "single")
assert (class (octforge_gamrnd (1, single (2))), "single")
assert (class (octforge_gamrnd (1, single ([2 2]))), "single")
: octforge_normcdf (x)
: octforge_normcdf (x, mu, sigma)

For each element of x, compute the cumulative distribution function (CDF) at x of the normal distribution with mean mu and standard deviation sigma.

Default values are mu = 0, sigma = 1.

Examples

x = [-Inf 1 2 Inf];
y = [0, 0.5, 1/2*(1+erf(1/sqrt(2))), 1];
ssert (octforge_normcdf (x, ones (1,4), ones (1,4)), y)
ssert (octforge_normcdf (x, 1, ones (1,4)), y)
ssert (octforge_normcdf (x, ones (1,4), 1), y)
ssert (octforge_normcdf (x, [0 -Inf NaN Inf], 1), [y(1) NaN NaN NaN])
ssert (octforge_normcdf (x, 1, [Inf NaN -1 0]), [NaN NaN NaN NaN])
ssert (octforge_normcdf ([x(1:2) NaN x(4)], 1, 1), [y(1:2) NaN y(4)])
assert (octforge_normcdf ([x, NaN], 1, 1), [y, NaN])
assert (octforge_normcdf (single ([x, NaN]), 1, 1), single ([y, NaN]), eps ("single"))
assert (octforge_normcdf ([x, NaN], single (1), 1), single ([y, NaN]), eps ("single"))
assert (octforge_normcdf ([x, NaN], 1, single (1)), single ([y, NaN]), eps ("single"))
: octforge_norminv (x)
: octforge_norminv (x, mu, sigma)

For each element of x, compute the quantile (the inverse of the CDF) at x of the normal distribution with mean mu and standard deviation sigma.

Default values are mu = 0, sigma = 1.

Examples

x = [-1 0 0.5 1 2];
ssert (octforge_norminv (x, ones (1,5), ones (1,5)), [NaN -Inf 1 Inf NaN])
ssert (octforge_norminv (x, 1, ones (1,5)), [NaN -Inf 1 Inf NaN])
ssert (octforge_norminv (x, ones (1,5), 1), [NaN -Inf 1 Inf NaN])
ssert (octforge_norminv (x, [1 -Inf NaN Inf 1], 1), [NaN NaN NaN NaN NaN])
ssert (octforge_norminv (x, 1, [1 0 NaN Inf 1]), [NaN NaN NaN NaN NaN])
ssert (octforge_norminv ([x(1:2) NaN x(4:5)], 1, 1), [NaN -Inf NaN Inf NaN])
assert (octforge_norminv ([x, NaN], 1, 1), [NaN -Inf 1 Inf NaN NaN])
assert (octforge_norminv (single ([x, NaN]), 1, 1), single ([NaN -Inf 1 Inf NaN NaN]))
assert (octforge_norminv ([x, NaN], single (1), 1), single ([NaN -Inf 1 Inf NaN NaN]))
assert (octforge_norminv ([x, NaN], 1, single (1)), single ([NaN -Inf 1 Inf NaN NaN]))
: octforge_normpdf (x)
: octforge_normpdf (x, mu, sigma)

For each element of x, compute the probability density function (PDF) at x of the normal distribution with mean mu and standard deviation sigma.

Default values are mu = 0, sigma = 1.

Examples

x = [-Inf 1 2 Inf];
y = 1/sqrt(2*pi)*exp (-(x-1).^2/2);
ssert (octforge_normpdf (x, ones (1,4), ones (1,4)), y, eps)
ssert (octforge_normpdf (x, 1, ones (1,4)), y, eps)
ssert (octforge_normpdf (x, ones (1,4), 1), y, eps)
ssert (octforge_normpdf (x, [0 -Inf NaN Inf], 1), [y(1) NaN NaN NaN], eps)
ssert (octforge_normpdf (x, 1, [Inf NaN -1 0]), [NaN NaN NaN NaN], eps)
ssert (octforge_normpdf ([x, NaN], 1, 1), [y, NaN], eps)
assert (octforge_normpdf (single ([x, NaN]), 1, 1), single ([y, NaN]), eps ("single"))
assert (octforge_normpdf ([x, NaN], single (1), 1), single ([y, NaN]), eps ("single"))
assert (octforge_normpdf ([x, NaN], 1, single (1)), single ([y, NaN]), eps ("single"))
: octforge_normrnd (mu, sigma)
: octforge_normrnd (mu, sigma, r)
: octforge_normrnd (mu, sigma, r, c, …)
: octforge_normrnd (mu, sigma, [sz])

Return a matrix of random samples from the normal distribution with parameters mean mu and standard deviation sigma.

When called with a single size argument, return a square matrix with the dimension specified. When called with more than one scalar argument the first two arguments are taken as the number of rows and columns and any further arguments specify additional matrix dimensions. The size may also be specified with a vector of dimensions sz.

If no size arguments are given then the result matrix is the common size of mu and sigma.

Examples

assert (size (octforge_normrnd (1,2)), [1, 1])
assert (size (octforge_normrnd (ones (2,1), 2)), [2, 1])
assert (size (octforge_normrnd (ones (2,2), 2)), [2, 2])
assert (size (octforge_normrnd (1, 2*ones (2,1))), [2, 1])
assert (size (octforge_normrnd (1, 2*ones (2,2))), [2, 2])
assert (size (octforge_normrnd (1, 2, 3)), [3, 3])
assert (size (octforge_normrnd (1, 2, [4 1])), [4, 1])
assert (size (octforge_normrnd (1, 2, 4, 1)), [4, 1])
assert (class (octforge_normrnd (1, 2)), "double")
assert (class (octforge_normrnd (single (1), 2)), "single")
assert (class (octforge_normrnd (single ([1 1]), 2)), "single")
assert (class (octforge_normrnd (1, single (2))), "single")
assert (class (octforge_normrnd (1, single ([2 2]))), "single")
: octforge_stdnormal_cdf (x)

For each element of x, compute the cumulative distribution function (CDF) at x of the standard normal distribution (mean = 0, standard deviation = 1).

Examples

x = [-Inf 0 1 Inf];
y = [0, 0.5, 1/2*(1+erf(1/sqrt(2))), 1];
ssert (octforge_stdnormal_cdf ([x, NaN]), [y, NaN])
assert (octforge_stdnormal_cdf (single ([x, NaN])), single ([y, NaN]), eps ("single"))
: octforge_stdnormal_inv (x)

For each element of x, compute the quantile (the inverse of the CDF) at x of the standard normal distribution (mean = 0, standard deviation = 1).

Examples

x = [-1 0 0.5 1 2];
ssert (octforge_stdnormal_inv (x), [NaN -Inf 0 Inf NaN])
assert (octforge_stdnormal_inv ([x, NaN]), [NaN -Inf 0 Inf NaN NaN])
assert (octforge_stdnormal_inv (single ([x, NaN])), single ([NaN -Inf 0 Inf NaN NaN]))
: octforge_stdnormal_pdf (x)

For each element of x, compute the probability density function (PDF) at x of the standard normal distribution (mean = 0, standard deviation = 1).

Examples

x = [-Inf 0 1 Inf];
y = 1/sqrt(2*pi)*exp (-x.^2/2);
ssert (octforge_stdnormal_pdf ([x, NaN]), [y, NaN], eps)
assert (octforge_stdnormal_pdf (single ([x, NaN])), single ([y, NaN]), eps ("single"))
: octforge_stdnormal_rnd (r)
: octforge_stdnormal_rnd (r, c, …)
: octforge_stdnormal_rnd ([sz])

Return a matrix of random samples from the standard normal distribution (mean = 0, standard deviation = 1).

When called with a single size argument, return a square matrix with the dimension specified. When called with more than one scalar argument the first two arguments are taken as the number of rows and columns and any further arguments specify additional matrix dimensions. The size may also be specified with a vector of dimensions sz.

Examples

assert (size (octforge_stdnormal_rnd (3)), [3, 3])
assert (size (octforge_stdnormal_rnd ([4 1])), [4, 1])
assert (size (octforge_stdnormal_rnd (4,1)), [4, 1])
: octforge_unifrnd (a, b)
: octforge_unifrnd (a, b, r)
: octforge_unifrnd (a, b, r, c, …)
: octforge_unifrnd (a, b, [sz])

Return a matrix of random samples from the uniform distribution on [a, b].

When called with a single size argument, return a square matrix with the dimension specified. When called with more than one scalar argument the first two arguments are taken as the number of rows and columns and any further arguments specify additional matrix dimensions. The size may also be specified with a vector of dimensions sz.

If no size arguments are given then the result matrix is the common size of a and b.

Examples

assert (size (octforge_unifrnd (1,2)), [1, 1])
assert (size (octforge_unifrnd (ones (2,1), 2)), [2, 1])
assert (size (octforge_unifrnd (ones (2,2), 2)), [2, 2])
assert (size (octforge_unifrnd (1, 2*ones (2,1))), [2, 1])
assert (size (octforge_unifrnd (1, 2*ones (2,2))), [2, 2])
assert (size (octforge_unifrnd (1, 2, 3)), [3, 3])
assert (size (octforge_unifrnd (1, 2, [4 1])), [4, 1])
assert (size (octforge_unifrnd (1, 2, 4, 1)), [4, 1])
assert (class (octforge_unifrnd (1, 2)), "double")
assert (class (octforge_unifrnd (single (1), 2)), "single")
assert (class (octforge_unifrnd (single ([1 1]), 2)), "single")
assert (class (octforge_unifrnd (1, single (2))), "single")
assert (class (octforge_unifrnd (1, single ([2 2]))), "single")
assert (octforge_unifrnd (0,0), 0)
assert (octforge_unifrnd (1,1), 1)
assert (octforge_unifrnd (1,0), NaN)
Function File: ret = pickFromRange ( range, [ num ] )

function to return a number of random-values (specified by the optional argument num, default is 1. Return is a column-vector) from within ’range’, which can be a single number, or a vector with [min, max] entries

Examples

pickFromRange([10,20],5);
Function File: p = randPointInNSphere ( n, u )

Generate random points (with)in a n-dimensional sphere

Arguments

n

dimensionality of sphere

u

vector of numbers used to chose the radius; set

u = rand(1, m)

to generate m points uniformly within the sphere, or

u = ones(1, m)

to generate m points uniformly over the sphere’s surface

Examples

assert(norm(randPointInNSphere(1, 1)), 1.0, 1e-4)
assert(norm(randPointInNSphere(2, 1)), 1.0, 1e-4)
assert(norm(randPointInNSphere(3, 1)), 1.0, 1e-4)
assert(norm(randPointInNSphere(4, 1)), 1.0, 1e-4)
assert(norm(randPointInNSphere(5, 1)), 1.0, 1e-4)
Function File: ret = rngmed ( data, window )

return a ’smoothed’ vector using a running-median of the given window-size. output-vector has same number of entries, with window/2 bins at the borders filled with identical values

Note

this is the most ’naive’ implementation, not optimized at all!

Examples

assert(rngmed(1:10, 3), [1.5 2.0 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.0])

Next: , Previous: , Up: Directory Index   [Contents][Index]