changeset 12530:d70c99028ba3

Make helper functions for logistic_regression private.
author Rik <octave@nomad.inbox5.com>
date Sat, 19 Mar 2011 13:53:38 -0700
parents 0579a13f29a1
children 33716f289ba5
files scripts/ChangeLog scripts/statistics/models/logistic_regression.m scripts/statistics/models/logistic_regression_derivatives.m scripts/statistics/models/logistic_regression_likelihood.m scripts/statistics/models/module.mk scripts/statistics/models/private/logistic_regression_derivatives.m scripts/statistics/models/private/logistic_regression_likelihood.m
diffstat 7 files changed, 105 insertions(+), 91 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Sat Mar 19 13:06:50 2011 -0700
+++ b/scripts/ChangeLog	Sat Mar 19 13:53:38 2011 -0700
@@ -1,3 +1,12 @@
+2010-03-19  Rik  <octave@nomad.inbox5.com>
+
+	* statistics/models/logistic_regression.m: Do not split function
+	declaration with line continuation.
+	* statistics/models/private/logistic_regression_likelihood.m,
+	statistics/models/private/logistic_regression_derivatives.m: Make
+	helper functions private.
+	* statistics/models/module.mk: Make helper functions private.
+
 2010-03-19  Rik  <octave@nomad.inbox5.com>
 
 	* plot/isocolors.m, plot/isonormals.m, plot/isosurface.m: Improve
--- a/scripts/statistics/models/logistic_regression.m	Sat Mar 19 13:06:50 2011 -0700
+++ b/scripts/statistics/models/logistic_regression.m	Sat Mar 19 13:53:38 2011 -0700
@@ -84,8 +84,7 @@
 ## Uses the auxiliary functions logistic_regression_derivatives and
 ## logistic_regression_likelihood.
 
-function [theta, beta, dev, dl, d2l, p] ...
-  = logistic_regression (y, x, print, theta, beta)
+function [theta, beta, dev, dl, d2l, p] = logistic_regression (y, x, print, theta, beta)
 
   ## check input
   y = round (vec (y));
--- a/scripts/statistics/models/logistic_regression_derivatives.m	Sat Mar 19 13:06:50 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-## Copyright (C) 1995-2011 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} {[@var{dl}, @var{d2l}] =} logistic_regression_derivatives (@var{x}, @var{z}, @var{z1}, @var{g}, @var{g1}, @var{p})
-## Called by logistic_regression.  Calculates derivates of the
-## log-likelihood for ordinal logistic regression model.
-## @end deftypefn
-
-## Author: Gordon K. Smyth <gks@maths.uq.oz.au>
-## Adapted-By: KH <Kurt.Hornik@wu-wien.ac.at>
-## Description: Derivates of log-likelihood in logistic regression
-
-function [dl, d2l] = logistic_regression_derivatives (x, z, z1, g, g1, p)
-
-  if (nargin != 6)
-    print_usage ();
-  endif
-
-  ## first derivative
-  v = g .* (1 - g) ./ p; v1 = g1 .* (1 - g1) ./ p;
-  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]' * diag (w) * [z, x] - [z1, x]' * diag (w1) * [z1, x] ...
-      - dlogp' * dlogp;
-
-endfunction
--- a/scripts/statistics/models/logistic_regression_likelihood.m	Sat Mar 19 13:06:50 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,42 +0,0 @@
-## Copyright (C) 1995-2011 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} {[@var{g}, @var{g1}, @var{p}, @var{dev}] =} logistic_regression_likelihood (@var{y}, @var{x}, @var{beta}, @var{z}, @var{z1})
-## Calculates likelihood for the ordinal logistic regression model.
-## Called by logistic_regression.
-## @end deftypefn
-
-## Author: Gordon K. Smyth <gks@maths.uq.oz.au>
-## Adapted-By: KH <Kurt.Hornik@wu-wien.ac.at>
-## Description: Likelihood in logistic regression
-
-function [g, g1, p, dev] = logistic_regression_likelihood (y, x, beta, z, z1)
-
-  if (nargin != 5)
-    print_usage ();
-  endif
-
-  e = exp ([z, x] * beta); e1 = exp ([z1, x] * beta);
-  g = e ./ (1 + e); g1 = e1 ./ (1 + e1);
-  g = max (y == max (y), g); g1 = min (y > min(y), g1);
-
-  p = g - g1;
-  dev = -2 * sum (log (p));
-
-endfunction
--- a/scripts/statistics/models/module.mk	Sat Mar 19 13:06:50 2011 -0700
+++ b/scripts/statistics/models/module.mk	Sat Mar 19 13:53:38 2011 -0700
@@ -1,9 +1,12 @@
 FCN_FILE_DIRS += statistics/models
 
+statistics_models_PRIVATE_FCN_FILES = \
+  statistics/models/private/logistic_regression_derivatives.m \
+  statistics/models/private/logistic_regression_likelihood.m
+
 statistics_models_FCN_FILES = \
   statistics/models/logistic_regression.m \
-  statistics/models/logistic_regression_derivatives.m \
-  statistics/models/logistic_regression_likelihood.m
+  $(statistics_models_PRIVATE_FCN_FILES) 
 
 FCN_FILES += $(statistics_models_FCN_FILES)
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/statistics/models/private/logistic_regression_derivatives.m	Sat Mar 19 13:53:38 2011 -0700
@@ -0,0 +1,47 @@
+## Copyright (C) 1995-2011 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} {[@var{dl}, @var{d2l}] =} logistic_regression_derivatives (@var{x}, @var{z}, @var{z1}, @var{g}, @var{g1}, @var{p})
+## Calculate derivatives of the log-likelihood for ordinal logistic regression
+## model.
+## Private function called by @code{logistic_regression}.
+## @seealso{logistic_regression}
+## @end deftypefn
+
+## Author: Gordon K. Smyth <gks@maths.uq.oz.au>
+## Adapted-By: KH <Kurt.Hornik@wu-wien.ac.at>
+## Description: Derivates of log-likelihood in logistic regression
+
+function [dl, d2l] = logistic_regression_derivatives (x, z, z1, g, g1, p)
+
+  if (nargin != 6)
+    print_usage ();
+  endif
+
+  ## first derivative
+  v = g .* (1 - g) ./ p; v1 = g1 .* (1 - g1) ./ p;
+  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]' * diag (w) * [z, x] - [z1, x]' * diag (w1) * [z1, x] ...
+      - dlogp' * dlogp;
+
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/statistics/models/private/logistic_regression_likelihood.m	Sat Mar 19 13:53:38 2011 -0700
@@ -0,0 +1,43 @@
+## Copyright (C) 1995-2011 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} {[@var{g}, @var{g1}, @var{p}, @var{dev}] =} logistic_regression_likelihood (@var{y}, @var{x}, @var{beta}, @var{z}, @var{z1})
+## Calculate the likelihood for the ordinal logistic regression model.
+## Private function called by @code{logistic_regression}.
+## @seealso{logistic_regression}
+## @end deftypefn
+
+## Author: Gordon K. Smyth <gks@maths.uq.oz.au>
+## Adapted-By: KH <Kurt.Hornik@wu-wien.ac.at>
+## Description: Likelihood in logistic regression
+
+function [g, g1, p, dev] = logistic_regression_likelihood (y, x, beta, z, z1)
+
+  if (nargin != 5)
+    print_usage ();
+  endif
+
+  e = exp ([z, x] * beta); e1 = exp ([z1, x] * beta);
+  g = e ./ (1 + e); g1 = e1 ./ (1 + e1);
+  g = max (y == max (y), g); g1 = min (y > min(y), g1);
+
+  p = g - g1;
+  dev = -2 * sum (log (p));
+
+endfunction