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.8+
  • 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.4.tar.gz (22.6 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.4-py3-none-any.whl (22.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: less_squares-0.1.4.tar.gz
  • Upload date:
  • Size: 22.6 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.4.tar.gz
Algorithm Hash digest
SHA256 4a3d12ffde211691ca6acb425e844699fbedd203365d65f5ab8c909b2824e857
MD5 0dc88ce7dde68a3357765c33d2b070c1
BLAKE2b-256 6c42f5b611a1eef15c94f0424ccd012e989239099fad3ffe7011f10976f3ee74

See more details on using hashes here.

File details

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

File metadata

  • Download URL: less_squares-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 22.0 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 93bd9dd662e775842fcfe8bdb89a42e4447a43cde479aab40f772c3848f01127
MD5 028472e9df08b3699852d3203c73e1a6
BLAKE2b-256 df6713c043d38416d3d37d16706fb9afa734adafbb69a28e2631421e132cbe0b

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