Skip to main content

Simple fixed-point solver implemented in JAX

Project description

PyPI version CI CD

Fixed-point solver

fxp-jax is a simple implementation of a fixed-point iteration algorithm for root finding in JAX. The implementation allow the user to solve the system of fixed point equations by standard fixed point iterations and the SQUAREM accelerator, see Du and Varadhan (2020).

Installation

pip install fxp-jax

Usage

import jax
import jax.numpy as jnp
from jax import random

from fxp_jax import fxp_root

jax.config.update("jax_enable_x64", True)

accelerator = "SQUAREM"

N = 100

a = random.uniform(random.PRNGKey(111), (N,1))
b = random.uniform(random.PRNGKey(112), (1,1))

def fun(x: jnp.ndarray) -> tuple[jnp.ndarray, jnp.ndarray]:
    y = a + x @ b
    return y, y - x

fxp = fxp_root(fun, accelerator=accelerator)

result = fxp.solve(jnp.zeros_like(a))

y, z = fxp.fun(result.x)

print('--------------------------------------------------------')
print(f'System of fixed-point equations is solved: {jnp.allclose(result.x, y)}.')
print(f'Roots are zero: {jnp.allclose(z, 0.0)}.')
print('--------------------------------------------------------')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fxp_jax-0.2.4.tar.gz (30.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fxp_jax-0.2.4-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file fxp_jax-0.2.4.tar.gz.

File metadata

  • Download URL: fxp_jax-0.2.4.tar.gz
  • Upload date:
  • Size: 30.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.14

File hashes

Hashes for fxp_jax-0.2.4.tar.gz
Algorithm Hash digest
SHA256 2f98c0c418c31dcde7574dc6051cb68eee918a6d3aef3c09d82495fd552f0c47
MD5 27ea471d9c667861cdca58e2857b502e
BLAKE2b-256 e265527dab55f4d21fd0d90d21da152bae88d6e7e1cea71f400979b27fe9468e

See more details on using hashes here.

File details

Details for the file fxp_jax-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: fxp_jax-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.14

File hashes

Hashes for fxp_jax-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 cf2c0007931ea3c18e944f37dbe7665ce9d6a57f7fdac03073257f95d3885523
MD5 3193f568caeb56f5aeb725a18b66ac98
BLAKE2b-256 e23d0984b738e3d71255694f28851a7dd307ee3fa91ae11994f252f372f31d3e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page