def _distSpearmanW_NU(x, y, w): """x,y,w must be Numeric """ x = Numeric.asarray(x) y = Numeric.asarray(y) w = Numeric.asarray(w) assert Numeric.rank(x) == Numeric.rank(y) == Numeric.rank(w) == 1 rankx = Numeric.array(statc.rankdata(x.tolist())) ranky = Numeric.array(statc.rankdata(y.tolist())) return distPearsonW(rankx, ranky, w)
def mad(m,axis=0): """Returns Median Absolute Deviation of the given array along the given axis. """ m = Numeric.asarray(m) mx = Numeric.asarray(median(m,axis),Numeric.Float) xt = Numeric.transpose(m, [axis]+range(axis)+range(axis+1,Numeric.rank(m))) # do not use swapaxes: (0,1,2) -swap-> (2,1,0); (0,1,2) -transpose-> (2,0,1) return MLab.median(Numeric.absolute(xt-mx))
def __init__ ( self, x=None, y=None, ireg=None, triangle=None ): try: self.x = array ( x, typecode=Float, copy=0 ) except: raise TypeError( "Could not cast x to numpy array") if not ( rank(self.x) == 2 and shape(self.x)[0] >=2 and shape(self.x)[1] >= 2 ): raise TypeError( "x must be 2D") try: self.y = array ( y, typecode=Float, copy=0 ) except: raise TypeError( "Could not cast y to numpy array") if not ( rank(self.y) == 2 and shape(self.y)[0] >=2 and shape(self.y)[1] >= 2 ): raise TypeError( "y must be 2D") if ireg is None: self.ireg = zeros ( shape(self.x), Int ) self.ireg[1:,1:] = 1 else: try: self.ireg = array ( ireg, typecode=Int, copy=0 ) except: raise TypeError( "Could not cast ireg to numpy array") if not ( rank(self.ireg) == 2 and shape(self.ireg)[0] >=2 and shape(self.ireg)[1] >= 2 ): raise TypeError( "ireg must be 2D") if triangle is None: self.triangle = zeros ( shape(self.x), Int16 ) else: try: self.triangle = array ( triangle, typecode=Int16, copy=0 ) except: raise TypeError( "Could not cast triangle to numpy array") if not ( rank(self.triangle) == 2 and shape(self.triangle)[0] >=2 and shape(self.triangle)[1] >= 2 ): raise TypeError( "triangle must be 2D") self.shape = shape(self.x)
def rankData(n, inverse=False): """Returns ranks of 1D Numeric array in range 1...shape[0]. """ n = Numeric.asarray(n) assert Numeric.rank(n) == 1 r = Numeric.zeros(n.shape[0], Numeric.Float) Numeric.put(r, Numeric.argsort(n), Numeric.arange(n.shape[0])) if inverse: return -1*r+n.shape[0] else: return r+1
def setReg ( self, ireg ): try: self.ireg = array ( ireg, typecode=Int, copy=0 ) except: raise TypeError( "Could not cast ireg to numpy array") if not ( rank(self.ireg) == 2 and shape(self.ireg)[0] >=2 and shape(self.ireg)[1] >= 2 ): raise TypeError( "ireg must be 2D") if self.shape != shape ( self.ireg ): raise InputError( "ireg has incompatible shape.")
def setTriangle ( self, triangle ): try: self.triangle = array ( triangle, typecode=Int16, copy=0 ) except: raise TypeError( "Could not cast triangle to numpy array") if not ( rank(self.triangle) == 2 and shape(self.triangle)[0] >=2 and shape(self.triangle)[1] >= 2 ): raise TypeError( "triangle must be 2D") if self.shape != shape (self.triangle): raise InputError( "triangle has incompatible shape.")