duvida


Nameduvida JSON
Version 0.0.3 PyPI version JSON
download
home_pageNone
SummaryCalculating exact and approximate confidence and information metrics for differentiable functions.
upload_time2025-10-15 15:34:07
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseMIT License Copyright (c) [year] [fullname] Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords ai active-learning bayesian-optimization data deep-learning machine-learning
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 🧐 duvida

![GitHub Workflow Status (with branch)](https://img.shields.io/github/actions/workflow/status/scbirlab/duvida/python-publish.yml)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/duvida)
![PyPI](https://img.shields.io/pypi/v/duvida)

**duvida** (Portuguese for _doubt_) is a suite of python tools for calculating confidence and information metrics 
for deep learning. It provides lower-level function transforms for exact and approximate Hessian diagonals 
in JAX and pytorch. 

- [Installation](#installation)
- [Python API](#python-api)
- [Issues, problems, suggestions](#issues-problems-suggestions)
- [Documentation](#documentation)

## Installation

### The easy way

You can install the precompiled version directly using `pip`. You need to specify the machine learning framework
that you want to use:

```bash
$ pip install duvida[jax]
# or
$ pip install duvida[jax_cuda12]  # for JAX installing CUDA 12 for GPU support
# or
$ pip install duvida[jax_cuda12_local]  # for JAX using a locally-installed CUDA 12
# or
$ pip install duvida[torch]
```

We have implemented JAX and pytorch functional transformations for approximate and exact Hessian diagonals,
and doubtscore and information sensitivity. These can be used with JAX- and pytorch-based frameworks.

### From source

Clone the repository, then `cd` into it. Then run:

```bash
$ pip install -e .[torch]
```

## Python API

**duvida** provides functional transforms for JAX and pytorch that calculate 
either exact or approximate Hessian diagonals.

You can check which backend you're using:

```python
>>> from duvida.stateless.config import config
>>> config
Config(backend='jax', precision='double', fallback=True)
```

It can be changed:

```python
>>> config.set_backend("torch")
'torch'
>>> config
Config(backend='torch', precision='double', fallback=True)
```

Now you can calculate exact Hessian diagonals without calculating the 
full matrix:

```python
>>> from duvida.stateless.utils import hessian
>>> import duvida.stateless.numpy as dnp 
>>> f = lambda x: dnp.sum(x ** 3. + x ** 2. + 4.)
>>> a = dnp.array([1., 2.])
>>> exact_diagonal(f)(a) == dnp.diag(hessian(f)(a))
Array([ True,  True], dtype=bool)
```

Various approximations are also allowed.

```python
>>> from duvida.stateless.hessians import get_approximators
>>> get_approximators()  # Use no arguments to show what's available
('squared_jacobian', 'exact_diagonal', 'bekas', 'rough_finite_difference')
```

Now apply:

```python
>>> approx_hessian_diag = get_approximators("bekas")
>>> g = lambda x: dnp.sum(dnp.sum(x) ** 3. + x ** 2. + 4.)
>>> a = dnp.array([1., 2.])
>>> dnp.diag(hessian(g)(a))  # Exact
Array([38., 38.], dtype=float64)
>>> approx_hessian_diag(g, n=1000)(a)  # Less accurate when parameters interact
Array([38.52438307, 38.49679655], dtype=float64)
>>> approx_hessian_diag(g, n=1000, seed=1)(a)  # Change the seed to alter the outcome
Array([39.07878869, 38.97796601], dtype=float64)
```

## Issues, problems, suggestions

Add to the [issue tracker](https://www.github.com/scbirlab/duvida/issues).

## Documentation

(To come at [ReadTheDocs](https://duvida.readthedocs.org).)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "duvida",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "ai, active-learning, bayesian-optimization, data, deep-learning, machine-learning",
    "author": null,
    "author_email": "Eachan Johnson <eachan.johnson@crick.ac.uk>",
    "download_url": "https://files.pythonhosted.org/packages/65/b2/df76ec919a63b22463677bd734fe27ef756f396231dddfba66e389167844/duvida-0.0.3.tar.gz",
    "platform": null,
    "description": "# \ud83e\uddd0 duvida\n\n![GitHub Workflow Status (with branch)](https://img.shields.io/github/actions/workflow/status/scbirlab/duvida/python-publish.yml)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/duvida)\n![PyPI](https://img.shields.io/pypi/v/duvida)\n\n**duvida** (Portuguese for _doubt_) is a suite of python tools for calculating confidence and information metrics \nfor deep learning. It provides lower-level function transforms for exact and approximate Hessian diagonals \nin JAX and pytorch. \n\n- [Installation](#installation)\n- [Python API](#python-api)\n- [Issues, problems, suggestions](#issues-problems-suggestions)\n- [Documentation](#documentation)\n\n## Installation\n\n### The easy way\n\nYou can install the precompiled version directly using `pip`. You need to specify the machine learning framework\nthat you want to use:\n\n```bash\n$ pip install duvida[jax]\n# or\n$ pip install duvida[jax_cuda12]  # for JAX installing CUDA 12 for GPU support\n# or\n$ pip install duvida[jax_cuda12_local]  # for JAX using a locally-installed CUDA 12\n# or\n$ pip install duvida[torch]\n```\n\nWe have implemented JAX and pytorch functional transformations for approximate and exact Hessian diagonals,\nand doubtscore and information sensitivity. These can be used with JAX- and pytorch-based frameworks.\n\n### From source\n\nClone the repository, then `cd` into it. Then run:\n\n```bash\n$ pip install -e .[torch]\n```\n\n## Python API\n\n**duvida** provides functional transforms for JAX and pytorch that calculate \neither exact or approximate Hessian diagonals.\n\nYou can check which backend you're using:\n\n```python\n>>> from duvida.stateless.config import config\n>>> config\nConfig(backend='jax', precision='double', fallback=True)\n```\n\nIt can be changed:\n\n```python\n>>> config.set_backend(\"torch\")\n'torch'\n>>> config\nConfig(backend='torch', precision='double', fallback=True)\n```\n\nNow you can calculate exact Hessian diagonals without calculating the \nfull matrix:\n\n```python\n>>> from duvida.stateless.utils import hessian\n>>> import duvida.stateless.numpy as dnp \n>>> f = lambda x: dnp.sum(x ** 3. + x ** 2. + 4.)\n>>> a = dnp.array([1., 2.])\n>>> exact_diagonal(f)(a) == dnp.diag(hessian(f)(a))\nArray([ True,  True], dtype=bool)\n```\n\nVarious approximations are also allowed.\n\n```python\n>>> from duvida.stateless.hessians import get_approximators\n>>> get_approximators()  # Use no arguments to show what's available\n('squared_jacobian', 'exact_diagonal', 'bekas', 'rough_finite_difference')\n```\n\nNow apply:\n\n```python\n>>> approx_hessian_diag = get_approximators(\"bekas\")\n>>> g = lambda x: dnp.sum(dnp.sum(x) ** 3. + x ** 2. + 4.)\n>>> a = dnp.array([1., 2.])\n>>> dnp.diag(hessian(g)(a))  # Exact\nArray([38., 38.], dtype=float64)\n>>> approx_hessian_diag(g, n=1000)(a)  # Less accurate when parameters interact\nArray([38.52438307, 38.49679655], dtype=float64)\n>>> approx_hessian_diag(g, n=1000, seed=1)(a)  # Change the seed to alter the outcome\nArray([39.07878869, 38.97796601], dtype=float64)\n```\n\n## Issues, problems, suggestions\n\nAdd to the [issue tracker](https://www.github.com/scbirlab/duvida/issues).\n\n## Documentation\n\n(To come at [ReadTheDocs](https://duvida.readthedocs.org).)\n",
    "bugtrack_url": null,
    "license": "MIT License\n        \n        Copyright (c) [year] [fullname]\n        \n        Permission is hereby granted, free of charge, to any person obtaining a copy\n        of this software and associated documentation files (the \"Software\"), to deal\n        in the Software without restriction, including without limitation the rights\n        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n        copies of the Software, and to permit persons to whom the Software is\n        furnished to do so, subject to the following conditions:\n        \n        The above copyright notice and this permission notice shall be included in all\n        copies or substantial portions of the Software.\n        \n        THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n        SOFTWARE.",
    "summary": "Calculating exact and approximate confidence and information metrics for differentiable functions.",
    "version": "0.0.3",
    "project_urls": {
        "Bug Tracker": "https://github.com/scbirlab/duvida/issues",
        "Homepage": "https://github.com/scbirlab/duvida"
    },
    "split_keywords": [
        "ai",
        " active-learning",
        " bayesian-optimization",
        " data",
        " deep-learning",
        " machine-learning"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "d92b1fd9f5546b96b2beb3fef98c5c5a31bf0275f2f386f77b9a44aea1098868",
                "md5": "bbf9da7c7ed9e27fc249d8ff28456c24",
                "sha256": "b95621c29245ea476f03ac54c237fcb7d190b250bec56bd877cf8d22f53ce397"
            },
            "downloads": -1,
            "filename": "duvida-0.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bbf9da7c7ed9e27fc249d8ff28456c24",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 15430,
            "upload_time": "2025-10-15T15:34:03",
            "upload_time_iso_8601": "2025-10-15T15:34:03.214643Z",
            "url": "https://files.pythonhosted.org/packages/d9/2b/1fd9f5546b96b2beb3fef98c5c5a31bf0275f2f386f77b9a44aea1098868/duvida-0.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "65b2df76ec919a63b22463677bd734fe27ef756f396231dddfba66e389167844",
                "md5": "4e4d5ef481df995f4159b38821643487",
                "sha256": "12484feb7bf9fecf65ff9996de1fd7d2c581f7d80e528fdf408c55f8b72ac1e6"
            },
            "downloads": -1,
            "filename": "duvida-0.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "4e4d5ef481df995f4159b38821643487",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 14677,
            "upload_time": "2025-10-15T15:34:07",
            "upload_time_iso_8601": "2025-10-15T15:34:07.955808Z",
            "url": "https://files.pythonhosted.org/packages/65/b2/df76ec919a63b22463677bd734fe27ef756f396231dddfba66e389167844/duvida-0.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-15 15:34:07",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "scbirlab",
    "github_project": "duvida",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "duvida"
}
        
Elapsed time: 2.30814s