def plot_eigs_cover(obj, la): r""" :param obj: object of the class ``BrakeClass`` :param la: eigenavlues :return: radius of the disc covering all the eigenvalues """ x1 = obj.target[0] x2 = obj.target[1] y1 = obj.target[2] y2 = obj.target[3] # calculate center of the obj.target rectangular region tau = complex((x1 + x2) / 2, (y1 + y2) / 2) radius = max(abs(la - tau)) #fig = plt.gcf() fig = plt.figure(figsize=(24.0, 15.0)) circle = plt.Circle((tau.real, tau.imag), radius, color='g', fill=False) react = plt.Rectangle((x1, y1), abs(x2 - x1), abs(y2 - y1), color='black', fill=False) ax = plt.gca() ax.cla() # clear things for fresh plot ax.set_xlim((tau.real - 1.1 * radius, tau.real + 1.1 * radius)) ax.set_ylim((tau.imag - 1.1 * radius, tau.imag + 1.1 * radius)) plt.axhline(0, color='blue') plt.axvline(0, color='blue') x = la.real y = la.imag for i in range(0, len(x)): if x[i] >= 0: ax.plot(x[i], y[i], 'o', color='red') else: ax.plot(x[i], y[i], 'o', color='green') ax.plot((tau.real), (tau.imag), '+', color='r') fig.gca().add_artist(circle) fig.gca().add_artist(react) #fig.savefig(obj.output_path+'plotcover.png') brake.save(obj.output_path + 'plotEigsCover', ext="png", close=True, verbose=False) return radius
rank = estimate_rank(aslinearoperator(componentMatrix), eps) #print 'Approximate rank with relative error of(', eps, ')for numerical rank definition = ',rank print obj.data_file_list[i], obj.data_file_name[ i], componentMatrix.shape, ' NonZeros = ', componentMatrix.nnz, ' 1-Norm = ', normMatrix, ' rank ', rank obj.logger_i.info(obj.data_file_list[i] + ' ' + obj.data_file_name[i] + str(componentMatrix.shape) + ' NonZeros = ' + str(componentMatrix.nnz) + ' 1-Norm = ' + str(normMatrix) + ' rank ' + str(rank)) #saving the sparsity pattern fig = plt.figure(figsize=(24.0, 15.0)) fig.clf() fig.gca().add_artist(plt.spy(componentMatrix)) brake.save(obj.output_path + 'dataAnalysis/' + obj.data_file_name[i], ext="png", close=True, verbose=False) end_program = timeit.default_timer() print "\n", "\n", "\n", 'Total Run Time = : ' + "%.2f" % ( end_program - begin_program) + ' sec' if (obj.log_level): obj.logger_i.info( '\nNote: The rank obtained using python estimate_rank utility') obj.logger_i.info( 'is observed to be lower than the rank obtained using MATLAB') obj.logger_i.info( '\nNote: The norm computed is a lower bound of the 1-norm of the sparse matrix.' )
plt.subplot(223) plt.plot(xDim, yTheta2List[0], '-ro', label='Traditional') plt.plot(xDim, yTheta2List[1], '-kD', label='wset1') plt.plot(xDim, yTheta2List[2], '-bs', label='wset2') plt.plot(xDim, yTheta2List[3], '-go', label='wset3') plt.legend(loc='lower left', shadow=True) plt.yscale('log') plt.xlabel('dimension') plt.ylabel('theta2') #plt.title('maximum angle between exact eigenvector and the computed eigenvector') plt.grid(True) plt.subplot(224) #plt.plot(xDim, ySingularList[0], '-ro', label='Traditional') plt.plot(xDim, ySingularList[1], '-kD', label='wset1') plt.plot(xDim, ySingularList[2], '-bs', label='wset2') plt.plot(xDim, ySingularList[3], '-go', label='wset3') plt.legend(loc='lower left', shadow=True) plt.yscale('log') plt.xlabel('dimension') plt.ylabel('singular values') plt.title('Decay of singular values') plt.grid(True) brake.save(obj.output_path + 'traditionalVsPOD' + str(obj.omegaTest / (2 * math.pi)), ext="png", close=False, verbose=True) plt.show()
def draw_circles(obj, next_shift, next_radius): r""" :param obj: object of the class ``BrakeClass`` :param next_shift: the shift point to be shown on the plot :param next_radius: the radius of the shift point to be shown :return: plots a circle corresponding to the next shift point and appends it to the existing plot. :raises: ``Cover_BadInputError``, When the provided input is not as expected """ target = obj.target # Exceptions #------------------------------------------------------------ if len(target) == 0: raise Cover_BadInputError('The target is not specified') elif len(target) < 4: raise Cover_BadInputError('target region does not define a reactangle') elif target[1] <= target[0] or target[3] <= target[2]: raise Cover_BadInputError('the target reactangle is not defined') if not next_radius: raise Cover_BadInputError('The previous_radius is not specified') elif next_radius <= 0: raise Cover_BadInputError('The radius is nonpositive') x1 = target[0] x2 = target[1] y1 = target[2] y2 = target[3] if not next_shift: raise Cover_BadInputError('The next_shift array is not length 1') elif next_shift.real < x1 \ or next_shift.real > x2 \ or next_shift.imag < y1 \ or next_shift.imag > y2: raise Cover_BadInputError('shift point not in target region') #------------------------------------------------------------ x1 = target[0] x2 = target[1] y1 = target[2] y2 = target[3] fig = plt.gcf() circle = plt.Circle((next_shift.real, next_shift.imag), next_radius, color='b', fill=False) react = plt.Rectangle((x1, y1), abs(x2 - x1), abs(y2 - y1), color='black', fill=False) ax = plt.gca() #ax.cla() # clear things for fresh plot ax.set_xlim((y1 - 1000, y2 + 1000)) ax.set_ylim((y1 - 1000, y2 + 1000)) plt.axhline(0, color='blue') plt.axvline(0, color='blue') fig.gca().add_artist(circle) fig.gca().add_artist(react) brake.save(obj.output_path + 'drawCircles', ext="png", close=True, verbose=False) return
plt.title('relative error between computed and exact eigenvalues') plt.grid(True) plt.subplot(222) plt.plot(x, y, '-kD') plt.yscale('log') plt.xlabel('dimension') plt.title('maximum angle between exact eigenvector and the projection space') plt.grid(True) plt.subplot(223) plt.plot(x, y, '-bs') plt.yscale('log') plt.xlabel('dimension') plt.title( 'maximum angle between exact eigenvector and the computed eigenvector') plt.grid(True) plt.subplot(224) plt.plot(x, y, '-go') plt.yscale('log') plt.xlabel('dimension') plt.title('decay of singular values') plt.grid(True) #plt.subplot_tool() #plt.show() brake.save(obj.output_path + 'testBrake', ext="png", close=False, verbose=True) plt.show()