changeset 4983:13aaef87cf18

[project @ 2004-09-10 13:51:29 by jwe]
author jwe
date Fri, 10 Sep 2004 13:54:22 +0000
parents c0866f89c43d
children 98e4b7da360a
files scripts/ChangeLog scripts/statistics/distributions/binomial_rnd.m scripts/statistics/distributions/poisson_rnd.m src/ov-intx.h
diffstat 4 files changed, 45 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Fri Sep 10 13:48:18 2004 +0000
+++ b/scripts/ChangeLog	Fri Sep 10 13:54:22 2004 +0000
@@ -1,3 +1,11 @@
+2004-09-10  David Bateman  <dbateman@free.fr>
+
+	* statistics/distributions/binomial_rnd.m: Fix error for scalar n
+	and p with n > 1, and fix for matrix n and p with n == 1.
+
+	* statistics/distributions/poisson_rnd.m: Fix for matrix length,
+	due to row vs. column vector operations.
+
 2004-09-03  David Bateman  <dbateman@free.fr>
 
 	* general/repmat.m: Fix to allow logical classes.
--- a/scripts/statistics/distributions/binomial_rnd.m	Fri Sep 10 13:48:18 2004 +0000
+++ b/scripts/statistics/distributions/binomial_rnd.m	Fri Sep 10 13:54:22 2004 +0000
@@ -82,7 +82,7 @@
     else
       nel = prod (sz);
       tmp = rand (n, nel);
-      rnd = tmp < ones (n, nel) * p;
+      rnd = sum(tmp < ones (n, nel) * p, 1);
       rnd = reshape(rnd, sz);
     endif
   else
@@ -101,7 +101,7 @@
       tmp = rand (N, L);
       ind = (1 : N)' * ones (1, L);
       rnd(k) = sum ((tmp < ones (N, 1) * p(k)(:)') &
-                    (ind <= ones (N, 1) * n(k)(:)'));
+                    (ind <= ones (N, 1) * n(k)(:)'),1);
     endif
   endif
 
--- a/scripts/statistics/distributions/poisson_rnd.m	Fri Sep 10 13:48:18 2004 +0000
+++ b/scripts/statistics/distributions/poisson_rnd.m	Fri Sep 10 13:54:22 2004 +0000
@@ -101,7 +101,7 @@
 	ind = find (sum < 1);
 	if (any (ind))
           sum(ind) = (sum(ind)
-                      - log (1 - rand (1, length (ind))) ./ l(ind));
+                      - log (1 - rand (length (ind), 1)) ./ l(ind));
           num(ind) = num(ind) + 1;
 	else
           break;
--- a/src/ov-intx.h	Fri Sep 10 13:48:18 2004 +0000
+++ b/src/ov-intx.h	Fri Sep 10 13:54:22 2004 +0000
@@ -51,12 +51,10 @@
 
   ~OCTAVE_VALUE_INT_MATRIX_T (void) { }
 
-  octave_value *
-  clone (void) const
+  octave_value *clone (void) const
     { return new OCTAVE_VALUE_INT_MATRIX_T (*this); }
 
-  octave_value *
-  empty_clone (void) const
+  octave_value *empty_clone (void) const
     { return new OCTAVE_VALUE_INT_MATRIX_T (); }
 
   OCTAVE_INT_NDARRAY_T
@@ -83,11 +81,7 @@
       
     }
 
-  double
-  scalar_value (bool = false) const
-    {
-      return double_value ();
-    }
+  double scalar_value (bool = false) const { return double_value (); }
 
   NDArray
   array_value (bool = false) const
@@ -137,39 +131,39 @@
 
   ~OCTAVE_VALUE_INT_SCALAR_T (void) { }
 
-  octave_value *
-  clone (void) const
+  octave_value *clone (void) const
     { return new OCTAVE_VALUE_INT_SCALAR_T (*this); }
 
-  octave_value *
-  empty_clone (void) const
+  octave_value *empty_clone (void) const
     { return new OCTAVE_VALUE_INT_SCALAR_T (); }
 
   octave_value do_index_op (const octave_value_list& idx, int resize_ok)
-  {
-    octave_value retval;
+    {
+      octave_value retval;
+
+      if (idx.valid_scalar_indices ())
+	retval = scalar;
+      else
+	{
+	  // XXX FIXME XXX -- this doesn't solve the problem of
+	  //
+	  //   a = 1; a([1,1], [1,1], [1,1])
+	  //
+	  // and similar constructions.  Hmm...
 
-    if (idx.valid_scalar_indices ())
-      retval = scalar;
-    else
-      {
-	// XXX FIXME XXX -- this doesn't solve the problem of
-	//
-	//   a = 1; a([1,1], [1,1], [1,1])
-	//
-	// and similar constructions.  Hmm...
+	  // XXX FIXME XXX -- using this constructor avoids narrowing the
+	  // 1x1 matrix back to a scalar value.  Need a better solution
+	  // to this problem.
 
-	// XXX FIXME XXX -- using this constructor avoids narrowing the
-	// 1x1 matrix back to a scalar value.  Need a better solution
-	// to this problem.
+	  octave_value tmp
+	    (new OCTAVE_VALUE_INT_MATRIX_T
+	     (OCTAVE_VALUE_INT_NDARRAY_EXTRACTOR_FUNCTION ())); 
 
-	octave_value tmp (new OCTAVE_VALUE_INT_MATRIX_T (
-			     OCTAVE_VALUE_INT_NDARRAY_EXTRACTOR_FUNCTION ())); 
-	retval = tmp.do_index_op (idx, resize_ok);
-      }
+	  retval = tmp.do_index_op (idx, resize_ok);
+	}
 
-    return retval;
-  }
+      return retval;
+    }
 
   OCTAVE_INT_T
   OCTAVE_VALUE_INT_SCALAR_EXTRACTOR_FUNCTION (void) const
@@ -180,19 +174,16 @@
     { return OCTAVE_INT_NDARRAY_T (dim_vector (1, 1), scalar); }
 
   octave_value resize (const dim_vector& dv) const
-    { OCTAVE_INT_NDARRAY_T retval (dv); if (dv.numel()) retval(0) = scalar; return retval; }
-
-  double
-  double_value (bool = false) const
     {
-      return double (scalar);
+      OCTAVE_INT_NDARRAY_T retval (dv);
+      if (dv.numel())
+	retval(0) = scalar;
+      return retval;
     }
 
-  double
-  scalar_value (bool = false) const
-    {
-      return double (scalar);
-    }
+  double double_value (bool = false) const { return double (scalar); }
+
+  double scalar_value (bool = false) const { return double (scalar); }
 
   NDArray
   array_value (bool = false) const