Skip to main content
. 2024 Mar 19;24(6):1949. doi: 10.3390/s24061949
Algorithm 1: pseudo code of AGGD
1 Tensor W0, Tensor L0
2 Parameters: W0: Weight Parameters of Neural Network Nodes in the Previous Training Epoch; L0: Loss Values of the Neural Network for the Previous n Training Epochs.
3 Operation: The algorithm is based on the Pytorch framework, please refer to Pytorch [47] for related torch operations.
4 Output: W: Weight Parameters of Neural Network Nodes in this Training Epoch.
5 def AGGD(self, W0,L0):
6   # Initialization
7   W = W0
8   optimizer = torch.optim.Adam(model.parameters(), lr = 0.0004)
9   yPred = model(x)  #Predict output using previous generation weights
10   l = torch.nn.MSE(yPred, yReal)
11
  yPredVariance=1mni=1nj=1myiPredMeanyPred2,yPrediyPred
12   L = L0.append(l)
13   Lvariance=1ninliMeanL2,liL
14   # Update network weights
15   flag=count150&l>0.006&Lvariance<0.1&yPredVariance<0.2
16   if flag:
17     W=torch.random.initWeightW0whileW=W0
18     count = 0
19     L = []
20   else:
21     optimizer.zero_grad()
22     loss.backward()
23     count += 1
24     valid()