neuroprob/base.py
def eval_XZ(self, net_input=None):
        """
        Evaluate the (latent) input variables. The latent variable structure is defined by the input 
        structure to the variational distributions specified.
        
        :param torch.tensor net_input: the input to the VAE for fast inference of shape (time, moment)
        :returns: a list with elements of shape (timesteps,) for input variables, if separate trial runs, 
                 we get additional first list dimension over runs/trials
        :rtype: list
        """
        X_loc, X_std = [], []
        
        ### retrieve/compute the input variables ###
        if self.regressor_mode:
            c = torch.cat(tuple(cov for cov in self.XZ), dim=1).permute(2, 1, 0)
            X_loc = list(c.cpu().numpy()) # dims x (timesteps, samples)
            X_std = list(np.zeros_like(c.cpu().numpy()))
            
        else:  
            with torch.no_grad():
                for k, vi in enumerate(self.VI_tuples):
                    p, v, topo, dims = vi
                    
                    if self.XZ[k] is not None:
                        c = torch.cat(tuple(cov for cov in self.XZ[k]), dim=1)
                        c = torch.cat((c, torch.zeros_like(c)), dim=-1).permute(1, 2, 0) # timesteps, moment_dim, samples
                    elif v == 'VAE':
                        input = net_input.t().to(self.dummy.device)
                        mu = getattr(self, 'lv_mu_{}'.format(k))(input)
                        std = self.lf(getattr(self, 'lv_std_{}'.format(k))(input))
                        c = torch.cat((mu, std), dim=-1) # (timesteps, moment_dim)
                    else:
                        if topo == 'sphere': # normalize
                            l = getattr(self, 'lv_mu_{}'.format(k))
                            l.data /= l.data.norm(2, -1)[..., None]
                        c = torch.cat((getattr(self, 'lv_mu_{}'.format(k)), # (time, moment_dim)
                                       self.lf(getattr(self, 'lv_std_{}'.format(k)))), dim=1)

                    if dims == 1:
                        X_loc.append(c[:, 0].cpu().numpy())
                        X_std.append(c[:, 1].cpu().numpy())
                    else:
                        X_loc.append(c[:, :dims].cpu().numpy())
                        X_std.append(c[:, dims:].cpu().numpy())
        
        ### deal with continuity of data ###        
        X_loc_, X_std_ = [], []
        for k, vi in enumerate(self.VI_tuples):
            p, v, topo, dims = vi
            
            if v == 'VAE': # no batching
                X_loc_.append(X_loc[k])
                X_std_.append(X_std[k])
                continue

            _X_loc, _X_std = [], []
            for b in range(self.batches):
                if self.batch_link[b] is False:
                    if b > 0: # safe current data
                        _X_loc.append(np.concatenate(X_loc__, axis=0))
                        _X_std.append(np.concatenate(X_std__, axis=0))
                    X_loc__, X_std__ = [], []
                    
                X_loc__.append(X_loc[k][self.batch_edge[b]:self.batch_edge[b+1]])
                X_std__.append(X_std[k][self.batch_edge[b]:self.batch_edge[b+1]])
                
            # final segment or whole segment
            _X_loc.append(np.concatenate(X_loc__, axis=0))
            _X_std.append(np.concatenate(X_std__, axis=0))
            
            if len(_X_loc) > 1: # multiple segments
                X_loc_.append(_X_loc)
                X_std_.append(_X_std)
            else: # continuous segment
                X_loc_.append(_X_loc[0])
                X_std_.append(_X_std[0])

        return X_loc_, X_std_

        Evaluate the (latent) input variables. The latent variable structure is defined by the input 
        structure to the variational distributions specified.
        
        :param torch.tensor net_input: the input to the VAE for fast inference of shape (time, moment)
        :returns: a list with elements of shape (timesteps,) for input variables, if separate trial runs, 
                 we get additional first list dimension over runs/trials
        :rtype: list
        
Evaluate the (latent) input variables. The latent variable structure is defined by the input
structure to the variational distributions specified.
Evaluate the ( latent ) input variables . The latent variable structure is defined by the input structure to the variational distributions specified .
def eval_XZ(self, net_input=None):
        X_loc, X_std = [], []
        if self.regressor_mode:
            c = torch.cat(tuple(cov for cov in self.XZ), dim=1).permute(2, 1, 0)
            X_loc = list(c.cpu().numpy()) 
            X_std = list(np.zeros_like(c.cpu().numpy()))
        else:  
            with torch.no_grad():
                for k, vi in enumerate(self.VI_tuples):
                    p, v, topo, dims = vi
                    if self.XZ[k] is not None:
                        c = torch.cat(tuple(cov for cov in self.XZ[k]), dim=1)
                        c = torch.cat((c, torch.zeros_like(c)), dim=-1).permute(1, 2, 0) 
                    elif v == 'VAE':
                        input = net_input.t().to(self.dummy.device)
                        mu = getattr(self, 'lv_mu_{}'.format(k))(input)
                        std = self.lf(getattr(self, 'lv_std_{}'.format(k))(input))
                        c = torch.cat((mu, std), dim=-1) 
                    else:
                        if topo == 'sphere': 
                            l = getattr(self, 'lv_mu_{}'.format(k))
                            l.data /= l.data.norm(2, -1)[..., None]
                        c = torch.cat((getattr(self, 'lv_mu_{}'.format(k)), 
                                       self.lf(getattr(self, 'lv_std_{}'.format(k)))), dim=1)
                    if dims == 1:
                        X_loc.append(c[:, 0].cpu().numpy())
                        X_std.append(c[:, 1].cpu().numpy())
                    else:
                        X_loc.append(c[:, :dims].cpu().numpy())
                        X_std.append(c[:, dims:].cpu().numpy())
        X_loc_, X_std_ = [], []
        for k, vi in enumerate(self.VI_tuples):
            p, v, topo, dims = vi
            if v == 'VAE': 
                X_loc_.append(X_loc[k])
                X_std_.append(X_std[k])
                continue
            _X_loc, _X_std = [], []
            for b in range(self.batches):
                if self.batch_link[b] is False:
                    if b > 0: 
                        _X_loc.append(np.concatenate(X_loc__, axis=0))
                        _X_std.append(np.concatenate(X_std__, axis=0))
                    X_loc__, X_std__ = [], []
                X_loc__.append(X_loc[k][self.batch_edge[b]:self.batch_edge[b+1]])
                X_std__.append(X_std[k][self.batch_edge[b]:self.batch_edge[b+1]])
            _X_loc.append(np.concatenate(X_loc__, axis=0))
            _X_std.append(np.concatenate(X_std__, axis=0))
            if len(_X_loc) > 1: 
                X_loc_.append(_X_loc)
                X_std_.append(_X_std)
            else: 
                X_loc_.append(_X_loc[0])
                X_std_.append(_X_std[0])
        return X_loc_, X_std_
def eval_XZ ( self , net_input = None ) : X_loc , X_std = [ ] , [ ] if self . regressor_mode : c = torch . cat ( tuple ( cov for cov in self . XZ ) , dim = 1 ) . permute ( 2 , 1 , 0 ) X_loc = list ( c . cpu ( ) . numpy ( ) ) X_std = list ( np . zeros_like ( c . cpu ( ) . numpy ( ) ) ) else : with torch . no_grad ( ) : for k , vi in enumerate ( self . VI_tuples ) : p , v , topo , dims = vi if self . XZ [ k ] is not None : c = torch . cat ( tuple ( cov for cov in self . XZ [ k ] ) , dim = 1 ) c = torch . cat ( ( c , torch . zeros_like ( c ) ) , dim = - 1 ) . permute ( 1 , 2 , 0 ) elif v == 'VAE' : input = net_input . t ( ) . to ( self . dummy . device ) mu = getattr ( self , 'lv_mu_{}' . format ( k ) ) ( input ) std = self . lf ( getattr ( self , 'lv_std_{}' . format ( k ) ) ( input ) ) c = torch . cat ( ( mu , std ) , dim = - 1 ) else : if topo == 'sphere' : l = getattr ( self , 'lv_mu_{}' . format ( k ) ) l . data /= l . data . norm ( 2 , - 1 ) [ ... , None ] c = torch . cat ( ( getattr ( self , 'lv_mu_{}' . format ( k ) ) , self . lf ( getattr ( self , 'lv_std_{}' . format ( k ) ) ) ) , dim = 1 ) if dims == 1 : X_loc . append ( c [ : , 0 ] . cpu ( ) . numpy ( ) ) X_std . append ( c [ : , 1 ] . cpu ( ) . numpy ( ) ) else : X_loc . append ( c [ : , : dims ] . cpu ( ) . numpy ( ) ) X_std . append ( c [ : , dims : ] . cpu ( ) . numpy ( ) ) X_loc_ , X_std_ = [ ] , [ ] for k , vi in enumerate ( self . VI_tuples ) : p , v , topo , dims = vi if v == 'VAE' : X_loc_ . append ( X_loc [ k ] ) X_std_ . append ( X_std [ k ] ) continue _X_loc , _X_std = [ ] , [ ] for b in range ( self . batches ) : if self . batch_link [ b ] is False : if b > 0 : _X_loc . append ( np . concatenate ( X_loc__ , axis = 0 ) ) _X_std . append ( np . concatenate ( X_std__ , axis = 0 ) ) X_loc__ , X_std__ = [ ] , [ ] X_loc__ . append ( X_loc [ k ] [ self . batch_edge [ b ] : self . batch_edge [ b + 1 ] ] ) X_std__ . append ( X_std [ k ] [ self . batch_edge [ b ] : self . batch_edge [ b + 1 ] ] ) _X_loc . append ( np . concatenate ( X_loc__ , axis = 0 ) ) _X_std . append ( np . concatenate ( X_std__ , axis = 0 ) ) if len ( _X_loc ) > 1 : X_loc_ . append ( _X_loc ) X_std_ . append ( _X_std ) else : X_loc_ . append ( _X_loc [ 0 ] ) X_std_ . append ( _X_std [ 0 ] ) return X_loc_ , X_std_
Evaluate the (latent) input variables.
Evaluate the ( latent ) input variables .
"""
        Evaluate the (latent) input variables. The latent variable structure is defined by the input 
        structure to the variational distributions specified.
        
        :param torch.tensor net_input: the input to the VAE for fast inference of shape (time, moment)
        :returns: a list with elements of shape (timesteps,) for input variables, if separate trial runs, 
                 we get additional first list dimension over runs/trials
        :rtype: list
        """ ### retrieve/compute the input variables ### # dims x (timesteps, samples) # timesteps, moment_dim, samples # (timesteps, moment_dim) # normalize # (time, moment_dim) ### deal with continuity of data ###         # no batching # safe current data # final segment or whole segment # multiple segments # continuous segment
a list with elements of shape (timesteps,) for input variables, if separate trial runs,
we get additional first list dimension over runs/trials
a list with elements of shape ( timesteps ) for input variables if separate trial runs we get additional first list dimension over runs / trials
list
self
net_input
the input to the VAE for fast inference of shape (time, moment)
the input to the VAE for fast inference of shape ( time moment )