annotate scripts/statistics/distributions/logistic_rnd.m @ 19697:4197fc428c7d

maint: Update copyright notices for 2015.
author John W. Eaton <jwe@octave.org>
date Wed, 11 Feb 2015 14:19:08 -0500
parents d63878346099
children 9fc020886ae9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 13171
diff changeset
1 ## Copyright (C) 2012 Rik Wehbring
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
2 ## Copyright (C) 1995-2015 Kurt Hornik
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3191
diff changeset
3 ##
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3457
diff changeset
4 ## This file is part of Octave.
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3457
diff changeset
5 ##
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3457
diff changeset
6 ## Octave is free software; you can redistribute it and/or modify it
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3457
diff changeset
7 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7007
diff changeset
8 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7007
diff changeset
9 ## your option) any later version.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3191
diff changeset
10 ##
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3457
diff changeset
11 ## Octave is distributed in the hope that it will be useful, but
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3191
diff changeset
14 ## General Public License for more details.
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3191
diff changeset
15 ##
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
16 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7007
diff changeset
17 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7007
diff changeset
18 ## <http://www.gnu.org/licenses/>.
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
19
3456
434790acb067 [project @ 2000-01-19 06:58:51 by jwe]
jwe
parents: 3426
diff changeset
20 ## -*- texinfo -*-
13171
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
21 ## @deftypefn {Function File} {} logistic_rnd (@var{r})
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
22 ## @deftypefnx {Function File} {} logistic_rnd (@var{r}, @var{c}, @dots{})
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
23 ## @deftypefnx {Function File} {} logistic_rnd ([@var{sz}])
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
24 ## Return a matrix of random samples from the logistic distribution.
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
25 ##
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
26 ## When called with a single size argument, return a square matrix with
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
27 ## the dimension specified. When called with more than one scalar argument the
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
28 ## first two arguments are taken as the number of rows and columns and any
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
29 ## further arguments specify additional matrix dimensions. The size may also
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
30 ## be specified with a vector of dimensions @var{sz}.
3456
434790acb067 [project @ 2000-01-19 06:58:51 by jwe]
jwe
parents: 3426
diff changeset
31 ## @end deftypefn
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3191
diff changeset
32
5428
2a16423e4aa0 [project @ 2005-08-23 18:38:27 by jwe]
jwe
parents: 5307
diff changeset
33 ## Author: KH <Kurt.Hornik@wu-wien.ac.at>
3456
434790acb067 [project @ 2000-01-19 06:58:51 by jwe]
jwe
parents: 3426
diff changeset
34 ## Description: Random deviates from the logistic distribution
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
35
13171
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
36 function rnd = logistic_rnd (varargin)
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3191
diff changeset
37
13171
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
38 if (nargin < 1)
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
39 print_usage ();
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
40 endif
4859
265d566cc770 [project @ 2004-04-08 23:52:45 by jwe]
jwe
parents: 4030
diff changeset
41
13171
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
42 if (nargin == 1)
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
43 if (isscalar (varargin{1}) && varargin{1} >= 0)
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
44 sz = [varargin{1}, varargin{1}];
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
45 elseif (isrow (varargin{1}) && all (varargin{1} >= 0))
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
46 sz = varargin{1};
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
47 else
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
48 error ("logistic_rnd: dimension vector must be row vector of non-negative integers");
4859
265d566cc770 [project @ 2004-04-08 23:52:45 by jwe]
jwe
parents: 4030
diff changeset
49 endif
13171
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
50 elseif (nargin > 1)
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
51 if (any (cellfun (@(x) (!isscalar (x) || x < 0), varargin)))
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
52 error ("logistic_rnd: dimensions must be non-negative integers");
4859
265d566cc770 [project @ 2004-04-08 23:52:45 by jwe]
jwe
parents: 4030
diff changeset
53 endif
13171
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
54 sz = [varargin{:}];
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
55 endif
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
56
4859
265d566cc770 [project @ 2004-04-08 23:52:45 by jwe]
jwe
parents: 4030
diff changeset
57 rnd = - log (1 ./ rand (sz) - 1);
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3191
diff changeset
58
3191
e4f4b2d26ee9 [project @ 1998-10-23 05:43:59 by jwe]
jwe
parents:
diff changeset
59 endfunction
13171
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
60
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
61
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
62 %!assert (size (logistic_rnd (3)), [3, 3])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
63 %!assert (size (logistic_rnd ([4 1])), [4, 1])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
64 %!assert (size (logistic_rnd (4,1)), [4, 1])
13171
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
65
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
66 %% Test input validation
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
67 %!error logistic_rnd ()
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
68 %!error logistic_rnd (-1)
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
69 %!error logistic_rnd (ones (2))
13171
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
70 %!error logistic_rnd ([2 -1 2])
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
71 %!error logistic_rnd (1, ones (2))
13171
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
72 %!error logistic_rnd (1, -1)
19b9f17d22af Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
73