API Referenceο
The API is organized as follows:
Config: Configuration for the simulation. ThisConfigclass can be used as an alternative to specifying a YAML config file.Models: Models used by the simulation engine. Namely,Patient,State,Transition,History, andUtility.Simulation: Simulation engine. ThisSimulationclass is responsible for running patients through the workflow (i.e. running the actual simulation).Run: Helper functions for running a set of simulations.Draw: Helper functions for drawing the workflow.Parse: Helper functions for parsing the YAML config file.
Configο
Python Pydantic models for defining an APLUSΒ simulation configuration.
- class aplusml.config.Config(*, metadata: ConfigMetadata, variables: Dict[str, ConfigVariable] = {}, states: Dict[str, ConfigState] = {})[source]ο
Specification for an APLUS simulation. All three fields are required β metadata, variables, and states.
Each field is a Pydantic model, as defined in this API.
Instead of specifying this Config object directly, you can use the
create_from_yamlmethod to load a YAML file that follows the schema in Configuration.Use via:
config = Config( metadata=ConfigMetadata(...), variables=ConfigVariable(...), states=ConfigState(...), ) simulation = aplusml.Simulation.create_from_config(config)
- Parameters:
metadata (ConfigMetadata) β Metadata section of config.
variables (Dict[str, ConfigVariable]) β Variables section of config.
states (Dict[str, ConfigState]) β States section of config.
- class aplusml.config.ConfigMetadata(*, name: str | None = None, path_to_properties: str | None = None, properties_col_for_patient_id: str | None = None, patient_sort_preference_property: ConfigPatientSortPreferenceProperty | None = None)[source]ο
Metadata section of config.
- Parameters:
name (Optional[str]) β Name of the simulation.
path_to_properties (Optional[str]) β Path to CSV file where each row is a patient, each column is a property. This is optional β if you donβt have a patient property CSV, you can leave this as None. Note: Only properties explicitly enumerated in the βvariablesβ config section will be imported.
properties_col_for_patient_id (Optional[str]) β Column name in the CSV that contains unique patient IDs.
patient_sort_preference_property (Optional[ConfigPatientSortPreferenceProperty]) β Property to sort patients by when prioritizing allocation of a finite resource.
- class aplusml.config.ConfigPatientSortPreferenceProperty(*, variable: str, is_ascending: bool = True)[source]ο
Patient sort preference property section of config.
- Parameters:
variable (str) β Name of a property (must be defined in the variables config section) that will be used to sort patients when prioritizing allocation of a finite resource
is_ascending (bool) β True = ascending order, False = descending. Default: True
- class aplusml.config.ConfigState(*, type: Literal['start', 'end', 'intermediate'] = 'intermediate', label: str | None = None, transitions: List[ConfigTransition] = [], duration: int = 0, utilities: str | int | float | bool | List[ConfigUtility] = [], resource_deltas: Dict[str, float] = {})[source]ο
State section of config β i.e. a dictionary mapping State IDs to States.
- Parameters:
type (str) β Whether the state is a start, end, or intermediate state within the workflow. Default: βintermediateβ.
label (Optional[str]) β Human-readable label for the state. Default: value of key.
transitions (List[ConfigTransition]) β List of possible state transitions.
duration (int) β Number of timesteps to wait before transitions are evaluated. Default: 0
utilities (Union[str, int, float, bool, List[ConfigUtility]]) β If str, float, or bool, itβs evaluated as a Python expression. Default: [].
resource_deltas (Dict[str, float]) β Changes to resource levels from entering this state. Default: {}. [key] = name of a resource defined in variables. [value] = how much to change each resource level AS SOON AS this state is hit
- class aplusml.config.ConfigTransition(*, dest: str, label: str | None = '', if_: str | bool | None = None, prob: int | float | str | None = None, duration: int = 0, utilities: str | int | float | bool | List[ConfigUtility] = [], resource_deltas: Dict[str, float] = {})[source]ο
Transition within a State.
Transition conditions can either haveβ¦
All transitions have an βifβ condition (where if the last transition doesnβt have an βifβ, it defaults to always TRUE)
All transitions have a βprobβ condition (where if the last transition doesnβt have a βprobβ, it defaults to = 1 - (sum of other probs))
The first set of transitions have an βifβ condition, but the second set have a βprobβ
- Parameters:
dest (str) β ID of the destination state.
label (Optional[str]) β Human-readable label for the transition. Default: ββ.
if (Optional[Union[str, bool]]) β A Python expression. If it evaluates to TRUE, then the transition is taken.
prob (Optional[Union[str, float, int]]) β Probability of the transition.
duration (int) β Number of timesteps to wait before transitions are evaluated. Default: 0
utilities (Union[str, int, float, bool, List[ConfigUtility]]) β If str, float, or bool, itβs evaluated as a Python expression. Default: [].
resource_deltas (Dict[str, float]) β Changes to resource levels from taking this transition. Default: {}. [key] = name of a resource defined in variables. [value] = how much to change each resource level AS SOON AS this transition is taken
- class aplusml.config.ConfigUtility(*, value: int | float | str | None = None, if_: str | bool | None = None, unit: str = '')[source]ο
Utility within a State or Transition.
- Parameters:
value β If str, itβs evaluated as a Python expression.
if β A Python expression. If it evaluates to TRUE, then the value for this utility is set to this value. Note: These βifβ statements are not mutually exclusive (i.e. if multiple conditions within the same State evaluate to TRUE, then they will simply be summed together)
unit β Measurement unit. Default: ββ.
- class aplusml.config.ConfigVariable(*, type: Literal['scalar', 'resource', 'property', 'simulation'] = 'scalar', value: int | float | bool | str | list | dict | set | None = None, init_amount: int | None = None, max_amount: int | None = None, refill_amount: int | None = None, refill_duration: int | None = None, column: str | None = None, distribution: Literal['bernoulli', 'exponential', 'binomial', 'normal', 'poisson', 'uniform'] | None = None, mean: int | float | None = None, std: int | float | None = None, start: int | float | None = None, end: int | float | None = None)[source]ο
Variable section of config β i.e. a dictionary mapping variable IDs to variables.
- Parameters:
type (str) β
Type of variable. Must be one of: βscalarβ, βresourceβ, βpropertyβ, βsimulationβ.
scalar: A scalar value that is shared across all patients. It can be used to model things like the sensitivity of a screening test, the prevalence of a disease, etc. If set, then
valuemust be specified.resource: A finite resource that is shared across all patients. It can be decremented, incremented, and reset by the simulation. It can be used to model things like hospital beds, lab capacity, etc. If set, then
init_amount,max_amount,refill_amount, andrefill_durationmust be specified.property: A property that is unique to each patient. This is a property that is unique to each patient (i.e. each patient may have a different value for this property). It can be used to model things like the age of a patient, the gender of a patient, etc. If set, then
column(if loaded from a CSV file),value(if specified as a constant), ordistribution(if randomly sampled) must be specified.simulation: A simulation variable that is set and tracked automatically by APLUS. Must be one of: βtime_left_in_simβ, βtime_already_in_simβ, βsim_current_timestepβ.
value (Optional[Union[int, float, bool, str, list, dict, set]]) β Scalar value. Must be a valid Python type. Use β!!setβ tag for sets.
init_amount (Optional[int]) β Initial amount of the resource.
max_amount (Optional[int]) β Maximum amount of resource allowed.
refill_amount (Optional[int]) β Amount added per refill.
refill_duration (Optional[int]) β Time interval between refills.
column (Optional[str]) β If this property is loaded from a CSV file, use the column parameter to specify the column name (e.g. βyβ or βy_hat_dlβ). Each row of the CSV will be a patient, and the value of this property for each patient will be the value of the column in the CSV file.
value β Scalar value. Must be a valid Python type. Use β!!setβ tag for sets.
distribution (Optional[VALID_DISTRIBUTION_TYPES]) β If randomly sampled, specify the distribution type.
mean (Optional[Union[int, float]]) β Mean value for distribution.
std (Optional[Union[int, float]]) β Standard deviation.
start (Optional[Union[int, float]]) β Minimum value.
end (Optional[Union[int, float]]) β Maximum value.
Modelsο
Classes used for modeling components of an APLUS simulation β namely: Utility, Transition, State, History, and Patient.
- class aplusml.models.History(current_timestep: int, state_id: str, transition_idx: int, state_utility_idxs: List[int], transition_utility_idxs: List[int], state_utility_vals: List[float], transition_utility_vals: List[float], sim_variables: Dict)[source]ο
The history of a patientβs states and transitions.
- current_timestepο
The current timestep.
- Type:
int
- state_idο
The ID of the current state.
- Type:
str
- transition_idxο
The index of the current transition.
- Type:
int
- state_utility_idxsο
The indices of the utilities of the current state.
- Type:
List[int]
- transition_utility_idxsο
The indices of the utilities of the current transition.
- Type:
List[int]
- state_utility_valsο
The evaluated utility values of the current state.
- Type:
List[float]
- transition_utility_valsο
The evaluated utility values of the current transition.
- Type:
List[float]
- __init__(current_timestep: int, state_id: str, transition_idx: int, state_utility_idxs: List[int], transition_utility_idxs: List[int], state_utility_vals: List[float], transition_utility_vals: List[float], sim_variables: Dict)[source]ο
- Parameters:
current_timestep (int) β The current timestep. Example: 1
state_id (str) β The ID of the current state. Example: βstate1β
transition_idx (int) β The index of the current transition. Example: 0
state_utility_idxs (List[int]) β The indices of the utilities of the current state. Example: [0]
transition_utility_idxs (List[int]) β The indices of the utilities of the current transition. Example: [0]
state_utility_vals (List[float]) β The evaluated utility values of the current state. Example: [100000]
transition_utility_vals (List[float]) β The evaluated utility values of the current transition. Example: [100000]
sim_variables (Dict) β The variables of the simulation. Example: {βy_hatβ: 0.5}
- class aplusml.models.Patient(id: str, start_timestep: int, properties: dict | None = None)[source]ο
A patient in the simulation.
- idο
The ID of the patient. IMPORTANT: Must be unique across all patients.
- Type:
str
- start_timestepο
The start timestep of the patient, i.e. at which timestep in the simulation this patient starts their workflow.
- Type:
int
- propertiesο
The properties of the patient.
- Type:
dict
- historyο
The history of the patient, i.e. all past states, transitions, and utilities the patient has experienced.
- Type:
List[History]
- current_stateο
The ID of the current state the patient is in.
- Type:
str
- __init__(id: str, start_timestep: int, properties: dict | None = None)[source]ο
- Parameters:
id (str) β The ID of the patient. Example:
patient1start_timestep (int) β The start timestep of the patient. Example:
1properties (dict, optional) β The properties of the patient. Example:
{'y_hat': 0.5}
- get_state_history()[source]ο
Get the state history of this patient. Returns a list of state IDs (in chronological order) that the patient has visited.
- get_sum_utilities(simulation: aplusml.sim.Simulation) Dict[str, float][source]ο
Returns a dictionary of the sum of the utilities of the patientβs history.
- Parameters:
simulation (Simulation) β The simulation.
- Returns:
A dictionary where each [key] is a unit, and each [value] is the sum of the utilities of the patientβs history for that unit. Example: {βUSDβ: 100000}
- Return type:
Dict[str, float]
- class aplusml.models.State(id: str, label: str, type: str, duration: int, utilities: List[Utility], transitions: List[Transition], resource_deltas: Dict[str, float])[source]ο
A state in the workflow.
- idο
The ID of the state. Must be unique across all states.
- Type:
str
- labelο
The label of the state.
- Type:
str
- typeο
The type of the state. Must be one of: βstartβ, βintermediateβ, βendβ
- Type:
str
- durationο
The duration of the state. Must be a non-negative integer.
- Type:
int
- transitionsο
The transitions of the state.
- Type:
List[Transition]
- __init__(id: str, label: str, type: str, duration: int, utilities: List[Utility], transitions: List[Transition], resource_deltas: Dict[str, float])[source]ο
- Parameters:
id (str) β The ID of the state.
label (str) β The label of the state.
type (str) β The type of the state. Must be one of: βstartβ, βintermediateβ, βendβ
duration (int) β The duration of the state. Example: 1
utilities (List[Utility]) β The utilities of the state. Example: [Utility(value=β100000β, unit=βUSDβ)]
transitions (List[Transition]) β The transitions of the state. Example: [Transition(dest=βstate2β, label=βTo State 2β, duration=1, utilities=[Utility(value=β100000β, unit=βUSDβ)], resource_deltas={βMRIβ: -1})]
resource_deltas (Dict[str, float]) β The resource deltas of the state. Example: {βMRIβ: -1}
- class aplusml.models.Transition(dest: str, label: str, duration: int, utilities: List[Utility], resource_deltas: Dict[str, float], if_: str | bool | None = None, prob: str | float | None = None)[source]ο
A transition between states.
- destο
The destination state.
- Type:
str
- labelο
The label of the transition.
- Type:
str
- durationο
The duration of the transition.
- Type:
int
- resource_deltasο
The resource deltas of the transition.
- Type:
Dict[str, float]
- if_ο
The condition for the transition, specified as a Python expression.
- Type:
Optional[Union[str, bool]]
- probο
The probability of the transition.
- Type:
Optional[Union[str, float]]
- __init__(dest: str, label: str, duration: int, utilities: List[Utility], resource_deltas: Dict[str, float], if_: str | bool | None = None, prob: str | float | None = None)[source]ο
- Parameters:
dest (str) β The destination state.
label (str) β The label of the transition.
duration (int) β The duration of the transition. Example: 1
utilities (List[Utility]) β The utilities of the transition. Example: [Utility(value=β100000β, unit=βUSDβ)]
resource_deltas (Dict[str, float]) β The resource deltas of the transition. Example: {βMRIβ: -1}
if (Union[str, bool], optional) β The condition for the transition, specified as a Python expression. Defaults to None. Example: βy_hat > 0.5β
prob (Union[str, float], optional) β The probability of the transition. Defaults to None. Example: 0.5
- get_variables_in_conditional() List[str][source]ο
Returns a list of variables involved in the conditional expression.
- class aplusml.models.Utility(value: str, unit: str = '', if_: str | None = None)[source]ο
A utility is a value that is associated with being in a state or undergoing a transition.
- valueο
The value of the utility. Example: β100000β
- Type:
str
- unitο
The unit of the utility. Defaults to ββ. Example: βUSDβ, βdaysβ, βkgβ, βcmβ, etc.
- Type:
str, optional
- if_ο
The condition for the utility, specified as a Python expression. Defaults to None. Example: βy_hat > 0.5β
- Type:
str, optional
- __init__(value: str, unit: str = '', if_: str | None = None)[source]ο
A utility is a value that is associated with being in a state or undergoing a transition.
- Parameters:
value (str) β The value of the utility. Example: β100000β
unit (str, optional) β The unit of the utility. Defaults to ββ. Example: βUSDβ, βdaysβ, βkgβ, βcmβ, etc.
if (str, optional) β The condition for the utility, specified as a Python expression. Defaults to None. Example: βy_hat > 0.5β
Simulationο
Core APLUS simulation engine which progresses patients through a given workflow
- class aplusml.sim.Simulation[source]ο
The core APLUS simulation engine which progresses patients through a given workflow.
This class manages the entire simulation process including:
Patient state transitions and history tracking
Variable evaluation and management
Resource allocation and replenishment
Utility calculations
Workflow visualization
The simulation operates on a timestep basis, processing patients through states and transitions based on conditional and probabilistic rules defined in the workflow configuration.
- metadataο
Configuration metadata for the simulation
- Type:
dict
- variablesο
Variables used in the simulation, keyed by ID
- Type:
Dict[str, Dict]
- variable_historyο
History of variable values over time
- Type:
Dict[List[Tuple[int, Any]]]
- current_timestepο
Current simulation timestep
- Type:
int
- classmethod create_from_config(config: Config, path_to_patient_properties: str | None = None) aplusml.sim.Simulation[source]ο
Create a
Simulationobject from aConfigobject.If
path_to_patient_propertiesis provided, then it overwrites the current Metadata sectionβspath_to_propertieskey.- Parameters:
- Returns:
A
Simulationobject that contains all of the metadata, variables, states, and transitions from the YAML file- Return type:
- classmethod create_from_yaml(path_to_yaml: str, path_to_patient_properties: str | None = None) aplusml.sim.Simulation[source]ο
Create a
Simulationobject from YAMLIf
path_to_patient_propertiesis provided, then it overwrites the current Metadata sectionβspath_to_propertieskey.- Parameters:
path_to_yaml (str) β Path to YAML file
path_to_patient_properties (str) β Path to patient properties CSV file. Optional.
- Returns:
A
Simulationobject that contains all of the metadata, variables, states, and transitions from the YAML file- Return type:
- create_patients_for_simulation(patients: List[Patient], func_match_patient_to_property_column: Callable | None = None, is_overwrite_existing_properties: bool = True, random_seed: int = 0) List[Patient][source]ο
Creates a deep copy of patients and initializes their properties.
Deep copies patients using pickle
Sorts patients by ID
- Initializes patient properties from:
Constants
CSV file data (using matching function)
Random distributions
- Parameters:
patients (List[Patient]) β Template patients to copy and initialize
func_match_patient_to_property_column (Callable, optional) β Function to match patients to rows in properties CSV. Takes
(patient_id, random_idx, df, column). Required if using CSV properties without ID column. Defaults toNone.is_overwrite_existing_properties (bool, optional) β If TRUE, then overwrite each patientβs existing properties with their default values, as specified in self.variables. If FALSE, then only initialize properties that are not already set. Defaults to
True.random_seed (int, optional) β Random seed for reproducibility. Defaults to
0.
- Returns:
New list of initialized patients
- Return type:
List[Patient]
- Raises:
ValueError β If property configuration is invalid or required matching function missing
- draw_workflow_diagram(path_to_file: str | None = None, is_display: bool = True, figsize: Tuple[int, int] = (20, 20))[source]ο
Visualizes the workflow as a directed graph using pydot.
Creates a visual diagram showing:
States as nodes
Transitions as edges
Transition conditions and probabilities
State/transition utilities and durations
- Parameters:
path_to_file (str, optional) β Path to save diagram. Must include supported file extension. If None, diagram is not saved. Defaults to None.
is_display (bool, optional) β Whether to display diagram (useful for Jupyter). Defaults to True.
figsize (Tuple[int, int], optional) β Figure size for matplotlib. Defaults to (20, 20).
- Raises:
ValueError β If path_to_file has unsupported file extension
- evaluate_duration(patient: Patient, duration: str, variables: Dict[str, Any]) int[source]ο
Evaluates how long a patient should remain in a state or transition.
Duration can be a constant or an expression using available variables.
- Parameters:
patient (Patient) β The patient to evaluate duration for
duration (str) β The duration expression to evaluate
variables (Dict[str, Any]) β Variables available for duration evaluation
- Returns:
Number of timesteps the duration should last
- Return type:
int
- evaluate_expression(patient: Patient, expression: Any, variables: dict, expression_compiled: CodeType | None = None) Any[source]ο
Evaluates a Python expression in the context of a patient and variables.
Handles evaluation of:
Literal values (bool, int, float)
String expressions using Pythonβs eval()
Pre-compiled expressions for better performance
The expression can reference any variables passed in the variables dict.
- Parameters:
patient (Patient) β The patient context for evaluation
expression (Any) β The expression to evaluate - can be literal value or string expression
variables (dict) β Dictionary of variables available during evaluation
expression_compiled (CodeType, optional) β Pre-compiled version of the expression
- Returns:
The result of evaluating the expression
- Return type:
Any
- Raises:
NameError β If expression references undefined variables
- evaluate_transition_if(patient: Patient, transition: Transition, variables: dict) bool[source]ο
Evaluates whether a conditional transition should be taken.
Checks if the transition has an βifβ condition and evaluates it in the context of the given patient and variables. If there is no condition, returns True.
- Parameters:
patient (Patient) β The patient attempting the transition
transition (Transition) β The transition to evaluate
variables (dict) β Variables available for condition evaluation
- Returns:
True if transition condition is met or no condition exists, False otherwise
- Return type:
bool
- evaluate_transition_prob(patient: Patient, transition: Transition, variables: Dict[str, Any]) float[source]ο
Evaluates whether a probabilistic transition should be taken.
For transitions with a βprobβ value, evaluates the probability expression. For transitions without a βprobβ, returns None (will be set to remaining probability).
- Parameters:
patient (Patient) β The patient attempting the transition
transition (Transition) β The transition to evaluate
variables (Dict[str, Any]) β Variables available for probability evaluation
- Returns:
Evaluated probability value between 0 and 1, or None if no probability specified
- Return type:
float
- evaluate_utility_if(patient: Patient, utility: Utility, variables: Dict[str, Any]) bool[source]ο
Evaluates whether a utility should be applied based on its condition.
Similar to evaluate_transition_if, but for utility conditions. Returns True if utility has no condition or if condition evaluates to True.
- evaluate_utility_value(patient: Patient, utility: Utility, variables: Dict[str, Any]) Any[source]ο
Evaluates the actual value of a utility.
Evaluates the utilityβs value expression in the context of the patient and variables. The value can be a constant or an expression using available variables.
- evaluate_variables(patient: Patient) Dict[str, Any][source]ο
Evaluates all variables for a given patient at the current timestep.
Processes different variable types:
scalar: Returns constant value
resource: Returns current resource level
property: Returns patient-specific property value
simulation: Returns simulation-specific values (time remaining, elapsed time, current timestep)
function: Executes and returns function result
- Parameters:
patient (Patient) β The patient to evaluate variables for
- Returns:
Dictionary mapping variable IDs to their evaluated values
- Return type:
Dict[str, Any]
- Raises:
AssertionError β If number of evaluated variables doesnβt match total variables
- get_all_utility_units() List[str][source]ο
Gets all unique utility unit types used in the workflow.
Examines all utilities across all states and transitions to find unique unit types (e.g. βQALYβ, βUSDβ).
- Returns:
List of unique utility unit names
- Return type:
List[str]
- init_patients(patients: List[Patient])[source]ο
Initializes patients for simulation.
For each patient: - Sets initial state to βstartβ - Initializes empty history list
- Parameters:
patients (List[Patient]) β List of patients to initialize, modified in place
- init_run(random_seed: int = 0)[source]ο
Initializes the simulation for a new run.
Resets simulation state by: - Setting current timestep to 0 - Initializing all variables - Setting random seeds for reproducibility
- Parameters:
random_seed (int, optional) β Seed for random number generators. Defaults to 0.
- init_variables(variables: Dict[str, dict])[source]ο
Initializes resource variables with their starting values.
Note: Modifies βvariablesβ in place
For each resource variable, sets:
Initial resource level from init_amount
Last refill timestep to 0
Empty history tracking list
- Parameters:
variables (Dict[str, dict]) β Dictionary of variables from config, modified in place
- is_valid_patients(patients: List[Patient]) Tuple[bool, str][source]ο
Validates a list of patients for simulation.
Currently checks: - All patients have unique IDs
- Parameters:
patients (List[Patient]) β List of patients to validate
- Returns:
- (is_valid, error_message) where is_valid is True if validation passes,
and error_message contains details if validation fails
- Return type:
Tuple[bool, str]
- load_seismometer_patients_for_simulation(patients: List[Patient], df_patients_seismometer: pandas.DataFrame, func_match_patient_to_property_column: Callable | None = None, random_seed: int = 0) List[Patient][source]ο
Loads patient properties from an Epic Seismometer dataframe.
Similar to create_patients_for_simulation but loads properties from a provided dataframe instead of CSV file.
- Parameters:
patients (List[Patient]) β Template patients to initialize
df_patients_seismometer (pd.DataFrame) β Dataframe containing patient properties
func_match_patient_to_property_column (Callable, optional) β Function to match patients to rows in dataframe. Takes
(patient_id, random_idx, df, column). Required if not using ID column. Defaults toNone.random_seed (int, optional) β Random seed for reproducibility. Defaults to
0.
- Returns:
Patients with initialized properties
- Return type:
List[Patient]
- Raises:
ValueError β If property configuration is invalid or required matching function missing
- log(string: str)[source]ο
Logs a message if logging is enabled.
Format: t=<current timestep of simulation> | {string}
- Parameters:
string (str) β Message to log
- run(all_patients: List[Patient], max_timesteps: int | None = None, random_seed: int = 0, is_print_log: bool = False, is_print_tqdm: bool = True) List[Patient][source]ο
Runs the simulation by progressing all patients through the workflow.
Core simulation loop that:
Processes patients in order of admission time and preference sorting
Moves each patient through states based on transitions
Tracks utilities and resource usage
Handles patient pausing/unpausing for state/transition durations
Continues until all patients finish or max timesteps reached
Performance: Takes ~3 seconds for 15,000 patients, ~10 seconds for 50,000 patients.
- Parameters:
all_patients (List[Patient]) β All patients to simulate across all admit days. Modified in place - only history and current_state attributes are changed.
max_timesteps (int, optional) β Maximum timesteps to simulate. If reached, simulation stops with current_timestep = max_timesteps - 1. Defaults to None.
random_seed (int, optional) β Random seed for reproducibility. Defaults to 0.
is_print_log (bool, optional) β Whether to print debug logs. Defaults to False.
is_print_tqdm (bool, optional) β Whether to print a progress bar. Defaults to True.
- Returns:
The patients after simulation with updated histories.
- Return type:
List[Patient]
- Raises:
AssertionError β If patients are invalid or simulation state becomes invalid
- select_transition(patient: Patient, transitions: List[Transition], variables: Dict[str, Any]) int[source]ο
Determines which transition a patient should take from their current state.
First evaluates all conditional (βifβ) transitions in order. If none are true, then evaluates probabilistic transitions. For probabilistic transitions, ensures probabilities sum to 1 and handles default probability case.
- Parameters:
patient (Patient) β The patient attempting to transition
transitions (List[Transition]) β Available transitions from current state
variables (Dict[str, Any]) β Variables available for transition evaluation
- Returns:
Index of selected transition, or None if no valid transition found
- Return type:
int
- Raises:
AssertionError β If no valid transition can be selected
- aplusml.sim.get_unit_utility_baselines(patients: List[Patient], utilities: Dict[str, float], y_true_column_name: str = 'ground_truth') Dict[str, float][source]ο
Calculates baseline utility metrics for different treatment strategies.
Computes average per-patient utility for: - Treat all patients - Treat no patients - Perfect treatment (treat only true positives)
- Parameters:
patients (List[Patient]) β Patients to analyze
utilities (Dict[str, float]) β Utility values for TP/FP/FN/TN outcomes
y_true_column_name (str, optional) β Patient property containing ground truth. Defaults to βground_truthβ.
- Returns:
Average utilities for βallβ, βnoneβ, and βperfectβ strategies
- Return type:
Dict[str, float]
- aplusml.sim.log_patients(simulation: Simulation, patients: List[Patient])[source]ο
Prints detailed debug information about patients.
- For each patient, prints:
ID and start timestep
Properties
State history
Sum of utilities
- Parameters:
simulation (Simulation) β Simulation context
patients (List[Patient]) β Patients to log
- aplusml.sim.sort_patient_by_preference(patients: List[Patient], property_to_sort_by: str | None = None, is_ascending: bool = True) List[int][source]ο
Returns indices that would sort patients by specified property.
- Can sort by:
Direct
Patientattributes (id,start_timestep)Patient properties dictionary values
- Parameters:
patients (List[Patient]) β Patients to sort
property_to_sort_by (str, optional) β Property name to sort by. Defaults to
None.is_ascending (bool, optional) β Sort order. Defaults to
True.
- Returns:
Indices that would sort the patients list
- Return type:
List[int]
Runο
Wrapper functions around sim.py to help run/track multiple simulations
- aplusml.run.run_test(simulation: Simulation, all_patients: list[Patient], labels: list, keys2values: list[dict[dict]], df: pandas.DataFrame | None = None, func_run_test: Callable | None = None, func_match_patient_to_property_column: Callable | None = None, is_refresh_patients: bool = False, is_use_multi_processing: bool = False) pandas.DataFrame[source]ο
Runs multiple simulation tests with different variable settings.
This is the main entry point for running simulation experiments. It supports:
Testing multiple configurations in parallel or serial
Custom test functions (e.g. threshold testing)
Patient property refreshing between runs
Appending results to existing dataframes
Multiprocessing for improved performance
The function pairs each label with its corresponding variable settings from
keys2valuesand runs the simulation with those settings. Results from all runs are combined into a single dataframe.- Parameters:
simulation (sim.Simulation) β Base simulation object
all_patients (list[sim.Patient]) β List of patients to simulate
labels (list) β Names for each test configuration
keys2values (list[dict[dict]]) β List of variable settings to test. Each dict maps variable names to new values/settings for that test run.
df (pd.DataFrame, optional) β Existing results to append to. Defaults to None.
func_run_test (Callable, optional) β Custom function to run each test. Typically test_diff_thresholds. If
None, runs basic simulation. Defaults toNone.func_match_patient_to_property_column (Callable, optional) β Function to match patients to properties in CSV. Required if refreshing patients. Defaults to
None.is_refresh_patients (bool, optional) β If
True, recreates patients with new properties between runs. Defaults toFalse.is_use_multi_processing (bool, optional) β If
True, runs tests in parallel using available CPU cores. Defaults toFalse.
- Returns:
- Combined results from all test runs. Format depends on
func_run_test, but always includes a
labelcolumn identifying the test configuration.
- Combined results from all test runs. Format depends on
- Return type:
pd.DataFrame
References
For usage examples, see: - Tutorial (PAD)
- aplusml.run.test_diff_thresholds(simulation: Simulation, all_patients: list[Patient], thresholds: list[float], utility_unit: str = '', positive_outcome_state_ids: list[str] = ['positive_end_state'], **kwargs) pandas.DataFrame[source]ο
Tests different model threshold values to find optimal cutoff point for binary predictions.
For each threshold value, runs the simulation and calculates utility metrics. The simulation must contain a
model_thresholdvariable that is used to binarize probabilistic predictions. After testing all thresholds, sets the simulation and patients to use the threshold that maximizes mean utility.- Parameters:
simulation (sim.Simulation) β Simulation object containing workflow definition
all_patients (list[sim.Patient]) β List of patients to simulate through workflow
thresholds (list[float]) β List of threshold values to test (between 0 and 1)
utility_unit (str, optional) β Name of utility unit to optimize (e.g.
'qaly','usd'). Defaults to''.positive_outcome_state_ids (list[str], optional) β State IDs that represent positive outcomes (treatment administered). Used to calculate work per timestep. Defaults to
['positive_end_state'].**kwargs β Additional arguments passed to
simulation.run()
- Returns:
Results for each threshold tested with columns
threshold: Threshold value testedmean_utility: Mean utility achieved across all patientsstd_utility: Standard deviation of utilitiessem_utility: Standard error of mean utilitymean_work_per_timestep: Average number of positive outcomes per timestep
- Return type:
pd.DataFrame
- Raises:
AssertionError β If
model_thresholdvariable is not defined insimulation.variables
Drawο
Functions for drawing graphs using graphviz.
This module provides utilities for creating and formatting graphviz diagrams of workflows, including HTML table generation and text escaping.
- aplusml.draw._html_escape(text: str) str[source]ο
Escape HTML special characters for use in HTML tables in graphviz.
Replaces special characters with their HTML entity equivalents to ensure proper rendering in graphviz HTML-like labels.
- Parameters:
text (str) β The input text to escape.
- Returns:
The escaped text with the following replacements:
&β&<β<>β>Newlineβ<br align="left"/>
- Return type:
str
- aplusml.draw.create_node_label(title: str, id: str | None, duration: float, utilities: list, resource_deltas: dict, is_edge: bool = False) str[source]ο
Creates an HTML-formatted label string for use in graphviz diagrams, containing information about the nodeβs title, duration, utilities, and resource changes.
- Parameters:
title (str) β Title of the node.
duration (float) β Duration of the node.
utilities (list) β List of utilities associated with the node.
resource_deltas (dict) β Dictionary of resource deltas associated with the node.
is_edge (bool, optional) β Whether the node represents an edge. Defaults to
False.
- Returns:
An HTML-formatted string containing the nodeβs label.
- Return type:
str
Note
The returned string uses graphvizβs HTML-like label syntax and includes: * A title section with optional edge formatting * Duration information * List of utilities * List of resource changes
Plotο
Plotting functions for visualizing simulation results.
- Some quick notes:
For all functions, the df_preds dataframe must contain two columns β βyβ (ground truth) and βy_hatβ (predicted labels).
For all functions, the utilities dictionary must contain four keys β βtpβ, βfpβ, βtnβ, βfnβ β which map to the utility values for each class.
- aplusml.plot.calc_model_performance_metrics(df_preds: pandas.DataFrame, thresholds: list[float] = [0.5]) dict[source]ο
Returns a dictionary containing performance metrics for this model
- Parameters:
df_preds (pd.DataFrame) β Dataframe with two columns, βyβ and βy_hatβ
thresholds (list[float]) β Cutoffs for thresholding predictions to binary 0/1 (used for accuracy, Matthews correlation)
- Returns:
Dictionary containing performance metrics
- Return type:
dict
- aplusml.plot.calc_pearsonr(a: numpy.ndarray, b: numpy.ndarray) float[source]ο
Pearson correlation coefficient between two 1d vectors
- Parameters:
a (np.ndarray) β First vector
b (np.ndarray) β Second vector
- Returns:
Pearson correlation coefficient
- Return type:
float
- aplusml.plot.calc_spearmanr(a: numpy.ndarray, b: numpy.ndarray) float[source]ο
Spearman correlation coefficient between two 1d vectors
- Parameters:
a (np.ndarray) β First vector
b (np.ndarray) β Second vector
- Returns:
Spearman correlation coefficient
- Return type:
float
- aplusml.plot.get_df_utility_from_df_preds(df_preds: pandas.DataFrame, utilities: dict, thresholds: numpy.ndarray, is_add_0_and_1: bool = True) pandas.DataFrame[source]ο
Adds metrics (Utilities + TP/FP/TN/FN) to DataFrame of predictions
- Parameters:
df_preds (pd.DataFrame) β DataFrame containing βy_hatβ (predictions) and βyβ (ground truth) columns
utilities (dict) β Dictionary containing utility values for each class. Must contain four keys: βtpβ, βfpβ, βtnβ, βfnβ
thresholds (np.ndarray) β Array of model thresholds to consider
is_add_0_and_1 (bool) β If TRUE, add 0 and 1 to the start/end of the thresholds array
- Returns:
DataFrame that mirrors βdf_predsβ, but with additional columns
- Return type:
pd.DataFrame
- aplusml.plot.make_model_utility_plots(df_preds: pandas.DataFrame, utilities: dict, is_show: bool = False, path_to_plots_prefix: str | None = None)[source]ο
Run all plotting functions
- Parameters:
df_preds (pd.DataFrame) β
dataframe with two columns, βyβ and βy_hatβ
is_show (bool, optional) β If TRUE, show plots. Defaults to False.
path_to_plots_prefix (str, optional) β Prefix for path to saved plot files. Defaults to None.
- aplusml.plot.plot_bar_mean_utilities(title: str, plot_avg_utilities: dict[float]) plotnine.ggplot[source]ο
Plots bar chart of mean utilities for different settings
- Parameters:
title (str) β Title of the plot
plot_avg_utilities (dict[float]) β Dictionary of mean utilities for different settings
- Returns:
A plotnine plot object showing bar chart of mean utilities
- Return type:
p9.ggplot
- aplusml.plot.plot_calibration_curve(df_preds: pandas.DataFrame, ax: matplotlib.pyplot.Axes | None = None) matplotlib.pyplot.figure[source]ο
- Generate Calibration curve where:
x-axis = mean predicted probability for each bin
y-axis = fraction of positive cases in each bin
The calibration curve shows how well the predicted probabilities match the actual observed frequencies. A perfectly calibrated model will follow the diagonal line y=x.
- Parameters:
df_preds (pd.DataFrame) β DataFrame containing βy_hatβ (predictions) and βyβ (ground truth) columns
ax (plt.Axes, optional) β Matplotlib axes to plot on. If None, creates new figure. Defaults to None.
- Returns:
Matplotlib figure object containing the plot
- Return type:
plt.figure
- aplusml.plot.plot_confusion_matrix(df_preds: pandas.DataFrame, utilities: dict | None = None, threshold: float | None = None, ax: matplotlib.pyplot.Axes | None = None) matplotlib.pyplot.figure[source]ο
- Generate Confusion Matrix @ highest utility threshold (if threshold is not specified) where:
x-axis = predictions (βy_hatβ)
y-axis = ground truth (βyβ)
- Parameters:
df_preds (pd.DataFrame) β DataFrame containing βy_hatβ (predictions) and βyβ (ground truth) columns
utilities (dict, optional) β Dictionary containing utility values for each class
threshold (float, optional) β Cutoff threshold for confusion matrix. If not specified, uses the threshold with highest utility
ax (plt.Axes, optional) β Matplotlib axes to plot on. If None, creates new figure. Defaults to None.
- Returns:
Matplotlib figure object containing the plot
- Return type:
plt.figure
- aplusml.plot.plot_decision_curve(df_preds: pandas.DataFrame, utilities: dict, ax: matplotlib.pyplot.Axes | None = None) matplotlib.pyplot.figure[source]ο
- Generate Decision Curve for model where:
y-axis = X - U_none (i.e. everything is relative to Treat None)
x-axis = R
Risk Threshold (R) is defined as βthe cutpoint for calling a result positive that maximizes expected utilityβ
Thus, βTreat Noneβ on this graph = U_none - U_none = 0.
Thus, at R = r, the βTreat Allβ graph shows what the net benefit would be if you treated everyone AND the optimal risk threshold = r.
Guarantee: βTreat Allβ and βTreat Noneβ lines should intersect at R = Prevalence.
- Parameters:
df_preds (pd.DataFrame) β DataFrame containing βy_hatβ (predictions) and βyβ (ground truth) columns
utilities (dict, optional) β Dictionary containing utility values for each class
ax (plt.Axes, optional) β Matplotlib axes to plot on. If None, creates new figure. Defaults to None.
- Returns:
Matplotlib figure object containing the plot
- Return type:
plt.figure
- aplusml.plot.plot_dodged_bar_mean_utilities(title: str, df: pandas.DataFrame, label_sort_order: list[str] | None = None, label_names: list[str] | None = None, color_sort_order: list[str] | None = None, color_names: list[str] | None = None, is_percent_of_optimistic: bool = False, x_label: str | None = None) plotnine.ggplot[source]ο
Plot relative utility using the optimistic model as a baseline.
Creates a bar plot where bars are grouped by label (x-axis) and colored by a secondary category. Utility values are measured relative to a baseline, optionally as a percentage of the optimistic modelβs performance.
- Parameters:
title (str) β Title of the plot
df (pd.DataFrame) β DataFrame containing columns: y, label, color
label_sort_order (list[str], optional) β Custom ordering for x-axis labels. Defaults to None.
label_names (list[str], optional) β Display names for labels. Defaults to None.
color_sort_order (list[str], optional) β Custom ordering for color categories. Defaults to None.
color_names (list[str], optional) β Display names for color categories. Defaults to None.
is_percent_of_optimistic (bool, optional) β If True, show utilities as percentage of optimistic model. Defaults to False.
x_label (str, optional) β Custom x-axis label. Defaults to None.
- Returns:
A plotnine plot object showing grouped bars of relative utilities
- Return type:
p9.ggplot
- aplusml.plot.plot_hist_pred(df_preds: pandas.DataFrame, ax: matplotlib.pyplot.Axes | None = None) matplotlib.pyplot.figure[source]ο
- Generate Histogram of predictions
x-axis = predictions (βy_hatβ)
y-axis = density
- Parameters:
df_preds (pd.DataFrame) β DataFrame containing βy_hatβ (predictions) and βyβ (ground truth) columns
ax (plt.Axes, optional) β Matplotlib axes to plot on. If None, creates new figure. Defaults to None.
- Returns:
Matplotlib figure object containing the plot
- Return type:
plt.figure
- aplusml.plot.plot_line_compare_multiple_settings(title: str, df: list[pandas.DataFrame], x_label: str | None = None, line_labels: list[str] | None = None) plotnine.ggplot[source]ο
Plots multiple lines on the same x- and y-axis. Used to generate Figure 2 from Jung et al. 2021
- Parameters:
title (str) β Title of the plot
df (list[pd.DataFrame]) β List of DataFrames, each containing columns: x, y, line
x_label (str, optional) β Label for the x-axis. Defaults to None.
line_labels (list[str], optional) β Labels for the lines. Defaults to None.
- Returns:
A plotnine plot object showing multiple lines
- Return type:
p9.ggplot
- aplusml.plot.plot_line_mean_utilities(title: str, df: pandas.DataFrame, group_sort_order: list | None = None, groups_to_drop: list | None = None, label_sort_order: list | None = None, color_sort_order: list | None = None, color_names: list[str] | None = None, shape_sort_order: list | None = None, is_percent_of_optimistic: bool = False, color_title: str | None = None, shape_title: str | None = None, x_label: str | None = None) plotnine.ggplot[source]ο
Creates a line plot comparing mean utilities across different groups and settings.
This function creates a line plot where each line represents a group of related points. Lines can be differentiated by color and points by shape. Unlike the dodged bar plot, this supports multiple grouping dimensions.
- Parameters:
title (str) β Title of the plot
df (pd.DataFrame) β DataFrame containing at minimum these columns: - y: numeric utility values - label: categories for x-axis - group: groups points that should be connected by lines Optional columns: - color: categories for line colors - shape: categories for point shapes
group_sort_order (list, optional) β Custom ordering for line groups. Defaults to None.
groups_to_drop (list, optional) β Groups to exclude from plot. Defaults to None.
label_sort_order (list, optional) β Custom ordering for x-axis labels. Defaults to None.
color_sort_order (list, optional) β Custom ordering for colors. Defaults to None.
color_names (list[str], optional) β Display names for color categories. Defaults to None.
shape_sort_order (list, optional) β Custom ordering for point shapes. Defaults to None.
is_percent_of_optimistic (bool, optional) β If True, show utilities as percentage of optimistic model. Defaults to False.
color_title (str, optional) β Title for color legend. Defaults to None.
shape_title (str, optional) β Title for shape legend. Defaults to None.
x_label (str, optional) β Custom x-axis label. Defaults to None.
- Returns:
A plotnine plot object showing utility comparisons across groups
- Return type:
p9.ggplot
- aplusml.plot.plot_mean_utility_v_threshold(title: str, df: pandas.DataFrame, label_sort_order: list[str] | None = None, label_names: list[str] | None = None, label_title: str = '') plotnine.ggplot[source]ο
Plot mean utility vs. threshold
- Parameters:
title (str) β Title of the plot
df (pd.DataFrame) β Output of run.run_test(). Columns: threshold, mean_utility, std_utility, sem_utility, mean_work_per_timestep, label
label_sort_order (list[str], optional) β Custom ordering for x-axis labels. Defaults to None.
label_names (list[str], optional) β Display names for labels. Defaults to None.
label_title (str, optional) β Title of label legend. Defaults to None.
- Returns:
Plot object
- Return type:
p9.ggplot
- aplusml.plot.plot_ppv_v_utility_curve(df_preds: pandas.DataFrame, utilities: dict, ax: matplotlib.pyplot.Axes | None = None) matplotlib.pyplot.figure[source]ο
- Generate PPV v. Unit Utility curve where:
x-axis = precision (PPV)
y-axis = unit utility
- Parameters:
df_preds (pd.DataFrame) β DataFrame containing βy_hatβ (predictions) and βyβ (ground truth) columns
utilities (dict, optional) β Dictionary containing utility values for each class
ax (plt.Axes, optional) β Matplotlib axes to plot on. If None, creates new figure. Defaults to None.
- Returns:
Matplotlib figure object containing the plot
- Return type:
plt.figure
- aplusml.plot.plot_precision_recall_curve(df_preds: pandas.DataFrame, utilities: dict | None = None, ax: matplotlib.pyplot.Axes | None = None) matplotlib.pyplot.figure[source]ο
- Generate Precision-Recall curve with utility contours where:
x-axis = recall (TPR)
y-axis = precision (PPV)
Explanation of Expected Utility (EU) calculations (Appendix A): https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2804257/pdf/nihms-108324.pdf
- Parameters:
df_preds (pd.DataFrame) β DataFrame containing βy_hatβ (predictions) and βyβ (ground truth) columns
utilities (dict, optional) β Dictionary containing utility values for each class
ax (plt.Axes, optional) β Matplotlib axes to plot on. If None, creates new figure. Defaults to None.
- Returns:
Matplotlib figure object containing the plot
- Return type:
plt.figure
- aplusml.plot.plot_pred_v_true(df_preds: pandas.DataFrame, ax: matplotlib.pyplot.Axes | None = None) matplotlib.pyplot.figure[source]ο
Generate a scatter plot comparing predicted vs true values with density coloring.
- Parameters:
df_preds (pd.DataFrame) β DataFrame containing βy_hatβ (predictions) and βyβ (ground truth) columns
ax (plt.Axes, optional) β Matplotlib axes to plot on. If None, creates new figure. Defaults to None.
- Returns:
Matplotlib figure object containing the plot
- Return type:
plt.figure
- aplusml.plot.plot_relative_utility_curve(lines: list[dict[pandas.DataFrame]], utilities: dict, xlim: Tuple = (0, 1), ylim: Tuple = (-0.1, None), ax: matplotlib.pyplot.Axes | None = None) matplotlib.pyplot.figure[source]ο
- Generate Relative Utility Curve where:
y-axis = relative utility
x-axis = risk threshold
βThe relative utility curve plots the fraction of the expected utility of perfect prediction obtained by the risk prediction model at the optimal cut point associated with the risk threshold Rβ
- Parameters:
lines (list[dict[pd.DataFrame]]) β List of dictionaries containing βdfβ (dataframe) and βlabelβ (string)
utilities (dict, optional) β Dictionary containing utility values for each class
xlim (Tuple, optional) β Tuple containing the x-axis limits. Defaults to (0, 1).
ylim (Tuple, optional) β Tuple containing the y-axis limits. Defaults to (-0.1, None).
ax (plt.Axes, optional) β Matplotlib axes to plot on. If None, creates new figure. Defaults to None.
- Returns:
Matplotlib figure object containing the plot
- Return type:
plt.figure
- aplusml.plot.plot_roc_curve(df_preds: pandas.DataFrame, utilities: dict | None = None, ax: matplotlib.pyplot.Axes | None = None) matplotlib.pyplot.figure[source]ο
- Generate ROC curve with indifference curves where:
x-axis = false positive rate (FPR)
y-axis = true positive rate (TPR)
Explanation of indifference curves: http://www0.cs.ucl.ac.uk/staff/ucacbbl/roc/
- Parameters:
df_preds (pd.DataFrame) β DataFrame containing βy_hatβ (predictions) and βyβ (ground truth) columns
utilities (dict, optional) β Dictionary containing utility values for each class
ax (plt.Axes, optional) β Matplotlib axes to plot on. If None, creates new figure. Defaults to None.
- Returns:
Matplotlib figure object containing the plot
- Return type:
plt.figure
- aplusml.plot.plot_threshold_v_ppv_tpr_work(df_preds: pandas.DataFrame, utilities: dict, ax: matplotlib.pyplot.Axes | None = None) matplotlib.pyplot.figure[source]ο
- Generate Cutoff Threshold v. PPV/TPR/Work curve where:
x-axis = cutoff threshold
y-axis = PPV/TPR/Work
- Parameters:
df_preds (pd.DataFrame) β DataFrame containing βy_hatβ (predictions) and βyβ (ground truth) columns
utilities (dict, optional) β Dictionary containing utility values for each class
ax (plt.Axes, optional) β Matplotlib axes to plot on. If None, creates new figure. Defaults to None.
- Returns:
Matplotlib figure object containing the plot
- Return type:
plt.figure
- aplusml.plot.plot_threshold_v_utility_curve(df_preds: pandas.DataFrame, utilities: dict, ax: matplotlib.pyplot.Axes | None = None) matplotlib.pyplot.figure[source]ο
- Generate Cutoff Threshold v. Unit Utility curve where:
x-axis = cutoff threshold
y-axis = unit utility
- Parameters:
df_preds (pd.DataFrame) β DataFrame containing βy_hatβ (predictions) and βyβ (ground truth) columns
utilities (dict, optional) β Dictionary containing utility values for each class
ax (plt.Axes, optional) β Matplotlib axes to plot on. If None, creates new figure. Defaults to None.
- Returns:
Matplotlib figure object containing the plot
- Return type:
plt.figure
- aplusml.plot.plot_work_v_ppv_tpr_fpr(df_preds: pandas.DataFrame, utilities: dict, ax: matplotlib.pyplot.Axes | None = None) matplotlib.pyplot.figure[source]ο
Generate Work v. PPV/TPR/FPR curve where:
x-axis = work (%)
y-axis = PPV/TPR/FPR
- Parameters:
df_preds (pd.DataFrame) β DataFrame containing βy_hatβ (predictions) and βyβ (ground truth) columns
utilities (dict, optional) β Dictionary containing utility values for each class
ax (plt.Axes, optional) β Matplotlib axes to plot on. If None, creates new figure. Defaults to None.
- Returns:
Matplotlib figure object containing the plot
- Return type:
plt.figure
- aplusml.plot.plot_work_v_utility(df_preds: pandas.DataFrame, utilities: dict, ax: matplotlib.pyplot.Axes | None = None) matplotlib.pyplot.figure[source]ο
- Generate Work v. Unit Utility curve where:
x-axis = work (%)
y-axis = unit utility
- Parameters:
df_preds (pd.DataFrame) β DataFrame containing βy_hatβ (predictions) and βyβ (ground truth) columns
utilities (dict, optional) β Dictionary containing utility values for each class
ax (plt.Axes, optional) β Matplotlib axes to plot on. If None, creates new figure. Defaults to None.
- Returns:
Matplotlib figure object containing the plot
- Return type:
plt.figure
Parseο
Functions to parse APLUS config YAML files into Python objects for use in sim.py. Contains a list of required and optional keys for each config section.
- aplusml.parse.is_keys_valid(yaml_entry: dict, yaml_entry_id: str, yaml_entry_type: str, valid_keys: dict[str], is_check_required_keys: bool = True, is_check_optional_keys: bool = True) bool[source]ο
Check that the keys in a given YAML entry are valid (i.e. all required keys are present, and no extraneous keys are present).
- Parameters:
yaml_entry (dict) β The YAML entry to check
yaml_entry_id (str) β The ID of the YAML entry
yaml_entry_type (str) β The type of YAML entry
valid_keys (dict) β A dictionary of valid keys for the YAML entry
is_check_required_keys (bool) β Whether to check that all required keys are present
is_check_optional_keys (bool) β Whether to check that no extraneous keys are present
- Returns:
True if the keys are valid, False otherwise
- Return type:
bool
- aplusml.parse.is_valid_config_yaml(yaml: dict) bool[source]ο
Return TRUE if the provided YAML config is valid, FALSE otherwise.