From ccf8fa200222a264d78d074b65afbb194a86ed05 Mon Sep 17 00:00:00 2001 From: "qiangliu.7@outlook.com" Date: Thu, 14 Nov 2024 17:24:32 +0100 Subject: [PATCH] minor bugs on experiments --- docs/examples/pinn_burgers.ipynb | 2 +- experiments/PINN/lib_pinns/burgers/networks.py | 2 +- experiments/PINN/lib_pinns/network_initialization.py | 4 +++- experiments/PINN/lib_pinns/trainer_basis.py | 2 -- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/examples/pinn_burgers.ipynb b/docs/examples/pinn_burgers.ipynb index 064ddfe..abb3c14 100644 --- a/docs/examples/pinn_burgers.ipynb +++ b/docs/examples/pinn_burgers.ipynb @@ -109,7 +109,7 @@ " for i in range(n_layers):\n", " self.net.append(nn.Sequential(nn.Linear(channel_basics, channel_basics), nn.Tanh()))\n", " self.net=nn.Sequential(*self.net)\n", - " self.out_net=nn.Sequential(nn.Linear(channel_basics, 1))\n", + " self.out_net=nn.Linear(channel_basics, 1)\n", " \n", " \n", " def forward(self, x, t):\n", diff --git a/experiments/PINN/lib_pinns/burgers/networks.py b/experiments/PINN/lib_pinns/burgers/networks.py index a1a8e3b..52b8fe3 100644 --- a/experiments/PINN/lib_pinns/burgers/networks.py +++ b/experiments/PINN/lib_pinns/burgers/networks.py @@ -48,7 +48,7 @@ def __init__(self,channel_basics=50,n_layers=4, *args, **kwargs) -> None: for i in range(n_layers): self.net.append(nn.Sequential(nn.Linear(channel_basics, channel_basics), nn.Tanh())) self.net=nn.Sequential(*self.net) - self.out_net=nn.Sequential(nn.Linear(channel_basics, 1)) + self.out_net=nn.Linear(channel_basics, 1) def forward(self, x, t): ini_shape=x.shape diff --git a/experiments/PINN/lib_pinns/network_initialization.py b/experiments/PINN/lib_pinns/network_initialization.py index 8f0b3b2..1923489 100644 --- a/experiments/PINN/lib_pinns/network_initialization.py +++ b/experiments/PINN/lib_pinns/network_initialization.py @@ -3,4 +3,6 @@ def xavier_init_weights(m): if type(m) == nn.Linear: torch.nn.init.xavier_normal_(m.weight, 1) - m.bias.data.fill_(0.001) \ No newline at end of file + if hasattr(m, 'bias'): + if m.bias is not None: + m.bias.data.fill_(0.001) \ No newline at end of file diff --git a/experiments/PINN/lib_pinns/trainer_basis.py b/experiments/PINN/lib_pinns/trainer_basis.py index c2636ca..8955a87 100644 --- a/experiments/PINN/lib_pinns/trainer_basis.py +++ b/experiments/PINN/lib_pinns/trainer_basis.py @@ -297,7 +297,6 @@ def get_momentum_trainer(sub_trainer,operator): class MomentumTrainer(MomentumGradVecTrainerBasis): def initialize_momentum_handler(self,network): self.momentum_handler=PseudoMomentumOperator(num_vectors=self.configs.n_losses, - network=network, gradient_operator=operator, loss_recorder=LatestLossRecorder(self.configs.n_losses)) class Trainer(sub_trainer,MomentumTrainer): @@ -308,7 +307,6 @@ def get_separate_momentum_trainer(sub_trainer,operator): class MomentumTrainer(MomentumGradVecTrainerBasis): def initialize_momentum_handler(self,network): self.momentum_handler=SeparateMomentumOperator(num_vectors=self.configs.n_losses, - network=network, gradient_operator=operator, loss_recorder=LatestLossRecorder(self.configs.n_losses)) class Trainer(sub_trainer,MomentumTrainer):