MLP Dynamics¶
Neural-network-based vehicle dynamics model.
Notes
Implements a simple MLP dynamics model registered via ModelSpec for
integration with the Physics-Constrained Learning (PCT) optimization stack.
Param ¶
Parameters for the neural network vehicle dynamics model.
Supports scalar parameters; create can generate sized defaults.
Attributes:
| Name | Type | Description |
|---|---|---|
W1 |
Array
|
First layer weights shaped |
b1 |
Array
|
First layer bias shaped |
W2 |
Array
|
Second layer weights shaped |
b2 |
Array
|
Second layer bias shaped |
alpha |
Array
|
Activation scaling factor. |
timestep |
float
|
Physics integration timestep. |
timestep_ratio |
int
|
Simulation steps per control step (static field). |
hidden_size |
int
|
Hidden layer width (static field). |
create
classmethod
¶
create(
*,
hidden_size=DEFAULT_HIDDEN_SIZE,
alpha=1.0,
timestep=0.05,
timestep_ratio=1,
)
Construct a parameter bundle with the requested hidden size.
build_base_params_with_hidden ¶
build_base_params_with_hidden(
timestep_hundredths, *, hidden_size=DEFAULT_HIDDEN_SIZE
)
Construct a Param instance with the desired hidden size.
default_params ¶
default_params(hidden_size=DEFAULT_HIDDEN_SIZE)
Return zero-initialized network parameters for the requested hidden size.
param_bounds ¶
param_bounds(hidden_size=DEFAULT_HIDDEN_SIZE)
Return lower/upper bounds for each parameter.
param_shapes ¶
param_shapes(hidden_size=DEFAULT_HIDDEN_SIZE)
Return parameter shapes keyed by parameter name.
vehicle_dynamics_mlp ¶
vehicle_dynamics_mlp(x_and_u, params)
Evaluate the neural network vehicle dynamics model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_and_u
|
Array
|
Concatenated state-control vector of shape |
required |
params
|
Param
|
Parameters containing the network weights and offsets. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Concatenated time derivative of state and control vectors. |
yaw_normalized_loss ¶
yaw_normalized_loss(output_states, target_states)
Yaw-normalized loss between output and target states.
Handles angular differences by wrapping them to [-pi, pi] and uses
L1 loss for non-angular components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_states
|
Array
|
Predicted states of shape |
required |
target_states
|
Array
|
Target states of shape |
required |
Returns:
| Type | Description |
|---|---|
float
|
Total loss summed over all elements. |
yaw_normalized_loss_per_element ¶
yaw_normalized_loss_per_element(
output_states, target_states
)
Yaw-normalized loss per state dimension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_states
|
Array
|
Predicted states of shape |
required |
target_states
|
Array
|
Target states of shape |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Loss per dimension of shape |
yaw_normalized_loss_per_item ¶
yaw_normalized_loss_per_item(output_states, target_states)
Yaw-normalized loss per item in the batch.
Assumes input shape is (B, T, D) where D=5.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_states
|
Array
|
Predicted states of shape |
required |
target_states
|
Array
|
Target states of shape |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Loss per batch item of shape |
yaw_normalized_loss_weighted ¶
yaw_normalized_loss_weighted(
output_states, target_states, weights=None
)
Weighted yaw-normalized loss for state dimensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_states
|
Array
|
Predicted states of shape |
required |
target_states
|
Array
|
Target states of shape |
required |
weights
|
Array
|
Per-dimension weights of shape |
None
|
Returns:
| Type | Description |
|---|---|
float
|
Weighted loss value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |