def _bcbcg_exp(self): bcbcg_solver_obj = BCBCG() step_val_a = 3 step_val_b = 5 self._final_X_a, self._final_R_a, self._residual_hist_a = \ bcbcg_solver_obj.bcbcg_solver(self._mat, self._B, self._X, step_val_a, self._tol, self._maxiter,0) self._final_X_b, self._final_R_b, self._residual_hist_b = \ bcbcg_solver_obj.bcbcg_solver(self._mat, self._B, self._X, step_val_b, self._tol, self._maxiter,0)
def _db_bcbcg_lstsq (self): """ """ bcbcg_solver_obj = BCBCG() self._final_X_a, self._final_R_a, self._residual_hist_a = \ bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB, self._BX, self._step_val, self._tol, self._maxiter,0) self._final_X_b, self._final_R_b, self._residual_hist_b = \ bcbcg_solver_obj.bcbcg_solver(self._mat, self._BB, self._BX, self._step_val, self._tol, self._maxiter,0) plot_worker = Presenter() residual_list = [self._residual_hist_a, self._residual_hist_b] legend_list = ["bcbcg_s20b4_lstsq","bcbcg_s20b4"] color_list = ["r","k"] plot_worker.instant_plot_y_log10(residual_list, "crystm02", "#iteration", "$\\frac{||x_1||}{||b_1||}$", legend_list, color_list)
def _bcbcg_blbcg_least_square_exp_b(self): """ figure 2""" print("_bcbcg_blbcg_least_square_exp_b starting ... ") m=3 self._BB = np.random.random( ( self._mat.shape[0],m) ) self._BX = np.ones ( (self._mat.shape[1],m) ) #line 1 blbcg_solver_obj = BLBCG() self._final_x_blbcg_a, self._final_r_blbcg_a, self._residual_hist_blbcg_a = \ blbcg_solver_obj.blbcg_solver_least_square(self._mat, self._BB, self._BX, 16, self._tol, self._maxiter, 0) #line 2 blbcg_solver_obj = BLBCG() self._final_x_blbcg_b, self._final_r_blbcg_b, self._residual_hist_blbcg_b = \ blbcg_solver_obj.blbcg_solver_least_square(self._mat, self._BB, self._BX, 32, self._tol, self._maxiter, 0) #line addition #blbcg_solver_obj = BLBCG() #self._final_x_blbcg_c, self._final_r_blbcg_c, self._residual_hist_blbcg_c = \ # blbcg_solver_obj.blbcg_solver_least_square(self._mat, self._BB_4, self._BX_4, 32, self._tol, self._maxiter, 0) #line 3 bcbcg_solver_obj = BCBCG() self._final_x_bcbcg_a, self._final_r_bcbcg_a, self._residual_hist_bcbcg_a = \ bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB, self._BX, 16, self._tol, self._maxiter, 0) #line 4 bcbcg_solver_obj = BCBCG() self._final_x_bcbcg_b, self._final_r_bcbcg_b, self._residual_hist_bcbcg_b = \ bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB, self._BX, 32, self._tol, self._maxiter, 0) #line addition #bcbcg_solver_obj = BCBCG() #self._final_x_bcbcg_c, self._final_r_bcbcg_c, self._residual_hist_bcbcg_c = \ # bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_4, self._BX_4, 32, self._tol, self._maxiter, 0) plot_worker = Presenter() #residual_list = [self._residual_hist_blbcg_a, self._residual_hist_blbcg_b, self._residual_hist_blbcg_c, \ # self._residual_hist_bcbcg_a, self._residual_hist_bcbcg_b, self._residual_hist_bcbcg_c ] residual_list = [self._residual_hist_blbcg_a, self._residual_hist_blbcg_b, \ self._residual_hist_bcbcg_a, self._residual_hist_bcbcg_b ] #legend_list = ["blbcg_m4s4", "blbcg_m4s8", "blbcg_m4s12", "bcbcg_m4s4", "bcbcg_m4s8", "bcbcg_m4s12"] legend_list = ["blbcg_m3s16", "blbcg_m3s32", "bcbcg_m3s16", "bcbcg_m3s32"] #color_list = ["r","k","b","y","g","m"] color_list = ["r","k","b","g"] #plot_worker.instant_plot_y_log10(residual_list, "test", "#iteration", "$\\mathbf{log_{10}\\frac{||x_1||}{||b_1||}}$", legend_list, color_list) plot_worker.instant_plot_y_log10(residual_list, "bodyy6", "#iteration", "$\\mathbf{log_{10}\\frac{||x_1||}{||b_1||}}$", legend_list, color_list)
def _blbcg_least_square_exp(self): """ """ blbcg_solver_obj = BLBCG() self._final_x_a, self._final_r_a, self._residual_hist_a = \ blbcg_solver_obj.blbcg_solver_least_square(self._mat, self._BB, self._BX, self._step_val, self._tol, self._maxiter, 0) bcbcg_solver_obj = BCBCG() self._final_x_b, self._final_r_b, self._residual_hist_b = \ bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB, self._BX, self._step_val, self._tol, self._maxiter, 0) plot_worker = Presenter() residual_list = [self._residual_hist_a, self._residual_hist_b] legend_list = ["blbcg_s64b4_lstsq","bcbcg_s64b4_lstsq"] color_list = ["r","k"] #plot_worker.instant_plot_y_log10(residual_list, "crystm01", "#iteration", "$\\frac{||x_1||}{||b_1||}$", legend_list, color_list) plot_worker.instant_plot_y_log10(residual_list, "bodyy6", "#iteration", "$\\frac{||x_1||}{||b_1||}$", legend_list, color_list)
def _db_blbcg_exp(self): """ """ lbcg_solver_obj = LBCG() self._final_x_a, self._final_r_a, self._residual_hist_a = \ lbcg_solver_obj.lbcg_solver(self._mat, self._SB, self._SX, 8, self._tol, self._maxiter) blbcg_solver_obj = BLBCG() self._final_x_b, self._final_r_b, self._residual_hist_b = \ blbcg_solver_obj.blbcg_solver(self._mat, self._BB, self._BX, 8, self._tol, self._maxiter, 0) bcbcg_solver_obj = BCBCG() self._final_x_c, self._final_r_c, self._residual_hist_c = \ bcbcg_solver_obj.bcbcg_solver(self._mat, self._BB, self._BX, 8, self._tol, self._maxiter, 0) plot_worker = Presenter() residual_list = [self._residual_hist_a, self._residual_hist_b, self._residual_hist_c] legend_list = ["lbcg_s8","blbcg_s8b10", "bcbcg_s8b10"] color_list = ["r","k", "b"] plot_worker.instant_plot_y_log10(residual_list, "bodyy6", "#iteration", "$\\frac{||x_1||}{||b_1||}$", legend_list, color_list)
def _cg_bcg_bcbcg_blcg_exp(self, block_size): """ """ print("_cg_bcg_bcbcg_least_square_exp starting, ... ") self._BB_1 = np.random.random( ( self._mat.shape[0],1) ) self._BX_1 = np.ones ( (self._mat.shape[1],1) ) self._BB_X = np.random.random( ( self._mat.shape[0],block_size) ) self._BX_X = np.ones ( (self._mat.shape[1],block_size) ) #line 1 bcg_solver_obj = NativeBlockConjugateGradient(self._mat, self._BX_1, self._BB_1, self._tol, self._maxiter) self._final_X_cg, self._final_R_cg, self._residual_hist_cg = bcg_solver_obj.bcg_variant_lstsq_run(0) ##line 2 bcg_solver_obj = NativeBlockConjugateGradient(self._mat, self._BX_X, self._BB_X, self._tol, self._maxiter) self._final_X_bcg_mX, self._final_R_bcg_mX, self._residual_hist_bcg_mX = bcg_solver_obj.bcg_variant_lstsq_run(0) #line 3 bcbcg_solver_obj = BCBCG() self._final_x_bcbcg_m1sY, self._final_r_bcbcg_m1sY, self._residual_hist_bcbcg_m1sY = \ bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_1, self._BX_1, self._step_val, self._tol, self._maxiter, 0) #line 4 bcbcg_solver_obj = BCBCG() self._final_x_bcbcg_mXsY, self._final_r_bcbcg_mXsY, self._residual_hist_bcbcg_mXsY = \ bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_X, self._BX_X, self._step_val, self._tol, self._maxiter, 0) #line 5 blbcg_solver_obj = BLBCG() self._final_x_blbcg_mXsY, self._final_r_blbcg_mXsY, self._residual_hist_blbcg_mXsY = \ blbcg_solver_obj.blbcg_solver_least_square(self._mat, self._BB_X, self._BX_X, self._step_val, self._tol, self._maxiter, 0) plot_worker = Presenter() residual_list = [self._residual_hist_cg, self._residual_hist_bcg_mX, self._residual_hist_bcbcg_m1sY, \ self._residual_hist_bcbcg_mXsY, self._residual_hist_blbcg_mXsY] legend_list = ["cg","bcg_m"+str(block_size), "bcbcg_m1_s"+str(self._step_val), \ "bcbcg_m"+str(block_size)+"s"+str(self._step_val), "blbcg_m"+str(block_size)+"s"+str(self._step_val)] color_list = ["r","k","b","g","m"] plot_worker.instant_plot_y_log10(residual_list, "MG", "#iteration", "$\\mathbf{log_{10}\\frac{||r_1||}{||b_1||}}$", legend_list, color_list)
def _bcbcg_blbcg_least_square_exp_b(self): """ """ self._BB_6 = np.random.random( ( self._mat.shape[0],6) ) self._BX_6 = np.ones ( (self._mat.shape[1],6) ) #line 1 blbcg_solver_obj = BLBCG() self._final_x_blbcg_m6s6, self._final_r_blbcg_m6s6, self._residual_hist_blbcg_m6s6 = \ blbcg_solver_obj.blbcg_solver_least_square(self._mat, self._BB_6, self._BX_6, 6, self._tol, self._maxiter, 0) #line 2 blbcg_solver_obj = BLBCG() self._final_x_blbcg_m6s12, self._final_r_blbcg_m6s12, self._residual_hist_blbcg_m6s12 = \ blbcg_solver_obj.blbcg_solver_least_square(self._mat, self._BB_6, self._BX_6, 12, self._tol, self._maxiter, 0) #line 3 bcbcg_solver_obj = BCBCG() self._final_x_bcbcg_m6s6, self._final_r_bcbcg_m6s6, self._residual_hist_bcbcg_m6s6 = \ bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_6, self._BX_6, 6, self._tol, self._maxiter, 0) #line 4 bcbcg_solver_obj = BCBCG() self._final_x_bcbcg_m6s12, self._final_r_bcbcg_m6s12, self._residual_hist_bcbcg_m6s12 = \ bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_6, self._BX_6, 12, self._tol, self._maxiter, 0) plot_worker = Presenter() residual_list = [self._residual_hist_blbcg_m6s6, self._residual_hist_blbcg_m6s12, \ self._residual_hist_bcbcg_m6s6, self._residual_hist_bcbcg_m6s12 ] legend_list = ["blbcg_m6s6", "blbcg_m6s12", "bcbcg_m6s6", "bcbcg_m6s12"] color_list = ["r","k","b","y"] #plot_worker.instant_plot_y_log10(residual_list, "Chem97ZtZ", "#iteration", "$\\frac{||x_1||}{||b_1||}$", legend_list, color_list) plot_worker.instant_plot_y_log10(residual_list, "test", "#iteration", "$\\mathbf{log_{10}\\frac{||x_1||}{||b_1||}}$", legend_list, color_list)
def _bcbcg_blbcg_least_square_exp_b(self): """ figure 2""" print("_bcbcg_blbcg_least_square_exp_b starting ... ") m = 3 self._BB = np.random.random((self._mat.shape[0], m)) self._BX = np.ones((self._mat.shape[1], m)) #line 1 blbcg_solver_obj = BLBCG() self._final_x_blbcg_a, self._final_r_blbcg_a, self._residual_hist_blbcg_a = \ blbcg_solver_obj.blbcg_solver_least_square(self._mat, self._BB, self._BX, 16, self._tol, self._maxiter, 0) #line 2 blbcg_solver_obj = BLBCG() self._final_x_blbcg_b, self._final_r_blbcg_b, self._residual_hist_blbcg_b = \ blbcg_solver_obj.blbcg_solver_least_square(self._mat, self._BB, self._BX, 32, self._tol, self._maxiter, 0) #line addition #blbcg_solver_obj = BLBCG() #self._final_x_blbcg_c, self._final_r_blbcg_c, self._residual_hist_blbcg_c = \ # blbcg_solver_obj.blbcg_solver_least_square(self._mat, self._BB_4, self._BX_4, 32, self._tol, self._maxiter, 0) #line 3 bcbcg_solver_obj = BCBCG() self._final_x_bcbcg_a, self._final_r_bcbcg_a, self._residual_hist_bcbcg_a = \ bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB, self._BX, 16, self._tol, self._maxiter, 0) #line 4 bcbcg_solver_obj = BCBCG() self._final_x_bcbcg_b, self._final_r_bcbcg_b, self._residual_hist_bcbcg_b = \ bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB, self._BX, 32, self._tol, self._maxiter, 0) #line addition #bcbcg_solver_obj = BCBCG() #self._final_x_bcbcg_c, self._final_r_bcbcg_c, self._residual_hist_bcbcg_c = \ # bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_4, self._BX_4, 32, self._tol, self._maxiter, 0) plot_worker = Presenter() #residual_list = [self._residual_hist_blbcg_a, self._residual_hist_blbcg_b, self._residual_hist_blbcg_c, \ # self._residual_hist_bcbcg_a, self._residual_hist_bcbcg_b, self._residual_hist_bcbcg_c ] residual_list = [self._residual_hist_blbcg_a, self._residual_hist_blbcg_b, \ self._residual_hist_bcbcg_a, self._residual_hist_bcbcg_b ] #legend_list = ["blbcg_m4s4", "blbcg_m4s8", "blbcg_m4s12", "bcbcg_m4s4", "bcbcg_m4s8", "bcbcg_m4s12"] legend_list = [ "blbcg_m3s16", "blbcg_m3s32", "bcbcg_m3s16", "bcbcg_m3s32" ] #color_list = ["r","k","b","y","g","m"] color_list = ["r", "k", "b", "g"] #plot_worker.instant_plot_y_log10(residual_list, "test", "#iteration", "$\\mathbf{log_{10}\\frac{||x_1||}{||b_1||}}$", legend_list, color_list) plot_worker.instant_plot_y_log10( residual_list, "bodyy6", "#iteration", "$\\mathbf{log_{10}\\frac{||x_1||}{||b_1||}}$", legend_list, color_list)
def _cg_bcg_bcbcg_blcg_exp(self, block_size): """ """ print("_cg_bcg_bcbcg_least_square_exp starting, ... ") self._BB_1 = np.random.random((self._mat.shape[0], 1)) self._BX_1 = np.ones((self._mat.shape[1], 1)) self._BB_X = np.random.random((self._mat.shape[0], block_size)) self._BX_X = np.ones((self._mat.shape[1], block_size)) #line 1 bcg_solver_obj = NativeBlockConjugateGradient(self._mat, self._BX_1, self._BB_1, self._tol, self._maxiter) self._final_X_cg, self._final_R_cg, self._residual_hist_cg = bcg_solver_obj.bcg_variant_lstsq_run( 0) ##line 2 bcg_solver_obj = NativeBlockConjugateGradient(self._mat, self._BX_X, self._BB_X, self._tol, self._maxiter) self._final_X_bcg_mX, self._final_R_bcg_mX, self._residual_hist_bcg_mX = bcg_solver_obj.bcg_variant_lstsq_run( 0) #line 3 bcbcg_solver_obj = BCBCG() self._final_x_bcbcg_m1sY, self._final_r_bcbcg_m1sY, self._residual_hist_bcbcg_m1sY = \ bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_1, self._BX_1, self._step_val, self._tol, self._maxiter, 0) #line 4 bcbcg_solver_obj = BCBCG() self._final_x_bcbcg_mXsY, self._final_r_bcbcg_mXsY, self._residual_hist_bcbcg_mXsY = \ bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_X, self._BX_X, self._step_val, self._tol, self._maxiter, 0) #line 5 blbcg_solver_obj = BLBCG() self._final_x_blbcg_mXsY, self._final_r_blbcg_mXsY, self._residual_hist_blbcg_mXsY = \ blbcg_solver_obj.blbcg_solver_least_square(self._mat, self._BB_X, self._BX_X, self._step_val, self._tol, self._maxiter, 0) plot_worker = Presenter() residual_list = [self._residual_hist_cg, self._residual_hist_bcg_mX, self._residual_hist_bcbcg_m1sY, \ self._residual_hist_bcbcg_mXsY, self._residual_hist_blbcg_mXsY] legend_list = ["cg","bcg_m"+str(block_size), "bcbcg_m1_s"+str(self._step_val), \ "bcbcg_m"+str(block_size)+"s"+str(self._step_val), "blbcg_m"+str(block_size)+"s"+str(self._step_val)] color_list = ["r", "k", "b", "g", "m"] plot_worker.instant_plot_y_log10( residual_list, "MG", "#iteration", "$\\mathbf{log_{10}\\frac{||r_1||}{||b_1||}}$", legend_list, color_list)
def _db_bcbcg_eigen_param(self): """ """ self._BB_6 = np.random.random( ( self._mat.shape[0],6) ) self._BX_6 = np.ones ( (self._mat.shape[1],6) ) gerschgorin_estimator = GerschgorinCircleTheoremEigenvalueEstimator() max_eigenvalue, min_eigenvalue = gerschgorin_estimator.csr_mat_extreme_eigenvalue_estimation(self._mat) print("################", "max:",max_eigenvalue, " , min:", min_eigenvalue) bcbcg_solver_obj = BCBCG() self._final_x_bcbcg_eigenparam_m6s6, self._final_r_bcbcg_eigenparam_m6s6, self._residual_hist_bcbcg_eigenparam_m6s6 = \ bcbcg_solver_obj.bcbcg_solver_least_square_eigen_param(self._mat, self._BB_6, self._BX_6, 6, self._tol, self._maxiter, 0, max_eigenvalue, min_eigenvalue) bcbcg_solver_obj = BCBCG() self._final_x_bcbcg_m6s6, self._final_r_bcbcg_m6s6, self._residual_hist_bcbcg_m6s6 = \ bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_6, self._BX_6, 6, self._tol, self._maxiter, 0) plot_worker = Presenter() residual_list = [self._residual_hist_bcbcg_eigenparam_m6s6, self._residual_hist_bcbcg_m6s6] legend_list = ["bcbcg_eigenparam_m6s6", "bcbcg_m6s6"] color_list = ["r","k"] plot_worker.instant_plot_y_log10(residual_list, "test", "#iteration", "$\\mathbf{log_{10}\\frac{||x_1||}{||b_1||}}$", legend_list, color_list)
def _bcbcg_exp(self): bcbcg_solver_obj = BCBCG() self._final_X, self._final_R, self._residual_hist = \ bcbcg_solver_obj.bcbcg_solver(self._mat, self._B, self._X, self._step_val, self._tol, self._maxiter,1)
def _bcbcg_exp(self): bcbcg_solver_obj = BCBCG() self._final_X, self._final_R, self._residual_hist = \ bcbcg_solver_obj.bcbcg_solver(self._mat, self._B, self._X, self._step_val, self._tol, self._maxiter,0)
def _diff_eigen_estimation_test_c(self): """ """ print("_diff_eigen_estimation_test_c starting ...") gerschgorin_estimator = GerschgorinCircleTheoremEigenvalueEstimator() gerschgorin_max_eigenvalue, gerschgorin_min_eigenvalue = gerschgorin_estimator.csr_mat_extreme_eigenvalue_estimation( self._mat) print("################Gershchogrin theorem", "min:", gerschgorin_max_eigenvalue, " , old min:", gerschgorin_min_eigenvalue) if gerschgorin_min_eigenvalue < 0.: gerschgorin_min_eigenvalue = 0. print("################Gershchogrin theorem", "min:", gerschgorin_max_eigenvalue, " , new min:", gerschgorin_min_eigenvalue) eigs_vals, eigs_vecs = eigs(self._mat, k=6, which="LM") print("eigs_vals max", eigs_vals) #eigs_vals, eigs_vecs = eigs(self._mat, k=6, tol=1e-3,which="SR") #print("eigs_vals min", eigs_vals) power_method_solver = PowerIteration() self._init_eigen_vec = np.random.random((self._mat.shape[0], 1)) pm_maxiters = 500 pm_tol = 1e-6 pm_max_eigen_vec, pm_max_eigen_val, pm_max_eigen_list = power_method_solver.naive_power_iteration( self._mat, self._init_eigen_vec, pm_maxiters, pm_tol) print("################Power method max:", pm_max_eigen_val, " , iteration:", len(pm_max_eigen_list)) #self._init_eigen_vec = np.random.random( ( self._mat.shape[0],1) ) #pm_min_eigen_vec, pm_min_eigen_val, pm_min_eigen_list = power_method_solver.power_iteration_with_shifting_acc1 (self._mat, self._init_eigen_vec, pm_max_eigen_val, pm_maxiters, pm_tol) #pm_min_eigen_val = pm_min_eigen_val + pm_max_eigen_val #print("################Power method min:",pm_min_eigen_val, " , iteration:", len(pm_min_eigen_list)) ## eigen_repo = {"gerschgorin":(gerschgorin_max_eigenvalue, gerschgorin_min_eigenvalue),\ "mix_method":(pm_max_eigen_val,gerschgorin_min_eigenvalue) \ } print(eigen_repo["gerschgorin"], " , ", eigen_repo["mix_method"]) self._BB = np.random.random((self._mat.shape[0], 3)) self._BX = np.ones((self._mat.shape[1], 3)) step_val = 32 #line 2 bcbcg_solver_obj = BCBCG() self._final_gerschgorin_x_bcbcg_a, self._final_gerschgorin_r_bcbcg_a, self._gerschgorin_residual_hist_bcbcg_a = \ bcbcg_solver_obj.bcbcg_solver_least_square_eigen_param(self._mat, self._BB, self._BX, step_val, self._tol, self._maxiter, 0, eigen_repo["gerschgorin"][0], eigen_repo["gerschgorin"][1]) #line 4 bcbcg_solver_obj = BCBCG() self._final_mix_x_bcbcg_b, self._final_mix_r_bcbcg_b, self._mix_residual_hist_bcbcg_b = \ bcbcg_solver_obj.bcbcg_solver_least_square_eigen_param(self._mat, self._BB, self._BX, step_val, self._tol, self._maxiter, 0, eigen_repo["mix_method"][0], eigen_repo["mix_method"][1]) #addition blbcg_solver_obj = BLBCG() self._final_gerschgorin_x_blbcg_a, self._final_gerschgorin_r_blbcg_a, self._gerschgorin_residual_hist_blbcg_a = \ blbcg_solver_obj.blbcg_solver_least_square_eigen_param(self._mat, self._BB, self._BX, step_val, self._tol, self._maxiter, 0, eigen_repo["gerschgorin"][0], eigen_repo["gerschgorin"][1]) blbcg_solver_obj = BLBCG() self._final_mix_x_blbcg_b, self._final_mix_r_blbcg_b, self._mix_residual_hist_blbcg_b = \ blbcg_solver_obj.blbcg_solver_least_square_eigen_param(self._mat, self._BB, self._BX, step_val, self._tol, self._maxiter, 0, eigen_repo["mix_method"][0], eigen_repo["mix_method"][1]) plot_worker = Presenter() residual_list = [self._gerschgorin_residual_hist_bcbcg_a, self._mix_residual_hist_bcbcg_b , \ self._gerschgorin_residual_hist_blbcg_a, self._mix_residual_hist_blbcg_b ] legend_list = [ "G_bcbcg_m3s32", "M_bcbcg_m3s32", "G_blbcg_m3s32", "M_blbcg_m3s32" ] #legend_list = ["G_bcbcg_m3s8","M_bcbcg_m3s8" , "G_blbcg_m3s8","M_blbcg_m3s8"] color_list = ["r", "k", "b", "g"] #plot_worker.instant_plot_y_log10(residual_list, "test", "#iteration", "$\\mathbf{log_{10}\\frac{||x_1||}{||b_1||}}$", legend_list, color_list) #plot_worker.instant_plot_y_log10(residual_list, "wathen100", "#iteration", "$\\mathbf{log_{10}\\frac{||x_1||}{||b_1||}}$", legend_list, color_list) plot_worker.instant_plot_y_log10( residual_list, "bodyy6", "#iteration", "$\\mathbf{log_{10}\\frac{||x_1||}{||b_1||}}$", legend_list, color_list)
def _debug_bcbcg(self): bcbcg_solver_obj = BCBCG() self._final_X, self._final_R, self._residual_hist = \ bcbcg_solver_obj.bcbcg_solver(self._mat, self._B, self._X, self._step_val, self._tol, self._maxiter,1) print(self._residual_hist)
def _cg_bcg_bcbcg_least_square_exp(self): """ """ print("_cg_bcg_bcbcg_least_square_exp starting, ... ") self._BB_1 = np.random.random( ( self._mat.shape[0],1) ) self._BX_1 = np.ones ( (self._mat.shape[1],1) ) self._BB_4 = np.random.random( ( self._mat.shape[0],4) ) self._BX_4 = np.ones ( (self._mat.shape[1],4) ) self._BB_12 = np.random.random( ( self._mat.shape[0],12) ) self._BX_12 = np.ones ( (self._mat.shape[1],12) ) #line 1 bcg_solver_obj = NativeBlockConjugateGradient(self._mat, self._BX_1, self._BB_1, self._tol, self._maxiter) self._final_X_cg, self._final_R_cg, self._residual_hist_cg = bcg_solver_obj.bcg_variant_lstsq_run(0) #line 2 bcg_solver_obj = NativeBlockConjugateGradient(self._mat, self._BX_12, self._BB_12, self._tol, self._maxiter) self._final_X_bcg_m12, self._final_R_bcg_m12, self._residual_hist_bcg_m12 = bcg_solver_obj.bcg_variant_lstsq_run(0) #line 3 bcbcg_solver_obj = BCBCG() self._final_x_bcbcg_m1s2, self._final_r_bcbcg_m1s2, self._residual_hist_bcbcg_m1s2 = \ bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_1, self._BX_1, 2, self._tol, self._maxiter, 0) #line 4 bcbcg_solver_obj = BCBCG() self._final_x_bcbcg_m1s8, self._final_r_bcbcg_m1s8, self._residual_hist_bcbcg_m1s8 = \ bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_1, self._BX_1, 8, self._tol, self._maxiter, 0) #line 5 bcbcg_solver_obj = BCBCG() self._final_x_bcbcg_m4s2, self._final_r_bcbcg_m4s2, self._residual_hist_bcbcg_m4s2 = \ bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_4, self._BX_4, 2, self._tol, self._maxiter, 0) #line 6 bcbcg_solver_obj = BCBCG() self._final_x_bcbcg_m4s8, self._final_r_bcbcg_m4s8, self._residual_hist_bcbcg_m4s8 = \ bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_4, self._BX_4, 8, self._tol, self._maxiter, 0) plot_worker = Presenter() residual_list = [self._residual_hist_cg, self._residual_hist_bcg_m12, \ self._residual_hist_bcbcg_m1s2, self._residual_hist_bcbcg_m1s8, \ self._residual_hist_bcbcg_m4s2, self._residual_hist_bcbcg_m4s8 ] legend_list = ["cg","bcg_m12", "bcbcg_m1s2", "bcbcg_m1s8", "bcbcg_m4s2", "bcbcg_m4s8"] color_list = ["r","k","b","y","m","g"] #plot_worker.instant_plot_y_log10(residual_list, "test", "#iteration", "$\\mathbf{log_{10}\\frac{||x_1||}{||b_1||}}$", legend_list, color_list) #plot_worker.instant_plot_y_log10(residual_list, "wathen100(dim=30,401, nnz=471,601, cond=5816.01 )", "#iteration", "$\\mathbf{log_{10}\\frac{||x_1||}{||b_1||}}$", legend_list, color_list) plot_worker.instant_plot_y_log10(residual_list, "wathen100", "#iteration", "$\\mathbf{log_{10}\\frac{||x_1||}{||b_1||}}$", legend_list, color_list)
def _diff_eigen_estimation_test_c(self): """ """ print("_diff_eigen_estimation_test_c starting ...") gerschgorin_estimator = GerschgorinCircleTheoremEigenvalueEstimator() gerschgorin_max_eigenvalue, gerschgorin_min_eigenvalue = gerschgorin_estimator.csr_mat_extreme_eigenvalue_estimation(self._mat) print("################Gershchogrin theorem", "min:",gerschgorin_max_eigenvalue, " , old min:", gerschgorin_min_eigenvalue) if gerschgorin_min_eigenvalue< 0.: gerschgorin_min_eigenvalue = 0. print("################Gershchogrin theorem", "min:",gerschgorin_max_eigenvalue, " , new min:", gerschgorin_min_eigenvalue) eigs_vals, eigs_vecs = eigs(self._mat, k=6, which="LM") print("eigs_vals max", eigs_vals) #eigs_vals, eigs_vecs = eigs(self._mat, k=6, tol=1e-3,which="SR") #print("eigs_vals min", eigs_vals) power_method_solver = PowerIteration() self._init_eigen_vec = np.random.random( ( self._mat.shape[0],1) ) pm_maxiters = 500 pm_tol = 1e-6 pm_max_eigen_vec, pm_max_eigen_val, pm_max_eigen_list = power_method_solver.naive_power_iteration (self._mat, self._init_eigen_vec, pm_maxiters, pm_tol) print("################Power method max:",pm_max_eigen_val, " , iteration:", len(pm_max_eigen_list)) #self._init_eigen_vec = np.random.random( ( self._mat.shape[0],1) ) #pm_min_eigen_vec, pm_min_eigen_val, pm_min_eigen_list = power_method_solver.power_iteration_with_shifting_acc1 (self._mat, self._init_eigen_vec, pm_max_eigen_val, pm_maxiters, pm_tol) #pm_min_eigen_val = pm_min_eigen_val + pm_max_eigen_val #print("################Power method min:",pm_min_eigen_val, " , iteration:", len(pm_min_eigen_list)) ## eigen_repo = {"gerschgorin":(gerschgorin_max_eigenvalue, gerschgorin_min_eigenvalue),\ "mix_method":(pm_max_eigen_val,gerschgorin_min_eigenvalue) \ } print(eigen_repo["gerschgorin"], " , ", eigen_repo["mix_method"]) self._BB = np.random.random( ( self._mat.shape[0],3) ) self._BX = np.ones ( (self._mat.shape[1],3) ) step_val = 32 #line 2 bcbcg_solver_obj = BCBCG() self._final_gerschgorin_x_bcbcg_a, self._final_gerschgorin_r_bcbcg_a, self._gerschgorin_residual_hist_bcbcg_a = \ bcbcg_solver_obj.bcbcg_solver_least_square_eigen_param(self._mat, self._BB, self._BX, step_val, self._tol, self._maxiter, 0, eigen_repo["gerschgorin"][0], eigen_repo["gerschgorin"][1]) #line 4 bcbcg_solver_obj = BCBCG() self._final_mix_x_bcbcg_b, self._final_mix_r_bcbcg_b, self._mix_residual_hist_bcbcg_b = \ bcbcg_solver_obj.bcbcg_solver_least_square_eigen_param(self._mat, self._BB, self._BX, step_val, self._tol, self._maxiter, 0, eigen_repo["mix_method"][0], eigen_repo["mix_method"][1]) #addition blbcg_solver_obj = BLBCG() self._final_gerschgorin_x_blbcg_a, self._final_gerschgorin_r_blbcg_a, self._gerschgorin_residual_hist_blbcg_a = \ blbcg_solver_obj.blbcg_solver_least_square_eigen_param(self._mat, self._BB, self._BX, step_val, self._tol, self._maxiter, 0, eigen_repo["gerschgorin"][0], eigen_repo["gerschgorin"][1]) blbcg_solver_obj = BLBCG() self._final_mix_x_blbcg_b, self._final_mix_r_blbcg_b, self._mix_residual_hist_blbcg_b = \ blbcg_solver_obj.blbcg_solver_least_square_eigen_param(self._mat, self._BB, self._BX, step_val, self._tol, self._maxiter, 0, eigen_repo["mix_method"][0], eigen_repo["mix_method"][1]) plot_worker = Presenter() residual_list = [self._gerschgorin_residual_hist_bcbcg_a, self._mix_residual_hist_bcbcg_b , \ self._gerschgorin_residual_hist_blbcg_a, self._mix_residual_hist_blbcg_b ] legend_list = ["G_bcbcg_m3s32","M_bcbcg_m3s32" , "G_blbcg_m3s32","M_blbcg_m3s32"] #legend_list = ["G_bcbcg_m3s8","M_bcbcg_m3s8" , "G_blbcg_m3s8","M_blbcg_m3s8"] color_list = ["r","k","b","g"] #plot_worker.instant_plot_y_log10(residual_list, "test", "#iteration", "$\\mathbf{log_{10}\\frac{||x_1||}{||b_1||}}$", legend_list, color_list) #plot_worker.instant_plot_y_log10(residual_list, "wathen100", "#iteration", "$\\mathbf{log_{10}\\frac{||x_1||}{||b_1||}}$", legend_list, color_list) plot_worker.instant_plot_y_log10(residual_list, "bodyy6", "#iteration", "$\\mathbf{log_{10}\\frac{||x_1||}{||b_1||}}$", legend_list, color_list)
def _cg_bcg_bcbcg_least_square_exp(self): """ """ self._BB_1 = np.random.random( ( self._mat.shape[0],1) ) self._BX_1 = np.ones ( (self._mat.shape[1],1) ) self._BB_6 = np.random.random( ( self._mat.shape[0],6) ) self._BX_6 = np.ones ( (self._mat.shape[1],6) ) self._BB_12 = np.random.random( ( self._mat.shape[0],12) ) self._BX_12 = np.ones ( (self._mat.shape[1],12) ) #line 1 bcg_solver_obj = NativeBlockConjugateGradient(self._mat, self._BX_1, self._BB_1, self._tol, self._maxiter) self._final_X_cg, self._final_R_cg, self._residual_hist_cg = bcg_solver_obj.bcg_variant_lstsq_run(0) #line 2 bcg_solver_obj = NativeBlockConjugateGradient(self._mat, self._BX_12, self._BB_12, self._tol, self._maxiter) self._final_X_bcg_m12, self._final_R_bcg_m12, self._residual_hist_bcg_m12 = bcg_solver_obj.bcg_variant_lstsq_run(0) #line 3 bcbcg_solver_obj = BCBCG() self._final_x_bcbcg_m1s2, self._final_r_bcbcg_m1s2, self._residual_hist_bcbcg_m1s2 = \ bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_1, self._BX_1, 2, self._tol, self._maxiter, 0) #line 4 #bcbcg_solver_obj = BCBCG() #self._final_x_bcbcg_m1s6, self._final_r_bcbcg_m1s6, self._residual_hist_bcbcg_m1s6 = \ # bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_1, self._BX_1, 6, self._tol, self._maxiter, 0) bcbcg_solver_obj = BCBCG() self._final_x_bcbcg_m1s6, self._final_r_bcbcg_m1s6, self._residual_hist_bcbcg_m1s6 = \ bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_1, self._BX_1, 8, self._tol, self._maxiter, 0) #line 5 bcbcg_solver_obj = BCBCG() self._final_x_bcbcg_m6s2, self._final_r_bcbcg_m6s2, self._residual_hist_bcbcg_m6s2 = \ bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_6, self._BX_6, 2, self._tol, self._maxiter, 0) #line 6 #bcbcg_solver_obj = BCBCG() #self._final_x_bcbcg_m6s6, self._final_r_bcbcg_m6s6, self._residual_hist_bcbcg_m6s6 = \ # bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_6, self._BX_6, 6, self._tol, self._maxiter, 0) bcbcg_solver_obj = BCBCG() self._final_x_bcbcg_m6s6, self._final_r_bcbcg_m6s6, self._residual_hist_bcbcg_m6s6 = \ bcbcg_solver_obj.bcbcg_solver_least_square(self._mat, self._BB_6, self._BX_6, 8, self._tol, self._maxiter, 0) plot_worker = Presenter() residual_list = [self._residual_hist_cg, self._residual_hist_bcg_m12, \ self._residual_hist_bcbcg_m1s2, self._residual_hist_bcbcg_m1s6, \ self._residual_hist_bcbcg_m6s2, self._residual_hist_bcbcg_m6s6 ] legend_list = ["cg","bcg_m12", "bcbcg_m1s2", "bcbcg_m1s6", "bcbcg_m6s2", "bcbcg_m6s6"] color_list = ["r","k","b","y","m","g"] plot_worker.instant_plot_y_log10(residual_list, "test", "#iteration", "$\\mathbf{log_{10}\\frac{||x_1||}{||b_1||}}$", legend_list, color_list)