Define the MDP and constraints
Specify states, actions, reward and explicit constraint signals (costs or safety indicators) and how violations are measured.
Constrained policy optimisation. Monitor constraint satisfaction.
Constrained policy optimisation fits a policy to maximise expected return while respecting constraints (for example on cost, safety or resource consumption). Practical work emphasises defining constraint signals, stable optimisation (often via trust-region or Lagrangian methods), and thorough evaluation of violations and variability across seeds.
Learning concept · Not a validated service
Constrained policy optimisation fits a policy to maximise expected return while respecting constraints (for example on cost, safety or resource consumption). Practical work emphasises defining constraint signals, stable optimisation (often via trust-region or Lagrangian methods), and thorough evaluation of violations and variability across seeds.
A proposed use-case is a robotics control policy that maximises task success while bounding energy use or collision risk; a human operator should remain in control and approve any policy before deployment.
Specify states, actions, reward and explicit constraint signals (costs or safety indicators) and how violations are measured.
Start with a simple baseline such as a bandit or on-policy agent, then implement a constrained optimiser (e.g. Lagrangian / CPO) using only the defined signals.
Report average return, constraint violation rate, and variability across random seeds and episodes.
Wrap policies with monitors, manual override, and logging so a human can inspect and reject risky actions.
The supplied starter simulates a 4-armed Bernoulli bandit and runs an epsilon-greedy update loop: it selects actions either at random or by argmax of incremental estimated rewards, updates counts and sample-mean estimates, and prints action counts, estimated rates and cumulative reward.
for step in range(1, 2001):
if rng.random() < epsilon:
action = rng.integers(len(true_reward_rates))
else:
action = int(np.argmax(estimated_values))
reward = 1 if rng.random() < true_reward_rates[action] else 0
action_counts[action] += 1
total_reward += reward
estimated_values[action] += (reward - estimated_values[action]) / action_counts[action]This code implements a basic multi-armed bandit (epsilon-greedy sample-mean updates). It contains no MDP, episode structure, gradient-based policy optimiser, trust-region updates, Lagrangian constraints or safety-cost signals; therefore it does not implement constrained policy optimisation as titled, and it cannot evaluate constraint satisfaction or perform policy updates for sequential stateful control.
Proposed extension: replace the bandit with a Gymnasium environment, add a cost signal, and implement a Lagrangian or constrained policy-gradient method (for example a simple Lagrangian multiplier update or a CPO-style trust-region).
This is a potential application pathway, not a delivered product. The supplied starter does not implement this service or validate it with real users.
Networkers Home runs this topic inside its AI Engineer Course, with placement support and hands-on labs.