Package: beta-divergence-metrics
Beta-Divergence Loss ImplementationsThis repository contains code for Python implementations of the beta-divergence loss, including implementations compatibleNumPyandPyTorch.DependenciesThis library is written in Python, and requires Python (with recommended version >= 3.9) to run. In addition to a working PyTorch installation, this library relies on the following libraries and recommended version numbers:Python>= 3.9NumPy>= 1.22.0SciPy>= 1.7.3InstallationTo install the latest stable release, usepip. Use the following command to install:$ pip install beta-divergence-metricsUsageThenumpybd.lossmodule 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). Similarlytorchbd.lossmodule contains two beta-divergence class implementations compatible with PyTorch andPyTorch tensors. Beta-divergence implementations can be imported as follows:# Import beta-divergence loss implementationsfromnumpybd.lossimport*fromtorchbd.lossimport*Beta-divergence between two NumPy arraysTo calculate the beta-divergence between a NumPy arrayaand a target or reference arrayb, use thebeta_divloss function. Thebeta_divloss function can be used as follows:# Calculate beta-divergence loss between array a and target array bloss_val=beta_div(beta=0,reduction='mean')Beta-divergence between two PyTorch tensorsTo calculate the beta-divergence between tensoraand a target or reference tensorb, use theBetaDivLossloss function. TheBetaDivLossloss function can be instantiated and used as follows:# Instantiate beta-divergence loss objectloss_func=BetaDivLoss(beta=0,reduction='mean')# Calculate beta-divergence loss between tensor a and target tensor bloss_val=loss_func(input=a,target=b)NMF beta-divergence between NumPy array of data and data reconstructionTo calculate the NMF-specific beta-divergence between a NumPy array of data matrixXand the product of a scores matrixHand a components matrixW, use thenmf_beta_divloss function. Thenmf_beta_divloss function can beused as follows:# Calculate beta-divergence loss between data matrix X (target or# reference matrix) and matrix product of H and Wloss_val=nmf_beta_div(X=X,H=H,W=W,beta=0,reduction='mean')NMF beta-divergence between PyTorch tensor of data and data reconstructionTo calculate the NMF-specific beta-divergence between a PyTorch tensor of data matrixXand the matrix product of a scores matrixHand a components matrixW, use theNMFBetaDivLossloss class function. TheNMFBetaDivLossloss function can be instantiated and used as follows:# Instantiate NMF beta-divergence loss objectloss_func=NMFBetaDivLoss(beta=0,reduction='mean')# Calculate beta-divergence loss between data matrix X (target or# reference matrix) and matrix product of H and Wloss_val=loss_func(X=X,H=H,W=W)Choosing beta valueWhen 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:beta = 0:Itakura-Saito divergencebeta = 1:Kullback-Leibler divergencebeta = 2:mean-squared errorIssue Tracking and ReportsPlease use theGitHub issue trackerassociated with this repository for issue tracking, filing bug reports, and asking general questions about the package or project.