What SensAI can say about a job's input distributions and what each trial drew from them: the distributions themselves, one trial's draws, and the trials that drew an input far from its middle.
Each function reads the job's saved distributions and the trials' saved draws through trial_dists.py, the same code the Dojo's distributions panel uses, so SensAI and the panel cannot disagree on a draw, its unit or its z-score. Every function returns words, or for trials_beyond the trial numbers the plot agent pins, so the model never retypes a number it looked up.
How far out a draw is: where the Dojo's panel gives a z-score (a distribution with a mean and a spread, see has_z_score) it is that z-score. For any other distribution, a uniform say, the draw's percentile is read as the equivalent on a normal curve (the 97.7th percentile is 2). The answer says which of the two it is.
Draw
Bases: BaseModel
One trial's draw of one input, and how far out it is.
sigmas
instance-attribute
Signed distance from the middle of the distribution, in standard deviations.
Outliers
Bases: BaseModel
The trials that drew an input at least some distance from its middle.
unit
instance-attribute
The unit the distribution was declared in, empty when it has none.
exact
instance-attribute
True when sigmas are z-scores, False when they are read off the percentile.
drawn
instance-attribute
How many trials have a numeric draw of this input.
describe_distributions
The input distributions the job's trials were drawn from: each one's name, type, category, unit, nominal value, parameters (which say its range or spread), and any display name, source and comment.
Source code in src/mujoco_mojo/utils/layers/dojo/sensai/dist_report.py
| Python |
|---|
| def describe_distributions(job: JobStatus) -> str:
"""The input distributions the job's trials were drawn from: each one's name, type, category, unit, nominal value, parameters (which say its range or spread), and any display name, source and comment."""
dists = _dists(job)
if isinstance(dists, str):
return dists
lines = [
f"{len(dists)} input distribution(s), which each trial drew its inputs from:"
]
lines += [_describe_dist(d) for d in dists.values()]
return "\n".join(lines)
|
What one trial drew for each input, in the unit the input was declared in, with how far from the mean the draw is.
Source code in src/mujoco_mojo/utils/layers/dojo/sensai/dist_report.py
| Python |
|---|
| def describe_trial_inputs(job: JobStatus, trial_num: int) -> str:
"""What one trial drew for each input, in the unit the input was declared in, with how far from the mean the draw is."""
if (missing := _unknown_trial(job, trial_num)) is not None:
return missing
dists = _dists(job)
if isinstance(dists, str):
return dists
named_raw = read_named_values(job.trial_num_to_path(trial_num))
if not named_raw:
return f"Trial {trial_num} saved no sampled values (it may not have started)."
lines = [f"Trial {trial_num} drew:"]
lines += [f" {d.name}: {_draw_text(d, named_raw)}" for d in dists.values()]
return "\n".join(lines)
|
find_outliers
The trials that drew the input name (its name or part of it) at least min_sigma standard deviations from the middle of its distribution, or the sentence that says why there is nothing to give.
Every trial's saved draws are read, so call it off the event loop.
Source code in src/mujoco_mojo/utils/layers/dojo/sensai/dist_report.py
| Python |
|---|
| def find_outliers(job: JobStatus, name: str, min_sigma: float) -> Outliers | str:
"""
The trials that drew the input `name` (its name or part of it) at least `min_sigma` standard deviations from the middle of its distribution, or the sentence that says why there is nothing to give.
Every trial's saved draws are read, so call it off the event loop.
"""
if not math.isfinite(min_sigma) or min_sigma <= 0:
return f"min_sigma must be a number above 0, such as 2, not {min_sigma}."
dists = _dists(job)
if isinstance(dists, str):
return dists
dist = _pick_dist(dists, name)
if isinstance(dist, str):
return dist
draws: list[Draw] = []
for trial in sorted(job.trial_nums):
values = sampled_values_in_dist_unit(
read_named_values(job.trial_num_to_path(trial)), dist
)
if not values:
continue
sigmas = _sigmas(dist, values[0])
if sigmas is not None:
draws.append(Draw(trial=trial, value=values[0], sigmas=sigmas))
if not draws:
return f"No trial has a number saved for '{dist.name}', so there is no distance to measure. An input drawn as a label or a permutation has none."
return Outliers(
name=dist.name,
dist_type=dist.dist_type,
unit=str(dist.unit) if dist.unit is not None else "",
exact=has_z_score(dist),
drawn=len(draws),
beyond=[d for d in draws if abs(d.sigmas) >= min_sigma],
)
|
trials_beyond
The numbers of the trials that drew the input name at least min_sigma standard deviations from the middle of its distribution, in order, or the sentence that says why there are none to give. Reads every trial's draws, so call it off the event loop.
Source code in src/mujoco_mojo/utils/layers/dojo/sensai/dist_report.py
| Python |
|---|
| def trials_beyond(job: JobStatus, name: str, min_sigma: float) -> list[int] | str:
"""The numbers of the trials that drew the input `name` at least `min_sigma` standard deviations from the middle of its distribution, in order, or the sentence that says why there are none to give. Reads every trial's draws, so call it off the event loop."""
found = find_outliers(job, name, min_sigma)
if isinstance(found, str):
return found
return sorted(d.trial for d in found.beyond)
|
The trials that drew an input far from its mean, most extreme first, with each draw and its distance. Reads every trial's draws, so call it off the event loop.
Source code in src/mujoco_mojo/utils/layers/dojo/sensai/dist_report.py
| Python |
|---|
| def describe_input_outliers(
job: JobStatus, name: str, min_sigma: float = 2.0, count: int = 15
) -> str:
"""The trials that drew an input far from its mean, most extreme first, with each draw and its distance. Reads every trial's draws, so call it off the event loop."""
found = find_outliers(job, name, min_sigma)
if isinstance(found, str):
return found
head = (
f"{found.name} ({found.dist_type}): {len(found.beyond)} of {found.drawn} "
f"trials drew it {min_sigma:g} or more standard deviations from its mean."
)
if not found.exact:
head += " It is not measured by a z-score, so each distance is what the draw's percentile would be on a normal curve."
if not found.beyond:
return head
ordered = sorted(found.beyond, key=lambda d: -abs(d.sigmas))
shown = ordered[: max(1, min(count, _MAX_OUTLIERS_SHOWN))]
unit = f" {found.unit}" if found.unit else ""
lines = [head, "Most extreme first:"]
lines += [f" trial {d.trial}: {d.value:.6g}{unit}, {d.sigmas:+.2f}" for d in shown]
lines.append(f"All of them: {trial_numbers(d.trial for d in ordered)}.")
return "\n".join(lines)
|