KalmanNet, Machine Learning

I want to rebuild this machine learning structure, a KalmanNet. Machine Learning Structure KalmanNet. I have problems with the pointwise multiplication.
This is my code:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>class MB_KalmanNet_GRU(torch.nn.Module):
def __init__(self, F, in_gru, hidden_gru):
super().__init__()
self.F = F
self.FC11 = nn.Linear(6, in_gru).to(device)
self.GRU1 = nn.GRU(in_gru, hidden_gru).to(device)
self.FC21 = nn.Linear(hidden_gru, 9).to(device)
def forward(self, est, h_0, track_first):
track_total = torch.empty(est.shape).to(device)
track_total[0, :,: ] = track_first[0, :, :]
pred_prev = track_first[0, :, :]
h = h_0.clone()
for i in range(1, est.shape[0]):
pred = track_total[i-1, :,: ].unsqueeze(0) @ self.F.T
delta_y = est[i, :, :] - pred
delta_x = pred_prev - track_total[i-1, :,: ].unsqueeze(0)
pred_prev = pred
input_KGain = torch.cat((delta_y, delta_x), dim=2)
into_gru = self.FC11(input_KGain)
outta_gru, h = self.GRU1(into_gru, h)
KGain = self.FC21(outta_gru)
KGain_matrix = torch.reshape(KGain, (est.shape[1], 3, 3))
innovation = torch.bmm(KGain_matrix, delta_y.squeeze(0).unsqueeze(2))
track_total[i, :, :] = pred[0, :, :] + innovation.squeeze(2).unsqueeze(0)
return track_total
</code>
<code>class MB_KalmanNet_GRU(torch.nn.Module): def __init__(self, F, in_gru, hidden_gru): super().__init__() self.F = F self.FC11 = nn.Linear(6, in_gru).to(device) self.GRU1 = nn.GRU(in_gru, hidden_gru).to(device) self.FC21 = nn.Linear(hidden_gru, 9).to(device) def forward(self, est, h_0, track_first): track_total = torch.empty(est.shape).to(device) track_total[0, :,: ] = track_first[0, :, :] pred_prev = track_first[0, :, :] h = h_0.clone() for i in range(1, est.shape[0]): pred = track_total[i-1, :,: ].unsqueeze(0) @ self.F.T delta_y = est[i, :, :] - pred delta_x = pred_prev - track_total[i-1, :,: ].unsqueeze(0) pred_prev = pred input_KGain = torch.cat((delta_y, delta_x), dim=2) into_gru = self.FC11(input_KGain) outta_gru, h = self.GRU1(into_gru, h) KGain = self.FC21(outta_gru) KGain_matrix = torch.reshape(KGain, (est.shape[1], 3, 3)) innovation = torch.bmm(KGain_matrix, delta_y.squeeze(0).unsqueeze(2)) track_total[i, :, :] = pred[0, :, :] + innovation.squeeze(2).unsqueeze(0) return track_total </code>
class MB_KalmanNet_GRU(torch.nn.Module):
    def __init__(self, F, in_gru, hidden_gru):
        super().__init__()
        self.F = F

        self.FC11 = nn.Linear(6, in_gru).to(device)
        self.GRU1 = nn.GRU(in_gru, hidden_gru).to(device)
        self.FC21 = nn.Linear(hidden_gru,  9).to(device)

    def forward(self, est, h_0, track_first):
        track_total = torch.empty(est.shape).to(device)
        track_total[0, :,: ] = track_first[0, :, :]
        pred_prev = track_first[0, :, :]
        h = h_0.clone()

        for i in range(1, est.shape[0]):
            pred = track_total[i-1, :,: ].unsqueeze(0) @ self.F.T

            delta_y = est[i, :, :] - pred
            delta_x = pred_prev - track_total[i-1, :,: ].unsqueeze(0)
            pred_prev = pred

            input_KGain = torch.cat((delta_y, delta_x), dim=2)
            into_gru = self.FC11(input_KGain)
            outta_gru, h = self.GRU1(into_gru, h)
            KGain = self.FC21(outta_gru)

            KGain_matrix = torch.reshape(KGain, (est.shape[1], 3, 3))
            innovation = torch.bmm(KGain_matrix, delta_y.squeeze(0).unsqueeze(2))
           
            track_total[i, :, :] = pred[0, :, :] + innovation.squeeze(2).unsqueeze(0)

        return track_total

I have problems with the section

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> innovation = torch.bmm(KGain_matrix, delta_y.squeeze(0).unsqueeze(2))
</code>
<code> innovation = torch.bmm(KGain_matrix, delta_y.squeeze(0).unsqueeze(2)) </code>
           innovation = torch.bmm(KGain_matrix, delta_y.squeeze(0).unsqueeze(2))

If delta_y is just a tensor the gradiants are calculated correctly. Also if I add KGain_matrix and delta_y.squeeze(0).unsqueeze(2) everything works fine. Only whenmultiplication is performed the gradiants are not correctly calculated anymore. Thank you so much in advance.

I am expecting that the gradiants are calculated correctly, but instead they are NAN. I tried differnt structures and they work, just the multiplication which i need doesent work.

New contributor

plk48 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật