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.3.tar.gz (22.7 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.3-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: less_squares-0.1.3.tar.gz
  • Upload date:
  • Size: 22.7 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.3.tar.gz
Algorithm Hash digest
SHA256 6ab18aa6892540ad4de457fb6d836f8c4c3799a0e054c2a510246f0b2f766da2
MD5 34cb05d1cd8580c59c6505f0c172ab2f
BLAKE2b-256 056b3ad58d6e88e8d0ce776b1ccc3e5c5c2494b462e862ebbbfc22d504f96ccf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: less_squares-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 22.1 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7009aa5f437ff588ac548c5a2646d1124a1c6bfa651d77ec6a0048d8b95fce4e
MD5 ccf905c7d8a7af43ab74d95280d2b4c6
BLAKE2b-256 0d0a30c63309528205d285976423759d82e0302a17648e9820b9c997814dce37

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