duo_ai.algorithms.pyod¶
Classes¶
Configuration dataclass for PyODAlgorithm. |
|
Algorithm for out-of-distribution (OOD) detection using PyOD models. |
Module Contents¶
- class duo_ai.algorithms.pyod.PyODAlgorithmConfig[source]¶
Configuration dataclass for PyODAlgorithm.
- Parameters:
cls (str, optional) – Name of the algorithm class. Default is “PyODAlgorithm”.
num_rollouts (int, optional) – Number of rollouts to use for data generation. Default is 128.
percentiles (list of float, optional) – List of percentiles to use for threshold selection. Default is range(0, 101, 10).
explore_temps (list of float, optional) – List of temperatures to use during exploration rollouts. Default is [1.0].
accept_rate (float, optional) – Acceptance rate for sampling data during rollouts. Default is 0.05.
- name: str = 'pyod'¶
- num_rollouts: int = 128¶
- percentiles: List[float]¶
- explore_temps: List[float] = [1.0]¶
- accept_rate: float = 0.05¶
- class duo_ai.algorithms.pyod.PyODAlgorithm(config: PyODAlgorithmConfig)[source]¶
Bases:
duo_ai.core.AlgorithmAlgorithm for out-of-distribution (OOD) detection using PyOD models.
Examples
>>> algo = PyODAlgorithm(PyODAlgorithmConfig())
- config_cls¶
- config¶
- random¶
- train(policy: duo.policies.PPOPolicy, env: gym.Env, validators: Dict[str, duo.core.Evaluator]) None[source]¶
Train the PyODAlgorithm by searching for the best threshold parameter that maximizes evaluation reward.
- Parameters:
policy (duo.policies.PPOPolicy) – The policy to be evaluated and tuned.
env (gym.Env) – The environment instance for training and data generation.
validators (dict of str to duo.core.Evaluator) – Dictionary mapping split names to evaluator instances for evaluation.
- Return type:
None
Examples
>>> algorithm = PyODAlgorithm(PyODAlgorithmConfig()) >>> algorithm.train(policy, env, validators)
- save_checkpoint(policy: duo.policies.PPOPolicy, name: str) None[source]¶
Save the current policy configuration and parameters to a checkpoint file.
- Parameters:
policy (duo.policies.PPOPolicy) – The policy whose parameters are to be saved.
name (str) – Name for the checkpoint file.
- Return type:
None
Examples
>>> self.save_checkpoint(policy, "best_test")
- _generate_data(env: gym.Env, policy: duo.policies.PPOPolicy, temperature: float, num_rollouts: int, accept_rate: float) dict[source]¶
Generate data for OOD detection by rolling out the policy in the environment.
- Parameters:
env (gym.Env) – The environment used for rollouts.
policy (duo.policies.PPOPolicy) – The policy to be evaluated.
temperature (float) – Temperature parameter for action selection.
num_rollouts (int) – Total number of rollout episodes to generate.
accept_rate (float) – Acceptance rate for sampling data during rollouts.
- Returns:
data – Dictionary containing collected data arrays for each feature.
- Return type:
dict
Examples
>>> data = self._generate_data(env, policy, 1.0, 128, 0.05)