def mmean(ar):
    """
    Take the average of an array of arbitrary dimension. Works for
    slices and other arrays where ar.flat is undefined.
    """
    from Numeric import average
    if len(ar.shape) == 1:
        return average(ar)
    else:
        return average([mmean(x) for x in ar])
def stats(data):
    """
    Assumes a matrix of data with variables on the columns
    and observations on the rows.  Returns the mean,
    variance and standard error of the data.
    """
    from Numeric import average, sqrt
    mean = average(data)
    var = average((data - mean)**2)
    stderr = sqrt(var) / sqrt(len(data))
    return mean, var, stderr
Esempio n. 3
0
    def gaussian_activation(self):
        x = self.dists
        radii = zeros(self.dists.shape) * 0.0

        for u,conn_dict in enumerate(self.connections):
            neighbors = take(self.weights,conn_dict.keys())
            radii[u] = average(matrixnorm(neighbors-self.weights[u]))

        self.__activation = gaussian(x,radii/2)
    def gaussian_activation(self):
        x = self.dists
        radii = zeros(self.dists.shape) * 0.0

        for u, conn_dict in enumerate(self.connections):
            neighbors = take(self.weights, conn_dict.keys())
            radii[u] = average(matrixnorm(neighbors - self.weights[u]))

        self.__activation = gaussian(x, radii / 2)
Esempio n. 5
0
 def time_to_grow(self):
     from Numeric import average,sqrt
     e = average(self.error*self.beta)[0]
     
     result = (e > self.error_threshold
              and super(EquilibriumGNG,self).time_to_grow())
     if result:
         self.verbose("average error = %.4e"%e," -- Time to grow.")
     else:
         self.debug("average error = %.4e"%e," -- Not growing.")
         
     return result
    def time_to_grow(self):
        from Numeric import average, sqrt
        e = average(self.error * self.beta)[0]

        result = (e > self.error_threshold
                  and super(EquilibriumGNG, self).time_to_grow())
        if result:
            self.verbose("average error = %.4e" % e, " -- Time to grow.")
        else:
            self.debug("average error = %.4e" % e, " -- Not growing.")

        return result
Esempio n. 7
0
	def mcl_id2prediction_spaceTogo_no2prediction_space(self, mcl_id2prediction_space):
		"""
		07-05-05
			transform mcl_id2prediction_space to go_no2prediction_space, each mcl_id's prediction_space
			is averaged
		"""
		sys.stderr.write("Transforming mcl_id2prediction_space...")
		go_no2prediction_space = {}
		go_no = -1
		go_no2prediction_space[go_no] = []
		for (mcl_id, data) in mcl_id2prediction_space.iteritems():
			data = array(data)
			unit = [average(data[:,0]), average(data[:,1]), average(data[:,2]), average(data[:,3]), average(data[:,4]), average(data[:,-1])]
			if self.debug:
				print data
				print "averaged",unit
				is_continue = raw_input("Continue?Y/n")
				if is_continue =='n':
					sys.exit(2)
			go_no2prediction_space[go_no].append(unit)
		sys.stderr.write("%s data points to do fitting. Done.\n"%len(go_no2prediction_space[go_no]))
		return go_no2prediction_space
Esempio n. 8
0
def mean_center(X):
    """
    
    @param X: 2-dimensional matrix of number data 
    @type X: Numeric array
    
    
    @return: Mean centered X (always has same dimensions as X)
    
    """
    (rows, cols) = shape(X)
    new_X = zeros((rows, cols), Float)
    _averages = average(X, 0)
    #print _averages
        
    for row in range(rows):
        for col in range(cols):
            new_X[row, col] = X[row, col] - _averages[col]
    return new_X
Esempio n. 9
0
def mean_center(X):
    """
    
    @param X: 2-dimensional matrix of number data 
    @type X: Numeric array
    
    
    @return: Mean centered X (always has same dimensions as X)
    
    """
    (rows, cols) = shape(X)
    new_X = zeros((rows, cols), Float)
    _averages = average(X, 0)
    #print _averages

    for row in range(rows):
        for col in range(cols):
            new_X[row, col] = X[row, col] - _averages[col]
    return new_X
Esempio n. 10
0
def condense_matrix(matrix, smallest_index, large_value):
    """converges the rows and columns indicated by smallest_index
    
    Smallest index is returned from find_smallest_index.
    For both the rows and columns, the values for the two indices are
    averaged. The resulting vector replaces the first index in the array
    and the second index is replaced by an array with large numbers so that
    it is never chosen again with find_smallest_index.
    """
    first_index, second_index = smallest_index
    #get the rows and make a new vector that has their average
    rows = take(matrix, smallest_index)
    new_vector = average(rows)
    #replace info in the row and column for first index with new_vector
    matrix[first_index] = new_vector
    matrix[:, first_index] = new_vector
    #replace the info in the row and column for the second index with 
    #high numbers so that it is ignored
    matrix[second_index] = large_value
    matrix[:, second_index] = large_value
    return matrix