Source code for qdpy.benchmarks.arm

# SPDX-License-Identifier: LGPL-3.0-or-later
## @file
# @brief Analytic planar-arm illumination with end-effector descriptors.

"""Forward kinematics for the equal-link planar-arm benchmark."""

import numpy as np

__all__ = ["illumination_planar_arm"]


## @brief Score one planar arm and return its normalized end-effector position.
[docs] def illumination_planar_arm(genome): """Return maximising fitness and two Cartesian descriptors in [0, 1]. The finite one-dimensional genome encodes relative joint angles. Coordinates are clipped to [0, 1] and mapped to [-pi, pi]. The sum of the link lengths is one. Fitness is one minus twice the population standard deviation of the normalized joint angles. This rescales the objective of the QDax Arm task to [0, 1]. """ genes = np.asarray(genome, dtype=float) if genes.ndim != 1 or not genes.size or not np.isfinite(genes).all(): raise ValueError("The planar arm needs a nonempty vector of finite joint coordinates.") joints = np.clip(genes, 0.0, 1.0) angles = np.cumsum(2 * np.pi * joints - np.pi) x = (float(np.cos(angles).mean()) + 1.0) / 2.0 y = (float(np.sin(angles).mean()) + 1.0) / 2.0 return (1.0 - 2.0 * float(joints.std()),), (x, y)