algos/mst/deterministic.py
def to_data(self, max_time=10, bits=16):
        """
        Padding arrays and return nice tensors.
        For node tensors:
            1st dimension: number of nodes
            2nd dimension: number of time steps
            3rd dimension: others
        For edge tensors:
            1st dimension: 1 (batch dimension)
            2nd dimension: number of edges
            3rd dimension: number of time steps
            4th dimension: others

        :param max_time: pad time/edge dimensions tensors up to this value.
        :param bits: number of bits for bitwise encoding.
        :param debug: debug flag.
        :return: data tensors.
        """
        self.edge_index = self.edge_index.transpose(2, 0, 1)
        self.edge_index = pad_time(self.edge_index,
                                   (self.edge_index.shape[0], max_time,
                                    self.edge_index.shape[2]))

        def stupid_stupid_pad(pi, max_time):
            out = torch.full((max_time, pi.shape[1]), -1)
            out[:pi.shape[0]] = pi
            return out


        apout = stupid_stupid_pad(torch.tensor(self.asymmetric_pointers), max_time)
        assert (apout[:self.asymmetric_pointers.shape[0]] == torch.tensor(self.asymmetric_pointers)).all()

        self.edge_concepts = self.edge_concepts.transpose(1, 0, 2)

        self.edge_concepts = pad_time(self.edge_concepts,
                                      (self.edge_concepts.shape[0], max_time, self.edge_concepts.shape[2]))
        self.edge_concepts = pad_edge_concepts(self.edge_concepts, max_time)[np.newaxis]

        self.edge_targets = self.edge_targets.transpose(1, 0, 2)
        self.edge_targets = pad_time(self.edge_targets,
                                     (self.edge_targets.shape[0], max_time, self.edge_targets.shape[2]))
        self.edge_targets = pad_edge_concepts(self.edge_targets, max_time)[np.newaxis]

        edge_features_binary = array_to_bits(self.edge_features[np.newaxis], bits=bits).squeeze(0)
        edge_features_binary = pad_edges(edge_features_binary, max_time)[np.newaxis, :, np.newaxis]
        self.edge_features = self.edge_features.argsort()
        self.edge_features = pad_edge_features_int(self.edge_features, max_time)[np.newaxis, np.newaxis, :, np.newaxis]

        self.node_features = self.node_features.transpose(1, 0, 2)
        self.node_features = pad_node_features(self.node_features, max_time)

        mzero = np.zeros(max_time)
        mzero[:self.nodes_in_different_sets.shape[0]] = self.nodes_in_different_sets
        self.nodes_in_different_sets = mzero[np.newaxis, np.newaxis]

        self.nodes_not_in_path_to_roots = self.nodes_not_in_path_to_roots[:, :, np.newaxis]
        self.nodes_not_in_path_to_roots = self.nodes_not_in_path_to_roots.transpose(1, 0, 2)
        self.nodes_not_in_path_to_roots = pad_time(self.nodes_not_in_path_to_roots,
                                                   (self.nodes_not_in_path_to_roots.shape[0], max_time,
                                                    self.nodes_not_in_path_to_roots.shape[2]))

        mone = np.ones(max_time)
        mone[:self.termination.shape[0]] = self.termination
        self.termination = mone[np.newaxis, np.newaxis]

        self.time = np.arange(max_time)[np.newaxis, np.newaxis]

        data = Data(
            asymmetric_pointers_index=apout,
            edge_concepts=torch.FloatTensor(self.edge_concepts),
            edge_features=torch.FloatTensor(self.edge_features),
            edge_features_binary=torch.FloatTensor(edge_features_binary),
            edge_index=torch.LongTensor(self.edge_index),
            edge_nodes_index=torch.LongTensor(self.edge_nodes.T),
            edge_targets=torch.FloatTensor(self.edge_targets),
            x=torch.FloatTensor(self.node_features),
            nodes_in_different_sets=torch.FloatTensor(self.nodes_in_different_sets),
            nodes_not_in_path_to_roots=torch.FloatTensor(self.nodes_not_in_path_to_roots),
            termination=torch.FloatTensor(self.termination),
            time=torch.FloatTensor(self.time),
        )

        return data

        Padding arrays and return nice tensors.
        For node tensors:
            1st dimension: number of nodes
            2nd dimension: number of time steps
            3rd dimension: others
        For edge tensors:
            1st dimension: 1 (batch dimension)
            2nd dimension: number of edges
            3rd dimension: number of time steps
            4th dimension: others

        :param max_time: pad time/edge dimensions tensors up to this value.
        :param bits: number of bits for bitwise encoding.
        :param debug: debug flag.
        :return: data tensors.
        
Padding arrays and return nice tensors.
Padding arrays and return nice tensors .
def to_data(self, max_time=10, bits=16):
        self.edge_index = self.edge_index.transpose(2, 0, 1)
        self.edge_index = pad_time(self.edge_index,
                                   (self.edge_index.shape[0], max_time,
                                    self.edge_index.shape[2]))
        def stupid_stupid_pad(pi, max_time):
            out = torch.full((max_time, pi.shape[1]), -1)
            out[:pi.shape[0]] = pi
            return out
        apout = stupid_stupid_pad(torch.tensor(self.asymmetric_pointers), max_time)
        assert (apout[:self.asymmetric_pointers.shape[0]] == torch.tensor(self.asymmetric_pointers)).all()
        self.edge_concepts = self.edge_concepts.transpose(1, 0, 2)
        self.edge_concepts = pad_time(self.edge_concepts,
                                      (self.edge_concepts.shape[0], max_time, self.edge_concepts.shape[2]))
        self.edge_concepts = pad_edge_concepts(self.edge_concepts, max_time)[np.newaxis]
        self.edge_targets = self.edge_targets.transpose(1, 0, 2)
        self.edge_targets = pad_time(self.edge_targets,
                                     (self.edge_targets.shape[0], max_time, self.edge_targets.shape[2]))
        self.edge_targets = pad_edge_concepts(self.edge_targets, max_time)[np.newaxis]
        edge_features_binary = array_to_bits(self.edge_features[np.newaxis], bits=bits).squeeze(0)
        edge_features_binary = pad_edges(edge_features_binary, max_time)[np.newaxis, :, np.newaxis]
        self.edge_features = self.edge_features.argsort()
        self.edge_features = pad_edge_features_int(self.edge_features, max_time)[np.newaxis, np.newaxis, :, np.newaxis]
        self.node_features = self.node_features.transpose(1, 0, 2)
        self.node_features = pad_node_features(self.node_features, max_time)
        mzero = np.zeros(max_time)
        mzero[:self.nodes_in_different_sets.shape[0]] = self.nodes_in_different_sets
        self.nodes_in_different_sets = mzero[np.newaxis, np.newaxis]
        self.nodes_not_in_path_to_roots = self.nodes_not_in_path_to_roots[:, :, np.newaxis]
        self.nodes_not_in_path_to_roots = self.nodes_not_in_path_to_roots.transpose(1, 0, 2)
        self.nodes_not_in_path_to_roots = pad_time(self.nodes_not_in_path_to_roots,
                                                   (self.nodes_not_in_path_to_roots.shape[0], max_time,
                                                    self.nodes_not_in_path_to_roots.shape[2]))
        mone = np.ones(max_time)
        mone[:self.termination.shape[0]] = self.termination
        self.termination = mone[np.newaxis, np.newaxis]
        self.time = np.arange(max_time)[np.newaxis, np.newaxis]
        data = Data(
            asymmetric_pointers_index=apout,
            edge_concepts=torch.FloatTensor(self.edge_concepts),
            edge_features=torch.FloatTensor(self.edge_features),
            edge_features_binary=torch.FloatTensor(edge_features_binary),
            edge_index=torch.LongTensor(self.edge_index),
            edge_nodes_index=torch.LongTensor(self.edge_nodes.T),
            edge_targets=torch.FloatTensor(self.edge_targets),
            x=torch.FloatTensor(self.node_features),
            nodes_in_different_sets=torch.FloatTensor(self.nodes_in_different_sets),
            nodes_not_in_path_to_roots=torch.FloatTensor(self.nodes_not_in_path_to_roots),
            termination=torch.FloatTensor(self.termination),
            time=torch.FloatTensor(self.time),
        )
        return data
def to_data ( self , max_time = 10 , bits = 16 ) : self . edge_index = self . edge_index . transpose ( 2 , 0 , 1 ) self . edge_index = pad_time ( self . edge_index , ( self . edge_index . shape [ 0 ] , max_time , self . edge_index . shape [ 2 ] ) ) def stupid_stupid_pad ( pi , max_time ) : out = torch . full ( ( max_time , pi . shape [ 1 ] ) , - 1 ) out [ : pi . shape [ 0 ] ] = pi return out apout = stupid_stupid_pad ( torch . tensor ( self . asymmetric_pointers ) , max_time ) assert ( apout [ : self . asymmetric_pointers . shape [ 0 ] ] == torch . tensor ( self . asymmetric_pointers ) ) . all ( ) self . edge_concepts = self . edge_concepts . transpose ( 1 , 0 , 2 ) self . edge_concepts = pad_time ( self . edge_concepts , ( self . edge_concepts . shape [ 0 ] , max_time , self . edge_concepts . shape [ 2 ] ) ) self . edge_concepts = pad_edge_concepts ( self . edge_concepts , max_time ) [ np . newaxis ] self . edge_targets = self . edge_targets . transpose ( 1 , 0 , 2 ) self . edge_targets = pad_time ( self . edge_targets , ( self . edge_targets . shape [ 0 ] , max_time , self . edge_targets . shape [ 2 ] ) ) self . edge_targets = pad_edge_concepts ( self . edge_targets , max_time ) [ np . newaxis ] edge_features_binary = array_to_bits ( self . edge_features [ np . newaxis ] , bits = bits ) . squeeze ( 0 ) edge_features_binary = pad_edges ( edge_features_binary , max_time ) [ np . newaxis , : , np . newaxis ] self . edge_features = self . edge_features . argsort ( ) self . edge_features = pad_edge_features_int ( self . edge_features , max_time ) [ np . newaxis , np . newaxis , : , np . newaxis ] self . node_features = self . node_features . transpose ( 1 , 0 , 2 ) self . node_features = pad_node_features ( self . node_features , max_time ) mzero = np . zeros ( max_time ) mzero [ : self . nodes_in_different_sets . shape [ 0 ] ] = self . nodes_in_different_sets self . nodes_in_different_sets = mzero [ np . newaxis , np . newaxis ] self . nodes_not_in_path_to_roots = self . nodes_not_in_path_to_roots [ : , : , np . newaxis ] self . nodes_not_in_path_to_roots = self . nodes_not_in_path_to_roots . transpose ( 1 , 0 , 2 ) self . nodes_not_in_path_to_roots = pad_time ( self . nodes_not_in_path_to_roots , ( self . nodes_not_in_path_to_roots . shape [ 0 ] , max_time , self . nodes_not_in_path_to_roots . shape [ 2 ] ) ) mone = np . ones ( max_time ) mone [ : self . termination . shape [ 0 ] ] = self . termination self . termination = mone [ np . newaxis , np . newaxis ] self . time = np . arange ( max_time ) [ np . newaxis , np . newaxis ] data = Data ( asymmetric_pointers_index = apout , edge_concepts = torch . FloatTensor ( self . edge_concepts ) , edge_features = torch . FloatTensor ( self . edge_features ) , edge_features_binary = torch . FloatTensor ( edge_features_binary ) , edge_index = torch . LongTensor ( self . edge_index ) , edge_nodes_index = torch . LongTensor ( self . edge_nodes . T ) , edge_targets = torch . FloatTensor ( self . edge_targets ) , x = torch . FloatTensor ( self . node_features ) , nodes_in_different_sets = torch . FloatTensor ( self . nodes_in_different_sets ) , nodes_not_in_path_to_roots = torch . FloatTensor ( self . nodes_not_in_path_to_roots ) , termination = torch . FloatTensor ( self . termination ) , time = torch . FloatTensor ( self . time ) , ) return data
Padding arrays and return nice tensors.
Padding arrays and return nice tensors .
"""
        Padding arrays and return nice tensors.
        For node tensors:
            1st dimension: number of nodes
            2nd dimension: number of time steps
            3rd dimension: others
        For edge tensors:
            1st dimension: 1 (batch dimension)
            2nd dimension: number of edges
            3rd dimension: number of time steps
            4th dimension: others

        :param max_time: pad time/edge dimensions tensors up to this value.
        :param bits: number of bits for bitwise encoding.
        :param debug: debug flag.
        :return: data tensors.
        """
None
self
max_time
pad time/edge dimensions tensors up to this value.
pad time / edge dimensions tensors up to this value .
bits
number of bits for bitwise encoding.
number of bits for bitwise encoding .
debug
None