[Scipy-svn] r4615 - branches/stats_models

scipy-svn@scip... scipy-svn@scip...
Thu Aug 7 20:30:32 CDT 2008


Author: tom.waite
Date: 2008-08-07 20:30:30 -0500 (Thu, 07 Aug 2008)
New Revision: 4615

Modified:
   branches/stats_models/_bspline.py
Log:
weave to c-ext

Modified: branches/stats_models/_bspline.py
===================================================================
--- branches/stats_models/_bspline.py	2008-08-08 01:30:10 UTC (rev 4614)
+++ branches/stats_models/_bspline.py	2008-08-08 01:30:30 UTC (rev 4615)
@@ -20,7 +20,7 @@
 
 from scipy.linalg import solveh_banded
 from scipy.optimize import golden
-from scipy.stats.models import _bspline
+from scipy.stats.models import _hbspline
 
 
 # Issue warning regarding heavy development status of this module
@@ -198,6 +198,10 @@
                  Bspline to avoid extra evaluation in the __call__ method
 
     '''
+    # FIXME: update parameter names, replace single character names 
+    # FIXME: `order` should be actual spline order (implemented as order+1)
+    ## FIXME: update the use of spline order in extension code (evaluate is recursively called) 
+    # FIXME: eliminate duplicate M and m attributes (m is order, M is related to tau size)
 
     def __init__(self, knots, order=4, M=None, coef=None, x=None):
 
@@ -285,7 +289,7 @@
         x.shape = (N.product(_shape,axis=0),)
         if i < self.tau.shape[0] - 1:
            ## TODO: OWNDATA flags...
-            v = _bspline.evaluate(x, self.tau, self.m, d, i, i+1)
+            v = _hbspline.evaluate(x, self.tau, self.m, d, i, i+1)
         else:
             return N.zeros(x.shape, N.float64)
 
@@ -329,7 +333,7 @@
 
         d = N.asarray(d)
         if d.shape == ():
-            v = _bspline.evaluate(x, self.tau, self.m, int(d), lower, upper)
+            v = _hbspline.evaluate(x, self.tau, self.m, int(d), lower, upper)
         else:
             if d.shape[0] != 2:
                 raise ValueError, "if d is not an integer, expecting a jx2 \
@@ -338,7 +342,7 @@
 
             v = 0
             for i in range(d.shape[1]):
-                v += d[1,i] * _bspline.evaluate(x, self.tau, self.m, d[0,i], lower, upper)
+                v += d[1,i] * _hbspline.evaluate(x, self.tau, self.m, d[0,i], lower, upper)
 
         v.shape = (upper-lower,) + _shape
         if upper == self.tau.shape[0] - self.m:
@@ -381,7 +385,7 @@
 
         d = N.squeeze(d)
         if N.asarray(d).shape == ():
-            self.g = _bspline.gram(self.tau, self.m, int(d), int(d))
+            self.g = _hbspline.gram(self.tau, self.m, int(d), int(d))
         else:
             d = N.asarray(d)
             if d.shape[0] != 2:
@@ -393,7 +397,7 @@
             self.g = 0
             for i in range(d.shape[1]):
                 for j in range(d.shape[1]):
-                    self.g += d[1,i]* d[1,j] * _bspline.gram(self.tau, self.m, int(d[0,i]), int(d[0,j]))
+                    self.g += d[1,i]* d[1,j] * _hbspline.gram(self.tau, self.m, int(d[0,i]), int(d[0,j]))
         self.g = self.g.T
         self.d = d
         return N.nan_to_num(self.g)
@@ -433,6 +437,8 @@
 
            fhat = ARGMIN_f SUM_i=1^n (y_i-f(x_i))^2 + pen * int f^(2)^2
 
+	   int is integral. pen is lambda (from Hastie)
+
            See Chapter 5 of
 
            Hastie, Tibshirani and Friedman (2001). "The Elements of Statistical
@@ -561,7 +567,7 @@
         """
 
         if self.pen > 0:
-            _invband = _bspline.invband(self.chol.copy())
+            _invband = _hbspline.invband(self.chol.copy())
             tr = _trace_symbanded(_invband, self.btb, lower=1)
             return tr
         else:
@@ -655,3 +661,8 @@
             return a
 
         a = golden(_gcv, args=(y,x), brack=bracket, tol=tol)
+
+
+
+
+



More information about the Scipy-svn mailing list