{"id":15632702,"url":"https://github.com/brentyi/jaxls","last_synced_at":"2025-04-04T16:12:02.972Z","repository":{"id":42655093,"uuid":"313247352","full_name":"brentyi/jaxls","owner":"brentyi","description":"Sparse nonlinear least squares in JAX","archived":false,"fork":false,"pushed_at":"2025-03-14T10:46:48.000Z","size":18963,"stargazers_count":191,"open_issues_count":3,"forks_count":13,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-03-28T15:08:03.418Z","etag":null,"topics":["factor-graphs","jax","nonlinear-least-squares"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brentyi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-16T09:15:02.000Z","updated_at":"2025-03-28T07:33:34.000Z","dependencies_parsed_at":"2024-06-02T07:40:05.769Z","dependency_job_id":"03a1a287-6550-4b5f-8839-ed5b8705a8bc","html_url":"https://github.com/brentyi/jaxls","commit_stats":{"total_commits":235,"total_committers":3,"mean_commits":78.33333333333333,"dds":"0.029787234042553234","last_synced_commit":"a81af8adcb6676c26112ae398b3613d6f057f784"},"previous_names":["brentyi/jaxls"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brentyi%2Fjaxls","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brentyi%2Fjaxls/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brentyi%2Fjaxls/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brentyi%2Fjaxls/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brentyi","download_url":"https://codeload.github.com/brentyi/jaxls/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247208142,"owners_count":20901570,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["factor-graphs","jax","nonlinear-least-squares"],"created_at":"2024-10-03T10:45:00.910Z","updated_at":"2025-04-04T16:12:02.955Z","avatar_url":"https://github.com/brentyi.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jaxls\n\n[![pyright](https://github.com/brentyi/jaxls/actions/workflows/pyright.yml/badge.svg)](https://github.com/brentyi/jaxls/actions/workflows/pyright.yml)\n\n**`jaxls`** is a library for solving sparse [NLLS](https://en.wikipedia.org/wiki/Non-linear_least_squares) and [IRLS](https://en.wikipedia.org/wiki/Iteratively_reweighted_least_squares) problems in JAX.\nThese are common in classical robotics and computer vision.\n\nTo install on Python 3.12+:\n\n```bash\npip install git+https://github.com/brentyi/jaxls.git\n```\n\n### Overviews\n\nWe provide a factor graph interface for specifying and solving least squares\nproblems. **`jaxls`** takes advantage of structure in graphs: repeated factor\nand variable types are vectorized, and sparsity of adjacency is translated into\nsparse matrix operations.\n\nSupported:\n\n- Automatic sparse Jacobians.\n- Optimization on manifolds.\n  - Examples provided for SO(2), SO(3), SE(2), and SE(3).\n- Nonlinear solvers: Levenberg-Marquardt and Gauss-Newton.\n- Linear subproblem solvers:\n  - Sparse iterative with Conjugate Gradient.\n    - Preconditioning: block and point Jacobi.\n    - Inexact Newton via Eisenstat-Walker.\n    - Recommended for most problems.\n  - Dense Cholesky.\n    - Fast for small problems.\n  - Sparse Cholesky, on CPU. (CHOLMOD)\n\n`jaxls` borrows heavily from libraries like\n[GTSAM](https://gtsam.org/), [Ceres Solver](http://ceres-solver.org/),\n[minisam](https://github.com/dongjing3309/minisam),\n[SwiftFusion](https://github.com/borglab/SwiftFusion),\nand [g2o](https://github.com/RainerKuemmerle/g2o).\n\n### Pose graph example\n\n```python\nimport jaxls\nimport jaxlie\n```\n\n**Defining variables.** Each variable is given an integer ID. They don't need to\nbe contiguous.\n\n```\npose_vars = [jaxls.SE2Var(0), jaxls.SE2Var(1)]\n```\n\n**Defining factors.** Factors are defined using a callable cost function and a\nset of arguments.\n\n```python\n# Factors take two arguments:\n# - A callable with signature `(jaxls.VarValues, *Args) -\u003e jax.Array`.\n# - A tuple of arguments: the type should be `tuple[*Args]`.\n#\n# All arguments should be PyTree structures. Variable types within the PyTree\n# will be automatically detected.\nfactors = [\n    # Cost on pose 0.\n    jaxls.Factor(\n        lambda vals, var, init: (vals[var] @ init.inverse()).log(),\n        (pose_vars[0], jaxlie.SE2.from_xy_theta(0.0, 0.0, 0.0)),\n    ),\n    # Cost on pose 1.\n    jaxls.Factor(\n        lambda vals, var, init: (vals[var] @ init.inverse()).log(),\n        (pose_vars[1], jaxlie.SE2.from_xy_theta(2.0, 0.0, 0.0)),\n    ),\n    # Cost between poses.\n    jaxls.Factor(\n        lambda vals, var0, var1, delta: (\n            (vals[var0].inverse() @ vals[var1]) @ delta.inverse()\n        ).log(),\n        (pose_vars[0], pose_vars[1], jaxlie.SE2.from_xy_theta(1.0, 0.0, 0.0)),\n    ),\n]\n```\n\nFactors with similar structure, like the first two in this example, will be\nvectorized under-the-hood.\n\nBatched inputs can also be manually constructed, and are detected by inspecting\nthe shape of variable ID arrays in the input. Just add a leading batch axis to\nall elements in the arguments tuple.\n\n**Solving optimization problems.** To set up the optimization problem, solve\nit, and print solutions:\n\n```python\ngraph = jaxls.FactorGraph.make(factors, pose_vars)\nsolution = graph.solve()\nprint(\"All solutions\", solution)\nprint(\"Pose 0\", solution[pose_vars[0]])\nprint(\"Pose 1\", solution[pose_vars[1]])\n```\n\n### CHOLMOD setup\n\nBy default, we use an iterative linear solver. This requires no extra\ndependencies. For problems with strong supernodal structure or where our\npreconditioners are ineffective, a direct solver can be much faster.\n\nFor Cholesky factorization via CHOLMOD, we rely on SuiteSparse:\n\n```bash\n# Option 1: via conda.\nconda install conda-forge::suitesparse\n\n# Option 2: via apt.\nsudo apt install -y libsuitesparse-dev\n```\n\nYou'll also need _scikit-sparse_:\n\n```bash\npip install scikit-sparse\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrentyi%2Fjaxls","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrentyi%2Fjaxls","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrentyi%2Fjaxls/lists"}