QDpy
Loading...
Searching...
No Matches
arm.py
Go to the documentation of this file.
1# SPDX-License-Identifier: LGPL-3.0-or-later
2
4
5"""Forward kinematics for the equal-link planar-arm benchmark."""
6
7import numpy as np
8
9__all__ = ["illumination_planar_arm"]
10
11
12
13def illumination_planar_arm(genome):
14 """Return maximising fitness and two Cartesian descriptors in [0, 1].
15
16 The finite one-dimensional genome encodes relative joint angles.
17 Coordinates are clipped to [0, 1] and mapped to [-pi, pi]. The sum
18 of the link lengths is one. Fitness is one minus twice the
19 population standard deviation of the normalized joint angles.
20 This rescales the objective of the QDax Arm task to [0, 1].
21 """
22 genes = np.asarray(genome, dtype=float)
23 if genes.ndim != 1 or not genes.size or not np.isfinite(genes).all():
24 raise ValueError("The planar arm needs a nonempty vector of finite joint coordinates.")
25 joints = np.clip(genes, 0.0, 1.0)
26 angles = np.cumsum(2 * np.pi * joints - np.pi)
27 x = (float(np.cos(angles).mean()) + 1.0) / 2.0
28 y = (float(np.sin(angles).mean()) + 1.0) / 2.0
29 return (1.0 - 2.0 * float(joints.std()),), (x, y)