Mercurial > hg > octave-lyh
annotate scripts/statistics/distributions/kolmogorov_smirnov_cdf.m @ 11523:fd0a3ac60b0e
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 14 Jan 2011 05:47:45 -0500 |
parents | 1740012184f9 |
children | 19b9f17d22af |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1995-2011 Kurt Hornik |
3426 | 2 ## |
3922 | 3 ## This file is part of Octave. |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
3426 | 9 ## |
3922 | 10 ## Octave is distributed in the hope that it will be useful, but |
3191 | 11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
3426 | 13 ## General Public License for more details. |
14 ## | |
3191 | 15 ## You should have received a copy of the GNU General Public License |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
3191 | 18 |
3456 | 19 ## -*- texinfo -*- |
20 ## @deftypefn {Function File} {} kolmogorov_smirnov_cdf (@var{x}, @var{tol}) | |
21 ## Return the CDF at @var{x} of the Kolmogorov-Smirnov distribution, | |
22 ## @tex | |
6754 | 23 ## $$ Q(x) = \sum_{k=-\infty}^\infty (-1)^k \exp(-2 k^2 x^2) $$ |
3456 | 24 ## @end tex |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7795
diff
changeset
|
25 ## @ifnottex |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
26 ## |
3456 | 27 ## @example |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
28 ## @group |
3456 | 29 ## Inf |
30 ## Q(x) = SUM (-1)^k exp(-2 k^2 x^2) | |
31 ## k = -Inf | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
32 ## @end group |
3456 | 33 ## @end example |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
34 ## |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7795
diff
changeset
|
35 ## @end ifnottex |
3456 | 36 ## @noindent |
37 ## for @var{x} > 0. | |
38 ## | |
39 ## The optional parameter @var{tol} specifies the precision up to which | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
40 ## the series should be evaluated; the default is @var{tol} = @code{eps}. |
3456 | 41 ## @end deftypefn |
3426 | 42 |
5428 | 43 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
3456 | 44 ## Description: CDF of the Kolmogorov-Smirnov distribution |
3191 | 45 |
46 function cdf = kolmogorov_smirnov_cdf (x, tol) | |
3426 | 47 |
3191 | 48 if (nargin < 1 || nargin > 2) |
6046 | 49 print_usage (); |
3191 | 50 endif |
51 | |
52 if (nargin == 1) | |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
53 if (isa (x, "single")) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
54 tol = eps ("single"); |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
55 else |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
56 tol = eps; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
57 endif |
3426 | 58 else |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
9211
diff
changeset
|
59 if (! (isscalar (tol) && (tol > 0))) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
60 error ("kolmogorov_smirnov_cdf: TOL must be a positive scalar"); |
3191 | 61 endif |
62 endif | |
63 | |
4859 | 64 n = numel (x); |
65 if (n == 0) | |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
9211
diff
changeset
|
66 error ("kolmogorov_smirnov_cdf: X must not be empty"); |
3191 | 67 endif |
68 | |
4859 | 69 cdf = zeros (size (x)); |
70 | |
3191 | 71 ind = find (x > 0); |
72 if (length (ind) > 0) | |
4859 | 73 if (size(ind,2) < size(ind,1)) |
74 y = x(ind.'); | |
75 else | |
76 y = x(ind); | |
77 endif | |
3457 | 78 K = ceil (sqrt (- log (tol) / 2) / min (y)); |
3191 | 79 k = (1:K)'; |
3457 | 80 A = exp (- 2 * k.^2 * y.^2); |
3191 | 81 odd = find (rem (k, 2) == 1); |
3457 | 82 A(odd,:) = -A(odd,:); |
3191 | 83 cdf(ind) = 1 + 2 * sum (A); |
84 endif | |
85 | |
86 endfunction |