PlanetAlign.logger

TrainingLogger

Logger class for tracking the training process of a network alignment algorithm.

get_hits_mrr_log

Get formatted strings of Hits@K and MRR scores.

plot_loss_curve

Plot the loss curve along training (optimization).

plot_hits_curve

Plot the Hits@K curve along training (optimization).

plot_mrr_curve

Plot the MRR curve along training (optimization).

class TrainingLogger(log_dir: str = 'logs', log_name: str | None = None, top_ks: List[int] | Tuple[int, ...] = (1, 10, 30, 50), digits: int = 4, additional_headers: List[str] | None = None, save: bool = True)[source]

Logger class for tracking the training process of a network alignment algorithm.

Parameters:
  • log_dir (str) – Directory where logs are stored.

  • log_name (str, optional) – Custom log file name. Defaults to timestamp-based naming.

  • top_ks (List[int], optional) – List of K values for Hits@K metrics. Defaults to [1, 10, 30, 50].

  • digits (int, optional) – Number of decimal places for metrics. Defaults to 4.

  • additional_headers (List[str], optional) – Additional headers for the log file. Defaults to None.

  • save (bool, optional) – Flag to save logs to file. Defaults to True.

static format_log(log_entry: Dict) str[source]

Formats the log entry for printing.

get_logs() List[Dict][source]

Returns the logs as a list of dictionaries.

log(epoch: int, loss: float, epoch_time: float, hits: Dict[int, float], mrr: float, verbose: bool = True, **kwargs)[source]

Logs a single training step.

Parameters:

epochint

Current training epoch.

lossfloat

Training loss value.

time: float

Time taken for the current epoch.

hitsDict[int, float]

Dictionary of Hits@K values (e.g., {1: 0.5, 10: 0.7, 30: 0.8, 50: 0.85}).

mrrfloat

Mean Reciprocal Rank (MRR) score.

verbosebool

Flag for printing the log to console.

log_comments(comments: str | List[str] | Tuple[str, ...])[source]

Logs comments.

Parameters:

commentsList[str]

List of comments to log.

save_json()[source]

Saves the logs as a JSON file for structured analysis.

summary()[source]

Prints a summary of the training process.

get_hits_mrr_log(hits, mrr, prefix: str | None = None, digits: int = 4) str[source]

Get formatted strings of Hits@K and MRR scores.

<prefix> | Hits@1: <value> | Hits@10: <value> | Hits@30: <value> | Hits@50: <value> | MRR: <value>

Parameters:
  • hits (dict) – Dictionary containing Hits@K scores.

  • mrr (float) – Mean Reciprocal Rank score.

  • prefix (str, optional) – Prefix string to be included in the output. Default is None.

  • digits (int, optional) – Number of decimal places to display for the scores. Default is 4.

Returns:

Formatted string containing Hits@K and MRR scores.

Return type:

str

plot_hits_curve(hits_logs: dict, save_path: str | Path | None = None, title: str = 'Hits@K Curve', xlabel: str = 'Epochs', ylabel: str = 'Hits@K')[source]

Plot the Hits@K curve along training (optimization).

Parameters:
  • hits_logs (list[dict]) – List of Hits@K scores for each epoch.

  • save_path (str or Path, optional) – Path to save the plot. If None, the plot will not be saved. Default is None.

  • title (str, optional) – Title of the plot. Default is ‘Hits@K Curve’.

  • xlabel (str, optional) – Label for the x-axis. Default is ‘Epochs’.

  • ylabel (str, optional) – Label for the y-axis. Default is ‘Hits@K’.

Return type:

None

plot_loss_curve(loss_logs: dict, save_path: str | Path | None = None, title: str = 'Loss vs Epochs', xlabel: str = 'Epochs', ylabel: str = 'Loss')[source]

Plot the loss curve along training (optimization).

Parameters:
  • loss_logs (list[float]) – List of loss values for each epoch.

  • save_path (str or pathlib.Path, optional) – Path to save the plot. If None, the plot will not be saved. Default is None.

  • title (str, optional) – Title of the plot. Default is ‘Training Curve’.

  • xlabel (str, optional) – Label for the x-axis. Default is ‘Epochs’.

  • ylabel (str, optional) – Label for the y-axis. Default is ‘Loss’.

Return type:

None

plot_mrr_curve(mrr_logs: list | ndarray, save_path: str | Path | None = None, title: str = 'MRR Curve', xlabel: str = 'Epochs', ylabel: str = 'MRR', xlim=None, ylim=None, grid: bool = True)[source]

Plot the MRR curve along training (optimization).

Parameters:
  • mrr_logs (list or np.ndarray) – List of MRR values for each epoch.

  • save_path (str or Path, optional) – Path to save the plot. If None, the plot will not be saved. Default is None.

  • title (str, optional) – Title of the plot. Default is ‘MRR Curve’.

  • xlabel (str, optional) – Label for the x-axis. Default is ‘Epochs’.

  • ylabel (str, optional) – Label for the y-axis. Default is ‘MRR’.

  • xlim (tuple[float, float], optional) – Limits for the x-axis. Default is None.

  • ylim (tuple[float, float], optional) – Limits for the y-axis. Default is None.

  • grid (bool, optional) – Whether to show grid lines. Default is True.

Return type:

None