Policies

Base Interfaces

Policy interfaces and reusable policy state.

class ActionValuePolicy[source]

Bases: Policy

Base class for policies that estimate one value per action.

initial_value: float = 0.0
step: int = 0
total_reward: float = 0.0
counts: ndarray[tuple[Any, ...], dtype[float64]]
estimates: ndarray[tuple[Any, ...], dtype[float64]]
update(*, action, reward)[source]

Update policy state after observing a reward.

Parameters:
Return type:

None

reset()[source]

Reset learned state.

Return type:

None

recommend_action()[source]

Return the current best-arm recommendation without exploration.

Return type:

int

_parity_state()[source]

Return learned state in the language-neutral fixture shape.

Return type:

dict[str, object]

__init__(n_arms, initial_value=0.0)
Parameters:
Return type:

None

capabilities = PolicyCapabilities(contextual=False, reward_domains=frozenset({<RewardDomain.REAL: 'real'>, <RewardDomain.BINARY: 'binary'>, <RewardDomain.UNIT_INTERVAL: 'unit_interval'>}), objective=<PolicyObjective.CUMULATIVE_REWARD: 'cumulative_reward'>)
clone()

Create a fresh policy with the same configuration.

The default deep-copies configuration and then resets learned state. Policies that own non-copyable resources must override this method.

Return type:

Policy

abstractmethod select_action(*, rng)

Choose an action index.

Parameters:

rng (Generator)

Return type:

int

n_arms: int
class ContextualPolicy[source]

Bases: ABC

Base class for linear contextual bandit policies.

n_arms: int
n_features: int
capabilities = PolicyCapabilities(contextual=True, reward_domains=frozenset({<RewardDomain.REAL: 'real'>, <RewardDomain.BINARY: 'binary'>, <RewardDomain.UNIT_INTERVAL: 'unit_interval'>}), objective=<PolicyObjective.CUMULATIVE_REWARD: 'cumulative_reward'>)
abstractmethod select_action(*, context, rng)[source]

Choose an action index for a context matrix.

Parameters:
Return type:

int

abstractmethod update(*, action, reward, context)[source]

Update policy state after a contextual reward.

Parameters:
Return type:

None

abstractmethod reset()[source]

Reset learned state.

Return type:

None

clone()[source]

Create a fresh policy with the same immutable configuration.

Return type:

ContextualPolicy

recommend_action(*, context)[source]

Return the current recommendation without exploratory sampling.

Parameters:

context (ndarray[tuple[Any, ...], dtype[float64]])

Return type:

int

__init__(n_arms, n_features)
Parameters:
  • n_arms (int)

  • n_features (int)

Return type:

None

class Policy[source]

Bases: ABC

Base class for non-contextual bandit policies.

n_arms: int
capabilities = PolicyCapabilities(contextual=False, reward_domains=frozenset({<RewardDomain.REAL: 'real'>, <RewardDomain.BINARY: 'binary'>, <RewardDomain.UNIT_INTERVAL: 'unit_interval'>}), objective=<PolicyObjective.CUMULATIVE_REWARD: 'cumulative_reward'>)
abstractmethod select_action(*, rng)[source]

Choose an action index.

Parameters:

rng (Generator)

Return type:

int

abstractmethod update(*, action, reward)[source]

Update policy state after observing a reward.

Parameters:
Return type:

None

abstractmethod reset()[source]

Reset learned state.

Return type:

None

clone()[source]

Create a fresh policy with the same configuration.

The default deep-copies configuration and then resets learned state. Policies that own non-copyable resources must override this method.

Return type:

Policy

recommend_action()[source]

Return the current best-arm recommendation without exploration.

Return type:

int

__init__(n_arms)
Parameters:

n_arms (int)

Return type:

None

choose_argmax(values, rng)[source]

Break argmax ties uniformly at random.

Parameters:
Return type:

int

softmax(values, temperature=1.0)[source]

Numerically stable softmax.

Parameters:
Return type:

ndarray[tuple[Any, …], dtype[float64]]

validate_positive(value, *, name, allow_zero=False)[source]

Validate a finite positive or non-negative scalar.

Parameters:
Return type:

None

validate_positive_integer(value, *, name)[source]

Validate an integer count used to size arrays or loops.

Parameters:
Return type:

None

validate_probability(value, *, name)[source]

Validate a scalar probability.

Parameters:
Return type:

None

Classic Policies

Compatibility import for the Python reference greedy policy.

class GreedyPolicy

Bases: NativePolicyMixin, GreedyPolicy

Always select the action with the highest estimated value.

__init__(*args, **kwargs)
Parameters:
Return type:

None

property backend: str

Return the policy-state backend in use.

capabilities = PolicyCapabilities(contextual=False, reward_domains=frozenset({<RewardDomain.REAL: 'real'>, <RewardDomain.BINARY: 'binary'>, <RewardDomain.UNIT_INTERVAL: 'unit_interval'>}), objective=<PolicyObjective.CUMULATIVE_REWARD: 'cumulative_reward'>)
clone()

Create a fresh policy with the same configuration.

The default deep-copies configuration and then resets learned state. Policies that own non-copyable resources must override this method.

Return type:

Policy | ContextualPolicy

property configuration: Mapping[str, object]

Return immutable normalized constructor configuration.

estimated_state_bytes()

Estimate Rust-owned state memory including reserved capacities.

Return type:

int

initial_value: float = 0.0
recommend_action(*, context=None)

Return the current best-arm recommendation without exploration.

Parameters:

context (ndarray[tuple[Any, ...], dtype[float64]] | None)

Return type:

int

reset()

Reset learned state.

Return type:

None

select_action(*, rng, context=None)

Choose an action index.

Parameters:
Return type:

int

property step: int

Return the number of completed native updates.

property total_reward: float

Return cumulative reward observed by the native policy.

update(*, action, reward, context=None)

Update policy state after observing a reward.

Parameters:
Return type:

None

n_arms: int
n_features: int
counts: ndarray[tuple[Any, ...], dtype[float64]]
estimates: ndarray[tuple[Any, ...], dtype[float64]]

Compatibility import for the Python reference random policy.

class RandomPolicy

Bases: NativePolicyMixin, RandomPolicy

Select each action uniformly at random.

__init__(*args, **kwargs)
Parameters:
Return type:

None

property backend: str

Return the policy-state backend in use.

capabilities = PolicyCapabilities(contextual=False, reward_domains=frozenset({<RewardDomain.REAL: 'real'>, <RewardDomain.BINARY: 'binary'>, <RewardDomain.UNIT_INTERVAL: 'unit_interval'>}), objective=<PolicyObjective.CUMULATIVE_REWARD: 'cumulative_reward'>)
clone()

Create a fresh policy with the same configuration.

The default deep-copies configuration and then resets learned state. Policies that own non-copyable resources must override this method.

Return type:

Policy | ContextualPolicy

property configuration: Mapping[str, object]

Return immutable normalized constructor configuration.

estimated_state_bytes()

Estimate Rust-owned state memory including reserved capacities.

Return type:

int

initial_value: float = 0.0
recommend_action(*, context=None)

Return the current best-arm recommendation without exploration.

Parameters:

context (ndarray[tuple[Any, ...], dtype[float64]] | None)

Return type:

int

reset()

Reset learned state.

Return type:

None

select_action(*, rng, context=None)

Choose an action index.

Parameters:
Return type:

int

property step: int

Return the number of completed native updates.

property total_reward: float

Return cumulative reward observed by the native policy.

update(*, action, reward, context=None)

Update policy state after observing a reward.

Parameters:
Return type:

None

n_arms: int
n_features: int
counts: ndarray[tuple[Any, ...], dtype[float64]]
estimates: ndarray[tuple[Any, ...], dtype[float64]]

Compatibility imports for Python reference epsilon-greedy policies.

class DecayingEpsilonGreedyPolicy

Bases: NativePolicyMixin, DecayingEpsilonGreedyPolicy

Epsilon-greedy policy with a monotone exploration schedule.

The schedule is hyperbolic by default: epsilon_t = min_epsilon + (initial_epsilon - min_epsilon) / (1 + decay_rate * t). This gives users an intuitive policy that explores heavily early and settles into exploitation without fully disabling exploration unless min_epsilon is set to zero.

__init__(*args, **kwargs)
Parameters:
Return type:

None

property backend: str

Return the policy-state backend in use.

capabilities = PolicyCapabilities(contextual=False, reward_domains=frozenset({<RewardDomain.REAL: 'real'>, <RewardDomain.BINARY: 'binary'>, <RewardDomain.UNIT_INTERVAL: 'unit_interval'>}), objective=<PolicyObjective.CUMULATIVE_REWARD: 'cumulative_reward'>)
clone()

Create a fresh policy with the same configuration.

The default deep-copies configuration and then resets learned state. Policies that own non-copyable resources must override this method.

Return type:

Policy | ContextualPolicy

property configuration: Mapping[str, object]

Return immutable normalized constructor configuration.

property epsilon: float

Current exploration probability.

estimated_state_bytes()

Estimate Rust-owned state memory including reserved capacities.

Return type:

int

initial_value: float = 0.0
recommend_action(*, context=None)

Return the current best-arm recommendation without exploration.

Parameters:

context (ndarray[tuple[Any, ...], dtype[float64]] | None)

Return type:

int

reset()

Reset learned state.

Return type:

None

select_action(*, rng, context=None)

Choose an action index.

Parameters:
Return type:

int

property step: int

Return the number of completed native updates.

property total_reward: float

Return cumulative reward observed by the native policy.

update(*, action, reward, context=None)

Update policy state after observing a reward.

Parameters:
Return type:

None

n_arms: int
n_features: int
counts: ndarray[tuple[Any, ...], dtype[float64]]
estimates: ndarray[tuple[Any, ...], dtype[float64]]
class EpsilonGreedyPolicy

Bases: NativePolicyMixin, EpsilonGreedyPolicy

Explore uniformly with probability epsilon, otherwise exploit.

__init__(*args, **kwargs)
Parameters:
Return type:

None

property backend: str

Return the policy-state backend in use.

capabilities = PolicyCapabilities(contextual=False, reward_domains=frozenset({<RewardDomain.REAL: 'real'>, <RewardDomain.BINARY: 'binary'>, <RewardDomain.UNIT_INTERVAL: 'unit_interval'>}), objective=<PolicyObjective.CUMULATIVE_REWARD: 'cumulative_reward'>)
clone()

Create a fresh policy with the same configuration.

The default deep-copies configuration and then resets learned state. Policies that own non-copyable resources must override this method.

Return type:

Policy | ContextualPolicy

property configuration: Mapping[str, object]

Return immutable normalized constructor configuration.

estimated_state_bytes()

Estimate Rust-owned state memory including reserved capacities.

Return type:

int

initial_value: float = 0.0
recommend_action(*, context=None)

Return the current best-arm recommendation without exploration.

Parameters:

context (ndarray[tuple[Any, ...], dtype[float64]] | None)

Return type:

int

reset()

Reset learned state.

Return type:

None

select_action(*, rng, context=None)

Choose an action index.

Parameters:
Return type:

int

property step: int

Return the number of completed native updates.

property total_reward: float

Return cumulative reward observed by the native policy.

update(*, action, reward, context=None)

Update policy state after observing a reward.

Parameters:
Return type:

None

n_arms: int
n_features: int
counts: ndarray[tuple[Any, ...], dtype[float64]]
estimates: ndarray[tuple[Any, ...], dtype[float64]]

Compatibility import for the Python reference adversarial policy.

class EXP3Policy

Bases: NativePolicyMixin, EXP3Policy

EXP3 for adversarial rewards in [0, 1].

The policy maintains multiplicative weights over arms and updates the selected arm with an importance-weighted reward estimate. gamma mixes in uniform exploration and also serves as the default learning-rate scale.

__init__(*args, **kwargs)
Parameters:
Return type:

None

action_probabilities()[source]
Return type:

ndarray[tuple[Any, …], dtype[float64]]

property backend: str

Return the policy-state backend in use.

capabilities = PolicyCapabilities(contextual=False, reward_domains=frozenset({<RewardDomain.BINARY: 'binary'>, <RewardDomain.UNIT_INTERVAL: 'unit_interval'>}), objective=<PolicyObjective.CUMULATIVE_REWARD: 'cumulative_reward'>)
clone()

Create a fresh policy with the same configuration.

The default deep-copies configuration and then resets learned state. Policies that own non-copyable resources must override this method.

Return type:

Policy | ContextualPolicy

property configuration: Mapping[str, object]

Return immutable normalized constructor configuration.

estimated_state_bytes()

Estimate Rust-owned state memory including reserved capacities.

Return type:

int

initial_value: float = 0.0
recommend_action(*, context=None)

Return the current best-arm recommendation without exploration.

Parameters:

context (ndarray[tuple[Any, ...], dtype[float64]] | None)

Return type:

int

reset()

Reset learned state.

Return type:

None

select_action(*, rng, context=None)

Choose an action index.

Parameters:
Return type:

int

property step: int

Return the number of completed native updates.

property total_reward: float

Return cumulative reward observed by the native policy.

update(*, action, reward, context=None)

Update policy state after observing a reward.

Parameters:
Return type:

None

property weights: ndarray[tuple[Any, ...], dtype[float64]]

Return relative multiplicative weights, normalized to a maximum of one.

n_arms: int
n_features: int
counts: ndarray[tuple[Any, ...], dtype[float64]]
estimates: ndarray[tuple[Any, ...], dtype[float64]]

Compatibility imports for Python reference pure-exploration policies.

class MedianEliminationPolicy

Bases: NativePolicyMixin, MedianEliminationPolicy

Median elimination for rewards bounded to the unit interval.

__init__(*args, **kwargs)
Parameters:
Return type:

None

property backend: str

Return the policy-state backend in use.

property best_arm: int

Return the current best-arm recommendation.

capabilities = PolicyCapabilities(contextual=False, reward_domains=frozenset({<RewardDomain.BINARY: 'binary'>, <RewardDomain.UNIT_INTERVAL: 'unit_interval'>}), objective=<PolicyObjective.BEST_ARM: 'best_arm'>)
clone()

Create a fresh policy with the same configuration.

The default deep-copies configuration and then resets learned state. Policies that own non-copyable resources must override this method.

Return type:

Policy | ContextualPolicy

property configuration: Mapping[str, object]

Return immutable normalized constructor configuration.

estimated_state_bytes()

Estimate Rust-owned state memory including reserved capacities.

Return type:

int

initial_value: float = 0.0
recommend_action(*, context=None)

Return the current best-arm recommendation without exploration.

Parameters:

context (ndarray[tuple[Any, ...], dtype[float64]] | None)

Return type:

int

reset()

Reset learned state.

Return type:

None

select_action(*, rng, context=None)

Choose an action index.

Parameters:
Return type:

int

property step: int

Return the number of completed native updates.

property total_reward: float

Return cumulative reward observed by the native policy.

update(*, action, reward, context=None)

Update policy state after observing a reward.

Parameters:
Return type:

None

n_arms: int
n_features: int
counts: ndarray[tuple[Any, ...], dtype[float64]]
estimates: ndarray[tuple[Any, ...], dtype[float64]]
class SuccessiveEliminationPolicy

Bases: NativePolicyMixin, SuccessiveEliminationPolicy

Successive elimination for fixed-confidence best-arm identification.

__init__(*args, **kwargs)
Parameters:
Return type:

None

property backend: str

Return the policy-state backend in use.

property best_arm: int

Return the current best-arm recommendation.

capabilities = PolicyCapabilities(contextual=False, reward_domains=frozenset({<RewardDomain.REAL: 'real'>, <RewardDomain.BINARY: 'binary'>, <RewardDomain.UNIT_INTERVAL: 'unit_interval'>}), objective=<PolicyObjective.BEST_ARM: 'best_arm'>)
clone()

Create a fresh policy with the same configuration.

The default deep-copies configuration and then resets learned state. Policies that own non-copyable resources must override this method.

Return type:

Policy | ContextualPolicy

property configuration: Mapping[str, object]

Return immutable normalized constructor configuration.

estimated_state_bytes()

Estimate Rust-owned state memory including reserved capacities.

Return type:

int

initial_value: float = 0.0
recommend_action(*, context=None)

Return the current best-arm recommendation without exploration.

Parameters:

context (ndarray[tuple[Any, ...], dtype[float64]] | None)

Return type:

int

reset()

Reset learned state.

Return type:

None

select_action(*, rng, context=None)

Choose an action index.

Parameters:
Return type:

int

property step: int

Return the number of completed native updates.

property total_reward: float

Return cumulative reward observed by the native policy.

update(*, action, reward, context=None)

Update policy state after observing a reward.

Parameters:
Return type:

None

n_arms: int
n_features: int
active: ndarray
counts: ndarray[tuple[Any, ...], dtype[float64]]
estimates: ndarray[tuple[Any, ...], dtype[float64]]

Compatibility import for the Python reference softmax policy.

class SoftmaxPolicy

Bases: NativePolicyMixin, SoftmaxPolicy

Sample actions according to a softmax over estimated values.

__init__(*args, **kwargs)
Parameters:
Return type:

None

action_probabilities()[source]

Return the current softmax action probabilities.

Return type:

ndarray

property backend: str

Return the policy-state backend in use.

capabilities = PolicyCapabilities(contextual=False, reward_domains=frozenset({<RewardDomain.REAL: 'real'>, <RewardDomain.BINARY: 'binary'>, <RewardDomain.UNIT_INTERVAL: 'unit_interval'>}), objective=<PolicyObjective.CUMULATIVE_REWARD: 'cumulative_reward'>)
clone()

Create a fresh policy with the same configuration.

The default deep-copies configuration and then resets learned state. Policies that own non-copyable resources must override this method.

Return type:

Policy | ContextualPolicy

property configuration: Mapping[str, object]

Return immutable normalized constructor configuration.

estimated_state_bytes()

Estimate Rust-owned state memory including reserved capacities.

Return type:

int

initial_value: float = 0.0
recommend_action(*, context=None)

Return the current best-arm recommendation without exploration.

Parameters:

context (ndarray[tuple[Any, ...], dtype[float64]] | None)

Return type:

int

reset()

Reset learned state.

Return type:

None

select_action(*, rng, context=None)

Choose an action index.

Parameters:
Return type:

int

property step: int

Return the number of completed native updates.

property total_reward: float

Return cumulative reward observed by the native policy.

update(*, action, reward, context=None)

Update policy state after observing a reward.

Parameters:
Return type:

None

n_arms: int
n_features: int
counts: ndarray[tuple[Any, ...], dtype[float64]]
estimates: ndarray[tuple[Any, ...], dtype[float64]]

Compatibility import for the Python reference gradient policy.

class GradientBanditPolicy

Bases: NativePolicyMixin, GradientBanditPolicy

Gradient bandit algorithm using action preferences.

__init__(*args, **kwargs)
Parameters:
Return type:

None

property backend: str

Return the policy-state backend in use.

capabilities = PolicyCapabilities(contextual=False, reward_domains=frozenset({<RewardDomain.REAL: 'real'>, <RewardDomain.BINARY: 'binary'>, <RewardDomain.UNIT_INTERVAL: 'unit_interval'>}), objective=<PolicyObjective.CUMULATIVE_REWARD: 'cumulative_reward'>)
clone()

Create a fresh policy with the same configuration.

The default deep-copies configuration and then resets learned state. Policies that own non-copyable resources must override this method.

Return type:

Policy | ContextualPolicy

property configuration: Mapping[str, object]

Return immutable normalized constructor configuration.

estimated_state_bytes()

Estimate Rust-owned state memory including reserved capacities.

Return type:

int

recommend_action(*, context=None)

Return the current best-arm recommendation without exploration.

Parameters:

context (ndarray[tuple[Any, ...], dtype[float64]] | None)

Return type:

int

reset()

Reset learned state.

Return type:

None

select_action(*, rng, context=None)

Choose an action index.

Parameters:
Return type:

int

property step: int

Return the number of completed native updates.

property total_reward: float

Return cumulative reward observed by the native policy.

update(*, action, reward, context=None)

Update policy state after observing a reward.

Parameters:
Return type:

None

n_arms: int
n_features: int

UCB and Bayesian Policies

Compatibility imports for Python reference UCB policies.

class KLUCBPolicy

Bases: NativePolicyMixin, KLUCBPolicy

KL-UCB for Bernoulli rewards.

__init__(*args, **kwargs)
Parameters:
Return type:

None

property backend: str

Return the policy-state backend in use.

capabilities = PolicyCapabilities(contextual=False, reward_domains=frozenset({<RewardDomain.BINARY: 'binary'>}), objective=<PolicyObjective.CUMULATIVE_REWARD: 'cumulative_reward'>)
clone()

Create a fresh policy with the same configuration.

The default deep-copies configuration and then resets learned state. Policies that own non-copyable resources must override this method.

Return type:

Policy | ContextualPolicy

property configuration: Mapping[str, object]

Return immutable normalized constructor configuration.

estimated_state_bytes()

Estimate Rust-owned state memory including reserved capacities.

Return type:

int

indices()[source]

Return current KL-UCB indices for all arms.

Return type:

ndarray[tuple[Any, …], dtype[float64]]

initial_value: float = 0.0
recommend_action(*, context=None)

Return the current best-arm recommendation without exploration.

Parameters:

context (ndarray[tuple[Any, ...], dtype[float64]] | None)

Return type:

int

reset()

Reset learned state.

Return type:

None

select_action(*, rng, context=None)

Choose an action index.

Parameters:
Return type:

int

property step: int

Return the number of completed native updates.

property total_reward: float

Return cumulative reward observed by the native policy.

update(*, action, reward, context=None)

Update policy state after observing a reward.

Parameters:
Return type:

None

n_arms: int
n_features: int
counts: ndarray[tuple[Any, ...], dtype[float64]]
estimates: ndarray[tuple[Any, ...], dtype[float64]]
class MOSSPolicy

Bases: NativePolicyMixin, MOSSPolicy

Minimax Optimal Strategy in the Stochastic case (MOSS).

__init__(*args, **kwargs)
Parameters:
Return type:

None

property backend: str

Return the policy-state backend in use.

capabilities = PolicyCapabilities(contextual=False, reward_domains=frozenset({<RewardDomain.REAL: 'real'>, <RewardDomain.BINARY: 'binary'>, <RewardDomain.UNIT_INTERVAL: 'unit_interval'>}), objective=<PolicyObjective.CUMULATIVE_REWARD: 'cumulative_reward'>)
clone()

Create a fresh policy with the same configuration.

The default deep-copies configuration and then resets learned state. Policies that own non-copyable resources must override this method.

Return type:

Policy | ContextualPolicy

property configuration: Mapping[str, object]

Return immutable normalized constructor configuration.

estimated_state_bytes()

Estimate Rust-owned state memory including reserved capacities.

Return type:

int

initial_value: float = 0.0
recommend_action(*, context=None)

Return the current best-arm recommendation without exploration.

Parameters:

context (ndarray[tuple[Any, ...], dtype[float64]] | None)

Return type:

int

reset()

Reset learned state.

Return type:

None

select_action(*, rng, context=None)

Choose an action index.

Parameters:
Return type:

int

property step: int

Return the number of completed native updates.

property total_reward: float

Return cumulative reward observed by the native policy.

update(*, action, reward, context=None)

Update policy state after observing a reward.

Parameters:
Return type:

None

n_arms: int
n_features: int
counts: ndarray[tuple[Any, ...], dtype[float64]]
estimates: ndarray[tuple[Any, ...], dtype[float64]]
class UCBPolicy

Bases: NativePolicyMixin, UCBPolicy

UCB1 policy for stationary sub-Gaussian rewards.

__init__(*args, **kwargs)
Parameters:
Return type:

None

property backend: str

Return the policy-state backend in use.

capabilities = PolicyCapabilities(contextual=False, reward_domains=frozenset({<RewardDomain.REAL: 'real'>, <RewardDomain.BINARY: 'binary'>, <RewardDomain.UNIT_INTERVAL: 'unit_interval'>}), objective=<PolicyObjective.CUMULATIVE_REWARD: 'cumulative_reward'>)
clone()

Create a fresh policy with the same configuration.

The default deep-copies configuration and then resets learned state. Policies that own non-copyable resources must override this method.

Return type:

Policy | ContextualPolicy

property configuration: Mapping[str, object]

Return immutable normalized constructor configuration.

estimated_state_bytes()

Estimate Rust-owned state memory including reserved capacities.

Return type:

int

initial_value: float = 0.0
recommend_action(*, context=None)

Return the current best-arm recommendation without exploration.

Parameters:

context (ndarray[tuple[Any, ...], dtype[float64]] | None)

Return type:

int

reset()

Reset learned state.

Return type:

None

select_action(*, rng, context=None)

Choose an action index.

Parameters:
Return type:

int

property step: int

Return the number of completed native updates.

property total_reward: float

Return cumulative reward observed by the native policy.

update(*, action, reward, context=None)

Update policy state after observing a reward.

Parameters:
Return type:

None

n_arms: int
n_features: int
counts: ndarray[tuple[Any, ...], dtype[float64]]
estimates: ndarray[tuple[Any, ...], dtype[float64]]
class UCBStats[source]

Bases: object

Diagnostic UCB state.

estimates: ndarray[tuple[Any, ...], dtype[float64]]
counts: ndarray[tuple[Any, ...], dtype[float64]]
bonuses: ndarray[tuple[Any, ...], dtype[float64]]
__init__(estimates, counts, bonuses)
Parameters:
Return type:

None

Compatibility imports for Python reference Thompson-sampling policies.

class BernoulliThompsonSamplingPolicy

Bases: NativePolicyMixin, BernoulliThompsonSamplingPolicy

Thompson sampling with Beta-Bernoulli posteriors.

__init__(*args, **kwargs)
Parameters:
Return type:

None

property backend: str

Return the policy-state backend in use.

capabilities = PolicyCapabilities(contextual=False, reward_domains=frozenset({<RewardDomain.BINARY: 'binary'>}), objective=<PolicyObjective.CUMULATIVE_REWARD: 'cumulative_reward'>)
clone()

Create a fresh policy with the same configuration.

The default deep-copies configuration and then resets learned state. Policies that own non-copyable resources must override this method.

Return type:

Policy | ContextualPolicy

property configuration: Mapping[str, object]

Return immutable normalized constructor configuration.

estimated_state_bytes()

Estimate Rust-owned state memory including reserved capacities.

Return type:

int

initial_value: float = 0.0
recommend_action(*, context=None)

Return the current best-arm recommendation without exploration.

Parameters:

context (ndarray[tuple[Any, ...], dtype[float64]] | None)

Return type:

int

reset()

Reset learned state.

Return type:

None

select_action(*, rng, context=None)

Choose an action index.

Parameters:
Return type:

int

property step: int

Return the number of completed native updates.

property total_reward: float

Return cumulative reward observed by the native policy.

update(*, action, reward, context=None)

Update policy state after observing a reward.

Parameters:
Return type:

None

n_arms: int
n_features: int
counts: ndarray[tuple[Any, ...], dtype[float64]]
estimates: ndarray[tuple[Any, ...], dtype[float64]]
class GaussianThompsonSamplingPolicy

Bases: NativePolicyMixin, GaussianThompsonSamplingPolicy

Thompson sampling for Gaussian rewards with known observation variance.

__init__(*args, **kwargs)
Parameters:
Return type:

None

property backend: str

Return the policy-state backend in use.

capabilities = PolicyCapabilities(contextual=False, reward_domains=frozenset({<RewardDomain.REAL: 'real'>, <RewardDomain.BINARY: 'binary'>, <RewardDomain.UNIT_INTERVAL: 'unit_interval'>}), objective=<PolicyObjective.CUMULATIVE_REWARD: 'cumulative_reward'>)
clone()

Create a fresh policy with the same configuration.

The default deep-copies configuration and then resets learned state. Policies that own non-copyable resources must override this method.

Return type:

Policy | ContextualPolicy

property configuration: Mapping[str, object]

Return immutable normalized constructor configuration.

estimated_state_bytes()

Estimate Rust-owned state memory including reserved capacities.

Return type:

int

initial_value: float = 0.0
recommend_action(*, context=None)

Return the current best-arm recommendation without exploration.

Parameters:

context (ndarray[tuple[Any, ...], dtype[float64]] | None)

Return type:

int

reset()

Reset learned state.

Return type:

None

select_action(*, rng, context=None)

Choose an action index.

Parameters:
Return type:

int

property step: int

Return the number of completed native updates.

property total_reward: float

Return cumulative reward observed by the native policy.

update(*, action, reward, context=None)

Update policy state after observing a reward.

Parameters:
Return type:

None

n_arms: int
n_features: int
means: ndarray[tuple[Any, ...], dtype[float64]]
precisions: ndarray[tuple[Any, ...], dtype[float64]]
counts: ndarray[tuple[Any, ...], dtype[float64]]
estimates: ndarray[tuple[Any, ...], dtype[float64]]

Compatibility imports for the Python reference Bayesian-UCB policies.

class BernoulliBayesianUCBPolicy

Bases: NativePolicyMixin, BernoulliBayesianUCBPolicy

Bayesian UCB using Beta posterior quantiles.

__init__(*args, **kwargs)
Parameters:
Return type:

None

property backend: str

Return the policy-state backend in use.

capabilities = PolicyCapabilities(contextual=False, reward_domains=frozenset({<RewardDomain.BINARY: 'binary'>}), objective=<PolicyObjective.CUMULATIVE_REWARD: 'cumulative_reward'>)
clone()

Create a fresh policy with the same configuration.

The default deep-copies configuration and then resets learned state. Policies that own non-copyable resources must override this method.

Return type:

Policy | ContextualPolicy

property configuration: Mapping[str, object]

Return immutable normalized constructor configuration.

estimated_state_bytes()

Estimate Rust-owned state memory including reserved capacities.

Return type:

int

initial_value: float = 0.0
recommend_action(*, context=None)

Return the current best-arm recommendation without exploration.

Parameters:

context (ndarray[tuple[Any, ...], dtype[float64]] | None)

Return type:

int

reset()

Reset learned state.

Return type:

None

select_action(*, rng, context=None)

Choose an action index.

Parameters:
Return type:

int

property step: int

Return the number of completed native updates.

property total_reward: float

Return cumulative reward observed by the native policy.

update(*, action, reward, context=None)

Update policy state after observing a reward.

Parameters:
Return type:

None

n_arms: int
n_features: int
counts: ndarray[tuple[Any, ...], dtype[float64]]
estimates: ndarray[tuple[Any, ...], dtype[float64]]
class GaussianBayesianUCBPolicy

Bases: NativePolicyMixin, GaussianBayesianUCBPolicy

Bayesian UCB for Gaussian rewards with known observation variance.

__init__(*args, **kwargs)
Parameters:
Return type:

None

property backend: str

Return the policy-state backend in use.

capabilities = PolicyCapabilities(contextual=False, reward_domains=frozenset({<RewardDomain.REAL: 'real'>, <RewardDomain.BINARY: 'binary'>, <RewardDomain.UNIT_INTERVAL: 'unit_interval'>}), objective=<PolicyObjective.CUMULATIVE_REWARD: 'cumulative_reward'>)
clone()

Create a fresh policy with the same configuration.

The default deep-copies configuration and then resets learned state. Policies that own non-copyable resources must override this method.

Return type:

Policy | ContextualPolicy

property configuration: Mapping[str, object]

Return immutable normalized constructor configuration.

estimated_state_bytes()

Estimate Rust-owned state memory including reserved capacities.

Return type:

int

initial_value: float = 0.0
recommend_action(*, context=None)

Return the current best-arm recommendation without exploration.

Parameters:

context (ndarray[tuple[Any, ...], dtype[float64]] | None)

Return type:

int

reset()

Reset learned state.

Return type:

None

select_action(*, rng, context=None)

Choose an action index.

Parameters:
Return type:

int

property step: int

Return the number of completed native updates.

property total_reward: float

Return cumulative reward observed by the native policy.

update(*, action, reward, context=None)

Update policy state after observing a reward.

Parameters:
Return type:

None

n_arms: int
n_features: int
means: ndarray[tuple[Any, ...], dtype[float64]]
precisions: ndarray[tuple[Any, ...], dtype[float64]]
counts: ndarray[tuple[Any, ...], dtype[float64]]
estimates: ndarray[tuple[Any, ...], dtype[float64]]

Non-stationary Policies

Compatibility imports for Python reference non-stationary policies.

class DiscountedBernoulliThompsonSamplingPolicy

Bases: NativePolicyMixin, DiscountedBernoulliThompsonSamplingPolicy

Beta-Bernoulli Thompson Sampling with exponential forgetting.

__init__(*args, **kwargs)
Parameters:
Return type:

None

property backend: str

Return the policy-state backend in use.

capabilities = PolicyCapabilities(contextual=False, reward_domains=frozenset({<RewardDomain.BINARY: 'binary'>}), objective=<PolicyObjective.CUMULATIVE_REWARD: 'cumulative_reward'>)
clone()

Create a fresh policy with the same configuration.

The default deep-copies configuration and then resets learned state. Policies that own non-copyable resources must override this method.

Return type:

Policy | ContextualPolicy

property configuration: Mapping[str, object]

Return immutable normalized constructor configuration.

estimated_state_bytes()

Estimate Rust-owned state memory including reserved capacities.

Return type:

int

initial_value: float = 0.0
recommend_action(*, context=None)

Return the current best-arm recommendation without exploration.

Parameters:

context (ndarray[tuple[Any, ...], dtype[float64]] | None)

Return type:

int

reset()

Reset learned state.

Return type:

None

select_action(*, rng, context=None)

Choose an action index.

Parameters:
Return type:

int

property step: int

Return the number of completed native updates.

property total_reward: float

Return cumulative reward observed by the native policy.

update(*, action, reward, context=None)

Update policy state after observing a reward.

Parameters:
Return type:

None

n_arms: int
n_features: int
successes: ndarray[tuple[Any, ...], dtype[float64]]
failures: ndarray[tuple[Any, ...], dtype[float64]]
counts: ndarray[tuple[Any, ...], dtype[float64]]
estimates: ndarray[tuple[Any, ...], dtype[float64]]
class DiscountedUCBPolicy

Bases: NativePolicyMixin, DiscountedUCBPolicy

UCB with exponentially discounted counts and estimates.

__init__(*args, **kwargs)
Parameters:
Return type:

None

property backend: str

Return the policy-state backend in use.

capabilities = PolicyCapabilities(contextual=False, reward_domains=frozenset({<RewardDomain.REAL: 'real'>, <RewardDomain.BINARY: 'binary'>, <RewardDomain.UNIT_INTERVAL: 'unit_interval'>}), objective=<PolicyObjective.CUMULATIVE_REWARD: 'cumulative_reward'>)
clone()

Create a fresh policy with the same configuration.

The default deep-copies configuration and then resets learned state. Policies that own non-copyable resources must override this method.

Return type:

Policy | ContextualPolicy

property configuration: Mapping[str, object]

Return immutable normalized constructor configuration.

estimated_state_bytes()

Estimate Rust-owned state memory including reserved capacities.

Return type:

int

initial_value: float = 0.0
recommend_action(*, context=None)

Return the current best-arm recommendation without exploration.

Parameters:

context (ndarray[tuple[Any, ...], dtype[float64]] | None)

Return type:

int

reset()

Reset learned state.

Return type:

None

select_action(*, rng, context=None)

Choose an action index.

Parameters:
Return type:

int

property step: int

Return the number of completed native updates.

property total_reward: float

Return cumulative reward observed by the native policy.

update(*, action, reward, context=None)

Update policy state after observing a reward.

Parameters:
Return type:

None

n_arms: int
n_features: int
discounted_counts: ndarray[tuple[Any, ...], dtype[float64]]
discounted_sums: ndarray[tuple[Any, ...], dtype[float64]]
counts: ndarray[tuple[Any, ...], dtype[float64]]
estimates: ndarray[tuple[Any, ...], dtype[float64]]
class SlidingWindowBernoulliThompsonSamplingPolicy

Bases: NativePolicyMixin, SlidingWindowBernoulliThompsonSamplingPolicy

Beta-Bernoulli sampling over the most recent global time steps.

__init__(*args, **kwargs)
Parameters:
Return type:

None

property backend: str

Return the policy-state backend in use.

capabilities = PolicyCapabilities(contextual=False, reward_domains=frozenset({<RewardDomain.BINARY: 'binary'>}), objective=<PolicyObjective.CUMULATIVE_REWARD: 'cumulative_reward'>)
clone()

Create a fresh policy with the same configuration.

The default deep-copies configuration and then resets learned state. Policies that own non-copyable resources must override this method.

Return type:

Policy | ContextualPolicy

property configuration: Mapping[str, object]

Return immutable normalized constructor configuration.

estimated_state_bytes()

Estimate Rust-owned state memory including reserved capacities.

Return type:

int

initial_value: float = 0.0
recommend_action(*, context=None)

Return the current best-arm recommendation without exploration.

Parameters:

context (ndarray[tuple[Any, ...], dtype[float64]] | None)

Return type:

int

reset()

Reset learned state.

Return type:

None

select_action(*, rng, context=None)

Choose an action index.

Parameters:
Return type:

int

property step: int

Return the number of completed native updates.

property total_reward: float

Return cumulative reward observed by the native policy.

update(*, action, reward, context=None)

Update policy state after observing a reward.

Parameters:
Return type:

None

n_arms: int
n_features: int
successes: ndarray[tuple[Any, ...], dtype[float64]]
failures: ndarray[tuple[Any, ...], dtype[float64]]
counts: ndarray[tuple[Any, ...], dtype[float64]]
estimates: ndarray[tuple[Any, ...], dtype[float64]]
class SlidingWindowUCBPolicy

Bases: NativePolicyMixin, SlidingWindowUCBPolicy

UCB over observations from the most recent global time steps.

__init__(*args, **kwargs)
Parameters:
Return type:

None

property backend: str

Return the policy-state backend in use.

capabilities = PolicyCapabilities(contextual=False, reward_domains=frozenset({<RewardDomain.REAL: 'real'>, <RewardDomain.BINARY: 'binary'>, <RewardDomain.UNIT_INTERVAL: 'unit_interval'>}), objective=<PolicyObjective.CUMULATIVE_REWARD: 'cumulative_reward'>)
clone()

Create a fresh policy with the same configuration.

The default deep-copies configuration and then resets learned state. Policies that own non-copyable resources must override this method.

Return type:

Policy | ContextualPolicy

property configuration: Mapping[str, object]

Return immutable normalized constructor configuration.

estimated_state_bytes()

Estimate Rust-owned state memory including reserved capacities.

Return type:

int

initial_value: float = 0.0
recommend_action(*, context=None)

Return the current best-arm recommendation without exploration.

Parameters:

context (ndarray[tuple[Any, ...], dtype[float64]] | None)

Return type:

int

reset()

Reset learned state.

Return type:

None

select_action(*, rng, context=None)

Choose an action index.

Parameters:
Return type:

int

property step: int

Return the number of completed native updates.

property total_reward: float

Return cumulative reward observed by the native policy.

update(*, action, reward, context=None)

Update policy state after observing a reward.

Parameters:
Return type:

None

n_arms: int
n_features: int
counts: ndarray[tuple[Any, ...], dtype[float64]]
estimates: ndarray[tuple[Any, ...], dtype[float64]]

Compatibility imports for Python reference change-detection policies.

class CUSUMUCBPolicy

Bases: NativePolicyMixin, CUSUMUCBPolicy

CUSUM-triggered resetting UCB.

__init__(*args, **kwargs)
Parameters:
Return type:

None

property backend: str

Return the policy-state backend in use.

capabilities = PolicyCapabilities(contextual=False, reward_domains=frozenset({<RewardDomain.REAL: 'real'>, <RewardDomain.BINARY: 'binary'>, <RewardDomain.UNIT_INTERVAL: 'unit_interval'>}), objective=<PolicyObjective.CUMULATIVE_REWARD: 'cumulative_reward'>)
clone()

Create a fresh policy with the same configuration.

The default deep-copies configuration and then resets learned state. Policies that own non-copyable resources must override this method.

Return type:

Policy | ContextualPolicy

property configuration: Mapping[str, object]

Return immutable normalized constructor configuration.

estimated_state_bytes()

Estimate Rust-owned state memory including reserved capacities.

Return type:

int

initial_value: float = 0.0
recommend_action(*, context=None)

Return the current best-arm recommendation without exploration.

Parameters:

context (ndarray[tuple[Any, ...], dtype[float64]] | None)

Return type:

int

reset()

Reset learned state.

Return type:

None

select_action(*, rng, context=None)

Choose an action index.

Parameters:
Return type:

int

property step: int

Return the number of completed native updates.

property total_reward: float

Return cumulative reward observed by the native policy.

update(*, action, reward, context=None)

Update policy state after observing a reward.

Parameters:
Return type:

None

n_arms: int
n_features: int
counts: ndarray[tuple[Any, ...], dtype[float64]]
estimates: ndarray[tuple[Any, ...], dtype[float64]]
class ChangePointUCBPolicy

Bases: NativePolicyMixin, ChangePointUCBPolicy

UCB with per-arm change detection and local arm resets.

__init__(*args, **kwargs)
Parameters:
Return type:

None

property backend: str

Return the policy-state backend in use.

capabilities = PolicyCapabilities(contextual=False, reward_domains=frozenset({<RewardDomain.REAL: 'real'>, <RewardDomain.BINARY: 'binary'>, <RewardDomain.UNIT_INTERVAL: 'unit_interval'>}), objective=<PolicyObjective.CUMULATIVE_REWARD: 'cumulative_reward'>)
clone()

Create a fresh policy with the same configuration.

The default deep-copies configuration and then resets learned state. Policies that own non-copyable resources must override this method.

Return type:

Policy | ContextualPolicy

property configuration: Mapping[str, object]

Return immutable normalized constructor configuration.

estimated_state_bytes()

Estimate Rust-owned state memory including reserved capacities.

Return type:

int

initial_value: float = 0.0
recommend_action(*, context=None)

Return the current best-arm recommendation without exploration.

Parameters:

context (ndarray[tuple[Any, ...], dtype[float64]] | None)

Return type:

int

reset()

Reset learned state.

Return type:

None

select_action(*, rng, context=None)

Choose an action index.

Parameters:
Return type:

int

property step: int

Return the number of completed native updates.

property total_reward: float

Return cumulative reward observed by the native policy.

update(*, action, reward, context=None)

Update policy state after observing a reward.

Parameters:
Return type:

None

n_arms: int
n_features: int
detector_counts: ndarray[tuple[Any, ...], dtype[float64]]
detector_means: ndarray[tuple[Any, ...], dtype[float64]]
positive_cusum: ndarray[tuple[Any, ...], dtype[float64]]
negative_cusum: ndarray[tuple[Any, ...], dtype[float64]]
ph_cumulative: ndarray[tuple[Any, ...], dtype[float64]]
ph_minimum: ndarray[tuple[Any, ...], dtype[float64]]
change_counts: ndarray[tuple[Any, ...], dtype[float64]]
counts: ndarray[tuple[Any, ...], dtype[float64]]
estimates: ndarray[tuple[Any, ...], dtype[float64]]
class PageHinkleyUCBPolicy

Bases: NativePolicyMixin, PageHinkleyUCBPolicy

Page-Hinkley-triggered resetting UCB.

__init__(*args, **kwargs)
Parameters:
Return type:

None

property backend: str

Return the policy-state backend in use.

capabilities = PolicyCapabilities(contextual=False, reward_domains=frozenset({<RewardDomain.REAL: 'real'>, <RewardDomain.BINARY: 'binary'>, <RewardDomain.UNIT_INTERVAL: 'unit_interval'>}), objective=<PolicyObjective.CUMULATIVE_REWARD: 'cumulative_reward'>)
clone()

Create a fresh policy with the same configuration.

The default deep-copies configuration and then resets learned state. Policies that own non-copyable resources must override this method.

Return type:

Policy | ContextualPolicy

property configuration: Mapping[str, object]

Return immutable normalized constructor configuration.

estimated_state_bytes()

Estimate Rust-owned state memory including reserved capacities.

Return type:

int

initial_value: float = 0.0
recommend_action(*, context=None)

Return the current best-arm recommendation without exploration.

Parameters:

context (ndarray[tuple[Any, ...], dtype[float64]] | None)

Return type:

int

reset()

Reset learned state.

Return type:

None

select_action(*, rng, context=None)

Choose an action index.

Parameters:
Return type:

int

property step: int

Return the number of completed native updates.

property total_reward: float

Return cumulative reward observed by the native policy.

update(*, action, reward, context=None)

Update policy state after observing a reward.

Parameters:
Return type:

None

n_arms: int
n_features: int
detector_counts: ndarray[tuple[Any, ...], dtype[float64]]
detector_means: ndarray[tuple[Any, ...], dtype[float64]]
positive_cusum: ndarray[tuple[Any, ...], dtype[float64]]
negative_cusum: ndarray[tuple[Any, ...], dtype[float64]]
ph_cumulative: ndarray[tuple[Any, ...], dtype[float64]]
ph_minimum: ndarray[tuple[Any, ...], dtype[float64]]
change_counts: ndarray[tuple[Any, ...], dtype[float64]]
counts: ndarray[tuple[Any, ...], dtype[float64]]
estimates: ndarray[tuple[Any, ...], dtype[float64]]

Contextual Policies

Compatibility imports for Python reference contextual policies.

class LinearEpsilonGreedyPolicy

Bases: NativePolicyMixin, LinearEpsilonGreedyPolicy

Linear contextual policy with epsilon-greedy exploration.

__init__(*args, **kwargs)
Parameters:
Return type:

None

property backend: str

Return the policy-state backend in use.

capabilities = PolicyCapabilities(contextual=True, reward_domains=frozenset({<RewardDomain.REAL: 'real'>, <RewardDomain.BINARY: 'binary'>, <RewardDomain.UNIT_INTERVAL: 'unit_interval'>}), objective=<PolicyObjective.CUMULATIVE_REWARD: 'cumulative_reward'>)
clone()

Create a fresh policy with the same immutable configuration.

Return type:

Policy | ContextualPolicy

property configuration: Mapping[str, object]

Return immutable normalized constructor configuration.

estimated_state_bytes()

Estimate Rust-owned state memory including reserved capacities.

Return type:

int

recommend_action(*, context=None)

Return the current recommendation without exploratory sampling.

Parameters:

context (ndarray[tuple[Any, ...], dtype[float64]] | None)

Return type:

int

reset()

Reset learned state.

Return type:

None

scores(context)[source]
Parameters:

context (ndarray[tuple[Any, ...], dtype[float64]])

Return type:

ndarray[tuple[Any, …], dtype[float64]]

select_action(*, rng, context=None)

Choose an action index for a context matrix.

Parameters:
Return type:

int

property step: int

Return the number of completed native updates.

property total_reward: float

Return cumulative reward observed by the native policy.

update(*, action, reward, context=None)

Update policy state after a contextual reward.

Parameters:
Return type:

None

n_arms: int
n_features: int
class LinearThompsonSamplingPolicy

Bases: NativePolicyMixin, LinearThompsonSamplingPolicy

Bayesian linear Thompson Sampling for contextual bandits.

__init__(*args, **kwargs)
Parameters:
Return type:

None

property backend: str

Return the policy-state backend in use.

capabilities = PolicyCapabilities(contextual=True, reward_domains=frozenset({<RewardDomain.REAL: 'real'>, <RewardDomain.BINARY: 'binary'>, <RewardDomain.UNIT_INTERVAL: 'unit_interval'>}), objective=<PolicyObjective.CUMULATIVE_REWARD: 'cumulative_reward'>)
clone()

Create a fresh policy with the same immutable configuration.

Return type:

Policy | ContextualPolicy

property configuration: Mapping[str, object]

Return immutable normalized constructor configuration.

estimated_state_bytes()

Estimate Rust-owned state memory including reserved capacities.

Return type:

int

recommend_action(*, context=None)

Return the current recommendation without exploratory sampling.

Parameters:

context (ndarray[tuple[Any, ...], dtype[float64]] | None)

Return type:

int

reset()

Reset learned state.

Return type:

None

select_action(*, rng, context=None)

Choose an action index for a context matrix.

Parameters:
Return type:

int

property step: int

Return the number of completed native updates.

property total_reward: float

Return cumulative reward observed by the native policy.

update(*, action, reward, context=None)

Update policy state after a contextual reward.

Parameters:
Return type:

None

n_arms: int
n_features: int
a: ndarray[tuple[Any, ...], dtype[float64]]
b: ndarray[tuple[Any, ...], dtype[float64]]
class LinUCBPolicy

Bases: NativePolicyMixin, LinUCBPolicy

Disjoint linear UCB for contextual bandits.

__init__(*args, **kwargs)
Parameters:
Return type:

None

property backend: str

Return the policy-state backend in use.

capabilities = PolicyCapabilities(contextual=True, reward_domains=frozenset({<RewardDomain.REAL: 'real'>, <RewardDomain.BINARY: 'binary'>, <RewardDomain.UNIT_INTERVAL: 'unit_interval'>}), objective=<PolicyObjective.CUMULATIVE_REWARD: 'cumulative_reward'>)
clone()

Create a fresh policy with the same immutable configuration.

Return type:

Policy | ContextualPolicy

property configuration: Mapping[str, object]

Return immutable normalized constructor configuration.

estimated_state_bytes()

Estimate Rust-owned state memory including reserved capacities.

Return type:

int

recommend_action(*, context=None)

Return the current recommendation without exploratory sampling.

Parameters:

context (ndarray[tuple[Any, ...], dtype[float64]] | None)

Return type:

int

reset()

Reset learned state.

Return type:

None

select_action(*, rng, context=None)

Choose an action index for a context matrix.

Parameters:
Return type:

int

property step: int

Return the number of completed native updates.

property total_reward: float

Return cumulative reward observed by the native policy.

update(*, action, reward, context=None)

Update policy state after a contextual reward.

Parameters:
Return type:

None

upper_confidence_bounds(context)[source]
Parameters:

context (ndarray[tuple[Any, ...], dtype[float64]])

Return type:

ndarray[tuple[Any, …], dtype[float64]]

n_arms: int
n_features: int
a: ndarray[tuple[Any, ...], dtype[float64]]
b: ndarray[tuple[Any, ...], dtype[float64]]
class LogisticContextualBanditPolicy

Bases: NativePolicyMixin, LogisticContextualBanditPolicy

Online logistic contextual bandit for Bernoulli rewards.

Each arm has an independent logistic model. The policy predicts click or conversion probability for each arm, explores with epsilon-greedy sampling, and updates the selected arm using one stochastic-gradient step.

__init__(*args, **kwargs)
Parameters:
Return type:

None

property backend: str

Return the policy-state backend in use.

capabilities = PolicyCapabilities(contextual=True, reward_domains=frozenset({<RewardDomain.BINARY: 'binary'>}), objective=<PolicyObjective.CUMULATIVE_REWARD: 'cumulative_reward'>)
clone()

Create a fresh policy with the same immutable configuration.

Return type:

Policy | ContextualPolicy

property configuration: Mapping[str, object]

Return immutable normalized constructor configuration.

estimated_state_bytes()

Estimate Rust-owned state memory including reserved capacities.

Return type:

int

predicted_probabilities(context)[source]
Parameters:

context (ndarray[tuple[Any, ...], dtype[float64]])

Return type:

ndarray[tuple[Any, …], dtype[float64]]

recommend_action(*, context=None)

Return the current recommendation without exploratory sampling.

Parameters:

context (ndarray[tuple[Any, ...], dtype[float64]] | None)

Return type:

int

reset()

Reset learned state.

Return type:

None

select_action(*, rng, context=None)

Choose an action index for a context matrix.

Parameters:
Return type:

int

property step: int

Return the number of completed native updates.

property total_reward: float

Return cumulative reward observed by the native policy.

update(*, action, reward, context=None)

Update policy state after a contextual reward.

Parameters:
Return type:

None

n_arms: int
n_features: int
theta: ndarray[tuple[Any, ...], dtype[float64]]