changeset 8826:d49678a78fb9

make dmult deprecated
author Jaroslav Hajek <highegg@gmail.com>
date Fri, 20 Feb 2009 12:07:30 +0100
parents c3445f1c8cb4
children 55d999c23728
files scripts/ChangeLog scripts/deprecated/Makefile.in scripts/deprecated/dmult.m scripts/linear-algebra/Makefile.in scripts/linear-algebra/dmult.m scripts/statistics/models/logistic_regression_derivatives.m
diffstat 6 files changed, 61 insertions(+), 96 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Fri Feb 20 10:55:03 2009 +0100
+++ b/scripts/ChangeLog	Fri Feb 20 12:07:30 2009 +0100
@@ -1,3 +1,12 @@
+2009-02-20  Jaroslav Hajek  <highegg@gmail.com>
+
+	* linear-algebra/dmult.m: Remove.
+	* linear-algebra/Makefile.in: Update.
+	* deprecated/dmult.m: Move here; revert to the 3.0.x version.
+	* deprecated/Makefile.in: Update.
+	* statistics/models/logistic_regression_derivatives.m: Replace dmult
+	by diagonal matrices.
+
 2009-02-19  Ben Abbott <bpabbott@mac.com>
 
 	* plot/gnuplot_drawnow.m: Only send figure position info to gnuplot
--- a/scripts/deprecated/Makefile.in	Fri Feb 20 10:55:03 2009 +0100
+++ b/scripts/deprecated/Makefile.in	Fri Feb 20 12:07:30 2009 +0100
@@ -35,7 +35,7 @@
 SOURCES = beta_cdf.m beta_inv.m beta_pdf.m beta_rnd.m \
   binomial_cdf.m binomial_inv.m binomial_pdf.m binomial_rnd.m \
   chisquare_cdf.m chisquare_inv.m chisquare_pdf.m chisquare_rnd.m \
-  clearplot.m clg.m com2str.m exponential_cdf.m exponential_inv.m \
+  clearplot.m clg.m com2str.m dmult.m exponential_cdf.m exponential_inv.m \
   exponential_pdf.m exponential_rnd.m f_cdf.m f_inv.m f_pdf.m \
   f_rnd.m gamma_cdf.m gamma_inv.m gamma_pdf.m gamma_rnd.m \
   geometric_cdf.m geometric_inv.m geometric_pdf.m geometric_rnd.m \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/deprecated/dmult.m	Fri Feb 20 12:07:30 2009 +0100
@@ -0,0 +1,48 @@
+## Copyright (C) 1995, 1996, 1997, 1998, 2000, 2002, 2004, 2005, 2006,
+##               2007 Kurt Hornik
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or (at
+## your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <http://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {} dmult (@var{a}, @var{b})
+## This function has been deprecated. Use the direct syntax @code{diag(A)*B}
+## which is more readable and now also more efficient.
+## @end deftypefn
+
+## Author: KH <Kurt.Hornik@wu-wien.ac.at>
+## Description: Rescale the rows of a matrix
+
+function M = dmult (a, B)
+
+  persistent warned = false;
+  if (! warned)
+    warned = true;
+    warning ("Octave:deprecated-function",
+             "dmult is obsolete and will be removed from a future version of Octave; please use the straightforward (and now efficient) syntax ""diag(A)*B"".");
+  endif
+
+  if (nargin != 2)
+    print_usage ();
+  endif
+ if (! isvector (a))
+    error ("dmult: a must be a vector of length rows (B)");
+  endif
+  a = a(:);
+  sb = size (B);
+  sb(1) = 1;
+  M = repmat (a(:), sb) .* B;
+endfunction
--- a/scripts/linear-algebra/Makefile.in	Fri Feb 20 10:55:03 2009 +0100
+++ b/scripts/linear-algebra/Makefile.in	Fri Feb 20 12:07:30 2009 +0100
@@ -34,7 +34,7 @@
 INSTALL_DATA = @INSTALL_DATA@
 
 SOURCES = commutation_matrix.m cond.m condest.m cross.m \
-  dmult.m dot.m duplication_matrix.m expm.m housh.m krylov.m krylovb.m logm.m \
+  dot.m duplication_matrix.m expm.m housh.m krylov.m krylovb.m logm.m \
   null.m onenormest.m orth.m planerot.m qzhess.m rank.m rref.m subspace.m \
   trace.m vec.m vech.m
 
--- a/scripts/linear-algebra/dmult.m	Fri Feb 20 10:55:03 2009 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,92 +0,0 @@
-## Copyright (C) 2008 VZLU Prague, a.s., Czech Republic
-##
-## This file is part of Octave.
-##
-## Octave is free software; you can redistribute it and/or modify it
-## under the terms of the GNU General Public License as published by
-## the Free Software Foundation; either version 3 of the License, or (at
-## your option) any later version.
-##
-## Octave is distributed in the hope that it will be useful, but
-## WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-## General Public License for more details.
-##
-## You should have received a copy of the GNU General Public License
-## along with Octave; see the file COPYING.  If not, see
-## <http://www.gnu.org/licenses/>.
-
-## -*- texinfo -*-
-## @deftypefn {Function File} {@var{c} =} dmult (@var{a}, @var{b})
-## @deftypefnx {Function File} {@var{c} =} dmult (@var{a}, @var{b}, @var{ind})
-## Scale a matrix by rows or columns, or a multidimensional tensor along 
-## a specified dimension.
-## If @var{a} is a vector of length @code{rows (@var{b})}, return
-## @code{diag (@var{a}) * @var{b}} (but computed much more efficiently).
-## Similarly, if @var{b} is a vector of length @code{columns(@var{a})},
-## return @code{@var{a} * diag(@var{b})}. 
-##
-## If @var{b} is a multidimensional array and @var{a} a vector,
-## @var{c} will have the same shape as @var{b}, with 
-## @code{@var{C}(i,:,@dots{}) = @var{a}(i)*@var{b}(i,:,@dots{})}.
-##
-## If @var{a} is a multidimensional array and @var{b} a vector,
-## @var{c} will have the same shape as @var{a}, with 
-## @code{@var{C}(:,@dots{},i) = @var{a}(:,@dots{},i)*@var{b}(i)}.
-##
-## If @var{ind} is supplied, @var{a} should be an array and @var{b}
-## a vector of length @code{size (@var{a},index)}. The result is then
-## @code{@var{C}(:,@dots{},i,:,@dots{}) = @var{a}(:,@dots{},i,:,@dots{})*@var{b}(i)}
-## where i indexes the @var{ind}-th dimension.
-## @end deftypefn
-
-## Author: Jaroslav Hajek <highegg@gmail.com>
-## Description: Scale a tensor along a dimension
-
-### Original Author: KH <Kurt.Hornik@wu-wien.ac.at>
-### Original Description: Rescale the rows of a matrix
-
-function m = dmult (a, b, ind)
-  if (nargin == 2)
-    sa = size (a);
-    sb = size (b);
-    if (isvector (a) && length (a) == sb(1))
-      a = a(:);
-      m = reshape (kron (ones (prod (sb(2:end)), 1), a), sb) .* b;
-    elseif (isvector (b) && length (b) == sa(end))
-      b = b(:);
-      m = reshape (kron (b, ones (prod (sa (1:end-1)), 1)), sa) .* a;
-    else
-      error ("dmult: dimensions mismatch");
-    endif
-
-  elseif (nargin == 3 && isscalar (ind))
-    if (isvector (b) && ind > 0 && ind <= ndims (a)
-	&& length (b) == size (a, ind))
-      b = b(:);
-      sa = size (a); 
-      sal = prod (sa(1:ind-1)); sat = prod (sa(ind+1:end));
-      s = kron (ones (sat, 1), kron (b, ones (sal, 1)));
-      m = reshape (s, sa) .* a;
-    else
-      error ("dmult: dimensions mismatch or index out of range");
-    endif
-  else
-    print_usage ();
-  endif
-
-endfunction
-
-%!test
-%! assert (dmult ([1,2,3], ones(3)), [1,1,1;2,2,2;3,3,3])
-%! assert (dmult ([1,2,3]', ones(3)), [1,1,1;2,2,2;3,3,3])
-%!test
-%! assert (dmult ([1,2,3], ones(3,2,2)), reshape ([1,1,1,1;2,2,2,2;3,3,3,3], [3,2,2]))
-%!test
-%! assert (dmult (ones(3), [1,2,3]), [1,2,3;1,2,3;1,2,3])
-%! assert (dmult (ones(3), [1,2,3]'), [1,2,3;1,2,3;1,2,3])
-%!test
-%! assert (dmult (ones(2,2,3), [1,2,3]), reshape ([1,2,3;1,2,3;1,2,3;1,2,3], [2,2,3]))
-%!test
-%! assert (dmult (ones(3,4,2), [1 2 3 4], 2),...
-%! reshape ([1 1 1 2 2 2 3 3 3 4 4 4 1 1 1 2 2 2 3 3 3 4 4 4], [3,4,2]))
--- a/scripts/statistics/models/logistic_regression_derivatives.m	Fri Feb 20 10:55:03 2009 +0100
+++ b/scripts/statistics/models/logistic_regression_derivatives.m	Fri Feb 20 12:07:30 2009 +0100
@@ -35,12 +35,12 @@
 
   ## first derivative
   v = g .* (1 - g) ./ p; v1 = g1 .* (1 - g1) ./ p;
-  dlogp = [(dmult (v, z) - dmult (v1, z1)), (dmult (v - v1, x))];
+  dlogp = [(diag (v) * z - diag (v1) * z1), (diag (v - v1) * x)];
   dl = sum (dlogp)';
 
   ## second derivative
   w = v .* (1 - 2 * g); w1 = v1 .* (1 - 2 * g1);
-  d2l = [z, x]' * dmult (w, [z, x]) - [z1, x]' * dmult (w1, [z1, x]) ...
+  d2l = [z, x]' * diag (w) * [z, x] - [z1, x]' * diag (w1) * [z1, x] ...
       - dlogp' * dlogp;
 
 endfunction