Skip to main content

A fast O(nm) iterative least squares solution

Project description

less_squares

less_squares is a Python package for efficient and dynamic manipulation of matrices, focusing on operations like updating pseudoinverses, adding or removing rows/columns, and checking matrix properties.

Features

  • Compute and update pseudoinverses dynamically.
  • Add or remove rows/columns without recomputing the entire pseudoinverse.
  • Swap rows/columns or update their values.
  • Check the validity of the pseudoinverse with various modes.
  • Expand matrices with placeholders for future updates.

Installation

Install the package via pip:

pip install less_squares

Usage

Importing and Initialization

from less_squares import LessSquares
import numpy as np

# Initialize with a matrix
matrix = np.random.rand(5, 3)
ls = LessSquares(matrix)

Properties

  • Retrieve the pseudoinverse:
pseudoinverse = ls.pseudo
  • Retrieve the original matrix:
original_matrix = ls.matrix

Methods

Adding and Removing Rows/Columns

  • Add a vector:
vector = np.random.rand(matrix.shape[1])
ls.append(vector, axis=0)  # Add as a new row
  • Remove a row or column:
ls.delete(index=1, axis=0)  # Delete the second row

Updating Values

  • Update a row or column:
updated_vector = np.random.rand(matrix.shape[1])
ls.update(updated_vector, index=2, axis=0)  # Update the third row

Swapping Rows/Columns

  • Swap two rows or columns:
ls.swap_slices(axis=0, index1=0, index2=2)  # Swap the first and third rows

Expanding the Matrix

  • Add a placeholder row or column:
ls.expand(axis=0)  # Add a placeholder row

Validating the Pseudoinverse

  • Check validity:
is_valid = ls.check(mode='fast')  # Quick validity check
max_errors = ls.check(mode='full')  # Detailed error metrics

Example

# Initialize the class with a random matrix
matrix = np.random.rand(4, 3)
ls = LessSquares(matrix)

# Add a new row
new_row = np.random.rand(matrix.shape[1])
ls.append(new_row, axis=0)

# Update a column
new_column = np.random.rand(matrix.shape[0])
ls.update(new_column, index=1, axis=1)

# Check the pseudoinverse
print("Pseudoinverse is valid:", not ls.check(mode='fast'))

Requirements

  • Python 3.7+
  • NumPy

License

This project is licensed under the GNU GPL3 License.

Contributing

Contributions are welcome! Please submit a pull request or open an issue on GitHub.

Fixes for issues with ill-conditioned matrices are in the works, the idea will be to store linearly dependent collumns seperately from the rest of the matrix itself and use the projection matrix to decide if new collumns should be allocated into that.

Author

Christopher D'Arcy

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

less_squares-0.1.2.tar.gz (23.0 kB view details)

Uploaded Source

Built Distribution

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

less_squares-0.1.2-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

Details for the file less_squares-0.1.2.tar.gz.

File metadata

  • Download URL: less_squares-0.1.2.tar.gz
  • Upload date:
  • Size: 23.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for less_squares-0.1.2.tar.gz
Algorithm Hash digest
SHA256 1bbf27a25360ee4e8767163cda306a86944e32cfabf29ec9ef1fcb9343cd4003
MD5 3b7acdbb32c805a52157bd55bb913300
BLAKE2b-256 f59e04e66204d02605a0fd53f7ba073baee374a9b3afaa0bfbcfe7b96f51ffac

See more details on using hashes here.

File details

Details for the file less_squares-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: less_squares-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 22.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for less_squares-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f3f9b03134e8a5123482fe3fdd70c7e9adc30976f7f71981fa10368dfdc643cc
MD5 5db6f8b6b9ee60c435c185be6da42140
BLAKE2b-256 d679206067109f026385ec80cca8bbce0b62aadb063b8543c6c12d2fcdd3c529

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