Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
gyrdym committed Jun 19, 2019
1 parent 5a7ca0a commit 773b8f9
Showing 1 changed file with 54 additions and 29 deletions.
83 changes: 54 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,47 @@

- [What is linear algebra](#linear-algebra)
- [What is SIMD](#what-is-simd)
+ [Vectors](#vectors)
- [Vectors](#vectors)
- [A couple of words about the underlying vector architecture](#a-couple-of-words-about-the-underlying-vector-architecture)
- [Vector operations](#vector-operations-examples)
+ [Matrices](#matrices)
- [Matrix operations](#matrix-operations-examples)
- [Vectors sum](#vectors-sum)
- [Vectors subtraction](#vectors-subtraction)
- [Element wise vector by vector multiplication](#element-wise-vector-by-vector-multiplication)
- [Element wise vector by vector division](#element-wise-vector-by-vector-division)
- [Euclidean norm](#euclidean-norm)
- [Manhattan norm](#manhattan-norm)
- [Mean value](#mean-value)
- [Sum of all vector elements](#sum-of-all-vector-elements)
- [Dot product](#dot-product-of-two-vectors)
- [Sum of a vector and a scalar](#sum-of-a-vector-and-a-scalar)
- [Subtraction of a scalar from a vector](#subtraction-of-a-scalar-from-a-vector)
- [Multiplication (scaling) of a vector by a scalar](#multiplication-scaling-of-a-vector-by-a-scalar)
- [Division (scaling) of a vector by a scalar value](#division-scaling-of-a-vector-by-a-scalar-value)
- [Euclidean distance between two vectors](#euclidean-distance-between-two-vectors)
- [Manhattan distance between two vectors](#manhattan-distance-between-two-vectors)
- [Cosine distance between two vectors](#cosine-distance-between-two-vectors)
- [Vector normalization (using Euclidean norm)](#vector-normalization-using-euclidean-norm)
- [Vector normalization (using Manhattan norm)](#vector-normalization-using-manhattan-norm)
- [Vector rescaling (min-max normalization)](#vector-rescaling-min-max-normalization)
- [Matrices](#matrices)
- [Matrix operations](#matrix-operations-examples)
- [Sum of a matrix and another matrix](#sum-of-a-matrix-and-another-matrix)
- [Sum of a matrix and a scalar](#sum-of-a-matrix-and-a-scalar)
- [Multiplication of a matrix and a vector](#multiplication-of-a-matrix-and-a-vector)
- [Multiplication of a matrix and another matrix](#multiplication-of-a-matrix-and-another-matrix)
- [Multiplication of a matrix and a scalar](#multiplication-of-a-matrix-and-a-scalar)
- [Element wise matrices subtraction](#element-wise-matrices-subtraction)
- [Matrix transposition](#matrix-transposition)
- [Matrix row wise reduce](#matrix-row-wise-reduce)
- [Matrix column wise reduce](#matrix-column-wise-reduce)
- [Matrix row wise map](#matrix-row-wise-map)
- [Matrix column wise map](#matrix-column-wise-map)
- [Submatrix](#submatrix-taking-a-lower-dimension-matrix-of-the-current-matrix)
- [Getting max value of the matrix](#getting-max-value-of-the-matrix)
- [Getting min value of the matrix](#getting-min-value-of-the-matrix)
- [Matrix fast map](#matrix-fast-map)
- [Matrix indexing](#matrix-indexing)
- [Add new columns to a matrix](#add-new-columns-to-a-matrix)
- [Contacts](#contacts)

### Linear algebra
Expand Down Expand Up @@ -58,22 +94,20 @@ operations on several operands in parallel, thus element-wise sum of two arrays

#### A couple of words about the underlying vector architecture

    The library contains a high performance SIMD vector class, based on [Float32x4](https://api.dartlang.org/stable/2.1.0/dart-typed_data/Float32x4-class.html) -
    The library contains a high performance SIMD vector class, based on [Float32x4](https://api.dartlang.org/stable/2.2.0/dart-typed_data/Float32x4-class.html) -
[Float32Vector](https://github.com/gyrdym/linalg/blob/master/lib/src/vector/float32/float32_vector.dart).
Most of operations in the vector class are performed in four "threads". This kind of parallelism is reached by special
128-bit processor registers, which are used directly by program code. It is also possible to implement [Float64x2](https://api.dartlang.org/stable/2.1.0/dart-typed_data/Float64x2-class.html)-based
version of vector using existing codebase, but so far there is no need to do so.
128-bit processor registers, which are used directly by program code.

    The class [Float32Vector](https://github.com/gyrdym/linalg/blob/master/lib/src/vector/float32/float32_vector.dart)
    [Float32Vector](https://github.com/gyrdym/linalg/blob/master/lib/src/vector/float32/float32_vector.dart)
is hidden from the library's users. You can create a [Float32Vector](https://github.com/gyrdym/linalg/blob/master/lib/src/vector/float32x4/float32x4_vector.dart)
instance via [Vector](https://github.com/gyrdym/ml_linalg/blob/master/lib/vector.dart) factory (see examples below).

    The vector is absolutely immutable - there is no way to change once created instance. All vector operations lead to
creation of a new vector instance (of course, if the operation is supposed to return `Vector`).

    It's possible to use vector instances as keys for Map, HashMap and similar data structures
and to look up a value by the vector-key, since hash code is not unique for every new instance, it's the same for equal
vectors:
    It's possible to use vector instances as keys for HashMap and similar data structures
and to look up a value by the vector-key, since the hash code is the same for equal vectors:

```dart
import 'package:ml_linalg/vector.dart';
Expand All @@ -83,10 +117,10 @@ final map = HashMap<Vector, bool>();
map[Vector.fromList([1, 2, 3, 4, 5])] = true;
print(map[Vector.fromList([1, 2, 3, 4, 5])]); // true
print(Vector.fromList([1, 2, 3, 4, 5]).hashCode == Vector.fromList([1, 2, 3, 4, 5]).hashCode); // true
```

#### Vector operations examples
At the present moment most common vector operations are implemented:

##### Vectors sum
````Dart
Expand Down Expand Up @@ -271,22 +305,11 @@ At the present moment most common vector operations are implemented:
print(result); // [0.555, 0.222, 0.777, 0.0, 1.0, 0.444]
````

##### Fast map

Performs mapping from one vector to another in efficient way (using simd computations)

````Dart
import 'package:ml_linalg/linalg.dart';
final vector = Vector.fromList([1.0, 2.0, 3.0, 4.0, 5.0]);
final result = vector.fastMap<Float32x4>((Float32x4 element) => element.scale(2.0));
print(result); // [2.0, 4.0, 6.0, 8.0, 10.0]
````

### Matrices

Also, a class for matrix is available. It is based on Float32x4 and Float32Vector types. `Matrix` is immutable as well
as `Vector`.
&nbsp;&nbsp;&nbsp;&nbsp;Along with SIMD vectors, the library presents SIMD-based Matrices. One can use the matrices via
[Matrix factory](https://github.com/gyrdym/ml_linalg/blob/master/lib/matrix.dart). The matrices are immutable as well
as vectors.

#### Matrix operations examples

Expand Down Expand Up @@ -562,10 +585,12 @@ Performs mapping from one matrix to another in efficient way (using simd computa
````

#### Matrix indexing
The library's matrix interface offers `pick` method, that supposes to return a new matrix, consisting of different
segments of a source matrix (like in Pandas dataframe in Python, e.g. `loc` method). It's possible to build a new
matrix from certain columns and vectors and they should not be necessarily subsequent: for example, it is needed to
create a matrix from rows 1, 3, 5 and columns 1 and 3. To do so, it's needed to access the matrix this way:
&nbsp;&nbsp;&nbsp;&nbsp;The library's matrix interface offers `pick` method, that returns a new matrix,
consisting of different segments of a source matrix (like in Pandas dataframe in Python, e.g. `loc` method). It's
possible to build a new matrix from certain columns and vectors and they should not be necessarily subsequent. For
example, one needs to create a matrix from rows 1, 3, 5 and columns 1 and 3. To do so, it's needed to access the
matrix this way:

````Dart
import 'package:ml_linalg/linalg.dart';
import 'package:xrange/zrange.dart';
Expand Down

0 comments on commit 773b8f9

Please sign in to comment.