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.1.tar.gz (17.1 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.1-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: less_squares-0.1.1.tar.gz
  • Upload date:
  • Size: 17.1 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.1.tar.gz
Algorithm Hash digest
SHA256 b40fb252ad0157c9ef215ab95e307579b4fcbbe9794bf6be538aa3b09602797d
MD5 8a39d9b1bd45bf38968c9838ba509a8c
BLAKE2b-256 0fc9ffaf8290371d8630819fc4609dc3119a1bdb438ab108eb4e53e966295769

See more details on using hashes here.

File details

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

File metadata

  • Download URL: less_squares-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.9 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 224f355153748c4b8366ad4105ab4f62f56ce045b147267c322f6376e905f420
MD5 ee4c136406e7d5bbdff9d210a048a35d
BLAKE2b-256 1e2cdff1c0ba5f3061604524ff9e4914b7209fa9ca35a797f23058815980bf2c

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