Environments with simulated people#
Human-in-the-loop environments for reinforcement learning (Gymnasium API).
The simulated people follow the package’s quantum-like models, so an agent trained here faces the effects that classical simulators leave out: answers that depend on the order of questions, and trust that changes when it is asked about. All people are simulated; the parameters are illustrative.
Every environment follows the Gymnasium interface: reset(seed=None) -> (observation, info) and
step(action) -> (observation, reward, terminated, truncated, info).
Examples
>>> from quantum_mind.envs import ClarificationEnv
>>> env = ClarificationEnv()
>>> obs, info = env.reset(seed=0)
>>> obs.shape, int(env.action_space.n)
((3,), 6)
>>> obs, reward, terminated, truncated, info = env.step(0) # ask question 0
>>> reward, terminated
(-0.3, False)
Classes
Resolve an ambiguous request by asking questions, then act. |
|
Hand objects to a simulated person whose trust follows the trust qubit. |
Functions
Register the environments with Gymnasium. |
|
Draw simulated people whose parameters reflect what is known, and not known, about real people. |
- class ClarificationEnv(model=None, ask_cost=0.3, success_reward=1.0, error_cost=5.0, max_questions=6, people=None)[source]#
Bases:
EnvResolve an ambiguous request by asking questions, then act.
Actions
0 .. Q-1ask a question; actionsQ .. Q+H-1act on a hypothesis (ending the episode). The observation has one entry per question: 0 if not asked yet, +1 for “yes”, -1 for “no”. The person’s answers follow aProjectiveAnswerModel, so they depend on the questions asked before.- Parameters:
model (
ProjectiveAnswerModelorIndependentAnswerModel, optional) – How the simulated person answers (default:default_domain()).ask_cost (
float, optional) – Reward penalty per question.success_reward (
float, optional) – Reward for acting on the right hypothesis.error_cost (
float, optional) – Penalty for acting on a wrong hypothesis.max_questions (
int, optional) – After this many questions the episode is truncated with the error cost.people (
listorcallable, optional) – A population of answer models (same questions and hypotheses) or a functionrng -> model; a new person is drawn at everyreset().
- reset(seed=None, options=None)[source]#
Start an episode with a new hidden intent.
- Parameters:
- Returns:
observation (
numpy.ndarray)info (
dict) –target(for evaluation only).
- class TrustHandoverEnv(model=None, n_steps=20, fail_cost=10.0, slow_cost=1.0, ask_cost=0.5, wait_cost=0.3, slow_factor=0.5, people=None)[source]#
Bases:
EnvHand objects to a simulated person whose trust follows the trust qubit.
Actions: 0 hand over, 1 hand over slowly, 2 ask about trust, 3 wait. Observation: the last hand-over outcome (+1 success, -1 failure, 0 none), the last answer to the trust question (+1, -1, 0) and the fraction of the episode elapsed. A hand-over fails with probability 1 - P(trust); asking collapses the person’s trust as in
OpenSystemBelief.- Parameters:
model (
OpenSystemBelief, optional) – Trust model of the simulated person.n_steps (
int, optional) – Episode length.fail_cost (
float, optional) – Costs (rewards are their negatives); a successful hand-over gives +1.slow_cost (
float, optional) – Costs (rewards are their negatives); a successful hand-over gives +1.ask_cost (
float, optional) – Costs (rewards are their negatives); a successful hand-over gives +1.wait_cost (
float, optional) – Costs (rewards are their negatives); a successful hand-over gives +1.slow_factor (
float, optional) – Failure probability of a slow hand-over relative to a normal one.people (
listorcallable, optional) – A population of trust models (for example fromsample_people()) or a functionrng -> model; a new person is drawn at everyreset().
- reset(seed=None, options=None)[source]#
Start an episode at the model’s initial trust.
- Parameters:
- Returns:
observation (
numpy.ndarray)info (
dict)
- sample_people(source, n, rng=None)[source]#
Draw simulated people whose parameters reflect what is known, and not known, about real people.
An agent trained against one simulated person learns that person. Drawing a new person for every episode from the uncertainty of the fitted human model (domain randomisation over people) trains a policy that holds up across the people the model is unsure about.
- Parameters:
source (
BootstrapResult,OnlinePersonModel,PopulationPriororModel) –BootstrapResult(refits of a fitted model),OnlinePersonModel(particles weighted by the posterior),PopulationPrior(Gaussian on the free parameters), or a single model (returnedntimes).n (
int) – Number of people.rng (
numpy.random.Generator, optional)
- Returns:
listofModel