gsnn.gsnn.optim.utils

Functions

compute_ECE(pred_dist, y_true[, num_intervals])

Compute the Expected Calibration Error (ECE) using the PICP at different confidence levels.

compute_picp(pred_dist, y_true[, alpha, N])

Compute the Prediction Interval Coverage Probability (PICP) for given predictions and true values.

dbscan_silhouette_score(embeddings[, ...])

Perform DBSCAN clustering on the embeddings and calculate the Silhouette Score.

neighborhood_preservation_score(edge_index, ...)

Compute the neighborhood preservation score.

root_mean_squared_picp_error(pred_dist, y_true)

gsnn.gsnn.optim.utils.compute_ECE(pred_dist, y_true, num_intervals=10)[source]

Compute the Expected Calibration Error (ECE) using the PICP at different confidence levels.

Parameters: - pred_dist (torch.distributions.Distribution): Predicted probability distribution. - y_true (torch.Tensor): Actual values to compare against. - num_intervals (int, optional): Number of confidence intervals to use for calibration. Default is 10.

Returns: - float: The ECE value.

gsnn.gsnn.optim.utils.compute_picp(pred_dist, y_true, alpha=0.05, N=100)[source]

Compute the Prediction Interval Coverage Probability (PICP) for given predictions and true values.

Parameters: - pred_dist (torch.distributions.Distribution): Predicted probability distribution. - y_true (torch.Tensor): Actual values to compare against. - alpha (float, optional): Significance level for prediction interval. Default is 0.05 for 95% PICP.

Returns: - float: The PICP value.

Note: If you’re computing a 95% Prediction Interval (which corresponds to an alpha of 0.05), a perfectly calibrated model would have a PICP score of 0.95. This means that 95% of the true values fall within the predicted intervals.

gsnn.gsnn.optim.utils.dbscan_silhouette_score(embeddings, max_eps=5, min_samples=5)[source]

Perform DBSCAN clustering on the embeddings and calculate the Silhouette Score.

Parameters: - embeddings: torch.Tensor of shape (num_nodes, embedding_dim), the node embeddings. - eps: float, the maximum distance between two samples for them to be considered as in the same neighborhood (DBSCAN parameter). - min_samples: int, the number of samples in a neighborhood for a point to be considered a core point (DBSCAN parameter).

Returns: - score: float, the silhouette score of the clustering. - labels: torch.Tensor, the cluster labels for each node (-1 means noise).

gsnn.gsnn.optim.utils.neighborhood_preservation_score(edge_index, embeddings, k=2)[source]

Compute the neighborhood preservation score.

Parameters: - edge_index: torch.LongTensor of shape (2, num_edges), the COO edge index representing the graph. - embeddings: torch.Tensor of shape (num_nodes, embedding_dim), the node embeddings. - k: int, the number of nearest neighbors to consider in the embedding space.

Returns: - score: float, the neighborhood preservation score (ratio of preserved neighbors in the embedding space).

gsnn.gsnn.optim.utils.root_mean_squared_picp_error(pred_dist, y_true, alphas=torch.linspace)[source]