JaxUtils


NameJaxUtils JSON
Version 0.0.3 PyPI version JSON
download
home_page
SummaryUtility functions for JaxGaussianProcesses
upload_time2022-12-16 14:24:23
maintainer
docs_urlNone
authorDaniel Dodd and Thomas Pinder
requires_python
licenseLICENSE
keywords gaussian-processes jax machine-learning bayesian
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # [JaxUtils](https://github.com/JaxGaussianProcesses/JaxUtils)

`JaxUtils` provides utility functions for the [`JaxGaussianProcesses`]() ecosystem.</h2>

# Contents
* [PyTree](#pytree)
* [Dataset](#dataset)
    
# PyTree
## Overview
`jaxutils.PyTree` is a mixin class for [registering a python class as a JAX PyTree](https://jax.readthedocs.io/en/latest/pytrees.html#extending-pytrees). You would define your Python class as follows.

```python
class MyClass(jaxutils.PyTree):
    ...

```

## Example

```python
import jaxutils

from jaxtyping import Float, Array

class Line(jaxutils.PyTree):
    def __init__(self, gradient: Float[Array, "1"], intercept: Float[Array, "1"]) -> None
        self.gradient = gradient
        self.intercept = intercept
        
    def y(self, x: Float[Array, "N"]) -> Float[Array, "N"]
        return x * self.gradient + self.intercept
```

# Dataset
## Overview
`jaxutils.Dataset` is a datset abstraction. In future, we wish to extend this to a heterotopic and isotopic data abstraction.

## Example

```python
import jaxutils
import jax.numpy as jnp

# Inputs
X = jnp.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]) 

# Outputs
y = jnp.array([[7.0], [8.0], [9.0]])

# Datset
D = jaxutils.Dataset(X=X, y=y)

print(f'The number of datapoints is {D.n}')
print(f'The input dimension is {D.in_dim}')
print(f'The output dimension is {D.out_dim}')
print(f'The input data is {D.X}')
print(f'The output data is {D.y}')
print(f'The data is supervised {D.is_supervised()}')
print(f'The data is unsupervised {D.is_unsupervised()}')
```
```
The number of datapoints is 3
The input dimension is 2
The output dimension is 1
The input data is [[1. 2.]
 [3. 4.]
 [5. 6.]]
The output data is [[7.]
 [8.]
 [9.]]
The data is supervised True
The data is unsupervised False
```

You can also add dataset together to concatenate them.

```python
# New inputs
X_new = jnp.array([[1.5, 2.5], [3.5, 4.5], [5.5, 6.5]])

# New outputs
y_new = jnp.array([[7.0], [8.0], [9.0]])

# New dataset
D_new = jaxutils.Dataset(X=X_new, y=y_new)

# Concatenate the two datasets
D = D + D_new

print(f'The number of datapoints is {D.n}')
print(f'The input dimension is {D.in_dim}')
print(f'The output dimension is {D.out_dim}')
print(f'The input data is {D.X}')
print(f'The output data is {D.y}')
print(f'The data is supervised {D.is_supervised()}')
print(f'The data is unsupervised {D.is_unsupervised()}')
```

```
The number of datapoints is 6
The input dimension is 2
The output dimension is 1
The input data is [[1.  2. ]
 [3.  4. ]
 [5.  6. ]
 [1.5 2.5]
 [3.5 4.5]
 [5.5 6.5]]
The output data is [[7.]
 [8.]
 [9.]
 [7.]
 [8.]
 [9.]]
The data is supervised True
The data is unsupervised False
```
            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "JaxUtils",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "gaussian-processes jax machine-learning bayesian",
    "author": "Daniel Dodd and Thomas Pinder",
    "author_email": "tompinder@live.co.uk",
    "download_url": "https://files.pythonhosted.org/packages/0d/ce/611b62499456ac0bac8483d9b452a845c4056febdd983147bf6d8a0d6953/JaxUtils-0.0.3.tar.gz",
    "platform": null,
    "description": "# [JaxUtils](https://github.com/JaxGaussianProcesses/JaxUtils)\n\n`JaxUtils` provides utility functions for the [`JaxGaussianProcesses`]() ecosystem.</h2>\n\n# Contents\n* [PyTree](#pytree)\n* [Dataset](#dataset)\n    \n# PyTree\n## Overview\n`jaxutils.PyTree` is a mixin class for [registering a python class as a JAX PyTree](https://jax.readthedocs.io/en/latest/pytrees.html#extending-pytrees). You would define your Python class as follows.\n\n```python\nclass MyClass(jaxutils.PyTree):\n    ...\n\n```\n\n## Example\n\n```python\nimport jaxutils\n\nfrom jaxtyping import Float, Array\n\nclass Line(jaxutils.PyTree):\n    def __init__(self, gradient: Float[Array, \"1\"], intercept: Float[Array, \"1\"]) -> None\n        self.gradient = gradient\n        self.intercept = intercept\n        \n    def y(self, x: Float[Array, \"N\"]) -> Float[Array, \"N\"]\n        return x * self.gradient + self.intercept\n```\n\n# Dataset\n## Overview\n`jaxutils.Dataset` is a datset abstraction. In future, we wish to extend this to a heterotopic and isotopic data abstraction.\n\n## Example\n\n```python\nimport jaxutils\nimport jax.numpy as jnp\n\n# Inputs\nX = jnp.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]) \n\n# Outputs\ny = jnp.array([[7.0], [8.0], [9.0]])\n\n# Datset\nD = jaxutils.Dataset(X=X, y=y)\n\nprint(f'The number of datapoints is {D.n}')\nprint(f'The input dimension is {D.in_dim}')\nprint(f'The output dimension is {D.out_dim}')\nprint(f'The input data is {D.X}')\nprint(f'The output data is {D.y}')\nprint(f'The data is supervised {D.is_supervised()}')\nprint(f'The data is unsupervised {D.is_unsupervised()}')\n```\n```\nThe number of datapoints is 3\nThe input dimension is 2\nThe output dimension is 1\nThe input data is [[1. 2.]\n [3. 4.]\n [5. 6.]]\nThe output data is [[7.]\n [8.]\n [9.]]\nThe data is supervised True\nThe data is unsupervised False\n```\n\nYou can also add dataset together to concatenate them.\n\n```python\n# New inputs\nX_new = jnp.array([[1.5, 2.5], [3.5, 4.5], [5.5, 6.5]])\n\n# New outputs\ny_new = jnp.array([[7.0], [8.0], [9.0]])\n\n# New dataset\nD_new = jaxutils.Dataset(X=X_new, y=y_new)\n\n# Concatenate the two datasets\nD = D + D_new\n\nprint(f'The number of datapoints is {D.n}')\nprint(f'The input dimension is {D.in_dim}')\nprint(f'The output dimension is {D.out_dim}')\nprint(f'The input data is {D.X}')\nprint(f'The output data is {D.y}')\nprint(f'The data is supervised {D.is_supervised()}')\nprint(f'The data is unsupervised {D.is_unsupervised()}')\n```\n\n```\nThe number of datapoints is 6\nThe input dimension is 2\nThe output dimension is 1\nThe input data is [[1.  2. ]\n [3.  4. ]\n [5.  6. ]\n [1.5 2.5]\n [3.5 4.5]\n [5.5 6.5]]\nThe output data is [[7.]\n [8.]\n [9.]\n [7.]\n [8.]\n [9.]]\nThe data is supervised True\nThe data is unsupervised False\n```",
    "bugtrack_url": null,
    "license": "LICENSE",
    "summary": "Utility functions for JaxGaussianProcesses",
    "version": "0.0.3",
    "split_keywords": [
        "gaussian-processes",
        "jax",
        "machine-learning",
        "bayesian"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "407a8225c09b31b2315b2dd7823a1109",
                "sha256": "4b922a00ce17dba08f80947451fe5eeaccb64e20cf4915226420040dab6d5e13"
            },
            "downloads": -1,
            "filename": "JaxUtils-0.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "407a8225c09b31b2315b2dd7823a1109",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 8990,
            "upload_time": "2022-12-16T14:24:23",
            "upload_time_iso_8601": "2022-12-16T14:24:23.551023Z",
            "url": "https://files.pythonhosted.org/packages/0d/ce/611b62499456ac0bac8483d9b452a845c4056febdd983147bf6d8a0d6953/JaxUtils-0.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-16 14:24:23",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "jaxutils"
}
        
Elapsed time: 0.01857s