def check_rows(f, comp_row): good_rows = 0 for row in util.parse_matrix_txt(f): if len(row) != len(comp_row): continue good = True for i, val in enumerate(row): if int(val) != int(comp_row[i]): good = False break if good: good_rows += 1 return good_rows
def check_diag_ones(f, nrows): abs_int = lambda x: int(round(math.fabs(x))) i = 0 for i, row in enumerate(util.parse_matrix_txt(f)): print row if len(row) != nrows: print 'Expected row of length %d but got row of length %d' % ( nrows, len(row)) return False for j in xrange(nrows): if j == i and abs_int(row[j]) != 1: print 'Expected absolute value of 1 for entry (%d, %d) of value %d' % ( i, j, abs_int(row[j])) return False elif j != i and abs_int(row[j]) != 0: print 'Expected absolute value of 0 for entry (%d, %d) of value %d' % ( i, j, abs_int(row[j])) return False if i + 1 != nrows: print 'Expected %d rows but only read %d.' % (nrows, i) return False return True
cm.error('no V^t matrix provided, use --Vt') matrices['Sigma'] = {'path': options.Sigma, 'mat': None} if matrices['Sigma']['path'] == '': cm.error('no Sigma matrix provided, use --Sigma') out = options.out for matrix in matrices: # copy the data over and parse it local_store = 'form_Y_' + matrix cm.copy_from_hdfs(matrices[matrix]['path'], local_store + '.mseq') cm.parse_seq_file(local_store + '.mseq', local_store + '.txt') # read the local data data = [] for line in util.parse_matrix_txt(local_store + '.txt'): data.append(line) matrices[matrix]['mat'] = numpy.mat(data) S = matrices['S']['mat'] V = numpy.transpose(matrices['Vt']['mat']) Sigma_inv = numpy.linalg.pinv(matrices['Sigma']['mat']) S_tilde = S * V * Sigma_inv eig_vals, Y = numpy.linalg.eig(S_tilde) Y_Re = numpy.real(Y) Y_Im = numpy.imag(Y) def write_Y(mat, path): if os.path.exists(path): os.remove(path)
#!/usr/bin/env python import numpy import util cm = util.CommandManager() norms = [[], [], []] for j in xrange(3): for i in xrange(17): if j == 0: mat = 'Stability_caqr_%d_Q' % i elif j == 1: mat = 'Stability_caqr_%d_IR_Q' % i elif j == 2: mat = 'Stability_full_%d_3' % i mat += '-ata' local_store = mat + '_local' cm.copy_from_hdfs(mat, local_store + '.mseq') cm.parse_seq_file(local_store + '.mseq', local_store + '.txt') data = [] for line in util.parse_matrix_txt(local_store + '.txt'): data.append(line) matrix = numpy.mat(data) - numpy.identity(10) norm = numpy.linalg.norm(matrix, 2) print norm norms[j].append(norm) for norm_list in norms: print norm_list
def parseM(self, mpath): data = [] for row in util.parse_matrix_txt(mpath): data.append(row) self.small = numpy.mat(data)
def parse_premult(self, matpath): data = [] for row in util.parse_matrix_txt(matpath): data.append(row) self.small = numpy.linalg.inv(numpy.mat(data))
def parseM(self, matpath): data = [] for row in util.parse_matrix_txt(matpath): data.append(row) return numpy.mat(data)