7017
|
1 ## Copyright (C) 1995, 1996, 1997, 1998, 2000, 2002, 2004, 2005, 2006, |
|
2 ## 2007 Kurt Hornik |
3426
|
3 ## |
3922
|
4 ## This file is part of Octave. |
|
5 ## |
|
6 ## Octave is free software; you can redistribute it and/or modify it |
|
7 ## under the terms of the GNU General Public License as published by |
7016
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
|
9 ## your option) any later version. |
3426
|
10 ## |
3922
|
11 ## Octave is distributed in the hope that it will be useful, but |
3191
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3426
|
14 ## General Public License for more details. |
|
15 ## |
3191
|
16 ## You should have received a copy of the GNU General Public License |
7016
|
17 ## along with Octave; see the file COPYING. If not, see |
|
18 ## <http://www.gnu.org/licenses/>. |
3191
|
19 |
3456
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} logistic_rnd (@var{r}, @var{c}) |
4862
|
22 ## @deftypefnx {Function File} {} logistic_rnd (@var{sz}) |
3456
|
23 ## Return an @var{r} by @var{c} matrix of random numbers from the |
5457
|
24 ## logistic distribution. Or if @var{sz} is a vector, create a matrix of |
4859
|
25 ## @var{sz}. |
3456
|
26 ## @end deftypefn |
3426
|
27 |
5428
|
28 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
3456
|
29 ## Description: Random deviates from the logistic distribution |
3191
|
30 |
|
31 function rnd = logistic_rnd (r, c) |
3426
|
32 |
4859
|
33 |
|
34 if (nargin == 2) |
|
35 if (! (isscalar (r) && (r > 0) && (r == round (r)))) |
|
36 error ("logistic_rnd: r must be a positive integer"); |
|
37 endif |
|
38 if (! (isscalar (c) && (c > 0) && (c == round (c)))) |
|
39 error ("logistic_rnd: c must be a positive integer"); |
|
40 endif |
|
41 sz = [r, c]; |
|
42 elseif (nargin == 1) |
|
43 if (isscalar (r) && (r > 0)) |
|
44 sz = [r, r]; |
|
45 elseif (isvector(r) && all (r > 0)) |
|
46 sz = r(:)'; |
|
47 else |
7007
|
48 error ("logistic_rnd: r must be a positive integer or vector"); |
4859
|
49 endif |
|
50 else |
6046
|
51 print_usage (); |
3191
|
52 endif |
|
53 |
4859
|
54 rnd = - log (1 ./ rand (sz) - 1); |
3426
|
55 |
3191
|
56 endfunction |