(self, x)
return torch.stack(res_list, dim=0)
Perform forward pass.

        Parameters
        ----------
        x : torch.Tensor
            Tensor of shape `(n_samples, n_channels, lookback, n_assets)`.

        Returns
        -------
        torch.Tensor
            Tensor of shape `(n_samples, n_channels, n_assets)`.
Perform forward pass.
Perform forward pass .
def forward(self, x):
        """Perform forward pass.

        Parameters
        ----------
        x : torch.Tensor
            Tensor of shape `(n_samples, n_channels, lookback, n_assets)`.

        Returns
        -------
        torch.Tensor
            Tensor of shape `(n_samples, n_channels, n_assets)`.

        """
        n_samples, n_channels, lookback, n_assets = x.shape

        res_list = []
        for i in range(n_samples):
            inp_single = x[i].permute(2, 1, 0)  # n_assets, lookback, n_channels
            tformed = self.affine(inp_single)  # n_assets, lookback, n_channels
            w = self.context_vector(tformed)  # n_assets, lookback, 1
            scaled_w = torch.nn.functional.softmax(w, dim=1)  # n_assets, lookback, 1
            weighted_sum = (inp_single * scaled_w).mean(dim=1)  # n_assets, n_channels
            res_list.append(weighted_sum.permute(1, 0))  # n_channels, n_assets

        return torch.stack(res_list, dim=0)
def forward ( self , x ) : n_samples , n_channels , lookback , n_assets = x . shape res_list = [ ] for i in range ( n_samples ) : inp_single = x [ i ] . permute ( 2 , 1 , 0 ) # n_assets, lookback, n_channels tformed = self . affine ( inp_single ) # n_assets, lookback, n_channels w = self . context_vector ( tformed ) # n_assets, lookback, 1 scaled_w = torch . nn . functional . softmax ( w , dim = 1 ) # n_assets, lookback, 1 weighted_sum = ( inp_single * scaled_w ) . mean ( dim = 1 ) # n_assets, n_channels res_list . append ( weighted_sum . permute ( 1 , 0 ) ) # n_channels, n_assets return torch . stack ( res_list , dim = 0 )