SessionTracker
anomaly_match.pipeline.SessionTracker
¶
Session tracking and state persistence.
IterationInfo(iteration_number, timestamp, model_loss=None, test_performance=None, model_state_path=None, num_newly_labeled_anomalous=0, num_newly_labeled_nominal=0, unlabelled_scores_file=None, test_scores_file=None)
dataclass
¶
Data class to store information about a single training iteration.
to_dict()
¶
Convert IterationInfo to dictionary.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict containing all iteration fields. |
Source code in anomaly_match/pipeline/SessionTracker.py
SessionTracker(session_name=None)
¶
Tracks important session metrics during AnomalyMatch training and evaluation.
This class maintains a record of: - Session iterations and their timestamps - Model training iterations and losses - Labeled samples (anomalous/normal) per session iteration - Test performance metrics - Model states and configurations
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_name
|
str
|
Optional name for the session. If None, uses timestamp. |
None
|
Source code in anomaly_match/pipeline/SessionTracker.py
start_new_session_iteration()
¶
Start a new session iteration.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The session iteration number that was started. |
Source code in anomaly_match/pipeline/SessionTracker.py
update_model_iteration(loss=None, num_iterations=1)
¶
Update model iteration count and optionally record loss.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
loss
|
float
|
Optional loss value for this iteration. |
None
|
num_iterations
|
int
|
Number of iterations to add (default 1). |
1
|
Source code in anomaly_match/pipeline/SessionTracker.py
add_labeled_sample(filename, label, iteration_number=None)
¶
Add a labeled sample to the current session iteration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Name of the labeled file. |
required |
label
|
str
|
Label assigned ('anomaly' or 'normal'). |
required |
iteration_number
|
int
|
Optional specific iteration number. If None, uses current iteration. |
None
|
Source code in anomaly_match/pipeline/SessionTracker.py
update_test_performance(performance_metrics)
¶
Update test performance for the current session iteration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
performance_metrics
|
Dict[str, float]
|
Dictionary of performance metrics (e.g., accuracy, AUC). |
required |
Source code in anomaly_match/pipeline/SessionTracker.py
update_model_state_path(model_path)
¶
Update the model state path for the current session iteration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_path
|
str
|
Path to the saved model state. |
required |
Source code in anomaly_match/pipeline/SessionTracker.py
get_session_info()
¶
Get comprehensive session information.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict containing session-level information. |
Source code in anomaly_match/pipeline/SessionTracker.py
get_iteration_info(iteration_number=None)
¶
Get information about a specific iteration or the latest one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iteration_number
|
int
|
Specific iteration to get info for. If None, returns latest. |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict containing iteration information. |
Source code in anomaly_match/pipeline/SessionTracker.py
get_all_iterations_info()
¶
Get information about all session iterations.
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
List of dictionaries containing iteration information, ordered by iteration number (newest first). |
Source code in anomaly_match/pipeline/SessionTracker.py
get_labeled_data_df()
¶
Get the current labeled data DataFrame.
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with labeled samples. |
update_labeled_data(labeled_data_df)
¶
Update the complete labeled dataset, preserving existing iteration information.
This method merges new labeled data with existing tracked samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labeled_data_df
|
DataFrame
|
DataFrame containing labeled data (may or may not have iteration column) |
required |