From: <fp...@us...> - 2009-06-02 10:05:17
|
Revision: 5887 http://octave.svn.sourceforge.net/octave/?rev=5887&view=rev Author: fpoto Date: 2009-06-02 10:05:07 +0000 (Tue, 02 Jun 2009) Log Message: ----------- Now it works with scalar observations, too. Modified Paths: -------------- trunk/octave-forge/main/statistics/inst/pdist.m Modified: trunk/octave-forge/main/statistics/inst/pdist.m =================================================================== --- trunk/octave-forge/main/statistics/inst/pdist.m 2009-06-01 07:54:14 UTC (rev 5886) +++ trunk/octave-forge/main/statistics/inst/pdist.m 2009-06-02 10:05:07 UTC (rev 5887) @@ -128,25 +128,25 @@ if (str2num(version()(1:3)) > 3.1) y = norm (d, "cols"); else - y = sqrt (sumsq (d)); + y = sqrt (sumsq (d, 1)); endif case "seuclidean" d = X(:,Xi) - X(:,Yi); - weights = inv (diag (var (x))); - y = sqrt (sum ((weights * d) .* d)); + weights = inv (diag (var (x, 0, 1))); + y = sqrt (sum ((weights * d) .* d, 1)); case "mahalanobis" d = X(:,Xi) - X(:,Yi); weights = inv (cov (x)); - y = sqrt (sum ((weights * d) .* d)); + y = sqrt (sum ((weights * d) .* d, 1)); case "cityblock" d = X(:,Xi) - X(:,Yi); if (str2num(version()(1:3)) > 3.1) y = norm (d, 1, "cols"); else - y = sum (abs (d)); + y = sum (abs (d), 1); endif case "minkowski" @@ -158,37 +158,43 @@ if (str2num(version()(1:3)) > 3.1) y = norm (d, p, "cols"); else - y = (sum ((abs (d)).^p)).^(1/p); + y = (sum ((abs (d)).^p, 1)).^(1/p); endif case "cosine" prod = X(:,Xi) .* X(:,Yi); - weights = sumsq (X(:,Xi)) .* sumsq (X(:,Yi)); - y = 1 - sum (prod) ./ sqrt (weights); + weights = sumsq (X(:,Xi), 1) .* sumsq (X(:,Yi), 1); + y = 1 - sum (prod, 1) ./ sqrt (weights); case "correlation" + if (rows(X) == 1) + error ("pdist: correlation distance between scalars not defined") + endif corr = cor (X); y = 1 - corr (sub2ind (size (corr), Xi, Yi))'; case "spearman" + if (rows(X) == 1) + error ("pdist: spearman distance between scalars not defined") + endif corr = spearman (X); y = 1 - corr (sub2ind (size (corr), Xi, Yi))'; case "hamming" d = logical (X(:,Xi) - X(:,Yi)); - y = sum (d) / rows (X); + y = sum (d, 1) / rows (X); case "jaccard" d = logical (X(:,Xi) - X(:,Yi)); weights = X(:,Xi) | X(:,Yi); - y = sum (d & weights) ./ sum (weights); + y = sum (d & weights, 1) ./ sum (weights, 1); case "chebychev" d = X(:,Xi) - X(:,Yi); if (str2num(version()(1:3)) > 3.1) y = norm (d, Inf, "cols"); else - y = max (abs (d)); + y = max (abs (d), [], 1); endif endswitch This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |