rem
stringlengths
0
322k
add
stringlengths
0
2.05M
context
stringlengths
8
228k
old_fval,old_old_fval,args=args)
old_fval,old_old_fval)
def fmin_bfgs(f, x0, fprime=None, args=(), gtol=1e-5, norm=Inf, epsilon=_epsilon, maxiter=None, full_output=0, disp=1, retall=0): """Minimize a function using the BFGS algorithm. Description: Optimize the function, f, whose gradient is given by fprime using the quasi-Newton method of Broyden, Fletcher, Goldfarb, and ...
func_calls = func_calls + fc grad_calls = grad_calls + gc
def fmin_bfgs(f, x0, fprime=None, args=(), gtol=1e-5, norm=Inf, epsilon=_epsilon, maxiter=None, full_output=0, disp=1, retall=0): """Minimize a function using the BFGS algorithm. Description: Optimize the function, f, whose gradient is given by fprime using the quasi-Newton method of Broyden, Fletcher, Goldfarb, and ...
if app_fprime: gfkp1 = apply(approx_fprime,(xkp1,f,epsilon)+args) func_calls = func_calls + len(x0) + 1 else: gfkp1 = apply(fprime,(xkp1,)+args) grad_calls = grad_calls + 1
gfkp1 = myfprime(xkp1)
def fmin_bfgs(f, x0, fprime=None, args=(), gtol=1e-5, norm=Inf, epsilon=_epsilon, maxiter=None, full_output=0, disp=1, retall=0): """Minimize a function using the BFGS algorithm. Description: Optimize the function, f, whose gradient is given by fprime using the quasi-Newton method of Broyden, Fletcher, Goldfarb, and ...
print " Function evaluations: %d" % func_calls print " Gradient evaluations: %d" % grad_calls
print " Function evaluations: %d" % func_calls[0] print " Gradient evaluations: %d" % grad_calls[0]
def fmin_bfgs(f, x0, fprime=None, args=(), gtol=1e-5, norm=Inf, epsilon=_epsilon, maxiter=None, full_output=0, disp=1, retall=0): """Minimize a function using the BFGS algorithm. Description: Optimize the function, f, whose gradient is given by fprime using the quasi-Newton method of Broyden, Fletcher, Goldfarb, and ...
retlist = xk, fval, gfk, Hk, func_calls, grad_calls, warnflag
retlist = xk, fval, gfk, Hk, func_calls[0], grad_calls[0], warnflag
def fmin_bfgs(f, x0, fprime=None, args=(), gtol=1e-5, norm=Inf, epsilon=_epsilon, maxiter=None, full_output=0, disp=1, retall=0): """Minimize a function using the BFGS algorithm. Description: Optimize the function, f, whose gradient is given by fprime using the quasi-Newton method of Broyden, Fletcher, Goldfarb, and ...
app_fprime = 0 if fprime is None: app_fprime = 1
def fmin_cg(f, x0, fprime=None, args=(), gtol=1e-5, norm=Inf, epsilon=_epsilon, maxiter=None, full_output=0, disp=1, retall=0): """Minimize a function with nonlinear conjugate gradient algorithm. Description: Optimize the function, f, whose gradient is given by fprime using the nonlinear conjugate gradient algorithm ...
func_calls = 0 grad_calls = 0
func_calls, f = wrap_function(f, args) if fprime is None: grad_calls, myfprime = wrap_function(approx_fprime, (f, epsilon)) else: grad_calls, myfprime = wrap_function(fprime, args) gfk = myfprime(x0)
def fmin_cg(f, x0, fprime=None, args=(), gtol=1e-5, norm=Inf, epsilon=_epsilon, maxiter=None, full_output=0, disp=1, retall=0): """Minimize a function with nonlinear conjugate gradient algorithm. Description: Optimize the function, f, whose gradient is given by fprime using the nonlinear conjugate gradient algorithm ...
old_fval = f(xk,*args)
old_fval = f(xk)
def fmin_cg(f, x0, fprime=None, args=(), gtol=1e-5, norm=Inf, epsilon=_epsilon, maxiter=None, full_output=0, disp=1, retall=0): """Minimize a function with nonlinear conjugate gradient algorithm. Description: Optimize the function, f, whose gradient is given by fprime using the nonlinear conjugate gradient algorithm ...
func_calls +=1 if app_fprime: gfk = apply(approx_fprime,(x0,f,epsilon)+args) myfprime = (approx_fprime,epsilon) func_calls = func_calls + len(x0) + 1 else: gfk = apply(fprime,(x0,)+args) myfprime = fprime grad_calls = grad_calls + 1
def fmin_cg(f, x0, fprime=None, args=(), gtol=1e-5, norm=Inf, epsilon=_epsilon, maxiter=None, full_output=0, disp=1, retall=0): """Minimize a function with nonlinear conjugate gradient algorithm. Description: Optimize the function, f, whose gradient is given by fprime using the nonlinear conjugate gradient algorithm ...
old_old_fval,args=args,c2=0.4)
old_old_fval,c2=0.4)
def fmin_cg(f, x0, fprime=None, args=(), gtol=1e-5, norm=Inf, epsilon=_epsilon, maxiter=None, full_output=0, disp=1, retall=0): """Minimize a function with nonlinear conjugate gradient algorithm. Description: Optimize the function, f, whose gradient is given by fprime using the nonlinear conjugate gradient algorithm ...
func_calls += fc grad_calls += gc
def fmin_cg(f, x0, fprime=None, args=(), gtol=1e-5, norm=Inf, epsilon=_epsilon, maxiter=None, full_output=0, disp=1, retall=0): """Minimize a function with nonlinear conjugate gradient algorithm. Description: Optimize the function, f, whose gradient is given by fprime using the nonlinear conjugate gradient algorithm ...
old_fval,old_old_fval,args=args) func_calls += fc grad_calls += gc
old_fval,old_old_fval)
def fmin_cg(f, x0, fprime=None, args=(), gtol=1e-5, norm=Inf, epsilon=_epsilon, maxiter=None, full_output=0, disp=1, retall=0): """Minimize a function with nonlinear conjugate gradient algorithm. Description: Optimize the function, f, whose gradient is given by fprime using the nonlinear conjugate gradient algorithm ...
if app_fprime: gfkp1 = apply(approx_fprime,(xk,f,epsilon)+args) func_calls = func_calls + len(x0) + 1 else: gfkp1 = apply(fprime,(xk,)+args) grad_calls = grad_calls + 1
gfkp1 = myfprime(xk)
def fmin_cg(f, x0, fprime=None, args=(), gtol=1e-5, norm=Inf, epsilon=_epsilon, maxiter=None, full_output=0, disp=1, retall=0): """Minimize a function with nonlinear conjugate gradient algorithm. Description: Optimize the function, f, whose gradient is given by fprime using the nonlinear conjugate gradient algorithm ...
print " Function evaluations: %d" % func_calls print " Gradient evaluations: %d" % grad_calls
print " Function evaluations: %d" % func_calls[0] print " Gradient evaluations: %d" % grad_calls[0]
def fmin_cg(f, x0, fprime=None, args=(), gtol=1e-5, norm=Inf, epsilon=_epsilon, maxiter=None, full_output=0, disp=1, retall=0): """Minimize a function with nonlinear conjugate gradient algorithm. Description: Optimize the function, f, whose gradient is given by fprime using the nonlinear conjugate gradient algorithm ...
retlist = xk, fval, func_calls, grad_calls, warnflag
retlist = xk, fval, func_calls[0], grad_calls[0], warnflag
def fmin_cg(f, x0, fprime=None, args=(), gtol=1e-5, norm=Inf, epsilon=_epsilon, maxiter=None, full_output=0, disp=1, retall=0): """Minimize a function with nonlinear conjugate gradient algorithm. Description: Optimize the function, f, whose gradient is given by fprime using the nonlinear conjugate gradient algorithm ...
fcalls = 0 gcalls = 0
fcalls, f = wrap_function(f, args) gcalls, fprime = wrap_function(fprime, args)
def fmin_ncg(f, x0, fprime, fhess_p=None, fhess=None, args=(), avextol=1e-5, epsilon=_epsilon, maxiter=None, full_output=0, disp=1, retall=0): """Description: Minimize the function, f, whose gradient is given by fprime using the Newton-CG method. fhess_p must compute the hessian times an arbitrary vector. If it is no...
old_fval = f(x0,*args) fcalls += 1
old_fval = f(x0)
def fmin_ncg(f, x0, fprime, fhess_p=None, fhess=None, args=(), avextol=1e-5, epsilon=_epsilon, maxiter=None, full_output=0, disp=1, retall=0): """Description: Minimize the function, f, whose gradient is given by fprime using the Newton-CG method. fhess_p must compute the hessian times an arbitrary vector. If it is no...
b = -apply(fprime,(xk,)+args) gcalls = gcalls + 1
b = -fprime(xk)
def fmin_ncg(f, x0, fprime, fhess_p=None, fhess=None, args=(), avextol=1e-5, epsilon=_epsilon, maxiter=None, full_output=0, disp=1, retall=0): """Description: Minimize the function, f, whose gradient is given by fprime using the Newton-CG method. fhess_p must compute the hessian times an arbitrary vector. If it is no...
Ap = apply(approx_fhess_p,(xk,psupi,fprime,epsilon)+args) gcalls = gcalls + 2
Ap = approx_fhess_p(xk,psupi,fprime,epsilon)
def fmin_ncg(f, x0, fprime, fhess_p=None, fhess=None, args=(), avextol=1e-5, epsilon=_epsilon, maxiter=None, full_output=0, disp=1, retall=0): """Description: Minimize the function, f, whose gradient is given by fprime using the Newton-CG method. fhess_p must compute the hessian times an arbitrary vector. If it is no...
Ap = apply(fhess_p,(xk,psupi)+args)
Ap = fhess_p(xk,psupi, *args)
def fmin_ncg(f, x0, fprime, fhess_p=None, fhess=None, args=(), avextol=1e-5, epsilon=_epsilon, maxiter=None, full_output=0, disp=1, retall=0): """Description: Minimize the function, f, whose gradient is given by fprime using the Newton-CG method. fhess_p must compute the hessian times an arbitrary vector. If it is no...
alphak, fc, gc, old_fval = line_search_BFGS(f,xk,pk,gfk,old_fval,args) fcalls = fcalls + fc gcalls = gcalls + gc
alphak, fc, gc, old_fval = line_search_BFGS(f,xk,pk,gfk,old_fval)
def fmin_ncg(f, x0, fprime, fhess_p=None, fhess=None, args=(), avextol=1e-5, epsilon=_epsilon, maxiter=None, full_output=0, disp=1, retall=0): """Description: Minimize the function, f, whose gradient is given by fprime using the Newton-CG method. fhess_p must compute the hessian times an arbitrary vector. If it is no...
print " Function evaluations: %d" % fcalls print " Gradient evaluations: %d" % gcalls
print " Function evaluations: %d" % fcalls[0] print " Gradient evaluations: %d" % gcalls[0]
def fmin_ncg(f, x0, fprime, fhess_p=None, fhess=None, args=(), avextol=1e-5, epsilon=_epsilon, maxiter=None, full_output=0, disp=1, retall=0): """Description: Minimize the function, f, whose gradient is given by fprime using the Newton-CG method. fhess_p must compute the hessian times an arbitrary vector. If it is no...
retlist = xk, fval, fcalls, gcalls, hcalls, warnflag
retlist = xk, fval, fcalls[0], gcalls[0], hcalls, warnflag
def fmin_ncg(f, x0, fprime, fhess_p=None, fhess=None, args=(), avextol=1e-5, epsilon=_epsilon, maxiter=None, full_output=0, disp=1, retall=0): """Description: Minimize the function, f, whose gradient is given by fprime using the Newton-CG method. fhess_p must compute the hessian times an arbitrary vector. If it is no...
si = Numeric.sign(xm-xf) + ((xm-xf)==0)
si = Num.sign(xm-xf) + ((xm-xf)==0)
def fminbound(func, x1, x2, args=(), xtol=1e-5, maxfun=500, full_output=0, disp=1): """Bounded minimization for scalar functions. Description: Finds a local minimizer of the scalar function func in the interval x1 < xopt < x2 using Brent's method. (See brent for auto-bracketing). Inputs: func -- the function to be...
si = Numeric.sign(rat) + (rat == 0)
si = Num.sign(rat) + (rat == 0)
def fminbound(func, x1, x2, args=(), xtol=1e-5, maxfun=500, full_output=0, disp=1): """Bounded minimization for scalar functions. Description: Finds a local minimizer of the scalar function func in the interval x1 < xopt < x2 using Brent's method. (See brent for auto-bracketing). Inputs: func -- the function to be...
global _powell_funcalls def _myfunc(alpha, func, x0, direc, args=()): funcargs = (x0 + alpha * direc,)+args return func(*funcargs) def _linesearch_powell(func, p, xi, args=(), tol=1e-3):
def _linesearch_powell(func, p, xi, tol=1e-3):
def bracket(func, xa=0.0, xb=1.0, args=(), grow_limit=110.0): """Given a function and distinct initial points, search in the downhill direction (as defined by the initital points) and return new points xa, xb, xc that bracket the minimum of the function: f(xa) > f(xb) < f(xc) """ _gold = 1.618034 _verysmall_num = 1e-21...
global _powell_funcalls extra_args = (func, p, xi, args) alpha_min, fret, iter, num = brent(_myfunc, args=extra_args, full_output=1, tol=tol)
def myfunc(alpha): return func(p + alpha * xi) alpha_min, fret, iter, num = brent(myfunc, full_output=1, tol=tol)
def _linesearch_powell(func, p, xi, args=(), tol=1e-3): # line-search algorithm using fminbound # find the minimium of the function # func(x0+ alpha*direc) global _powell_funcalls extra_args = (func, p, xi, args) alpha_min, fret, iter, num = brent(_myfunc, args=extra_args, full_output=1, tol=tol) xi = alpha_min*xi _p...
_powell_funcalls += num
def _linesearch_powell(func, p, xi, args=(), tol=1e-3): # line-search algorithm using fminbound # find the minimium of the function # func(x0+ alpha*direc) global _powell_funcalls extra_args = (func, p, xi, args) alpha_min, fret, iter, num = brent(_myfunc, args=extra_args, full_output=1, tol=tol) xi = alpha_min*xi _p...
global _powell_funcalls
fcalls, func = wrap_function(func, args)
def fmin_powell(func, x0, args=(), xtol=1e-4, ftol=1e-4, maxiter=None, maxfun=None, full_output=0, disp=1, retall=0): """Minimize a function using modified Powell's method. Description: Uses a modification of Powell's method to find the minimum of a function of N variables Inputs: func -- the Python function or met...
fval = squeeze(apply(func, (x,)+args)) _powell_funcalls = 1
fval = squeeze(func(x))
def fmin_powell(func, x0, args=(), xtol=1e-4, ftol=1e-4, maxiter=None, maxfun=None, full_output=0, disp=1, retall=0): """Minimize a function using modified Powell's method. Description: Uses a modification of Powell's method to find the minimum of a function of N variables Inputs: func -- the Python function or met...
fval, x, direc1 = _linesearch_powell(func, x, direc1, args=args, tol=xtol*100)
fval, x, direc1 = _linesearch_powell(func, x, direc1, tol=xtol*100)
def fmin_powell(func, x0, args=(), xtol=1e-4, ftol=1e-4, maxiter=None, maxfun=None, full_output=0, disp=1, retall=0): """Minimize a function using modified Powell's method. Description: Uses a modification of Powell's method to find the minimum of a function of N variables Inputs: func -- the Python function or met...
if _powell_funcalls >= maxfun: break
if fcalls[0] >= maxfun: break
def fmin_powell(func, x0, args=(), xtol=1e-4, ftol=1e-4, maxiter=None, maxfun=None, full_output=0, disp=1, retall=0): """Minimize a function using modified Powell's method. Description: Uses a modification of Powell's method to find the minimum of a function of N variables Inputs: func -- the Python function or met...
fx2 = squeeze(apply(func, (x2,)+args)) _powell_funcalls +=1
fx2 = squeeze(func(x2))
def fmin_powell(func, x0, args=(), xtol=1e-4, ftol=1e-4, maxiter=None, maxfun=None, full_output=0, disp=1, retall=0): """Minimize a function using modified Powell's method. Description: Uses a modification of Powell's method to find the minimum of a function of N variables Inputs: func -- the Python function or met...
if _powell_funcalls >= maxfun:
if fcalls[0] >= maxfun:
def fmin_powell(func, x0, args=(), xtol=1e-4, ftol=1e-4, maxiter=None, maxfun=None, full_output=0, disp=1, retall=0): """Minimize a function using modified Powell's method. Description: Uses a modification of Powell's method to find the minimum of a function of N variables Inputs: func -- the Python function or met...
print " Function evaluations: %d" % _powell_funcalls
print " Function evaluations: %d" % fcalls[0]
def fmin_powell(func, x0, args=(), xtol=1e-4, ftol=1e-4, maxiter=None, maxfun=None, full_output=0, disp=1, retall=0): """Minimize a function using modified Powell's method. Description: Uses a modification of Powell's method to find the minimum of a function of N variables Inputs: func -- the Python function or met...
retlist = x, fval, direc, iter, _powell_funcalls, warnflag
retlist = x, fval, direc, iter, fcalls[0], warnflag
def fmin_powell(func, x0, args=(), xtol=1e-4, ftol=1e-4, maxiter=None, maxfun=None, full_output=0, disp=1, retall=0): """Minimize a function using modified Powell's method. Description: Uses a modification of Powell's method to find the minimum of a function of N variables Inputs: func -- the Python function or met...
if __name__ == "__main__": import string
def main():
def _scalarfunc(*params): params = squeeze(asarray(params)) return func(params,*args)
if __name__ == "__main__": main()
def _scalarfunc(*params): params = squeeze(asarray(params)) return func(params,*args)
return special.bdtrik(q,n,pr)
vals = scipy.ceil(special.bdtrik(q,n,pr)) temp = special.bdtr(vals-1,n,pr) return where(temp >= q, vals-1, vals)
def binomppf(q, n, pr=0.5): return special.bdtrik(q,n,pr)
return special.bdtrik(1-p,n,pr)
return binomppf(1-p,n,pr)
def binomisf(p, n, pr=0.5): return special.bdtrik(1-p,n,pr)
out = where(lVar > noise, lMean, im)
res = (im - lMean) res *= (1-noise / lVar) res += lMean out = where(lVar < noise, lMean, res)
def wiener(im,mysize=None,noise=None): """Perform a wiener filter on an N-dimensional array. Description: Apply a wiener filter to the N-dimensional array in. Inputs: in -- an N-dimensional array. kernel_size -- A scalar or an N-length list giving the size of the median filter window in each dimension. Elements of...
int dim[2] = {upper-lower, Nx[0]};
npy_intp dim[2] = {upper-lower, Nx[0]};
def setup_bspline_module(): """ Builds an extension module with Bspline basis calculators using weave. """ mod = ext_tools.ext_module('_bspline', compiler='gcc') knots = N.linspace(0,1,11).astype(N.float64) nknots = knots.shape[0] x = N.array([0.4,0.5], N.float64) nx = x.shape[0] m = 4 d = 0 lower = 0 upper = 13 # Bs...
int dim[2] = {Nknots[0]-m, m};
npy_intp dim[2] = {Nknots[0]-m, m};
def setup_bspline_module(): """ Builds an extension module with Bspline basis calculators using weave. """ mod = ext_tools.ext_module('_bspline', compiler='gcc') knots = N.linspace(0,1,11).astype(N.float64) nknots = knots.shape[0] x = N.array([0.4,0.5], N.float64) nx = x.shape[0] m = 4 d = 0 lower = 0 upper = 13 # Bs...
int dim[2] = {NL[0], NL[1]};
npy_intp dim[2] = {NL[0], NL[1]};
def setup_bspline_module(): """ Builds an extension module with Bspline basis calculators using weave. """ mod = ext_tools.ext_module('_bspline', compiler='gcc') knots = N.linspace(0,1,11).astype(N.float64) nknots = knots.shape[0] x = N.array([0.4,0.5], N.float64) nx = x.shape[0] m = 4 d = 0 lower = 0 upper = 13 # Bs...
return
return {}
def configuration(parent_package=''): """ gist only works with an X-windows server This will install *.gs and *.gp files to '%spython%s/site-packages/scipy/xplt' % (sys.prefix,sys.version[:3]) """ x11 = x11_info().get_info() if not x11: return config = default_config_dict('xplt',parent_package) local_path = get_path(_...
self.log.WriteText("Print Preview failed." \ "Check that default printer is configured\n")
print "Print Preview failed." \ "Check that default printer is configured\n"
def OnFilePreview(self, event): printout = graph_printout(self.client) printout2 = graph_printout(self.client) self.preview = wx.wxPrintPreview(printout, printout2, self.print_data) if not self.preview.Ok(): self.log.WriteText("Print Preview failed." \ "Check that default printer is configured\n") return
f = rv.norm(old,w)[0]
f = rv.norm.rvs(old,w)[0]
def evaluate(self,gene): """ return a new value from the genes allele set """ size = len(gene.allele_set) if size == 1: return gene.allele_set[0] w = self.dev_width * size old = gene.index() new = -1; f = -1 while not (0 <= new < size): f = rv.norm(old,w)[0] new = round(f) if(old == new and f > new): new = new + 1 if(o...
new = rv.norm(gene._value,dev).rvs()[0]
new = rv.norm.rvs(gene._value,dev)[0]
def evaluate(self,gene): dev = (gene.bounds[1]-gene.bounds[0]) * self.dev_width new = gene.bounds[1]
alpha_k, fc, gc, old_fval_backup, old_old_fval_backup, gfkp1 = \
alpha_k, fc, gc, old_fval, old_old_fval, gfkp1 = \
def fmin_cg(f, x0, fprime=None, args=(), gtol=1e-5, norm=Inf, epsilon=_epsilon, maxiter=None, full_output=0, disp=1, retall=0): """Minimize a function with nonlinear conjugate gradient algorithm. Description: Optimize the function, f, whose gradient is given by fprime using the nonlinear conjugate gradient algorithm ...
old_fval,old_old_fval)
old_fval_backup,old_old_fval_backup)
def fmin_cg(f, x0, fprime=None, args=(), gtol=1e-5, norm=Inf, epsilon=_epsilon, maxiter=None, full_output=0, disp=1, retall=0): """Minimize a function with nonlinear conjugate gradient algorithm. Description: Optimize the function, f, whose gradient is given by fprime using the nonlinear conjugate gradient algorithm ...
format = self.getformat()
def __add__(self, other): format = self.getformat() csc = self.tocsc() res = csc + other return eval('%s_matrix'%format)(res)
return eval('%s_matrix'%format)(res)
return res
def __add__(self, other): format = self.getformat() csc = self.tocsc() res = csc + other return eval('%s_matrix'%format)(res)
format = self.getformat()
def __sub__(self, other): format = self.getformat() csc = self.tocsc() res = csc - other return eval('%s_matrix'%format)(res)
return eval('%s_matrix'%format)(res)
return res
def __sub__(self, other): format = self.getformat() csc = self.tocsc() res = csc - other return eval('%s_matrix'%format)(res)
format = self.getformat()
def __rsub__(self, other): # other - self format = self.getformat() csc = self.tocsc() res = csc.__rsub__(other) return eval('%s_matrix'%format)(res)
return eval('%s_matrix'%format)(res)
return res
def __rsub__(self, other): # other - self format = self.getformat() csc = self.tocsc() res = csc.__rsub__(other) return eval('%s_matrix'%format)(res)
format = self.getformat()
def __mul__(self, other): format = self.getformat() csc = self.tocsc() res = csc * other return eval('%s_matrix'%format)(res)
return eval('%s_matrix'%format)(res)
return res
def __mul__(self, other): format = self.getformat() csc = self.tocsc() res = csc * other return eval('%s_matrix'%format)(res)
format = self.getformat()
def __rmul__(self, other): format = self.getformat() csc = self.tocsc() res = csc.__rmul__(other) return eval('%s_matrix'%format)(res)
return eval('%s_matrix'%format)(res)
return res
def __rmul__(self, other): format = self.getformat() csc = self.tocsc() res = csc.__rmul__(other) return eval('%s_matrix'%format)(res)
format = self.getformat()
def __neg__(self): format = self.getformat() csc = self.tocsc() res = -csc return eval('%s_matrix'%format)(res)
return eval('%s_matrix'%format)(res)
return res def matmat(self, other): csc = self.tocsc() res = csc.matmat(other) return res
def __neg__(self): format = self.getformat() csc = self.tocsc() res = -csc return eval('%s_matrix'%format)(res)
format = self.getformat()
def matvec(self, vec): format = self.getformat() csc = self.tocsc() res = csc.matvec(vec) return res
M = max(self.rowind)
M = max(self.rowind) + 1
def __init__(self,s,ij=None,M=None,N=None,nzmax=100,typecode=Float,copy=0): spmatrix.__init__(self, 'csc') if isinstance(s,spmatrix): if isinstance(s, csc_matrix): # do nothing but copy information self.shape = s.shape if copy: self.data = s.data.copy() self.rowind = s.rowind.copy() self.indptr = s.indptr.copy() else: ...
if (len(self.data) != len(self.rowind)):
if (len(self.data) != nzmax):
def _check(self): M,N = self.shape if (rank(self.data) != 1) or (rank(self.rowind) != 1) or \ (rank(self.indptr) != 1): raise ValueError, "Data, rowind, and indptr arrays "\ "should be rank 1." if (len(self.data) != len(self.rowind)): raise ValueError, "Data and row list should have same length" if (len(self.indptr) !=...
if (len(self.rowind)>0) and (max(self.rowind) >= M):
if (nzmax>0) and (max(self.rowind[:nnz]) >= M):
def _check(self): M,N = self.shape if (rank(self.data) != 1) or (rank(self.rowind) != 1) or \ (rank(self.indptr) != 1): raise ValueError, "Data, rowind, and indptr arrays "\ "should be rank 1." if (len(self.data) != len(self.rowind)): raise ValueError, "Data and row list should have same length" if (len(self.indptr) !=...
self.nnz = self.indptr[-1] self.nzmax = len(self.rowind)
self.nnz = nnz self.nzmax = nzmax
def _check(self): M,N = self.shape if (rank(self.data) != 1) or (rank(self.rowind) != 1) or \ (rank(self.indptr) != 1): raise ValueError, "Data, rowind, and indptr arrays "\ "should be rank 1." if (len(self.data) != len(self.rowind)): raise ValueError, "Data and row list should have same length" if (len(self.indptr) !=...
if not (0<=row<M) or not (0<=col<N): raise KeyError, "Index out of bounds."
if (row < 0): row = M + row if (col < 0): col = N + col if (row < 0) or (col < 0): raise IndexError, "Index out of bounds." if (col >= N): self.indptr = resize1d(self.indptr, col+2) self.indptr[N+1:] = self.indptr[N] N = col+1 if (row >= M): M = row+1 self.shape = (M,N)
def __setitem__(self, key, val): if isinstance(key,types.TupleType): row = key[0] col = key[1] func = getattr(sparsetools,self.ftype+'cscsetel') M, N = self.shape if not (0<=row<M) or not (0<=col<N): raise KeyError, "Index out of bounds." nzmax = self.nzmax if (nzmax < self.nnz+1): # need more room alloc = max(1,self....
if not (0<=row<M) or not (0<=col<N): raise KeyError, "Index out of bounds."
if (row < 0): row = M + row if (col < 0): col = N + col if (row >= M ) or (col >= N) or (row < 0) or (col < 0): raise IndexError, "Index out of bounds."
def __getitem__(self, key): if isinstance(key,types.TupleType): row = key[0] col = key[1] func = getattr(sparsetools,self.ftype+'cscgetel') M, N = self.shape if not (0<=row<M) or not (0<=col<N): raise KeyError, "Index out of bounds." ind, val = func(self.data, self.colind, self.indptr, col, row) return val elif isinsta...
if not (0<=row<M) or not (0<=col<N):
if (row < 0): row = M + row if (col < 0): col = N + col if (row < 0) or (col < 0):
def __setitem__(self, key, val): if isinstance(key,types.TupleType): row = key[0] col = key[1] func = getattr(sparsetools,self.ftype+'cscsetel') M, N = self.shape if not (0<=row<M) or not (0<=col<N): raise KeyError, "Index out of bounds." nzmax = self.nzmax if (nzmax < self.nnz+1): # need more room alloc = max(1,self....
self.typecode = None
self.nnz = 0
def __init__(self,A=None): dict.__init__(self) spmatrix.__init__(self,'dok') self.shape = (0,0) self.typecode = None if A is not None: A = asarray(A) N,M = A.shape for n in range(N): for m in range(M): if A[n,m] != 0: self[n,m] = A[n,m]
res = dictmatrix()
res = dok_matrix()
def __add__(self, other): res = dictmatrix() res.update(self) res.shape = self.shape for key in other.keys(): try: res[key] += other[key] except KeyError: res[key] = other[key] return res
res = dictmatrix()
res = dok_matrix()
def __sub__(self, other): res = dictmatrix() res.update(self) res.shape = self.shape for key in other.keys(): try: res[key] -= other[key] except KeyError: res[key] = -other[key] return res
res = dictmatrix()
res = dok_matrix()
def __neg__(self): res = dictmatrix() for key in self.keys(): res[key] = -self[key] return res
if isinstance(other, dictmatrix):
if isinstance(other, dok_matrix):
def __mul__(self, other): if isinstance(other, dictmatrix): return self.matmat(other) other = asarray(other) if rank(other) > 0: return self.matvec(other) res = dictmatrix() for key in self.keys(): res[key] = other * self[key] return res
res = dictmatrix()
res = dok_matrix()
def __mul__(self, other): if isinstance(other, dictmatrix): return self.matmat(other) other = asarray(other) if rank(other) > 0: return self.matvec(other) res = dictmatrix() for key in self.keys(): res[key] = other * self[key] return res
new = dictmatrix()
new = dok_matrix()
def transp(self): # Transpose (return the transposed) new = dictmatrix() for key in self.keys(): new[key[1],key[0]] = self[key] return new
def matmat(self, other): res = dictmatrix() spself = spmatrix(self) spother = spmatrix(other) spres = spself * spother return spres.todict()
def matmat(self, other): res = dictmatrix() spself = spmatrix(self) spother = spmatrix(other) spres = spself * spother return spres.todict()
res = dictmatrix()
res = dok_matrix()
def take(self, cols_or_rows, columns=1): # Extract columns or rows as indictated from matrix # assume cols_or_rows is sorted res = dictmatrix() indx = int((columns == 1)) N = len(cols_or_rows) if indx: # columns for key in self.keys(): num = searchsorted(cols_or_rows,key[1]) if num < N: newkey = (key[0],num) res[newkey...
base = dictmatrix() ext = dictmatrix()
base = dok_matrix() ext = dok_matrix()
def split(self, cols_or_rows, columns=1): # similar to take but returns two array, the extracted # columns plus the resulting array # assumes cols_or_rows is sorted base = dictmatrix() ext = dictmatrix() indx = int((columns == 1)) N = len(cols_or_rows) if indx: for key in self.keys(): num = searchsorted(cols_or_rows,...
def getCSR(self):
def tocsr(self):
def getCSR(self): # Return Compressed Sparse Row format arrays for this matrix keys = self.keys() keys.sort() nnz = len(keys) data = [0]*nnz colind = [0]*nnz row_ptr = [0]*(self.shape[0]+1) current_row = -1 k = 0 for key in keys: ikey0 = int(key[0]) ikey1 = int(key[1]) if ikey0 != current_row: current_row = ikey0 row_p...
ptype = data.typecode() if ptype not in ['d','D','f','F']: data = data.astype('d') ptype = 'd' return _transtabl[ptype], nnz, data, colind, row_ptr def getCSC(self):
return csr_matrix(data,(colind, row_ptr)) def tocsc(self):
def getCSR(self): # Return Compressed Sparse Row format arrays for this matrix keys = self.keys() keys.sort() nnz = len(keys) data = [0]*nnz colind = [0]*nnz row_ptr = [0]*(self.shape[0]+1) current_row = -1 k = 0 for key in keys: ikey0 = int(key[0]) ikey1 = int(key[1]) if ikey0 != current_row: current_row = ikey0 row_p...
ptype = data.typecode() if ptype not in ['d','D','f','F']: data = data.astype('d') ptype = 'd' return _transtabl[ptype], nnz, data, colind, col_ptr def dense(self,typecode=None): if typecode is None: typecode = self.type
return csc_matrix(data, (colind, col_ptr)) def todense(self,typecode=None):
def getCSC(self): # Return Compressed Sparse Column format arrays for this matrix keys = self.keys() keys.sort(csc_cmp) nnz = len(keys) data = [None]*nnz colind = [None]*nnz col_ptr = [None]*(self.shape[1]+1) current_col = -1 k = 0 for key in keys: ikey0 = int(key[0]) ikey1 = int(key[1]) if ikey1 != current_col: curren...
pass
def __init__(self, obj, ij, M=None, N=None, nzmax=None, typecode=None): aobj = asarray(obj) aij = asarray(ij) if M is None: M = amax(aij[:,0]) if N is None: N = amax(aij[:,1]) self.shape = (M,N) if nzmax is None: nzmax = len(aobj) self.nzmax = nzmax self.data = aobj self.row = aij[:,0] self.col = aij[:,1] self.typecode...
def dense(self,typecode=None): if typecode is None: typecode = self.type if typecode is None: typecode = 'd' new = zeros(self.shape,typecode) for key in self.keys(): ikey0 = int(key[0]) ikey1 = int(key[1]) new[ikey0,ikey1] = self[key] return new
diagfunc = eval('_sparsekit.'+_transtabl[mtype]+'diacsr') nzmax = diags.shape[0]*diags.shape[1] s = spmatrix(m,n,nzmax,typecode=mtype) diagfunc(array(m), array(n), array(0), diags, offsets, s.data, s.index[0], s.index[1], array(diags.shape[1]),array(diags.shape[0])) s.lastel = min([m,n])*len(offsets) - 1 - \ sum(_...
diagfunc = eval('sparsetools.'+_transtabl[mtype]+'diatocsr') a, rowa, ptra, ierr = diagfunc(m,n,diags,offsets) if ierr: raise ValueError, "Ran out of memory (shouldn't have happened)" return csc_matrix(a,(rowa,ptra),M=m,N=n)
def spdiags(diags,offsets,m,n): """Return a sparse matrix given it's diagonals. B = spdiags(diags, offsets, M, N) Inputs: diags -- rows contain diagonal values offsets -- diagonals to set (0 is main) M, N -- sparse matrix returned is M X N """ diags = array(transpose(diags),copy=1) if diags.typecode() not in 'fd...
A.ftype, A.nnz, A.data, A.rowind, A.indptr
mat.ftype, mat.nnz, mat.data, mat.rowind, mat.indptr
def solve(A,b,permc_spec=2): if not hasattr(A, 'tocsr') and not hasattr(A, 'tocsc'): raise ValueError, "Sparse matrix must be able to return CSC format--"\ "A.tocsc()--or CSR format--A.tocsr()" if not hasattr(A,'shape'): raise ValueError, "Sparse matrix must be able to return shape (rows,cols) = A.shape" M,N = A.shape ...
A.ftype, A.nnz, A.data, A.colind, A.indptr
mat.ftype, mat.nnz, mat.data, mat.colind, mat.indptr
def solve(A,b,permc_spec=2): if not hasattr(A, 'tocsr') and not hasattr(A, 'tocsc'): raise ValueError, "Sparse matrix must be able to return CSC format--"\ "A.tocsc()--or CSR format--A.tocsr()" if not hasattr(A,'shape'): raise ValueError, "Sparse matrix must be able to return shape (rows,cols) = A.shape" M,N = A.shape ...
assert_array_almost_equal(numpy.matrixmultiply(a,x),b)
assert_array_almost_equal(numpy.dot(a,x),b)
def check_simple(self):
assert_array_almost_equal(numpy.matrixmultiply(a,x0),[1,0])
assert_array_almost_equal(numpy.dot(a,x0),[1,0])
def check_20Feb04_bug(self): a = [[1,1],[1.0,0]] # ok x0 = solve(a,[1,0j]) assert_array_almost_equal(numpy.matrixmultiply(a,x0),[1,0])
assert_array_almost_equal(numpy.matrixmultiply(a,x),b)
assert_array_almost_equal(numpy.dot(a,x),b)
def check_simple(self): a = [[1,20],[-30,4]] for b in ([[1,0],[0,1]],[1,0], [[2,1],[-30,4]]): x = solve(a,b) assert_array_almost_equal(numpy.matrixmultiply(a,x),b)
assert_array_almost_equal(numpy.matrixmultiply(a,x),b)
assert_array_almost_equal(numpy.dot(a,x),b)
def check_simple_sym(self): a = [[2,3],[3,5]] for lower in [0,1]: for b in ([[1,0],[0,1]],[1,0]): x = solve(a,b,sym_pos=1,lower=lower) assert_array_almost_equal(numpy.matrixmultiply(a,x),b)
assert_array_almost_equal(numpy.matrixmultiply(a,x),b)
assert_array_almost_equal(numpy.dot(a,x),b)
def check_simple_sym_complex(self): a = [[5,2],[2,4]] for b in [[1j,0], [[1j,1j], [0,2]], ]: x = solve(a,b,sym_pos=1) assert_array_almost_equal(numpy.matrixmultiply(a,x),b)
assert_array_almost_equal(numpy.matrixmultiply(a,x),b)
assert_array_almost_equal(numpy.dot(a,x),b)
def check_simple_complex(self): a = array([[5,2],[2j,4]],'D') for b in [[1j,0], [[1j,1j], [0,2]], [1,0j], array([1,0],'D'), ]: x = solve(a,b) assert_array_almost_equal(numpy.matrixmultiply(a,x),b)
assert_array_almost_equal(numpy.matrixmultiply(a,x),b)
assert_array_almost_equal(numpy.dot(a,x),b)
def check_random(self):
assert_array_almost_equal(numpy.matrixmultiply(a,x),b)
assert_array_almost_equal(numpy.dot(a,x),b)
def check_random_complex(self): n = 20 a = random([n,n]) + 1j * random([n,n]) for i in range(n): a[i,i] = 20*(.1+a[i,i]) for i in range(2): b = random([n,3]) x = solve(a,b) assert_array_almost_equal(numpy.matrixmultiply(a,x),b)
assert_array_almost_equal(numpy.matrixmultiply(a,x),b)
assert_array_almost_equal(numpy.dot(a,x),b)
def check_random_sym(self): n = 20 a = random([n,n]) for i in range(n): a[i,i] = abs(20*(.1+a[i,i])) for j in range(i): a[i,j] = a[j,i] for i in range(4): b = random([n]) x = solve(a,b,sym_pos=1) assert_array_almost_equal(numpy.matrixmultiply(a,x),b)
assert_array_almost_equal(numpy.matrixmultiply(a,x),b)
assert_array_almost_equal(numpy.dot(a,x),b)
def check_random_sym_complex(self): n = 20 a = random([n,n]) #a = a + 1j*random([n,n]) # XXX: with this the accuracy will be very low for i in range(n): a[i,i] = abs(20*(.1+a[i,i])) for j in range(i): a[i,j] = numpy.conjugate(a[j,i]) b = random([n])+2j*random([n]) for i in range(2): x = solve(a,b,sym_pos=1) assert_arr...
assert_array_almost_equal(numpy.matrixmultiply(a,a_inv),
assert_array_almost_equal(numpy.dot(a,a_inv),
def check_simple(self): a = [[1,2],[3,4]] a_inv = inv(a) assert_array_almost_equal(numpy.matrixmultiply(a,a_inv), [[1,0],[0,1]]) a = [[1,2,3],[4,5,6],[7,8,10]] a_inv = inv(a) assert_array_almost_equal(numpy.matrixmultiply(a,a_inv), [[1,0,0],[0,1,0],[0,0,1]])
assert_array_almost_equal(numpy.matrixmultiply(a,a_inv),
assert_array_almost_equal(numpy.dot(a,a_inv),
def check_random(self): n = 20 for i in range(4): a = random([n,n]) for i in range(n): a[i,i] = 20*(.1+a[i,i]) a_inv = inv(a) assert_array_almost_equal(numpy.matrixmultiply(a,a_inv), numpy.identity(n))
assert_array_almost_equal(numpy.matrixmultiply(a,a_inv),
assert_array_almost_equal(numpy.dot(a,a_inv),
def check_simple_complex(self): a = [[1,2],[3,4j]] a_inv = inv(a) assert_array_almost_equal(numpy.matrixmultiply(a,a_inv), [[1,0],[0,1]])