def _debug_bcg(self): bcg_solver_obj = NativeBlockConjugateGradient(self._mat, self._X, self._B, self._tol, self._maxiter) self._final_X, self._final_R, self._residual_hist = bcg_solver_obj.bcg_variant_one_run( 0) 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 ] residual_list = [self._residual_hist_cg, self._residual_hist_bcg_m12] #legend_list = ["cg","bcg_m12", "bcbcg_m1s2", "bcbcg_m1s8", "bcbcg_m4s2", "bcbcg_m4s8"] legend_list = ["cg","bcg_m12"] #color_list = ["r","k","b","y","m","g"] 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) #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, "MG", "#iteration", "$\\mathbf{log_{10}\\frac{||x_1||}{||b_1||}}$", legend_list, color_list)
def _db_bcg_least_square (self): """ """ m = 32 self._BB_m = np.random.random( ( self._mat.shape[0],m) ) self._BX_m = np.ones ( (self._mat.shape[1],m) ) bcg_solver_obj = NativeBlockConjugateGradient(self._mat, self._BX_m, self._BB_m, self._tol, self._maxiter) self._final_X_bcg, self._final_R_bcg, self._residual_hist_bcg = bcg_solver_obj.bcg_variant_one_run(0) bcg_solver_obj = NativeBlockConjugateGradient(self._mat, self._BX_m, self._BB_m, self._tol, self._maxiter) self._final_X_bcg_lstsq, self._final_R_bcg_lstsq, self._residual_hist_bcg_lstsq = bcg_solver_obj.bcg_variant_lstsq_run(0) plot_worker = Presenter() residual_list = [self._residual_hist_bcg, self._residual_hist_bcg_lstsq] legend_list = ["bcg","bcg_lstsq"] 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 _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 _cg_bcg_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) plot_worker = Presenter() residual_list = [self._residual_hist_cg, self._residual_hist_bcg_mX] legend_list = ["cg", "bcg_m" + str(block_size)] color_list = ["r", "k"] plot_worker.instant_plot_y_log10( residual_list, "MG", "#iteration", "$\\mathbf{log_{10}\\frac{||r_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)
def _debug_bcg(self): bcg_solver_obj = NativeBlockConjugateGradient(self._mat, self._X, self._B, self._tol, self._maxiter) self._final_X, self._final_R, self._residual_hist = bcg_solver_obj.bcg_variant_one_run(0) print(self._residual_hist)