comparison scripts/deprecated/mahalanobis.m @ 20537:afdb856e44f1

Deprecate mahalanobis function. * NEWS: Announce deprecation. * stats.txi: Remove from manual * scripts/deprecated/module.mk: Add to deprecated build dir. * scripts/statistics/base/module.mk: Remove from existing dir * scripts/deprecated/mahalanobis.m: Add warning message to deprecated function. * scripts/statistics/base/mahalanobis.m: Delete deprecated function.
author Rik <rik@octave.org>
date Tue, 22 Sep 2015 05:45:05 -0700
parents scripts/statistics/base/mahalanobis.m@d9341b422488
children
comparison
equal deleted inserted replaced
20536:1f330d33388f 20537:afdb856e44f1
1 ## Copyright (C) 1996-2015 John W. Eaton
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
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
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
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {} mahalanobis (@var{x}, @var{y})
21 ##
22 ## @code{mahalanobis} is deprecated and will be removed in Octave version 4.6.
23 ## See the @code{mahal} function in the statistics package from Octave-Forge
24 ## for equivalent functionality.
25 ##
26 ## Return the Mahalanobis' D-square distance between the multivariate
27 ## samples @var{x} and @var{y}.
28 ##
29 ## The data @var{x} and @var{y} must have the same number of components
30 ## (columns), but may have a different number of observations (rows).
31 ## @end deftypefn
32
33 ## Author: Friedrich Leisch <leisch@ci.tuwien.ac.at>
34 ## Created: July 1993
35 ## Adapted-By: jwe
36
37 function retval = mahalanobis (x, y)
38
39 persistent warned = false;
40 if (! warned)
41 warned = true;
42 warning ("Octave:deprecated-function",
43 "mahalanobis is obsolete and will be removed from a future version of Octave, please use mahal from the statistics package in Octave-Forge instead");
44 endif
45
46 if (nargin != 2)
47 print_usage ();
48 endif
49
50 if ( ! (isnumeric (x) || islogical (x))
51 || ! (isnumeric (y) || islogical (y)))
52 error ("mahalanobis: X and Y must be numeric matrices or vectors");
53 endif
54
55 if (ndims (x) != 2 || ndims (y) != 2)
56 error ("mahalanobis: X and Y must be 2-D matrices or vectors");
57 endif
58
59 [xr, xc] = size (x);
60 [yr, yc] = size (y);
61
62 if (xc != yc)
63 error ("mahalanobis: X and Y must have the same number of columns");
64 endif
65
66 if (isinteger (x))
67 x = double (x);
68 endif
69
70 xm = mean (x);
71 ym = mean (y);
72
73 ## Center data by subtracting means
74 x = bsxfun (@minus, x, xm);
75 y = bsxfun (@minus, y, ym);
76
77 w = (x' * x + y' * y) / (xr + yr - 2);
78
79 winv = inv (w);
80
81 retval = (xm - ym) * winv * (xm - ym)';
82
83 endfunction
84
85
86 ## Test input validation
87 %!error mahalanobis ()
88 %!error mahalanobis (1, 2, 3)
89 %!error mahalanobis ('A', 'B')
90 %!error mahalanobis ([1, 2], ['A', 'B'])
91 %!error mahalanobis (ones (2,2,2))
92 %!error mahalanobis (ones (2,2), ones (2,2,2))
93 %!error mahalanobis (ones (2,2), ones (2,3))
94