scpanel.GATclassifier
Attributes
Classes
Clusters/partitions a graph data object into multiple subgraphs, as |
|
The data loader scheme from the `"Cluster-GCN: An Efficient Algorithm |
|
A pytorch regressor |
Functions
|
Input: scipy csr_matrix |
Module Contents
- scpanel.GATclassifier.seed = 42
- scpanel.GATclassifier.scipysparse2torchsparse(x: scipy.sparse._csr.csr_matrix) Tuple[torch.Tensor, torch.Tensor]
Input: scipy csr_matrix Returns: torch tensor in experimental sparse format
REF: Code adatped from [PyTorch discussion forum](https://discuss.pytorch.org/t/better-way-to-forward-sparse-matrix/21915>)
- class scpanel.GATclassifier.ClusterData(data: torch_geometric.data.data.Data, num_parts: int, recursive: bool = False, save_dir: None = None)
Bases:
torch.utils.data.DatasetClusters/partitions a graph data object into multiple subgraphs, as motivated by the “Cluster-GCN: An Efficient Algorithm for Training Deep and Large Graph Convolutional Networks” paper.
- Parameters:
data (torch_geometric.data.Data) – The graph data object.
num_parts (int) – The number of partitions.
recursive (bool, optional) – If set to
True, will use multilevel recursive bisection instead of multilevel k-way partitioning. (default:False)save_dir (string, optional) – If set, will save the partitioned data to the
save_dirdirectory for faster re-use.
- num_parts
- recursive
- save_dir
- process(data: torch_geometric.data.data.Data) None
- __len__() int
- __getitem__(idx)
- __repr__()
- class scpanel.GATclassifier.ClusterLoader(cluster_data: ClusterData, batch_size: int = 1, shuffle: bool = False, **kwargs)
Bases:
torch.utils.data.DataLoaderThe data loader scheme from the “Cluster-GCN: An Efficient Algorithm for Training Deep and Large Graph Convolutional Networks” paper which merges partioned subgraphs and their between-cluster links from a large-scale graph data object to form a mini-batch.
- Parameters:
cluster_data (torch_geometric.data.ClusterData) – The already partioned data object.
batch_size (int, optional) – How many samples per batch to load. (default:
1)shuffle (bool, optional) – If set to
True, the data will be reshuffled at every epoch. (default:False)
- class scpanel.GATclassifier.GAT(n_nodes: int, nFeatures: int, nHiddenUnits: int, nHeads: int, alpha: float, dropout: float)
Bases:
torch.nn.Module- n_nodes
- nFeatures
- nHiddenUnits
- nHeads
- alpha
- dropout
- gat1
- gat2
- forward(data: torch_geometric.data.data.Data) torch.Tensor
- class scpanel.GATclassifier.GATclassifier(n_nodes: int = 2, nFeatures: int | None = None, nHiddenUnits: int = 8, nHeads: int = 8, alpha: float = 0.2, dropout: float = 0.4, clip: None = None, rs: int = random.randint(1, 1000000), LR: float = 0.001, WeightDecay: float = 0.0005, BatchSize: int = 256, NumParts: int = 200, nEpochs: int = 100, fastmode: bool = True, verbose: int = 0, device: str = 'cpu')
Bases:
sklearn.base.BaseEstimatorA pytorch regressor
- _history = None
- _model = None
- _build_model() None
- _train_model(X: numpy.ndarray, y: pandas.core.arrays.categorical.Categorical, adj: scipy.sparse._csr.csr_matrix) None
- fit(X: numpy.ndarray, y: pandas.core.arrays.categorical.Categorical, adj: scipy.sparse._csr.csr_matrix) GATclassifier
Trains the pytorch regressor.
- predict(X: numpy.ndarray, y: pandas.core.arrays.categorical.Categorical, adj: scipy.sparse._csr.csr_matrix) torch.Tensor
Makes a prediction using the trained pytorch model
- predict_proba(X: numpy.ndarray, y: pandas.core.arrays.categorical.Categorical, adj: scipy.sparse._csr.csr_matrix) numpy.ndarray
- score(X, y, sample_weight=None)
Scores the data using the trained pytorch model. Under current implementation returns negative mae.