Mercurial > octave-nkf
annotate scripts/statistics/distributions/lognpdf.m @ 11472:1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 09 Jan 2011 21:33:04 -0800 |
parents | a1dbe9d80eee |
children | fd0a3ac60b0e |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1995, 1996, 1997, 2005, 2006, 2007 Kurt Hornik |
5410 | 2 ## |
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. | |
5410 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
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/>. | |
5410 | 18 |
19 ## -*- texinfo -*- | |
5692 | 20 ## @deftypefn {Function File} {} lognpdf (@var{x}, @var{mu}, @var{sigma}) |
5410 | 21 ## For each element of @var{x}, compute the probability density function |
22 ## (PDF) at @var{x} of the lognormal distribution with parameters | |
5692 | 23 ## @var{mu} and @var{sigma}. If a random variable follows this distribution, |
24 ## its logarithm is normally distributed with mean @var{mu} | |
25 ## and standard deviation @var{sigma}. | |
5410 | 26 ## |
5692 | 27 ## Default values are @var{mu} = 1, @var{sigma} = 1. |
5410 | 28 ## @end deftypefn |
29 | |
5428 | 30 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
5410 | 31 ## Description: PDF of the log normal distribution |
32 | |
5692 | 33 function pdf = lognpdf (x, mu, sigma) |
5410 | 34 |
35 if (! ((nargin == 1) || (nargin == 3))) | |
6046 | 36 print_usage (); |
5410 | 37 endif |
38 | |
39 if (nargin == 1) | |
5692 | 40 mu = 0; |
41 sigma = 1; | |
5410 | 42 endif |
43 | |
44 ## The following "straightforward" implementation unfortunately does | |
45 ## not work for the special cases (Inf, ...) | |
6617 | 46 ## pdf = (x > 0) ./ x .* normpdf (log (x), mu, sigma); |
5410 | 47 ## Hence ... |
48 | |
5692 | 49 if (!isscalar (mu) || !isscalar (sigma)) |
50 [retval, x, mu, sigma] = common_size (x, mu, sigma); | |
5410 | 51 if (retval > 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:
7017
diff
changeset
|
52 error ("lognpdf: X, MU and SIGMA must be of common size or scalars"); |
5410 | 53 endif |
54 endif | |
55 | |
56 pdf = zeros (size (x)); | |
57 | |
5692 | 58 k = find (isnan (x) | !(sigma > 0) | !(sigma < Inf)); |
5410 | 59 if (any (k)) |
60 pdf(k) = NaN; | |
61 endif | |
62 | |
5692 | 63 k = find ((x > 0) & (x < Inf) & (sigma > 0) & (sigma < Inf)); |
5410 | 64 if (any (k)) |
5692 | 65 if (isscalar (mu) && isscalar (sigma)) |
6617 | 66 pdf(k) = normpdf (log (x(k)), mu, sigma) ./ x(k); |
5410 | 67 else |
6617 | 68 pdf(k) = normpdf (log (x(k)), mu(k), sigma(k)) ./ x(k); |
5692 | 69 endif |
5410 | 70 endif |
71 | |
72 endfunction |