# [Scipy-svn] r2922 - in trunk/Lib: integrate linalg optimize signal stats

scipy-svn@scip... scipy-svn@scip...
Sun Apr 15 00:38:15 CDT 2007

```Author: rkern
Date: 2007-04-15 00:37:57 -0500 (Sun, 15 Apr 2007)
New Revision: 2922

Modified:
trunk/Lib/linalg/basic.py
trunk/Lib/optimize/minpack.py
trunk/Lib/signal/wavelets.py
trunk/Lib/stats/distributions.py
Log:
Remove some interdependencies.

===================================================================
--- trunk/Lib/integrate/quadrature.py	2007-04-15 05:16:13 UTC (rev 2921)
+++ trunk/Lib/integrate/quadrature.py	2007-04-15 05:37:57 UTC (rev 2922)
@@ -6,6 +6,7 @@
'cumtrapz','newton_cotes','composite']

from scipy.special.orthogonal import p_roots
+from scipy.special import gammaln
from numpy import sum, ones, add, diff, isinf, isscalar, \
asarray, real, trapz, arange, empty
import scipy as sp
@@ -591,7 +592,7 @@

BN = BN - np.dot(yi**power, ai)
p1 = power+1
-    fac = power*math.log(N) - sp.special.gammaln(p1)
+    fac = power*math.log(N) - gammaln(p1)
fac = math.exp(fac)
return ai, BN*fac

Modified: trunk/Lib/linalg/basic.py
===================================================================
--- trunk/Lib/linalg/basic.py	2007-04-15 05:16:13 UTC (rev 2921)
+++ trunk/Lib/linalg/basic.py	2007-04-15 05:37:57 UTC (rev 2922)
@@ -20,10 +20,9 @@
import numpy
from numpy import asarray_chkfinite, outer, concatenate, reshape, single
from numpy import matrix as Matrix
+from numpy.linalg import LinAlgError
from scipy.linalg import calc_lwork

-class LinAlgError(Exception):
-    pass

def lu_solve((lu, piv), b, trans=0, overwrite_b=0):
""" lu_solve((lu, piv), b, trans=0, overwrite_b=0) -> x

Modified: trunk/Lib/optimize/minpack.py
===================================================================
--- trunk/Lib/optimize/minpack.py	2007-04-15 05:16:13 UTC (rev 2921)
+++ trunk/Lib/optimize/minpack.py	2007-04-15 05:37:57 UTC (rev 2922)
@@ -300,13 +300,14 @@

mesg = errors[info][0]
if full_output:
-        import scipy.linalg as sl
+        from numpy.dual import inv
+        from numpy.linalg import LinAlgError
perm = take(eye(n),retval[1]['ipvt']-1,0)
r = triu(transpose(retval[1]['fjac'])[:n,:])
R = dot(r, perm)
try:
-            cov_x = sl.inv(dot(transpose(R),R))
-        except sl.basic.LinAlgError:
+            cov_x = inv(dot(transpose(R),R))
+        except LinAlgError:
cov_x = None
return (retval[0], cov_x) + retval[1:-1] + (mesg,info)
else:

Modified: trunk/Lib/signal/wavelets.py
===================================================================
--- trunk/Lib/signal/wavelets.py	2007-04-15 05:16:13 UTC (rev 2921)
+++ trunk/Lib/signal/wavelets.py	2007-04-15 05:37:57 UTC (rev 2922)
@@ -1,9 +1,9 @@
-## Automatically adapted for scipy Oct 21, 2005 by convertcode.py

-
import numpy as sb
-import scipy as s
+from numpy.dual import eig
+from scipy.misc import comb

+
def daub(p):
"""The coefficients for the FIR low-pass filter producing Daubechies wavelets.

@@ -30,10 +30,10 @@
elif p<35:
# construct polynomial and factor it
if p<35:
-            P = [s.comb(p-1+k,k,exact=1) for k in range(p)][::-1]
+            P = [comb(p-1+k,k,exact=1) for k in range(p)][::-1]
yj = sb.roots(P)
else:  # try different polynomial --- needs work
-            P = [s.comb(p-1+k,k,exact=1)/4.0**k for k in range(p)][::-1]
+            P = [comb(p-1+k,k,exact=1)/4.0**k for k in range(p)][::-1]
yj = sb.roots(P) / 4
# for each root, compute two z roots, select the one with |z|>1
# Build up final polynomial
@@ -124,7 +124,7 @@
psi = 0*x

# find phi0, and phi1
-    lam, v = s.linalg.eig(m[0,0])
+    lam, v = eig(m[0,0])
ind = sb.argmin(sb.absolute(lam-1))
# a dictionary with a binary representation of the
#   evaluation points x < 1 -- i.e. position is 0.xxxx

Modified: trunk/Lib/stats/distributions.py
===================================================================
--- trunk/Lib/stats/distributions.py	2007-04-15 05:16:13 UTC (rev 2921)
+++ trunk/Lib/stats/distributions.py	2007-04-15 05:37:57 UTC (rev 2922)
@@ -6,8 +6,9 @@

from __future__ import nested_scopes
import scipy
-import scipy.special as special
-import scipy.optimize as optimize
+from scipy.misc import comb, derivative
+from scipy import special
+from scipy import optimize
import inspect
from numpy import alltrue, where, arange, put, putmask, \
ravel, take, ones, sum, shape, product, repeat, reshape, \
@@ -91,7 +92,7 @@
def _tosolve(self, x, q, *args):
return apply(self.cdf, (x, )+args) - q
def _single_call(self, q, *args):
-        return scipy.optimize.brentq(self._tosolve, self.xa, self.xb, args=(q,)+args, xtol=self.xtol)
+        return optimize.brentq(self._tosolve, self.xa, self.xb, args=(q,)+args, xtol=self.xtol)
def __call__(self, q, *args):
return self.vecfunc(q, *args)

@@ -327,7 +328,7 @@
return apply(self.cdf, (x, )+args)-q

def _ppf_single_call(self, q, *args):
-        return scipy.optimize.brentq(self._ppf_to_solve, self.xa, self.xb, args=(q,)+args, xtol=self.xtol)
+        return optimize.brentq(self._ppf_to_solve, self.xa, self.xb, args=(q,)+args, xtol=self.xtol)

# moment from definition
def _mom_integ0(self, x,m,*args):
@@ -352,7 +353,7 @@
return cond

def _pdf(self,x,*args):
-        return scipy.derivative(self._cdf,x,dx=1e-5,args=args,order=5)
+        return derivative(self._cdf,x,dx=1e-5,args=args,order=5)

## Could also define any of these (return 1-d using self._size to get number)
def _rvs(self, *args):
@@ -1600,7 +1601,7 @@
return vals
def _munp(self, n, c):
k = arange(0,n+1)
-        val = (-1.0/c)**n * sum(scipy.comb(n,k)*(-1)**k / (1.0-c*k),axis=0)
+        val = (-1.0/c)**n * sum(comb(n,k)*(-1)**k / (1.0-c*k),axis=0)
return where(c*n < 1, val, inf)
def _entropy(self, c):
if (c > 0):
@@ -1658,7 +1659,7 @@
return 1.0/c*(1-(-log(q))**c)
def _munp(self, n, c):
k = arange(0,n+1)
-        vals = 1.0/c**n * sum(scipy.comb(n,k) * (-1)**k * special.gamma(c*k + 1),axis=0)
+        vals = 1.0/c**n * sum(comb(n,k) * (-1)**k * special.gamma(c*k + 1),axis=0)
return where(c*n > -1, vals, inf)
genextreme = genextreme_gen(name='genextreme',
longname="A generalized extreme value",
@@ -3947,7 +3948,6 @@
return cond
def _pmf(self, k, M, n, N):
tot, good = M, n
-        comb = scipy.comb
return comb(good,k) * comb(bad,N-k) / comb(tot,N)
def _stats(self, M, n, N):
@@ -4038,6 +4038,7 @@
def _ppf(self, q, mu):
vals = ceil(special.pdtrik(q,mu))
temp = special.pdtr(vals-1,mu)
+        # fixme: vals1 = vals-1?
return where((temp >= q), vals1, vals)
def _stats(self, mu):
var = mu

```