6"""Measure behavior in the presence of virtual reference agents."""
8from dataclasses
import dataclass
9from math
import isfinite
11from .modern
import MOME
13__all__ = [
"CounterfactualEvaluator",
"CounterfactualMOME"]
17@dataclass(frozen=True)
19 """Call the rollout once and concatenate base and reference descriptor blocks.
21 :param rollout: Callback (genome) returning (objectives, trace).
22 :param references: Ordered reference agents, trajectories, or policies.
23 :param describe: Callback (trace, reference) measuring the agent's
24 interaction with one virtual reference. Return a numeric vector.
25 :param base: Optional callback (trace) returning the measured agent's
26 descriptor block before any reference blocks.
34 def __post_init__(self):
36 if not refs
or not callable(self.
rollout)
or not callable(self.
describe):
37 raise ValueError(
"Supply a rollout, a descriptor callback, and at least one reference.")
38 if self.
base is not None and not callable(self.
base):
39 raise TypeError(
"The base descriptor must be callable.")
40 object.__setattr__(self,
"references", refs)
44 objectives, trace = self.
rollout(genome)
45 objectives = tuple(map(float, objectives))
46 features = list(self.
base(trace))
if self.
base is not None else []
48 features.extend(self.
describe(trace, reference))
49 descriptors = tuple(map(float, features))
50 if not objectives
or not descriptors
or not all(map(isfinite, (*objectives, *descriptors))):
51 raise ValueError(
"Return nonempty finite objective and descriptor vectors.")
52 return objectives, descriptors
57 """Reuse native MOME evolution and front admission with a trace evaluator.
59 The ParetoGrid's descriptor domains follow the order of the optional
60 base measurements and then the reference blocks. Virtual agents may
61 be superimposed on one recorded trace. The rollout callback owns any
62 simulated dynamics and computes the unchanged objective vector.
66 def run(self, rollout, *, references, describe, base=None, budget=None, executor=None):
67 """Optimise with one measured rollout per candidate and native batch feedback."""
69 return self.
optimise(evaluator, budget=budget, executor=executor)
IndividualLike optimise(self, Callable evaluate, Optional[int] budget=None, bool batch_mode=True, Optional[ExecutorLike] executor=None, bool send_several_suggestions_to_fn=False, int max_nb_suggestions_per_call=10, bool verbose=False)
Compute native QD feedback from a trace and counterfactual references.
__call__(self, genome)
Return objective values and the concatenated behavior vector.
Run MOME with counterfactual reference-agent descriptors.
run(self, rollout, *, references, describe, base=None, budget=None, executor=None)
Apply the reference panel and return the native best individual.
Sample occupied cells and evolve their bounded Pareto fronts.