Skip to main content

Python and NumPy extension module implementing the generalized signular value decomposition (GSVD).

Project description

pygensvd.py

An updated version of the original pygsvd package by Benjamin Naecker. This version uses cmake for compilation rather than distutils, but only supports openblas as a backend (for now).

A Python wrapper to the LAPACK generalized singular value decomposition.

(C) 2017 Benjamin Naecker bnaecker@fastmail.com

Overview

The pygsvd module exports a single function gsvd, which computes the generalized singular value decomposition (GSVD) of a pair of matrices, A and B. The GSVD is a joint decomposition useful for computing regularized solutions to ill-posed least-squares problems, as well as dimensionality reduction and clustering.

The pygsvd module is very simple: it just wraps the underlying LAPACK routine ggsvd3, both the double-precision (dggsvd3) and complex-double precision versions (zggsvd3).

Building

Because the pygsvd module wraps a LAPACK routine itself, it is provided as a Python and NumPy extension module. The module must be compiled, and doing so requires a LAPACK header and a shared library. The module currently supports both the standard C bindings to LAPACK (called LAPACKE), and those provided by Intel's Math Kernel Library. Notably it does not support Apple's Accelerate framework, which seems to be outdated and differs in several subtle and annoying ways.

You can build against either of the supported implementations, by editing the setup.cfg file. Set the define= line in the file to be one of USE_LAPACK (the default) or USE_MKL.

You must also add the include and library directories for these. The build process already searches /usr/local/{include,lib}, but if these don't contain the header and library, add the directory containing these to the include_dirs= and library_dirs= line. Multiple directories are separated by a :. You can also set these on the command line when building.

For example, to use the LAPACK library, with a header in /some/dir/ and the library in /some/libdir/, you could run:

$ python3 setup.py build_ext --include-dirs="/some/dir" --library-dirs="/some/libdir"

Then you can install the module either as usual or in develop mode as:

$ python3 setup.py {install,develop}

Or via pip as:

$ pip3 install .

Usage

The GSVD of a pair of NumPy ndarrays a and b can be computed as:

>>> c, s, x = pygsvd.gsvd(a, b)

This returns the generalized singular values, in arrays c and s, and the right generalized singular vectors in x. Optionally, the transformation matrices u and v` may also be computed. E.g.:

>>> c, s, x, u = pygsvd.gsvd(a, b, extras='u')

also returns the left generalized singular vectors of a.

By default, the matrices u and v, if returned, are of shape (m, n) and (p, n). Using the optional argument full_matrices is set to True, then the matrices are square, of shape (m, m) and (p, p).

The generalized singular value decomposition

The GSVD is a joint decomposition of a pair of matrices. Given matrices A with shape (m, n) and B with shape (p, n), it computes:

    A = U*C*X.T
    B = V*S*X.T

where U and V are unitary matrices, with shapes (m, m) and (p, p), and X is shaped as (n, n), respectively. C and S are diagonal (possibly non-square) matrices containing the generalized singular value pairs.

This decomposition has many uses, including least-squares fitting of ill-posed problems. For example, letting B be the "second derivative" operator one can solve the equation

min_x ||Ax - b||^2 + \lambda ||Bx||^2

using the GSVD, which achieves a smoother solution as \lambda is increased. Similarly, setting B to the identity matrix, this becomes the standard ridge regression problem. These are both versions of the Tichonov regularization problem, for which the GSVD provides a useful and efficient solution.

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

pygensvd-0.1.0.tar.gz (10.7 kB view details)

Uploaded Source

Built Distributions

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

pygensvd-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pygensvd-0.1.0-cp311-cp311-macosx_10_9_x86_64.whl (11.6 MB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

pygensvd-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pygensvd-0.1.0-cp310-cp310-macosx_10_9_x86_64.whl (11.6 MB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

pygensvd-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.0 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

pygensvd-0.1.0-cp39-cp39-macosx_10_9_x86_64.whl (11.6 MB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

pygensvd-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.0 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

pygensvd-0.1.0-cp38-cp38-macosx_10_9_x86_64.whl (11.6 MB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

pygensvd-0.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.0 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

pygensvd-0.1.0-cp37-cp37m-macosx_10_9_x86_64.whl (11.6 MB view details)

Uploaded CPython 3.7mmacOS 10.9+ x86-64

File details

Details for the file pygensvd-0.1.0.tar.gz.

File metadata

  • Download URL: pygensvd-0.1.0.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for pygensvd-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c6857fa0522e1899673729c250eddb987f14cbd515ab33e958e98d81feb6016c
MD5 c1a62e5d690564510025e0f011f5ec08
BLAKE2b-256 97147fb79dc6a86fb0b2f061beeac84eae9316c196cbce75941df876f91c2c4e

See more details on using hashes here.

File details

Details for the file pygensvd-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pygensvd-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1e31c359bd0615e1e9de551225d3d5c81289cba51a2932c1121c51b4ccefc61e
MD5 119abc7fbf521336609b5787ab908f62
BLAKE2b-256 629c2335e2805e4e5b08df278a1d6479dc05fbd962b5dff9ca04897e233b91e5

See more details on using hashes here.

File details

Details for the file pygensvd-0.1.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pygensvd-0.1.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 6464e660ef9d814e2af5fad959ab909134caab15342e8de55357af64c82b598c
MD5 b1efc88c186de92875cabf9eb816c408
BLAKE2b-256 f03de7ab23b03df862d7f0575444a39eb379e44712da932635a8b1a3c703ce87

See more details on using hashes here.

File details

Details for the file pygensvd-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pygensvd-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1c5c56e725cd089277a687f9bb741b0cfefc07f28bffce6f4779795fb95852e5
MD5 8ec170d7e5ad344018ef7149ed24617d
BLAKE2b-256 78ee2d85d6a20620dc20a0aababe1e530ebac41e24e6e05e428dc5c57803efa4

See more details on using hashes here.

File details

Details for the file pygensvd-0.1.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pygensvd-0.1.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 7c9c4e145e8a09202279660d1885246fac58f181750ac47a0d1de7937c1ace05
MD5 ff795c13a4ad00f1f4ce205a2c83d354
BLAKE2b-256 64b1af2ba7e1963900fffe1424f55c54f6752d9a453eb0a450049095e381c571

See more details on using hashes here.

File details

Details for the file pygensvd-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pygensvd-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2bded7671052f2428dae559d440d7156dab46e93762e66ed4832b11efe4f425b
MD5 4677514f000f1ba1bfd00884e5dc95c8
BLAKE2b-256 1b78617fb2f730ed51c828c38b522d94bf4d6ccee9bfa317e850ca35452737cc

See more details on using hashes here.

File details

Details for the file pygensvd-0.1.0-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pygensvd-0.1.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 642765da943df098df101de8aced46a4b9a9c476dc1d3e2df4a917c117931b3a
MD5 a522ff6ac8b1d3b41fdffe5c257af162
BLAKE2b-256 be9b23b32e27994dd684852306adc346586bb0ba423b9effaa9acb78c63dd587

See more details on using hashes here.

File details

Details for the file pygensvd-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pygensvd-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 78885cbeab4568ff8b85383a135ec9f37087edf39ae763194cac4e694f172ee4
MD5 f87b84f26c7da78c0dda5c4bedb82d37
BLAKE2b-256 b01ad5f81f011ebe23656419451dc5a6acbd702340a6247340b3dc4aaade56e4

See more details on using hashes here.

File details

Details for the file pygensvd-0.1.0-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pygensvd-0.1.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a6a40781ebd6fafef50fcb5ead725ed1bd95132b5eebc2d3b1f34a010b378979
MD5 334fd1b1fd349b120dbfc7034cabc2ee
BLAKE2b-256 44982e7692d06e3e1522d554e3cb7793087838f86badbb9e61b3c5bde232f734

See more details on using hashes here.

File details

Details for the file pygensvd-0.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pygensvd-0.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e7db5355116858d55a151c4415a89f974fa13770160da7715ab3823343233fa1
MD5 a63006a838f80932ecba7d9a575e7ff2
BLAKE2b-256 94571417605322b2e4a01cedad660b102fcf402d08c8af19693c6230f6667139

See more details on using hashes here.

File details

Details for the file pygensvd-0.1.0-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pygensvd-0.1.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 d1f7c232cc1a2d1b5caac1e131aa4b81662728c90f431be5aa9a0d114f0484fb
MD5 c120595c9f8d1c1a85948d7ee65b183a
BLAKE2b-256 5df2ac2f5afdcd6feb136eaa81a1a913e52d9d9b733a70a85ea45c98cb6a08e8

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