Class HumanoidEnvV4
- Namespace
- Gym.Environments.Envs.MuJoCo
- Assembly
- Gym.Environments.dll
Humanoid-v4: the humanoid of HumanoidEnvV5 with v4's fixed model and frame skip, every body's rows
observed (the world's included), no contact cost, v4's healthy reward (paid on every step while
terminate_when_unhealthy is set) and the center of mass in the info. Byte for byte what Gymnasium's
Humanoid-v4 computes on MuJoCo 4.0.0 (DR-61, DR-64).
[PyName("HumanoidEnv")]
public class HumanoidEnvV4 : MujocoEnv, IEnv, IDisposable, IDynamicAttributes
- Inheritance
-
HumanoidEnvV4
- Implements
- Inherited Members
- Extension Methods
Remarks
Observation (float64): the positions without the root's x and y (unless asked for), the velocities, and the whole
cinert, cvel, qfrc_actuator and cfrc_ext arrays; the space declares 376 values
(378 with the root's x and y). Reward: forward_reward_weight * x_velocity + float(is_healthy or
terminate_when_unhealthy) * healthy_reward - ctrl_cost_weight * sum(ctrl**2). Info: reward_linvel,
reward_quadctrl, reward_alive, then the center of mass's x_position, y_position and
distance_from_origin, x_velocity, y_velocity and forward_reward. The reset's info
is empty; make warns that the id is out of date.
Not thread-safe. Reference: gymnasium/envs/mujoco/humanoid_v4.py.
Its info reads typed (DR-91): HumanoidInfoV4 info = step.Info; (HumanoidInfoV4), with the dict's own values still behind the indexer.
Constructors
HumanoidEnvV4(HumanoidEnvV4Options)
Builds the instance from its options record: the properties set, the constructor's defaults for the rest.
public HumanoidEnvV4(HumanoidEnvV4Options options)
Parameters
optionsHumanoidEnvV4OptionsThe options.
Exceptions
- ArgumentNullException
Thrown when
optionsis null.
HumanoidEnvV4(RenderMode, double, double, double, bool, (double Low, double High)?, double, bool, int, int, int?, string?, int, IReadOnlyDictionary<int, bool>?, EnvViewerFactory?)
Builds the env with the render mode given as the RenderMode enum (DR-84, DR-93), as
HumanoidEnvV4(double, double, double, bool, (double Low, double High)?, double, bool, string?, int, int, int?, string?, int, IReadOnlyDictionary<int, bool>?, EnvViewerFactory?)
builds it from the mode's string: new HumanoidEnvV4(RenderMode.RgbArray) builds what
new HumanoidEnvV4(renderMode: "rgb_array") builds, the member reaching the env as Gymnasium's string
(Name(RenderMode)), which its RenderMode property then holds.
public HumanoidEnvV4(RenderMode renderMode, double forwardRewardWeight = 1.25, double ctrlCostWeight = 0.1, double healthyReward = 5, bool terminateWhenUnhealthy = true, (double Low, double High)? healthyZRange = null, double resetNoiseScale = 0.01, bool excludeCurrentPositionsFromObservation = true, int width = 480, int height = 480, int? cameraId = null, string? cameraName = null, int maxGeom = 1000, IReadOnlyDictionary<int, bool>? visualOptions = null, EnvViewerFactory? viewerFactory = null)
Parameters
renderModeRenderModeThe render mode, which the env must list in its
metadata["render_modes"]as for the string; it behaves exactly as its Gymnasium string does in the other constructor.forwardRewardWeightdoubleThe weight of the forward velocity (
forward_reward_weight).ctrlCostWeightdoubleThe weight of the squared controls (
ctrl_cost_weight).healthyRewarddoubleThe healthy reward per step (
healthy_reward).terminateWhenUnhealthyboolWhether an unhealthy state ends the episode (
terminate_when_unhealthy).healthyZRange(double hx, double hy)?The exclusive range of a healthy torso height (
healthy_z_range); null is (1.0, 2.0).resetNoiseScaledoubleThe scale of the reset's noise (
reset_noise_scale).excludeCurrentPositionsFromObservationboolWhether the root's x and y leave the observation (
exclude_current_positions_from_observation).widthintThe rendered frame's width (
width).heightintThe rendered frame's height (
height).cameraIdint?The camera to render from (
camera_id).cameraNamestringThe camera to render from by name (
camera_name).maxGeomintThe most geoms a frame draws (
max_geom).visualOptionsIReadOnlyDictionary<int, bool>MuJoCo visual flags to switch (
visual_options).viewerFactoryEnvViewerFactoryGym.NET's
viewer_factory(DR-20) forhumanmode.
Remarks
The mode is required and comes first, so new HumanoidEnvV4() keeps meaning the other constructor, without a
mode; leave the mode out there for no rendering. Every other parameter means what it means there.
Exceptions
- ArgumentOutOfRangeException
Thrown for a value RenderMode does not declare (a cast integer such as
(RenderMode)99).- ValueError
Both a camera id and a camera name.
HumanoidEnvV4(double, double, double, bool, (double Low, double High)?, double, bool, string?, int, int, int?, string?, int, IReadOnlyDictionary<int, bool>?, EnvViewerFactory?)
Creates the env (Gymnasium's HumanoidEnv.init): humanoid.xml with a frame skip of 5.
public HumanoidEnvV4(double forwardRewardWeight = 1.25, double ctrlCostWeight = 0.1, double healthyReward = 5, bool terminateWhenUnhealthy = true, (double Low, double High)? healthyZRange = null, double resetNoiseScale = 0.01, bool excludeCurrentPositionsFromObservation = true, string? renderMode = null, int width = 480, int height = 480, int? cameraId = null, string? cameraName = null, int maxGeom = 1000, IReadOnlyDictionary<int, bool>? visualOptions = null, EnvViewerFactory? viewerFactory = null)
Parameters
forwardRewardWeightdoubleThe weight of the forward velocity (
forward_reward_weight).ctrlCostWeightdoubleThe weight of the squared controls (
ctrl_cost_weight).healthyRewarddoubleThe healthy reward per step (
healthy_reward).terminateWhenUnhealthyboolWhether an unhealthy state ends the episode (
terminate_when_unhealthy).healthyZRange(double hx, double hy)?The exclusive range of a healthy torso height (
healthy_z_range); null is (1.0, 2.0).resetNoiseScaledoubleThe scale of the reset's noise (
reset_noise_scale).excludeCurrentPositionsFromObservationboolWhether the root's x and y leave the observation (
exclude_current_positions_from_observation).renderModestringGymnasium's
render_mode:human,rgb_array,depth_array,rgbd_tupleor null.widthintThe rendered frame's width (
width).heightintThe rendered frame's height (
height).cameraIdint?The camera to render from (
camera_id).cameraNamestringThe camera to render from by name (
camera_name).maxGeomintThe most geoms a frame draws (
max_geom).visualOptionsIReadOnlyDictionary<int, bool>MuJoCo visual flags to switch (
visual_options).viewerFactoryEnvViewerFactoryGym.NET's
viewer_factory(DR-20) forhumanmode.
Exceptions
- ValueError
Both a camera id and a camera name.
Properties
ClassMetadata
Gymnasium's class attribute metadata: the four render modes at 67 frames per second. A new dict on every read.
public static Metadata ClassMetadata { get; }
Property Value
CtrlCostWeight
The weight of the squared controls (_ctrl_cost_weight), read every step.
[PyName("_ctrl_cost_weight")]
public double CtrlCostWeight { get; set; }
Property Value
ExcludeCurrentPositionsFromObservation
Whether the root's x and y leave the observation (_exclude_current_positions_from_observation). Footgun:
changing it after construction changes the observation's length but not the observation space, as in Gymnasium.
[PyName("_exclude_current_positions_from_observation")]
public bool ExcludeCurrentPositionsFromObservation { get; set; }
Property Value
ForwardRewardWeight
The weight of the forward velocity (_forward_reward_weight), read every step.
[PyName("_forward_reward_weight")]
public double ForwardRewardWeight { get; set; }
Property Value
HealthyReward
The healthy reward now (healthy_reward): float(is_healthy or terminate_when_unhealthy) *
_healthy_reward, so paid on every step while unhealthy states end the episode.
[PyName("healthy_reward")]
public double HealthyReward { get; }
Property Value
HealthyRewardWeight
The healthy reward per step (_healthy_reward), read every step.
[PyName("_healthy_reward")]
public double HealthyRewardWeight { get; set; }
Property Value
HealthyZRange
The exclusive range of a healthy torso height (_healthy_z_range).
[PyName("_healthy_z_range")]
public (double Low, double High) HealthyZRange { get; set; }
Property Value
IsHealthy
Whether the humanoid is healthy now (is_healthy): the torso's height inside the exclusive z range.
[PyName("is_healthy")]
public bool IsHealthy { get; }
Property Value
ResetNoiseScale
The scale of the reset's noise (_reset_noise_scale), read every reset.
[PyName("_reset_noise_scale")]
public double ResetNoiseScale { get; set; }
Property Value
TerminateWhenUnhealthy
Whether an unhealthy state ends the episode (_terminate_when_unhealthy), read every step.
[PyName("_terminate_when_unhealthy")]
public bool TerminateWhenUnhealthy { get; set; }
Property Value
Terminated
Whether the episode ended (terminated): unhealthy while terminate_when_unhealthy is set.
[PyName("terminated")]
public bool Terminated { get; }
Property Value
Methods
ControlCost(NDArray?)
The control cost (control_cost): ctrl_cost_weight * sum(ctrl**2) of the simulation's controls,
float64; action is taken but not read, as in Gymnasium.
[PyName("control_cost")]
public double ControlCost(NDArray? action)
Parameters
actionNDArrayThe action; ignored.
Returns
- double
The cost.
MassCenter(MjModel, MjData)
The center of mass's x and y (mass_center), as MassCenter(MjModel, MjData) computes it. A new
(2,) float64 array the caller owns.
[PyName("mass_center")]
public static NDArray MassCenter(MjModel model, MjData data)
Parameters
Returns
- NDArray
The
(2,)array.
Remarks
Reference: gymnasium/envs/mujoco/humanoid_v4.py.
Exceptions
- ArgumentNullException
A null model or data.
ResetModel()
The episode's start (reset_model): positions init_qpos + uniform(-scale, scale, nq), then
velocities init_qvel + uniform(-scale, scale, nv), drawn in that order.
protected override NDArray ResetModel()
Returns
- NDArray
The first observation.
Step(NDArray)
Applies action for 5 physics steps and reports the transition (step).
public override StepResult<NDArray> Step(NDArray action)
Parameters
actionNDArrayThe 17 controls, any real dtype (stored as float64).
Returns
- StepResult<NDArray>
The observation, the float64 reward, Terminated,
truncated=Falseand the info.
Exceptions
- ArgumentNullException
actionis null.- ValueError
The action is not of shape
(17,), with Gymnasium's message.