changeset 13823:94a37dae80a9

Use a cheaper Cholesky decomposition than a rank() svd in ols.m
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Fri, 04 Nov 2011 18:55:27 -0400
parents 38e3bfc4e076
children aa0cba2256f4
files scripts/statistics/base/ols.m
diffstat 1 files changed, 4 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/statistics/base/ols.m	Fri Nov 04 16:40:07 2011 -0400
+++ b/scripts/statistics/base/ols.m	Fri Nov 04 18:55:27 2011 -0400
@@ -109,12 +109,12 @@
 
   ## Start of algorithm
   z = x' * x;
-  rnk = rank (z);
+  [u, p] = chol (z);
 
-  if (rnk == nc)
-    beta = inv (z) * x' * y;
+  if (p)
+    beta = pinv (x) * y;
   else
-    beta = pinv (x) * y;
+    beta = u \ (u' \ x' * y);
   endif
 
   if (isargout (2) || isargout (3))