{"id":35076503,"url":"https://github.com/wecarsoniv/beta-divergence-metrics","last_synced_at":"2025-12-27T12:08:32.643Z","repository":{"id":57414720,"uuid":"444972863","full_name":"wecarsoniv/beta-divergence-metrics","owner":"wecarsoniv","description":"PyTorch implementations of the beta divergence loss.","archived":false,"fork":false,"pushed_at":"2022-01-31T18:16:21.000Z","size":369,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-26T15:03:05.856Z","etag":null,"topics":["beta-divergence","distance-measures","distance-metric","distance-metrics","divergence","divergences","itakura-saito-divergence","kl-divergence","kullback-leibler-divergence","loss","loss-functions","mean-square-error","mean-squared-error","nmf","nmf-decomposition","non-negative-matrix-factorization","numpy","objective-functions","pytorch","torch"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wecarsoniv.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}},"created_at":"2022-01-05T22:52:58.000Z","updated_at":"2024-12-04T07:35:28.000Z","dependencies_parsed_at":"2022-09-26T16:31:21.693Z","dependency_job_id":null,"html_url":"https://github.com/wecarsoniv/beta-divergence-metrics","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/wecarsoniv/beta-divergence-metrics","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wecarsoniv%2Fbeta-divergence-metrics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wecarsoniv%2Fbeta-divergence-metrics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wecarsoniv%2Fbeta-divergence-metrics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wecarsoniv%2Fbeta-divergence-metrics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wecarsoniv","download_url":"https://codeload.github.com/wecarsoniv/beta-divergence-metrics/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wecarsoniv%2Fbeta-divergence-metrics/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28078453,"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","status":"online","status_checked_at":"2025-12-27T02:00:05.897Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["beta-divergence","distance-measures","distance-metric","distance-metrics","divergence","divergences","itakura-saito-divergence","kl-divergence","kullback-leibler-divergence","loss","loss-functions","mean-square-error","mean-squared-error","nmf","nmf-decomposition","non-negative-matrix-factorization","numpy","objective-functions","pytorch","torch"],"created_at":"2025-12-27T12:08:32.022Z","updated_at":"2025-12-27T12:08:32.637Z","avatar_url":"https://github.com/wecarsoniv.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Beta-Divergence Loss Implementations\n\nThis repository contains code for Python implementations of the beta-divergence loss, including implementations compatible [NumPy](https://numpy.org/) and [PyTorch](https://pytorch.org/).\n\n\n## Dependencies\n\nThis library is written in Python, and requires Python (with recommended version \u003e= 3.9) to run. In addition to a working PyTorch installation, this library relies on the following libraries and recommended version numbers:\n\n* [Python](https://www.python.org/) \u003e= 3.9\n* [NumPy](https://numpy.org/) \u003e= 1.22.0\n* [SciPy](https://www.scipy.org/) \u003e= 1.7.3\n\n\n## Installation\n\nTo install the latest stable release, use [pip](https://pip.pypa.io/en/stable/). Use the following command to install:\n\n    $ pip install beta-divergence-metrics\n\n\n## Usage\n\nThe [`numpybd.loss`](https://github.com/wecarsoniv/beta-divergence-metrics/blob/main/src/numpybd/loss.py) module contains two beta-divergence function implementations compatible with NumPy and NumPy arrays: one general beta-divergence between two arrays, and a beta-divergence implementation specific to non-negative matrix factorization (NMF). Similarly [`torchbd.loss`](https://github.com/wecarsoniv/beta-divergence-metrics/blob/main/src/torchbd/loss.py) module contains two beta-divergence class implementations compatible with PyTorch and [PyTorch tensors](https://pytorch.org/tutorials/beginner/introyt/tensors_deeper_tutorial.html). Beta-divergence implementations can be imported as follows:\n\n```python\n# Import beta-divergence loss implementations\nfrom numpybd.loss import *\nfrom torchbd.loss import *\n\n```\n\n\n\n### Beta-divergence between two NumPy arrays\n\nTo calculate the beta-divergence between a NumPy array `a` and a target or reference array `b`, use the `beta_div` loss function. The `beta_div` loss function can be used as follows:\n\n```python\n# Calculate beta-divergence loss between array a and target array b\nloss_val = beta_div(beta=0, reduction='mean')\n\n```\n\n\n### Beta-divergence between two PyTorch tensors\n\nTo calculate the beta-divergence between tensor `a` and a target or reference tensor `b`, use the `BetaDivLoss` loss function. The `BetaDivLoss` loss function can be instantiated and used as follows:\n\n```python\n# Instantiate beta-divergence loss object\nloss_func = BetaDivLoss(beta=0, reduction='mean')\n\n# Calculate beta-divergence loss between tensor a and target tensor b\nloss_val = loss_func(input=a, target=b)\n\n```\n\n\n### NMF beta-divergence between NumPy array of data and data reconstruction\n\nTo calculate the NMF-specific beta-divergence between a NumPy array of data matrix `X` and the product of a scores matrix `H` and a components matrix `W`, use the `nmf_beta_div` loss function. The `nmf_beta_div` loss function can beused as follows:\n\n```python\n# Calculate beta-divergence loss between data matrix X (target or\n# reference matrix) and matrix product of H and W\nloss_val = nmf_beta_div(X=X, H=H, W=W, beta=0, reduction='mean')\n\n```\n\n\n### NMF beta-divergence between PyTorch tensor of data and data reconstruction\n\nTo calculate the NMF-specific beta-divergence between a PyTorch tensor of data matrix `X` and the matrix product of a scores matrix `H` and a components matrix `W`, use the `NMFBetaDivLoss` loss class function. The `NMFBetaDivLoss` loss function can be instantiated and used as follows:\n\n```python\n# Instantiate NMF beta-divergence loss object\nloss_func = NMFBetaDivLoss(beta=0, reduction='mean')\n\n# Calculate beta-divergence loss between data matrix X (target or\n# reference matrix) and matrix product of H and W\nloss_val = loss_func(X=X, H=H, W=W)\n\n```\n\n\n### Choosing beta value\n\nWhen instantiating beta-divergence loss objects, the value of beta should be chosen depending on data type and application. For NMF applications, a beta value of 0 (Itakura-Saito divergence) is recommemded. Integer values of beta correspond to the following divergences and loss functions:\n\n* beta = 0: [Itakura-Saito divergence](https://en.wikipedia.org/wiki/Itakura-Saito_distance)\n* beta = 1: [Kullback-Leibler divergence](https://en.wikipedia.org/wiki/Kullback-Leibler_divergence)\n* beta = 2: [mean-squared error](https://en.wikipedia.org/wiki/Mean_squared_error)\n\n\n## Issue Tracking and Reports\n\nPlease use the [GitHub issue tracker](https://github.com/wecarsoniv/beta-divergence-metrics/issues) associated with this repository for issue tracking, filing bug reports, and asking general questions about the package or project.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwecarsoniv%2Fbeta-divergence-metrics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwecarsoniv%2Fbeta-divergence-metrics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwecarsoniv%2Fbeta-divergence-metrics/lists"}