GithubHelp home page GithubHelp logo

jbrown1618 / vector Goto Github PK

View Code? Open in Web Editor NEW
13.0 2.0 1.0 2.73 MB

A linear algebra library for TypeScript and JavaScript

License: MIT License

TypeScript 99.65% JavaScript 0.35%
linear-algebra-library typescript vector matrix matrix-calculations matrix-multiplication matrix-factorization linear-algebra linear-regression qr-decomposition

vector's Introduction

Vector

A linear algebra library written in TypeScript that focuses on generality, extensibility, and ease of use.

Features

  • Core:
    • Basic manipulation of vectors and matrices
    • Out-of-the-box support for number and ComplexNumber
    • Extensible to support general scalar types
  • Matrix Operations:
    • Matrix determinants
    • Matrix exponentials
    • Elementary row operations
    • Gauss-Jordan elimination
    • Eigenvalue / Eigenvector finding
  • Matrix Factorizations:
    • Cholesky Decomposition
    • LU Decomposition
    • QR Decomposition
    • Singular Value Decomposition
  • Applications:
    • Calculus: Differentiation via finite differences
    • Statistics: Least-Squares Regression for arbitrary model functions
    • Statistics: Principal component analysis
  • Machine learning models
    • Regularized linear regression
    • Logistic Regression
    • Support Vector Machines
  • And more to come!

Using Vector

See our Usage Guide for more on how to use Vector in your project.

Contributing to Vector

See our Contribution Guide for contribution guidelines and coding standards.

Documentation

See the API Documentation

vector's People

Contributors

dependabot[bot] avatar jbrown1618 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

zemiret

vector's Issues

Finish `SparseVector`; implement `SparseMatrix`

Currently, the only complete implementations of Matrix and Vector are the subclasses of ArrayMatrix and ArrayVector. Since we're focusing on extensibility, it would be good to demonstrate alternative implementations, and sparse linear algebra is a good candidate.

Rethink exports

Change index.ts to modify how we export each module. It might be nicer to have a pattern like:

import { NumberVector, NumberMatrix } from '@jbrown/vector/types';
import { determinant } from '@jbrown/vector/algorithms'

Rename fromData

Change builder.fromData to builder.fromArray - it would be much clearer.

Consider restructuring repository.

Could this be multiple repositories? Should applications/algorithms be separate from the core linear algebra data types? What if ML applications are added? Should vector-examples live in the same repo?

Come up with a good pattern for aliases

We want, for example, v.innerProduct(w) to be accessible as v.dot(w). And ideally we wouldn't have to add the overhead of an extra function call.

One issue is that the documentation tool doesn't provide very good output for this:

export function mainFunction() {
  // impl
}

export const alias = mainFunction;

even though it is simple and types well.

Ditch typedoc

We've had issues three different times with unexpected breaking changes, and the generated api site isn't that great anyway.

Expand `MatrixBuilder`

Special named matrices:

  • Hilbert matrix
  • Toeplitz matrix

Complex or generic versions of the existing functions (a generic version could take in any ScalarContainer)

Deploy docs to github pages

Right now, the generated docs are tracked by git, which is not remotely ideal. Since it is generated markdown, the actual github repo can link to it and display it in a nice format - but for that, it has to be tracked.

If we deploy the docs as a static web page, we can take the generated markdown out of git (!).

Accept generic data types in algorithms

Everything is 90% there. We just need:

  • Figure out a way to construct vectors and matrices more generically - possibly by making newFromData() public (so we can just make a new vector/matrix of the type passed in)
  • Add getAdditiveInverse(scalar) and getMultiplicativeInverse(scalar) to ScalarContainer
  • Change instances of Matrix<number> to Matrix<any>

Add benchmarks

For random NxN matrices, save csv files for timings of:

  • A.add(B)
  • A.multiply(B)
  • A.apply(b)
  • inverse(A)
  • solve(A, b)
  • qr(A)
  • lu(A)
  • eig(A)

Write processes to

  • Generate benchmarks
  • Compare current performance with benchmarks

Expand `MatrixProperties`

Tests for particular matrix properties - both exact and approximate
isInvertible()
isSymmetric()
isUpperTriangular()
isLowerTriangular()
isIdentity()
isHermitian()
isOrthogonal()

Add `.scalarDivide` to Matrix and Vector classes

This is not technically a real matrix operation, but it is commonly needed, particularly for scaling. Right now, the approach commonly used is:

const inverse = ops.getMultiplicativeInverse(scaleFactor);
if (inverse === undefined) return someDefault;
return vector.scalarMultiply(inverse);

But this introduces a little bit of numerical error - 10 * (1/3) is less accurate than 10 / 3. We will need to re-implement NumberOperations.divide to get this to work correctly.

In particular, this will make the gauss-jordan equation solver more accurate.

Improve code coverage

  1. Get code coverage up to an acceptable threshold (maybe 90% overall and 80% per file?)
  2. Include coverage report as a precommit hook that will fail if the threshold is not met

Add aliases for commonly used builder functions

It's kind of a nasty API to have the most common function be NumberVector.builder().fromArray([1, 2, 3]). It would be nicer to do v([1, 2, 3]). Likewise, we could replace NumberMatrix.builder().fromArray([[1, 2, 3], [4, 5, 6]]) with M([[1, 2, 3], [4, 5, 6]]).

Add testing utilities

Consistent implementations for exact/approximate vector/matrix comparison would be nice.

Cholesky Decomposition is slow

The current implementation of the cholesky decomposition involves lots of copying, like L = L.set(i, j, value). The whole thing would be a little bit more efficient if we operated on a S[][] instead of a Matrix<S>.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.