Mercurial > hg > octave-avbm
changeset 10519:f6959aff84ca
Reimplement discrete_cdf using the lookup function
author | David Bateman <dbateman@free.fr> |
---|---|
date | Wed, 14 Apr 2010 02:30:41 +0200 |
parents | fcafe0e9bd58 |
children | 72c90e7132a9 |
files | scripts/ChangeLog scripts/statistics/distributions/discrete_cdf.m |
diffstat | 2 files changed, 7 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2010-04-13 David Bateman <dbateman@free.fr> + + * statistics/discrete_cdf.m: Reimplement using lookup. + 2010-04-13 Shai Ayal <shaiay@users.sourceforge.net> * plot/__fltk_ginput__.m: New functions, implement ginput for
--- a/scripts/statistics/distributions/discrete_cdf.m +++ b/scripts/statistics/distributions/discrete_cdf.m @@ -1,5 +1,4 @@ -## Copyright (C) 1996, 1997, 1998, 2000, 2001, 2002, 2004, 2005, 2006, -## 2007 Kurt Hornik +## Copyright (C) 2010 David Bateman ## ## This file is part of Octave. ## @@ -24,9 +23,6 @@ ## assumes the values in @var{v} with probabilities @var{p}. ## @end deftypefn -## Author: KH <Kurt.Hornik@wu-wien.ac.at> -## Description: CDF of a discrete distribution - function cdf = discrete_cdf (x, v, p) if (nargin != 3) @@ -57,7 +53,8 @@ k = find (!isnan (x)); if (any (k)) n = length (k); - cdf (k) = ((x(k) * ones (1, m)) >= (ones (n, 1) * v)) * p; + [vs, vi] = sort (v); + cdf = [0 ; cumsum(p(vi))](lookup (vs, x(k)) + 1); endif endfunction