diff --git a/jointContribution/PIRBN/README.md b/jointContribution/PIRBN/README.md index fdcc55d80..5bf5c11d5 100644 --- a/jointContribution/PIRBN/README.md +++ b/jointContribution/PIRBN/README.md @@ -32,6 +32,8 @@ For more details in terms of mathematical proofs and numerical examples, please + + # Enviornmental settings ``` diff --git a/jointContribution/PIRBN/analytical_solution.py b/jointContribution/PIRBN/analytical_solution.py index 51bbf6f4d..793d9dd1e 100644 --- a/jointContribution/PIRBN/analytical_solution.py +++ b/jointContribution/PIRBN/analytical_solution.py @@ -38,11 +38,11 @@ def output_fig(train_obj, mu, b, right_by, activation_function): # Loss history of the network during the training process. plt.subplot(2, 3, 3) - loss_b = train_obj.loss_b - x = range(len(loss_b)) + loss_g = train_obj.loss_g + x = range(len(loss_g)) plt.yscale("log") - plt.plot(x, loss_b) - plt.plot(x, train_obj.loss_g) + plt.plot(x, loss_g) + plt.plot(x, train_obj.loss_b) plt.legend(["Lg", "Lb"]) plt.ylabel("Loss") plt.xlabel("Iteration") diff --git a/jointContribution/PIRBN/train.py b/jointContribution/PIRBN/train.py index 1e0e2ccd9..8be628b05 100644 --- a/jointContribution/PIRBN/train.py +++ b/jointContribution/PIRBN/train.py @@ -23,8 +23,8 @@ def __init__( ] self.y_train = paddle.to_tensor(y_train, dtype=paddle.get_default_dtype()) self.maxiter = maxiter - self.loss_b = [] - self.loss_g = [] + self.loss_g = [] # eq loss + self.loss_b = [] # boundary loss self.iter = 0 self.a_g = paddle.to_tensor(1.0) self.a_b = paddle.to_tensor(1.0) @@ -36,24 +36,24 @@ def __init__( def Loss(self, x, y, a_g, a_b): tmp = self.pirbn(x, self.activation_function) - loss_b = 0.5 * paddle.mean(paddle.square(tmp[0] - y[0])) - loss_g = 0.5 * paddle.mean(paddle.square(tmp[1])) - loss = loss_b * a_g + loss_g * a_b - return loss, loss_b, loss_g + loss_g = 0.5 * paddle.mean(paddle.square(tmp[0] - y[0])) + loss_b = 0.5 * paddle.mean(paddle.square(tmp[1])) + loss = loss_g * a_g + loss_b * a_b + return loss, loss_g, loss_b def evaluate(self): # compute loss - loss, loss_b, loss_g = self.Loss(self.x_train, self.y_train, self.a_g, self.a_b) - loss_b_numpy = float(loss_b) + loss, loss_g, loss_b = self.Loss(self.x_train, self.y_train, self.a_g, self.a_b) loss_g_numpy = float(loss_g) - # boundary loss - self.loss_b.append(loss_b_numpy) + loss_b_numpy = float(loss_b) # eq loss self.loss_g.append(loss_g_numpy) + # boundary loss + self.loss_b.append(loss_b_numpy) if self.iter % 200 == 0: self.a_g, self.a_b, _ = self.pirbn.cal_ntk(self.x_train) print("\ta_g =", float(self.a_g), "\ta_b =", float(self.a_b)) - print("Iter: ", self.iter, "\tL1 =", loss_b_numpy, "\tL2 =", loss_g_numpy) + print("Iter: ", self.iter, "\tL1 =", loss_g_numpy, "\tL2 =", loss_b_numpy) self.iter = self.iter + 1 return loss