Commit Graph

13 Commits

Author SHA1 Message Date
winklemad 72c9f2af63 Fix least_squares xtol result 2026-07-22 08:17:25 +05:30
Hana Joo 78946ca94e Adding type suppressions for pyrefly
PiperOrigin-RevId: 950703735
Change-Id: I6b6d5826a0dd1f4c0a1cbb2a46aee944cd60d884
2026-07-20 02:40:02 -07:00
nas 55c6332f20 Copybara import of the project:
--
8ce7d8199ace95d0f429b0ca9169d290d167cee1 by Anas <anaselghoudane@gmail.com>:

Use box midpoint to choose finite-difference direction in jacobian_fd

When bounds are provided, `jacobian_fd` chooses each coordinate's
finite-difference direction so the perturbation steps away from the nearer
bound. It compared `x` against `0.5 * (bounds[1] - bounds[0])`, which is half
the box *width*, not the box midpoint. For bounds that are not centered on the
origin this selects the wrong direction, and at the lower bound the perturbation
steps outside the box.

Compare against the midpoint `0.5 * (bounds[0] + bounds[1])` instead. Adds a
regression test checking that all residual evaluations stay within an off-center
box when `x` is at the lower bound; it fails before this change and passes after.

--
cfa085484c30df808362898e322de8adc6660b59 by Kevin Zakka <kevinarmandzakka@gmail.com>:

Expand jacobian_fd bounds test and avoid midpoint overflow

Use the distributive form `0.5*lo + 0.5*hi` instead of
`0.5*(lo+hi)` to avoid overflow for extreme bound values.

Expand the single-case test into a parameterized subTest covering
all four boundary positions (lower/upper of positive and negative
off-center boxes), and rename it to `test_jacobian_fd_respects_bounds`.

COPYBARA_INTEGRATE_REVIEW=https://github.com/google-deepmind/mujoco/pull/3301 from Nas01010101:fix/minimize-fd-box-midpoint cfa085484c30df808362898e322de8adc6660b59
PiperOrigin-RevId: 933224876
Change-Id: I833cfe3324876cdeb7ca680c23d1d8a4d16adcf1
2026-06-16 12:06:34 -07:00
Copybara-Service ffe1eadd7e Merge pull request #3294 from kevinzakka:mujoco-minimize-x-scale
PiperOrigin-RevId: 923519000
Change-Id: I4a8fa1f031428cf41d194d17ea4c41975f93f745
2026-05-29 11:34:36 -07:00
Kevin Zakka aa4a43da17 Address reviewer feedback: default x_scale=None, drop TRF qualifier. 2026-05-27 12:55:14 -07:00
Kevin Zakka c12dc23852 Add x_scale to mujoco.minimize.least_squares.
Per-parameter scaling via change of variables z = x / D. Supports
'jac' (adaptive D_i = 1/||J(:,i)|| per iteration, matches scipy's TRF),
explicit array, or a positive scalar. Default 1.0 is a no-op.
2026-05-26 17:06:09 -07:00
Yuval Tassa 5031f88158 In minimize.least_squares, compute values at the solution at full verbosity.
PiperOrigin-RevId: 745301888
Change-Id: Ibd8e35e405bb2cebc7ac59a6dfc77118a6e6ba9f
2025-04-08 14:55:53 -07:00
Yuval Tassa 55e3ca3acf Improvements to minimize.least_squares.
All changes make functionality more similar to SciPy least squares:
- Use adaptive findiff epsilon.
- Make termination on step size relative to norm(x).
- Add termination on gradient norm.
- Make default tolerances like SciPy's.

PiperOrigin-RevId: 745221614
Change-Id: Iee93256651fca8154c97fa3bdaa9c67ede28e573
2025-04-08 11:23:24 -07:00
Baruch Tabanpour f3b3024291 Add pyink and isort config. Reformat.
PiperOrigin-RevId: 704533915
Change-Id: I37e9fd51261bd166b725c7460fc65d02fed2b391
2024-12-09 21:10:50 -08:00
Yuval Tassa 8d896529f0 Replace .copy() with list() in minimize.py
PiperOrigin-RevId: 631413376
Change-Id: I06dd3e3897078b57b0a0668b2182fa62dcd4a74e
2024-05-07 07:16:30 -07:00
Yuval Tassa 34e537e557 Updates to minimize.least_squares. Fixes #1585
- Residual callable is vectorized for easy multithreading by the user. Internally all vectors are now explicitly column vectors.
- Removed central findiff option, it wasn't applicable at the bounds anyway and just complicated the code.
- Added optional user-provided norm function for non-quadratic (robust) norms.
- Added an iter_callback callable for user convenience.
- Added option to internally check user-provided Jacobian and norm against finite differences.
- Updated the notebook accordingly.

PiperOrigin-RevId: 631205889
Change-Id: I3b9f8893756e329640de464e6f2e26a39e7dbd9e
2024-05-06 15:36:01 -07:00
Yuval Tassa 03a8fa9ca9 Improvements to minimize.least_squares:
- Added central differencing option.
- Changed `mu` semantics from log10 to actual values.
- `mu` control is now more aggressive, saves a few iterations.
- Use Armijo sufficient reduction criterion.
- Added some checks for float64 and NaNs.
- Added log of final result to trace.
- Removed unhelpful QP timing.

PiperOrigin-RevId: 610096950
Change-Id: Idf1a7c3155ce8e82fc2d5fe0f2da2f16636ff63d
2024-02-24 20:42:45 -08:00
Yuval Tassa b56d4bf8a5 Add mujoco.minimize module.
PiperOrigin-RevId: 608443678
Change-Id: Ib5dc78fe4523488b6c4e824f226591cf6a8a6216
2024-02-19 18:58:42 -08:00