the following code is used to optimize the parameters x0, y0, i , a, b for the build_airy_disk function
def __init__(self, guess_prms):
super().__init__()
# initialize weights with guess_prms
weights = torch.from_numpy(guess_prms)
# make weights torch parameters
self.weights = nn.Parameter(weights, requires_grad=True)
def forward(self, x_data):
x = torch.from_numpy(x_data[0, :])
y = torch.from_numpy(x_data[1, :])
arr = torch.zeros(x.shape)
I, X0, Y0, R, A, B = self.weights[:, 0], self.weights[:, 1], self.weights[:, 2], self.weights[:, 3],
self.weights[:, 4], self.weights[:, 5]
for i , x0, y0, r, a, b in zip(I, X0, Y0, R, A, B):#self.weights:
arr = arr + build_airy_disk(x, y, i, x0, y0, r, a, b)
return arr
the model.parameters() array is a 4 by 6 tensor however only the first value is updating.
it is worth noting that our model’s output is the sum of 4 airy disk that are considered as the final output .
thank you in advance