vectorgebra


Namevectorgebra JSON
Version 3.2.0 PyPI version JSON
download
home_pageNone
SummaryA numerical methods tool for python, in python.
upload_time2024-06-21 21:53:08
maintainerNone
docs_urlNone
authorAhmet Erdem
requires_python>=3.9
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Vectorgebra

A numerical methods tool for python, in python.

There are 7 main subclasses; Vector, Matrix, Tensor, Graph, Complex, Infinity, Undefined.
And also there are functions, constants and exception classes. 
Each section is explained below.

## Project details

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

_pip install vectorgebra_

https://pypi.org/project/vectorgebra/

[Github](https://github.com/ahmeterdem1/Vector)

A C++ remake of this library is currently being developed at [here](https://github.com/ahmeterdem1/Vector_cpp).

Tutorials for this library can be found at [here](https://github.com/ahmeterdem1/examples).

### What can be done with Vectorgebra?

[Here](https://github.com/ahmeterdem1/MLgebra) is a cool little project
I created with Vectorgebra. I want this library to be applicable to
more and more bigger projects as scale. And this was a good test to it.
Creating and training an ML model requires both floating point precision
and good handling of high dimensional tensors.

### Update notes on 3.2.0

LU decomposition is now added to Matrix class.

"lu" method is added to .inverse() method of the
Matrix class. It is by far the fastest method. It is
measured to be around 2 times faster than the Gauss-Jordan
method on 20x20 matrices.

.echelon() method is fixed for non-square matrices. In the
old versions, non-square matrices resulted in indexing
errors whilst row reduction. This is now fixed and the method
works properly for both square and non-square matrices.

Shorter algorithms are reduced to one-liners to speed them up.


## Vectorgebra.Vector

Includes basic and some sophisticated operations on vectors.

Addition, multiplication subtraction, division and operations alike are 
implemented as overloads. Comparison operators compare the length of the
vectors. Only exception is _==_ which returns True if and only if all the
terms of the vectors are equal.

### Vector Functions

You can pass functions as elements to Vector objects. If you chose to create
vector functions with this method, all elements of the vector must be a
function and must accept the same amount of arguments that have no default
values. Currently basic arithmetic operations are defined for vector functions.
We can say this feature is yet experimental.

Methods are listed below.

### _Vectorgebra.Vector_.dot(v)

Returns the dot product of self with v.

### _Vectorgebra.Vector_.append(v)

Appends the argument to the vector. Returns the new vector. Argument
can be int, float or Vector.

### _Vectorgebra.Vector_.copy()

Returns the copy of the vector.

### _Vectorgebra.Vector_.pop(ord)

Functions exactly the same as .pop() for the list class. If left blank,
pops the last element and returns it. If specified, pops the intended
element and returns it.

### _Vectorgebra.Vector_.length()

Returns the length of self.

### _Vectorgebra.Vector_.proj(v)

Projects self onto v and returns the resulting vector. Due to the 
division included, may result in inaccurate values that should have
been zero. However, these values are very close to zero and are of
magnitude 10<sup>-17</sup>. This situation is important for the method
Vector.spanify().

### _Vectorgebra.Vector_.unit()

Returns the unit vector.

### Vectorgebra.Vector.spanify(*args)

Applies Gram-Schmidt process to the given list of vectors. Returns the
list of resulting vectors. May have inaccuracies explained for Vector.dot()
method.

### Vectorgebra.Vector.does_span(*args)

Returns True if the given list of vectors span the R<sup>n</sup> space
where n is the number of vectors. Returns False otherwise. Eliminates
the possible error from Vector.spanify() method. Therefore, this method
will work just fine regardless the errors from divisions.

### Vectorgebra.Vector.randVint(dim , a, b, decimal=False)

Returns _dim_ dimensional vector which has its elements randomly selected
as integers within the interval (a, b). If decimal is true, generated contents
are decimal objects.

### Vectorgebra.Vector.randVfloat(dim, a, b, decimal=False)

Returns _dim_ dimensional vector which has its elements randomly selected
as floats within the interval (a, b). If decimal is true, generated contents
are decimal objects.

### Vectorgebra.Vector.randVbool(dim, decimal=False)

Returns _dim_ dimensional vector which has its elements randomly selected
as booleans. If decimal is true, generated contents are decimal objects.

### Vectorgebra.Vector.randVgauss(dim, mu, sigma, decimal=False)

Returns _dim_ dimensional vector which has its elements randomly selected
on gaussian curve defined by mu and sigma. Uses _random.gauss_ internally.
Therefore, limitations of this function should be kept in mind. If decimal 
is true, generated contents are decimal objects.

### Vectorgebra.Vector.determinant(*args)

Returns the determinant of the matrix which has rows given as vectors in
*args. This method is not intended for casual use. It is a background
tool for cross product and the determinant method for Matrix class.

### Vectorgebra.Vector.cross(*args)

Returns the cross product of the vectors given in *args.

### Vectorgebra.Vector.outer(v, w)

Returns the outer product of Vectors v and w. Return type is therefore
a Matrix.

### _Vectorgebra.Vector_.cumsum()

Returns the cumulative sum.

### Vectorgebra.Vector.zero(dim)

Returns _dim_ dimensional zero vector.

### Vectorgebra.Vector.one(dim)

Returns _dim_ dimensional all ones vector.

### _Vectorgebra.Vector_.reshape(a, b)

Returns the reshaped matrix.

### _Vectorgebra.Vector_.rotate(i, j, angle, resolution: int = 15)

Rotates the vector, self, around axes "i" and "j" by "angle". 
"resolution" argument is passed to cos() and sin(). Rotation
is done via Givens rotation matrix.

### _Vectorgebra.Vector_.softmax(resolution=15)

Applies softmax operation to self and returns it. "resolution" is passed
to e() function internally.

### _Vectorgebra.Vector_.minmax()

Applies MinMax operation to self and returns it.

### _Vectorgebra.Vector_.relu(leak=0, cutoff=0)

Maps self with ReLU function and returns the resultant vector. Put a
non-zero leak for leaky ReLU. You can also implement a cutoff for the
positive side of the function.

### _Vectorgebra.Vector_.sig(a=1, cutoff=None)

Applies the sigmoid to self and returns the resultant vector. "a" is the
coefficient of x, you can implement a cutoff which acts as a radius. Above
+cutoff will return 1, below -cutoff will return 0.

### Type conversions

.toInt(), .toFloat(), .toBool(), .toDecimal().

### _Vectorgebra.Vector_.map(f)

Maps the elements of the self according to the function "f".

### _Vectorgebra.Vector_.filter(f)

Filters the elements of self according to the function "f".

### _Vectorgebra.Vector_.sort(reverse=False)

Sorts the vector. This function uses built in sort. "reverse" argument is
directly passed into it.

### _Vectorgebra.Vector_.avg()

Returns the average of all numbers in self.

<hr>

## Vectorgebra.Matrix

Includes basic operations for matrices.

Basic operations like addition, multiplication subtraction, division
are implemented as overloads. Only comparison operator implemented is
_==_ which returns true if and only if all the elements of the matrices
are equal.

"pow" method accepts the parameter "decimal".

Methods are listed below.

### _Vectorgebra.Matrix_.determinant(choice="echelon")

Returns the determinant of the matrix m. Two choices are available currently;
echelon, analytic. Default is echelon.

### _Vectorgebra.Matrix_.append(arg)

Appends arg as a new row to self. Only accepts vectors as arguments.

### _Vectorgebra.Matrix_.copy()

Returns the copy of the matrix.

### _Vectorgebra.Matrix_.pop(ord)

Functions exactly the same as .pop() in list class. If left blank, pops
the last row and returns it. If specified, pops the row in the given 
order and returns it.

### _Vectorgebra.Matrix_.transpose()

Returns the transpose matrix of self

### _Vectorgebra.Matrix_.conjugate()

Returns the complex conjugate of the self.

### _Vectorgebra.Matrix_.normalize()

Divides self with its determinant.

### _Vectorgebra.Matrix_.hconj()

Returns the Hermitian conjugate of self.

### _Vectorgebra.Matrix_.norm(resolution: int = 15, decimal=False)

Returns the Frobenius norm of self. Utilizes the eigenvalue function.
Parameters are directly passed to eigenvalue function.

### _Vectorgebra.Matrix_.inverse(method="iteraitve", resolution=10, lowlimit=0.0000000001, highlimit=100000, decimal=False)

Returns the inverse matrix of self. Returns None if not invertible.
method can ben "analytic", "gauss", "neumann" or "iterative". Default is iterative
which uses Newton's method for matrix inversion. Resolution is the number
of iterations. lowlimit and highlimit are only for gauss method. They control
the "resolution" of multiplication and divisions. LU method only uses the decimal
choice. See the source code for a better inside look.

Neumann will only work for the right conditioned matrices (see [here](https://en.wikipedia.org/wiki/Matrix_norm)). Neumann only uses
resolution parameter.

LU decomposition is the fastest method amongst all.

### Vectorgebra.Matrix.identity(dim, decimal=False)

Returns _dimxdim_ dimensional identity matrix. If decimal is true, generated 
contents are decimal objects.

### Vectorgebra.Matrix.zero(a, b, decimal=False)

Returns _axb_ dimensional all 0 matrix. If decimal is true, generated 
contents are decimal objects.

### Vectorgebra.Matrix.one(a, b, decimal=False)

Returns _axb_ dimensional all 1 matrix. If decimal is true, generated 
contents are decimal objects.

### Vectorgebra.Matrix.randMint(m, n, a, b, decimal=False)

Returns _mxn_ matrix of random integers selected from the interval (a, b).
If decimal is true, generated contents are decimal objects.

### Vectorgebra.Matrix.randMfloat(m, n, a, b, decimal=False)

Returns _mxn_ matrix of random floats selected from the interval (a, b).
If decimal is true, generated contents are decimal objects.

### Vectorgebra.Matrix.randMbool(m, n, decimal=False)

Returns _mxn_ matrix of random booleans. If decimal is true, generated 
contents are decimal objects.

### Vectorgebra.Matrix.randMgauss(m, n, mu, sigma, decimal=False)

Returns _mxn_ matrix of random values on the gaussian curve described by mu
and sigma. If decimal is true, generated contents are decimal objects. Beware
of the limitations of _random.gauss_ for this method.

### _Vectorgebra.Matrix_.echelon()

Returns reduced row echelon form of self. Also does reorganization on
rows and multiplies one of them by -1 every 2 reorganization. This is
for the determinant to remain unchanged.

### Vectorgebra.Matrix.cramer(a, number)

Applies Cramers rule to the equation system represented by the matrix _a_.
_number_ indicates which variable to calculate.

### _Vectorgebra.Matrix_.cumsum()

Returns the cumulative sum.

### _Vectorgebra.Matrix_.reshape(*args)

Returns the reshaped matrix/vector. If the return is a matrix,
makes a call to the vectors reshape.

### _Vectorgebra.Matrix_.eigenvalue(resolution: int)

Calculates the eigenvalues of self and returns a list of them.
This function cannot calculate complex valued eigenvalues. So
if there are any, there will be incorrect numbers in the returned
list instead of the complex ones.

The underlying algorithm is QR decomposition and iteration. Resolution
is the number of iterations. Default is 10.

### _Vectorgebra.Matrix_.lu(decimal: bool = False)

Returns a tuple of L and U matrices, in order, which are the respective
LU decompositions of the self. This method does not check for PA = LU
cases, blindly applies the decomposition. Returned L and U matrices may
multiply to not A, but possibly a PA matrix.

### _Vectorgebra.Matrix_.qr()

Applies QR decomposition to self and returns the tuple (Q, R). The algorithm
just uses .spanify() from Vector class. If the columns of self do not consist
of independent vectors, returns matrices of zeroes for both Q and R. This is to
prevent errors that may have otherwise risen from written code.

### _Vectorgebra.Matrix_.cholesky()

Applies Cholesky decomposition to self, and returns the L matrix. Applied algorithm
is textbook [Cholesky–Banachiewicz](https://en.wikipedia.org/wiki/Cholesky_decomposition) algorithm.

### _Vectorgebra.Matrix_.get_diagonal()

Returns the diagonal Matrix such that A = L + D + U.

### _Vectorgebra.Matrix_.get_upper()

Returns the upper triangular Matrix such that A = L + D + U.

### _Vectorgebra.Matrix_.get_lower()

Returns the lower triangular Matrix such that A = L + D + U.

### Vectorgebra.Matrix.givens(dim, i, j, angle, resolution: int = 15)

Returns the Givens rotation matrix that applies rotation around axes
"i"-"j" by "angle". Matrix is dimxdim dimensional. "resolution" is
passed to cos() and sin()

### Vectorgebra.Matrix.frobenius_product(a, b)

Returns the Frobenius product of matrix a and matrix b.

### _Vectorgebra.Matrix_.trace()

Returns the trace of self.

### _Vectorgebra.Matrix_.diagonals()

Returns the list of diagonals.

### _Vectorgebra.Matrix_.diagonal_mul()

Returns the multiplication of diagonals.

### _Vectorgebra.Matrix_.gauss_seidel(b: Vector, initial=None, resolution=15, decimal=False)

Applies Gauss-Seidel method to the equation self * x = b. Returns the resultant x Vector.
If "initial" left unchanged, code creates an initial guess by default. This may not converge
though. "resolution" is the number of iterations. "decimal" argument is also passed to called
functions inside this method. Same for resolution.

### _Vectorgebra.Matrix_.least_squares(b, *args)

Accepts every argument that .inverse() accepts. Solves the equation _self * x = b_ for x.
Every argument except b is passed to .inverse().

### _Vectorgebra.Matrix_.jacobi_solve(b, resolution: int = 15)

Solves the equation self * x = b for x via Jacobi algorithm. "resolution" is the
number of iterations. Returns the x vector.

### Type conversions

.toInt(), .toFloat(), .toBool(), .toDecimal().

### _Vectorgebra.Matrix_.map(f)

Maps the elements of self according to the function "f".

### _Vectorgebra.Matrix_.filter(f)

Filters the elements of self according to the function "f".

Attention! This method is very prone to DimensionError. Be sure
that for each row, after the filtering, the same amount of elements
get through.

### _Vectorgebra.Matrix_.submatrix(a, b, c, d)

Slices the self by rows a:b, by columns c:d and returns the resulting
matrix.

### _Vectorgebra.Matrix_.avg()

Returns the average of all elements in self.

<hr>

## Vectorgebra.Tensor

A Tensor, is a container which contains either matrices or tensors.
Each element that it contains, has one less dimension factor than
the parent. This wrapper therefore creates a recursive data structure
of, eventually, vectorgebra.Matrix. Matrix is the last recursive step
of this container.

### _Vectorgebra.Tensor_.dot(arg)

Returns the dot product of self and arg. arg must be another Tensor.
Dimensions have to match.

### _Vectorgebra.Tensor_.append(arg)

Appends the Tensor arg to self. Dimensions need to be matching.

### _Vectorgebra.Tensor_.pop(ord=-1)

Pops the indexed element from the top most layer of the Tensor.

### _Vectorgebra.Tensor_.copy()

Returns the deep copy of self.

### Vectorgebra.Tensor.zero(dim, decimal=False)

Returns an all zero Tensor with the dimensions specified in "dim".

### Vectorgebra.Tensor.one(dim, decimal=False)

Returns an all one Tensor with the dimensions specified in "dim".

### Vectorgebra.Tensor.identity(dim, decimal=False)

Returns the identity Tensor with the dimensions specified in "dim".
The generated identity here has only ones in the all-dimensional
diagonal. The filled diagonal is always a "line", not "plane", etc.

### _Vectorgebra.Tensor_.map(f)

Maps the self with function f. Returns the Tensor filled with resultant
values.

### _Vectorgebra.Tensor_.avg()

Returns the average of all numbers in self.

### _Vectorgebra.Tensor_.flatten()

Flattens the Tensor. If more than 2-dimensional, returns a Matrix filled
with average values of higher dimensional parts in the original Tensor.
If not, just returns a deep copy of self.

<hr>

## Vectorgebra.Graph

The class for graphs. These can be constructed via matrices or manually. Can be both
directed or undirected.

Constructor accepts 5 arguments; vertices, edges, weights, matrix, directed. "directed"
is a bool and False by default. If "matrix" is given, "edges" and "weights" are ignored.
If given, "vertices" is not ignored. If left blank, vertices are named numerically. Matrix
must be a square, obviously. 

If manually constructed; "vertices" is the list (or tuple) of vertices names. Items can be
anything that is hashable. "edges" is a list (or tuple) of length-2 lists (or tuples). Both
items must be valid names of vertices, also named in the "vertices" argument. Weights to 
these edges are passed in-order from "weights" list if is not None. If "weights" is left blank,
1 is assigned as weight to given edges. The adjacency matrix is always generated.

Related data can be accessed through; self.vertices, self.edges, self.weights, self.matrix, 
self.directed.

Print method is overloaded. Printing is much better than matrices even though it kind of prints
the adjacency matrix.

### _Vectorgebra.Graph_.addedge(label, weight=1)

Add an edge with vertex pair "label". Weight is 1 by default. Returns self.

### _Vectorgebra.Graph_.popedge(label)

Pops the edge and returns it defined by "label". If there is more than one, pops the first instance.

### _Vectorgebra.Graph_.addvertex(v)

Adds a vertex named "v". Adjacency matrix is regenerated here.

### _Vectorgebra.Graph_.popvertex(v)

Removes the vertex named "v" and returns it. Removes all edges connected to vertex "v". Adjacency
matrix is naturally regenerated.

### _Vectorgebra.Graph_.getdegree(vertex)

Returns the degree of vertex.

### _Vectorgebra.Graph_.getindegree(vertex)

Returns the in-degree of vertex if the graph is directed. Otherwise just returns the undirected degree.

### _Vectorgebra.Graph_.getoutdegree(vertex)

Returns the out-degree of vertex if the graph is directed. Otherwise just returns the undirected degree.

### _Vectorgebra.Graph_.getdegrees()

Returns a dictionary of degrees and vertices. Keys are degrees, values are corresponding vertices' labels.

### _Vectorgebra.Graph_.getweight(label)

Returns the weight of the edge given via label.

### Vectorgebra.Graph.isIsomorphic(g, h)

Returns True if g and h are isomorphic, False otherwise. g and h must be Graphs.

### _Vectorgebra.Graph_.isEuler()

Returns True if self is an Euler graph, False otherwise.

<hr>

## Constants

Pi, e, log2(e), log2(10), ln(2), sqrt(2), sqrt(pi), sqrt(2 * pi).

## Functions

### Vectorgebra.Range(low, high, step)

A lazy implementation of range. There is indeed no range. Just a loop with
yield statement. Almost as fast as the built-in range.

### Vectorgebra.abs(arg)

Returns the absolute value of the argument.

### Vectorgebra.sqrt(arg, resolution: int = 10)

A square root implementation that uses Newton's method. You may choose the 
resolution, but any change is not needed there. Pretty much at the same
accuracy as the built-in math.sqrt(). Accepts negative numbers too.

### Vectorgebra.cumsum(arg: list or float)

Returns the cumulative sum of the iterable.

### Vectorgebra.__cumdiv(x, power: int)

Calculates x<sup>n</sup> / power!. This is used to calculate Taylor series
without data loss (at least minimal data loss).

### Vectorgebra.e(exponent, resolution: int)

Calculates e<sup>exponent</sup>. resolution is passed as _power_ to the
__cumdiv(). It will then define the maximal power of the power series
implementation, therefore is a resolution.

### Logarithms

There are 4 distinct logarithm functions: log2, ln, log10, log. Each have
the arguments x and resolution. "resolution" is the number of iterations
and by default is set to 15. "log" function also takes a "base" parameter.

All logarithms are calculated based on "log2" function. "ln" and "log10"
use the related constants instead of recalculating the same value over
and over again.

### Vectorgebra.sigmoid(x, a=1)

Returns the sigmoid functions value at x, where a is the coefficient of x.

### Vectorgebra.ReLU(x, leak=0, cutoff=0)

Applies rectified linear unit with leak and cutoff given to x.

### Vectorgebra.Sum(f, a, b, step=0.01, control: bool=False, limit=0.000001)

Returns the sum of f(x) from a to b. step is the step for Range. If control is true,
stops the sum when the absolute value of the derivative drops under "limit".

### Vectorgebra.mode(data)

Returns the mode of the data. Tuples, lists, vectors and matrices are
accepted.

### Vectorgebra.mean(data)

Calculates the mean of data. "data" must be a one dimensional iterable.

### Vectorgebra.median(data)

Returns the median of data. "data" must be a one dimensional iterable.

### Vectorgebra.expectation(values, probabilities, moment: int = 1)

"values" and "probabilities" are one dimensional iterables and their lengths must be
equal. There is no value checking for the probabilities. If they sum up
to more than 1 or have negative values, it is up to the user to check 
that. "moment" is the power of "values". Returns the expectation value of
given data.

### Vectorgebra.variance(values, probabilities)

Same constraints as "expectation" apply here. Returns the variance of the given data.

### Vectorgebra.sd(values, probabilities)

Same constraints as "variance" apply here. Returns the standard deviation of the
given data.

### Vectorgebra.maximum(dataset)

Returns the maximum value of dataset. Dataset can be anywhere from tuples to Matrices.

### Vectorgebra.minimum(dataset)

Returns the minimum value of dataset. Dataset can be anywhere from tuples to Matrices.

### Vectorgebra.unique(data)

Returns a dictionary that has unique elements as keys and counts of these elements appearances
in "data" as values. "data" must be an iterable.

### Vectorgebra.isAllUnique(data)

Returns True if all elements in data are unique. "data" must be an iterable.

### Vectorgebra.permutate(sample)

Returns all permutations of "sample" in a list. Only unique elements are counted in "sample".
This function utilizes helper function "Vectorgebra.__permutate()". "sample" must be an iterable.

### Vectorgebra.factorial(x: int)

Calculates the factorial with recursion. Default argument is 1.

### Vectorgebra.permutation(x: int, y: int)

Calculates the _y_ permutations of _x_ elements. Does not utilize
the factorial function. Indeed, uses loops to calculate the aimed
value more efficiently.

### Vectorgebra.combination(x: int, y: int)

Calculates _y_ combinations of _x_ elements. Again, this does not
utilize the factorial function.

### Vectorgebra.multinomial(n: int, *args)

Calculates the multinomial coefficient with n elements, with partitions
described in "args". Does not utilize the factorial.

### Vectorgebra.binomial(n: int, k: int, p: float)

Calculates the probability according to the binomial distribution. n is
the maximum number of events, k is the events that p describes, p is the
probability of the "event" happening.

### Vectorgebra.geometrical(n: int, p: float)

Calculates the probability according to the geometric distribution. n is
the number of total events. p is the probability that the event happens.

### Vectorgebra.poisson(k, l)

Calculates the probability according to the Poisson formula. l is the
lambda factor. k is the "variable" on the whatever system this function
is used to describe.

### Vectorgebra.normal(x, resolution: int = 15)

Calculates the _normal_ gaussian formula given x. "resolution" is directly
passed to the e() function.

### Vectorgebra.gaussian(x, mean, sigma, resolution: int = 15)

Calculates the gaussian given the parameters. "resolution" is directly 
passed to the e() function.

### Vectorgebra.laplace(x, sigma, resolution: int = 15)

Calculates the Laplace distribution given the parameters. "resolution" is directly 
passed to the e() function.

### Vectorgebra.linear_fit(x, y, rate=0.01, iterations: int = 15)

Returns the b0 and b1 constants for the linear regression of the given data.
x and y must be one dimensional iterables and their lengths must be equal.
"rate" is the learning rate. "iterations" is the total number of iterations
that this functions going to update the coefficients.

### Vectorgebra.general_fit(x, y, rate=0.0000002, iterations: int = 15, degree: int = 1)

Calculates the coefficients for at _degree_ polynomial regression. 
Default _rate_ argument is much much lower because otherwise result 
easily blows up. Returns the coefficients starting from the zeroth 
degree as a Vector object. 

Internally, x and y sets are converted to Vectors if they were not,
so it is faster to initialize them as Vectors.

### Vectorgebra.kmeans(dataset, k=2, iterations=15, a = 0, b = 10)

Applies the K-means algorithm on the dataset. "k" is the number of 
points to assign data clusters. "iterations" is the number of iterations
that the algorithm applies. Dataset must be non-empty. Each row of 
dataset is converted to Vectors internally. Predefining them as
such would make the function faster. 

Every element of dataset must be of the same type whether they are
Vectors or not. Type-checking is based on the first row of the dataset.

Returns a 2-element tuple. First element is a list of Vectors which
point to the cluster centers. Second element is a list of lists of Vectors
which consist of the initial data. This list has the same length as
number of generated cluster centers. Each internal list corresponds
to the same indexed center point. So this data is grouped by cluster
centers.

Initial guesses are random points whose components are random floats
between a and b.

This function does not have decimal support yet.

### Trigonometrics

All are of the format Vectorgebra.name(x, resolution: int).
Calculates the value of the named trigonometric function via Taylor
series. Again, resolution is passed as _power_ to __cumdiv().

Inverse trigonometrics(arcsin, arccos) do not use the helper function 
__cumdiv().

### Vectorgebra.__find(...)

This is a helper function for Math.solve(). Arguments are the same.
Returns the first zero that it finds and saves it to memory.

### Vectorgebra.solve(f, low, high, search_step, res)

Finds zeroes of function f. It may not be able to find all zeroes,
but is pretty precise when it finds some. If the functions derivative
large around its zero, then you should increase resolution to do a
better search.

Retrieves found zeroes from the memory, then clears it. Calling 
multiple instances of this function at the same time will result
in errors because of this global memory usage.

This function is optimized for polynomials. It doesn't matter how many
zeroes they have since this function utilizes a thread pool. This solver
is slow when utilized with Taylor series based functions.

There is an obvious solution to this speed problem though. Just put 
expanded form as the argument. Not the implicit function form.

Exits the main loop if the maximum thread count is reached. This can be used as
a limiter when given b=Infinity(). However, the thread count limit is
most likely 4096.

### Vectorgebra.derivative(f, x, h)

Takes the derivative of f around x with h = _h_. There is no algorithm 
here. It just calculates the derivative.

### Vectorgebra.integrate(f, a, b, delta)

Calculates the integral of f(x) in the interval (a, b) with the specified
delta. Default for delta is 0.01. Uses the midpoint rule.

### Vectorgebra.__mul(...)

A helper function to Vectorgebra.matmul(). Threads inside matmul call this
function.

### Vectorgebra.matmul(m1, m2, max=10)

Threaded matrix multiplication. Its speed depends on dimensions of given
matrices. Let it be axb and bxc, (a - b) is proportional to this functions
speed. Worst case scenario is square matrices. 44x44 (On CPython) is limit 
for this function to be faster than the normal version of matrix multiplication.

If b > a, normally this function gets even more slower. But there is a
way around. Let it be b > a;

A * B = C

B<sup>T</sup> * A<sup>T</sup> = C<sup>T</sup>

After taking the transposes, we get a > b again. All we have to do is 
to calculate the matrix C<sup>T</sup> instead of C directly then to
calculate the transpose of it.

(I didn't add this function to Matrix class because I have more plans on it.)

### Vectorgebra.findsol(f, x, resolution)

Calculates a single solution of f with Newton's method. x is the starting
guess. resolution is the number of iterations.

### Vectorgebra.Complex 

This is the complex number class. It has + - / * overloaded.

#### _Vectorgebra.Complex_.conjugate()

Returns the complex conjugate of self.

#### _Vectorgebra.Complex_.length()

Returns the length of self, with treating it as a vector.

#### _Vectorgebra.Complex_.unit()

Treats the complex number as a vector and returns the unit vector.

#### Vectorgebra.Complex.sqrt(arg, resolution: int = 200)

Calculates the square root of the complex number _arg_ and returns it
again, as a complex number. Resolution argument is only passed to arcsin
since it is the only limiting factor for this functions accuracy. Has an
average of 1 degree of error as angle. You may still increase the resolution.
But reaching less than half a degree of error requires for it to be at 
least 600.

The used algorithm calculates the unit vector as e<sup>i*x</sup>. Then halves
the degree, x. Returns the resultant vector at the proper length.

#### _Vectorgebra.Complex_.range(lowreal, highreal, lowimg, highimg, step1, step2)

Creates a complex number range, ranging from complex(lowreal, lowimg)
to complex(highreal, highimg). Steps are 1 by default. Again this is 
a lazy implementation.

#### _Vectorgebra.Complex_.inverse()

Returns 1 / self. This is used in division. If divisor is complex,
then this function is applied with multiplication to get the result.

#### _Vectorgebra.Complex_.rotate(angle: int or float)

Rotates self by angle.

#### _Vectorgebra.Complex_.rotationFactor(angle: int or float)

Returns e<sup>i*angle</sup> as a complex number.

<hr>

### Vectorgebra.Infinity

The class of infinities. When initialized, takes one argument describing its sign.
If "True", the infinity is positive (which is the default). If "False", the infinity
is negative.

Logical and mathematical operations are all overloaded. Operations may return "Undefined".
This is a special class that has every mathematical and logical operation overloaded.

### Vectorgebra.Undefined

A special class that corresponds to "undefined" in mathematics.

## Exceptions

### Vectorgebra.DimensionError

Anything related to dimensions of vectors and matrices. Raised in 
Vector class when dimensions of operands don't match or 0 is given
as a dimension to random vector generating functions.

This error is raised in Matrix class when non-square matrices are
passed into inverse calculating functions.

**DimensionError(1) has been changed to RangeError, but is still
in the code.**

### Vectorgebra.ArgTypeError

Anything related to types of arguments. Can take in a str argument
flagged as "hint".

### Vectorgebra.RangeError

Raised when given arguments are out of required range.

### Vectorgebra.AmountError

Raised when the amount of arguments in a function is wrong.


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "vectorgebra",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "Ahmet Erdem",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/32/be/d8d00fe29a82e348c97aa1be1dc06bb11bbd4d1a3931ace4bed3d93e6f61/vectorgebra-3.2.0.tar.gz",
    "platform": null,
    "description": "# Vectorgebra\n\nA numerical methods tool for python, in python.\n\nThere are 7 main subclasses; Vector, Matrix, Tensor, Graph, Complex, Infinity, Undefined.\nAnd also there are functions, constants and exception classes. \nEach section is explained below.\n\n## Project details\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n_pip install vectorgebra_\n\nhttps://pypi.org/project/vectorgebra/\n\n[Github](https://github.com/ahmeterdem1/Vector)\n\nA C++ remake of this library is currently being developed at [here](https://github.com/ahmeterdem1/Vector_cpp).\n\nTutorials for this library can be found at [here](https://github.com/ahmeterdem1/examples).\n\n### What can be done with Vectorgebra?\n\n[Here](https://github.com/ahmeterdem1/MLgebra) is a cool little project\nI created with Vectorgebra. I want this library to be applicable to\nmore and more bigger projects as scale. And this was a good test to it.\nCreating and training an ML model requires both floating point precision\nand good handling of high dimensional tensors.\n\n### Update notes on 3.2.0\n\nLU decomposition is now added to Matrix class.\n\n\"lu\" method is added to .inverse() method of the\nMatrix class. It is by far the fastest method. It is\nmeasured to be around 2 times faster than the Gauss-Jordan\nmethod on 20x20 matrices.\n\n.echelon() method is fixed for non-square matrices. In the\nold versions, non-square matrices resulted in indexing\nerrors whilst row reduction. This is now fixed and the method\nworks properly for both square and non-square matrices.\n\nShorter algorithms are reduced to one-liners to speed them up.\n\n\n## Vectorgebra.Vector\n\nIncludes basic and some sophisticated operations on vectors.\n\nAddition, multiplication subtraction, division and operations alike are \nimplemented as overloads. Comparison operators compare the length of the\nvectors. Only exception is _==_ which returns True if and only if all the\nterms of the vectors are equal.\n\n### Vector Functions\n\nYou can pass functions as elements to Vector objects. If you chose to create\nvector functions with this method, all elements of the vector must be a\nfunction and must accept the same amount of arguments that have no default\nvalues. Currently basic arithmetic operations are defined for vector functions.\nWe can say this feature is yet experimental.\n\nMethods are listed below.\n\n### _Vectorgebra.Vector_.dot(v)\n\nReturns the dot product of self with v.\n\n### _Vectorgebra.Vector_.append(v)\n\nAppends the argument to the vector. Returns the new vector. Argument\ncan be int, float or Vector.\n\n### _Vectorgebra.Vector_.copy()\n\nReturns the copy of the vector.\n\n### _Vectorgebra.Vector_.pop(ord)\n\nFunctions exactly the same as .pop() for the list class. If left blank,\npops the last element and returns it. If specified, pops the intended\nelement and returns it.\n\n### _Vectorgebra.Vector_.length()\n\nReturns the length of self.\n\n### _Vectorgebra.Vector_.proj(v)\n\nProjects self onto v and returns the resulting vector. Due to the \ndivision included, may result in inaccurate values that should have\nbeen zero. However, these values are very close to zero and are of\nmagnitude 10<sup>-17</sup>. This situation is important for the method\nVector.spanify().\n\n### _Vectorgebra.Vector_.unit()\n\nReturns the unit vector.\n\n### Vectorgebra.Vector.spanify(*args)\n\nApplies Gram-Schmidt process to the given list of vectors. Returns the\nlist of resulting vectors. May have inaccuracies explained for Vector.dot()\nmethod.\n\n### Vectorgebra.Vector.does_span(*args)\n\nReturns True if the given list of vectors span the R<sup>n</sup> space\nwhere n is the number of vectors. Returns False otherwise. Eliminates\nthe possible error from Vector.spanify() method. Therefore, this method\nwill work just fine regardless the errors from divisions.\n\n### Vectorgebra.Vector.randVint(dim , a, b, decimal=False)\n\nReturns _dim_ dimensional vector which has its elements randomly selected\nas integers within the interval (a, b). If decimal is true, generated contents\nare decimal objects.\n\n### Vectorgebra.Vector.randVfloat(dim, a, b, decimal=False)\n\nReturns _dim_ dimensional vector which has its elements randomly selected\nas floats within the interval (a, b). If decimal is true, generated contents\nare decimal objects.\n\n### Vectorgebra.Vector.randVbool(dim, decimal=False)\n\nReturns _dim_ dimensional vector which has its elements randomly selected\nas booleans. If decimal is true, generated contents are decimal objects.\n\n### Vectorgebra.Vector.randVgauss(dim, mu, sigma, decimal=False)\n\nReturns _dim_ dimensional vector which has its elements randomly selected\non gaussian curve defined by mu and sigma. Uses _random.gauss_ internally.\nTherefore, limitations of this function should be kept in mind. If decimal \nis true, generated contents are decimal objects.\n\n### Vectorgebra.Vector.determinant(*args)\n\nReturns the determinant of the matrix which has rows given as vectors in\n*args. This method is not intended for casual use. It is a background\ntool for cross product and the determinant method for Matrix class.\n\n### Vectorgebra.Vector.cross(*args)\n\nReturns the cross product of the vectors given in *args.\n\n### Vectorgebra.Vector.outer(v, w)\n\nReturns the outer product of Vectors v and w. Return type is therefore\na Matrix.\n\n### _Vectorgebra.Vector_.cumsum()\n\nReturns the cumulative sum.\n\n### Vectorgebra.Vector.zero(dim)\n\nReturns _dim_ dimensional zero vector.\n\n### Vectorgebra.Vector.one(dim)\n\nReturns _dim_ dimensional all ones vector.\n\n### _Vectorgebra.Vector_.reshape(a, b)\n\nReturns the reshaped matrix.\n\n### _Vectorgebra.Vector_.rotate(i, j, angle, resolution: int = 15)\n\nRotates the vector, self, around axes \"i\" and \"j\" by \"angle\". \n\"resolution\" argument is passed to cos() and sin(). Rotation\nis done via Givens rotation matrix.\n\n### _Vectorgebra.Vector_.softmax(resolution=15)\n\nApplies softmax operation to self and returns it. \"resolution\" is passed\nto e() function internally.\n\n### _Vectorgebra.Vector_.minmax()\n\nApplies MinMax operation to self and returns it.\n\n### _Vectorgebra.Vector_.relu(leak=0, cutoff=0)\n\nMaps self with ReLU function and returns the resultant vector. Put a\nnon-zero leak for leaky ReLU. You can also implement a cutoff for the\npositive side of the function.\n\n### _Vectorgebra.Vector_.sig(a=1, cutoff=None)\n\nApplies the sigmoid to self and returns the resultant vector. \"a\" is the\ncoefficient of x, you can implement a cutoff which acts as a radius. Above\n+cutoff will return 1, below -cutoff will return 0.\n\n### Type conversions\n\n.toInt(), .toFloat(), .toBool(), .toDecimal().\n\n### _Vectorgebra.Vector_.map(f)\n\nMaps the elements of the self according to the function \"f\".\n\n### _Vectorgebra.Vector_.filter(f)\n\nFilters the elements of self according to the function \"f\".\n\n### _Vectorgebra.Vector_.sort(reverse=False)\n\nSorts the vector. This function uses built in sort. \"reverse\" argument is\ndirectly passed into it.\n\n### _Vectorgebra.Vector_.avg()\n\nReturns the average of all numbers in self.\n\n<hr>\n\n## Vectorgebra.Matrix\n\nIncludes basic operations for matrices.\n\nBasic operations like addition, multiplication subtraction, division\nare implemented as overloads. Only comparison operator implemented is\n_==_ which returns true if and only if all the elements of the matrices\nare equal.\n\n\"pow\" method accepts the parameter \"decimal\".\n\nMethods are listed below.\n\n### _Vectorgebra.Matrix_.determinant(choice=\"echelon\")\n\nReturns the determinant of the matrix m. Two choices are available currently;\nechelon, analytic. Default is echelon.\n\n### _Vectorgebra.Matrix_.append(arg)\n\nAppends arg as a new row to self. Only accepts vectors as arguments.\n\n### _Vectorgebra.Matrix_.copy()\n\nReturns the copy of the matrix.\n\n### _Vectorgebra.Matrix_.pop(ord)\n\nFunctions exactly the same as .pop() in list class. If left blank, pops\nthe last row and returns it. If specified, pops the row in the given \norder and returns it.\n\n### _Vectorgebra.Matrix_.transpose()\n\nReturns the transpose matrix of self\n\n### _Vectorgebra.Matrix_.conjugate()\n\nReturns the complex conjugate of the self.\n\n### _Vectorgebra.Matrix_.normalize()\n\nDivides self with its determinant.\n\n### _Vectorgebra.Matrix_.hconj()\n\nReturns the Hermitian conjugate of self.\n\n### _Vectorgebra.Matrix_.norm(resolution: int = 15, decimal=False)\n\nReturns the Frobenius norm of self. Utilizes the eigenvalue function.\nParameters are directly passed to eigenvalue function.\n\n### _Vectorgebra.Matrix_.inverse(method=\"iteraitve\", resolution=10, lowlimit=0.0000000001, highlimit=100000, decimal=False)\n\nReturns the inverse matrix of self. Returns None if not invertible.\nmethod can ben \"analytic\", \"gauss\", \"neumann\" or \"iterative\". Default is iterative\nwhich uses Newton's method for matrix inversion. Resolution is the number\nof iterations. lowlimit and highlimit are only for gauss method. They control\nthe \"resolution\" of multiplication and divisions. LU method only uses the decimal\nchoice. See the source code for a better inside look.\n\nNeumann will only work for the right conditioned matrices (see [here](https://en.wikipedia.org/wiki/Matrix_norm)). Neumann only uses\nresolution parameter.\n\nLU decomposition is the fastest method amongst all.\n\n### Vectorgebra.Matrix.identity(dim, decimal=False)\n\nReturns _dimxdim_ dimensional identity matrix. If decimal is true, generated \ncontents are decimal objects.\n\n### Vectorgebra.Matrix.zero(a, b, decimal=False)\n\nReturns _axb_ dimensional all 0 matrix. If decimal is true, generated \ncontents are decimal objects.\n\n### Vectorgebra.Matrix.one(a, b, decimal=False)\n\nReturns _axb_ dimensional all 1 matrix. If decimal is true, generated \ncontents are decimal objects.\n\n### Vectorgebra.Matrix.randMint(m, n, a, b, decimal=False)\n\nReturns _mxn_ matrix of random integers selected from the interval (a, b).\nIf decimal is true, generated contents are decimal objects.\n\n### Vectorgebra.Matrix.randMfloat(m, n, a, b, decimal=False)\n\nReturns _mxn_ matrix of random floats selected from the interval (a, b).\nIf decimal is true, generated contents are decimal objects.\n\n### Vectorgebra.Matrix.randMbool(m, n, decimal=False)\n\nReturns _mxn_ matrix of random booleans. If decimal is true, generated \ncontents are decimal objects.\n\n### Vectorgebra.Matrix.randMgauss(m, n, mu, sigma, decimal=False)\n\nReturns _mxn_ matrix of random values on the gaussian curve described by mu\nand sigma. If decimal is true, generated contents are decimal objects. Beware\nof the limitations of _random.gauss_ for this method.\n\n### _Vectorgebra.Matrix_.echelon()\n\nReturns reduced row echelon form of self. Also does reorganization on\nrows and multiplies one of them by -1 every 2 reorganization. This is\nfor the determinant to remain unchanged.\n\n### Vectorgebra.Matrix.cramer(a, number)\n\nApplies Cramers rule to the equation system represented by the matrix _a_.\n_number_ indicates which variable to calculate.\n\n### _Vectorgebra.Matrix_.cumsum()\n\nReturns the cumulative sum.\n\n### _Vectorgebra.Matrix_.reshape(*args)\n\nReturns the reshaped matrix/vector. If the return is a matrix,\nmakes a call to the vectors reshape.\n\n### _Vectorgebra.Matrix_.eigenvalue(resolution: int)\n\nCalculates the eigenvalues of self and returns a list of them.\nThis function cannot calculate complex valued eigenvalues. So\nif there are any, there will be incorrect numbers in the returned\nlist instead of the complex ones.\n\nThe underlying algorithm is QR decomposition and iteration. Resolution\nis the number of iterations. Default is 10.\n\n### _Vectorgebra.Matrix_.lu(decimal: bool = False)\n\nReturns a tuple of L and U matrices, in order, which are the respective\nLU decompositions of the self. This method does not check for PA = LU\ncases, blindly applies the decomposition. Returned L and U matrices may\nmultiply to not A, but possibly a PA matrix.\n\n### _Vectorgebra.Matrix_.qr()\n\nApplies QR decomposition to self and returns the tuple (Q, R). The algorithm\njust uses .spanify() from Vector class. If the columns of self do not consist\nof independent vectors, returns matrices of zeroes for both Q and R. This is to\nprevent errors that may have otherwise risen from written code.\n\n### _Vectorgebra.Matrix_.cholesky()\n\nApplies Cholesky decomposition to self, and returns the L matrix. Applied algorithm\nis textbook [Cholesky\u2013Banachiewicz](https://en.wikipedia.org/wiki/Cholesky_decomposition) algorithm.\n\n### _Vectorgebra.Matrix_.get_diagonal()\n\nReturns the diagonal Matrix such that A = L + D + U.\n\n### _Vectorgebra.Matrix_.get_upper()\n\nReturns the upper triangular Matrix such that A = L + D + U.\n\n### _Vectorgebra.Matrix_.get_lower()\n\nReturns the lower triangular Matrix such that A = L + D + U.\n\n### Vectorgebra.Matrix.givens(dim, i, j, angle, resolution: int = 15)\n\nReturns the Givens rotation matrix that applies rotation around axes\n\"i\"-\"j\" by \"angle\". Matrix is dimxdim dimensional. \"resolution\" is\npassed to cos() and sin()\n\n### Vectorgebra.Matrix.frobenius_product(a, b)\n\nReturns the Frobenius product of matrix a and matrix b.\n\n### _Vectorgebra.Matrix_.trace()\n\nReturns the trace of self.\n\n### _Vectorgebra.Matrix_.diagonals()\n\nReturns the list of diagonals.\n\n### _Vectorgebra.Matrix_.diagonal_mul()\n\nReturns the multiplication of diagonals.\n\n### _Vectorgebra.Matrix_.gauss_seidel(b: Vector, initial=None, resolution=15, decimal=False)\n\nApplies Gauss-Seidel method to the equation self * x = b. Returns the resultant x Vector.\nIf \"initial\" left unchanged, code creates an initial guess by default. This may not converge\nthough. \"resolution\" is the number of iterations. \"decimal\" argument is also passed to called\nfunctions inside this method. Same for resolution.\n\n### _Vectorgebra.Matrix_.least_squares(b, *args)\n\nAccepts every argument that .inverse() accepts. Solves the equation _self * x = b_ for x.\nEvery argument except b is passed to .inverse().\n\n### _Vectorgebra.Matrix_.jacobi_solve(b, resolution: int = 15)\n\nSolves the equation self * x = b for x via Jacobi algorithm. \"resolution\" is the\nnumber of iterations. Returns the x vector.\n\n### Type conversions\n\n.toInt(), .toFloat(), .toBool(), .toDecimal().\n\n### _Vectorgebra.Matrix_.map(f)\n\nMaps the elements of self according to the function \"f\".\n\n### _Vectorgebra.Matrix_.filter(f)\n\nFilters the elements of self according to the function \"f\".\n\nAttention! This method is very prone to DimensionError. Be sure\nthat for each row, after the filtering, the same amount of elements\nget through.\n\n### _Vectorgebra.Matrix_.submatrix(a, b, c, d)\n\nSlices the self by rows a:b, by columns c:d and returns the resulting\nmatrix.\n\n### _Vectorgebra.Matrix_.avg()\n\nReturns the average of all elements in self.\n\n<hr>\n\n## Vectorgebra.Tensor\n\nA Tensor, is a container which contains either matrices or tensors.\nEach element that it contains, has one less dimension factor than\nthe parent. This wrapper therefore creates a recursive data structure\nof, eventually, vectorgebra.Matrix. Matrix is the last recursive step\nof this container.\n\n### _Vectorgebra.Tensor_.dot(arg)\n\nReturns the dot product of self and arg. arg must be another Tensor.\nDimensions have to match.\n\n### _Vectorgebra.Tensor_.append(arg)\n\nAppends the Tensor arg to self. Dimensions need to be matching.\n\n### _Vectorgebra.Tensor_.pop(ord=-1)\n\nPops the indexed element from the top most layer of the Tensor.\n\n### _Vectorgebra.Tensor_.copy()\n\nReturns the deep copy of self.\n\n### Vectorgebra.Tensor.zero(dim, decimal=False)\n\nReturns an all zero Tensor with the dimensions specified in \"dim\".\n\n### Vectorgebra.Tensor.one(dim, decimal=False)\n\nReturns an all one Tensor with the dimensions specified in \"dim\".\n\n### Vectorgebra.Tensor.identity(dim, decimal=False)\n\nReturns the identity Tensor with the dimensions specified in \"dim\".\nThe generated identity here has only ones in the all-dimensional\ndiagonal. The filled diagonal is always a \"line\", not \"plane\", etc.\n\n### _Vectorgebra.Tensor_.map(f)\n\nMaps the self with function f. Returns the Tensor filled with resultant\nvalues.\n\n### _Vectorgebra.Tensor_.avg()\n\nReturns the average of all numbers in self.\n\n### _Vectorgebra.Tensor_.flatten()\n\nFlattens the Tensor. If more than 2-dimensional, returns a Matrix filled\nwith average values of higher dimensional parts in the original Tensor.\nIf not, just returns a deep copy of self.\n\n<hr>\n\n## Vectorgebra.Graph\n\nThe class for graphs. These can be constructed via matrices or manually. Can be both\ndirected or undirected.\n\nConstructor accepts 5 arguments; vertices, edges, weights, matrix, directed. \"directed\"\nis a bool and False by default. If \"matrix\" is given, \"edges\" and \"weights\" are ignored.\nIf given, \"vertices\" is not ignored. If left blank, vertices are named numerically. Matrix\nmust be a square, obviously. \n\nIf manually constructed; \"vertices\" is the list (or tuple) of vertices names. Items can be\nanything that is hashable. \"edges\" is a list (or tuple) of length-2 lists (or tuples). Both\nitems must be valid names of vertices, also named in the \"vertices\" argument. Weights to \nthese edges are passed in-order from \"weights\" list if is not None. If \"weights\" is left blank,\n1 is assigned as weight to given edges. The adjacency matrix is always generated.\n\nRelated data can be accessed through; self.vertices, self.edges, self.weights, self.matrix, \nself.directed.\n\nPrint method is overloaded. Printing is much better than matrices even though it kind of prints\nthe adjacency matrix.\n\n### _Vectorgebra.Graph_.addedge(label, weight=1)\n\nAdd an edge with vertex pair \"label\". Weight is 1 by default. Returns self.\n\n### _Vectorgebra.Graph_.popedge(label)\n\nPops the edge and returns it defined by \"label\". If there is more than one, pops the first instance.\n\n### _Vectorgebra.Graph_.addvertex(v)\n\nAdds a vertex named \"v\". Adjacency matrix is regenerated here.\n\n### _Vectorgebra.Graph_.popvertex(v)\n\nRemoves the vertex named \"v\" and returns it. Removes all edges connected to vertex \"v\". Adjacency\nmatrix is naturally regenerated.\n\n### _Vectorgebra.Graph_.getdegree(vertex)\n\nReturns the degree of vertex.\n\n### _Vectorgebra.Graph_.getindegree(vertex)\n\nReturns the in-degree of vertex if the graph is directed. Otherwise just returns the undirected degree.\n\n### _Vectorgebra.Graph_.getoutdegree(vertex)\n\nReturns the out-degree of vertex if the graph is directed. Otherwise just returns the undirected degree.\n\n### _Vectorgebra.Graph_.getdegrees()\n\nReturns a dictionary of degrees and vertices. Keys are degrees, values are corresponding vertices' labels.\n\n### _Vectorgebra.Graph_.getweight(label)\n\nReturns the weight of the edge given via label.\n\n### Vectorgebra.Graph.isIsomorphic(g, h)\n\nReturns True if g and h are isomorphic, False otherwise. g and h must be Graphs.\n\n### _Vectorgebra.Graph_.isEuler()\n\nReturns True if self is an Euler graph, False otherwise.\n\n<hr>\n\n## Constants\n\nPi, e, log2(e), log2(10), ln(2), sqrt(2), sqrt(pi), sqrt(2 * pi).\n\n## Functions\n\n### Vectorgebra.Range(low, high, step)\n\nA lazy implementation of range. There is indeed no range. Just a loop with\nyield statement. Almost as fast as the built-in range.\n\n### Vectorgebra.abs(arg)\n\nReturns the absolute value of the argument.\n\n### Vectorgebra.sqrt(arg, resolution: int = 10)\n\nA square root implementation that uses Newton's method. You may choose the \nresolution, but any change is not needed there. Pretty much at the same\naccuracy as the built-in math.sqrt(). Accepts negative numbers too.\n\n### Vectorgebra.cumsum(arg: list or float)\n\nReturns the cumulative sum of the iterable.\n\n### Vectorgebra.__cumdiv(x, power: int)\n\nCalculates x<sup>n</sup> / power!. This is used to calculate Taylor series\nwithout data loss (at least minimal data loss).\n\n### Vectorgebra.e(exponent, resolution: int)\n\nCalculates e<sup>exponent</sup>. resolution is passed as _power_ to the\n__cumdiv(). It will then define the maximal power of the power series\nimplementation, therefore is a resolution.\n\n### Logarithms\n\nThere are 4 distinct logarithm functions: log2, ln, log10, log. Each have\nthe arguments x and resolution. \"resolution\" is the number of iterations\nand by default is set to 15. \"log\" function also takes a \"base\" parameter.\n\nAll logarithms are calculated based on \"log2\" function. \"ln\" and \"log10\"\nuse the related constants instead of recalculating the same value over\nand over again.\n\n### Vectorgebra.sigmoid(x, a=1)\n\nReturns the sigmoid functions value at x, where a is the coefficient of x.\n\n### Vectorgebra.ReLU(x, leak=0, cutoff=0)\n\nApplies rectified linear unit with leak and cutoff given to x.\n\n### Vectorgebra.Sum(f, a, b, step=0.01, control: bool=False, limit=0.000001)\n\nReturns the sum of f(x) from a to b. step is the step for Range. If control is true,\nstops the sum when the absolute value of the derivative drops under \"limit\".\n\n### Vectorgebra.mode(data)\n\nReturns the mode of the data. Tuples, lists, vectors and matrices are\naccepted.\n\n### Vectorgebra.mean(data)\n\nCalculates the mean of data. \"data\" must be a one dimensional iterable.\n\n### Vectorgebra.median(data)\n\nReturns the median of data. \"data\" must be a one dimensional iterable.\n\n### Vectorgebra.expectation(values, probabilities, moment: int = 1)\n\n\"values\" and \"probabilities\" are one dimensional iterables and their lengths must be\nequal. There is no value checking for the probabilities. If they sum up\nto more than 1 or have negative values, it is up to the user to check \nthat. \"moment\" is the power of \"values\". Returns the expectation value of\ngiven data.\n\n### Vectorgebra.variance(values, probabilities)\n\nSame constraints as \"expectation\" apply here. Returns the variance of the given data.\n\n### Vectorgebra.sd(values, probabilities)\n\nSame constraints as \"variance\" apply here. Returns the standard deviation of the\ngiven data.\n\n### Vectorgebra.maximum(dataset)\n\nReturns the maximum value of dataset. Dataset can be anywhere from tuples to Matrices.\n\n### Vectorgebra.minimum(dataset)\n\nReturns the minimum value of dataset. Dataset can be anywhere from tuples to Matrices.\n\n### Vectorgebra.unique(data)\n\nReturns a dictionary that has unique elements as keys and counts of these elements appearances\nin \"data\" as values. \"data\" must be an iterable.\n\n### Vectorgebra.isAllUnique(data)\n\nReturns True if all elements in data are unique. \"data\" must be an iterable.\n\n### Vectorgebra.permutate(sample)\n\nReturns all permutations of \"sample\" in a list. Only unique elements are counted in \"sample\".\nThis function utilizes helper function \"Vectorgebra.__permutate()\". \"sample\" must be an iterable.\n\n### Vectorgebra.factorial(x: int)\n\nCalculates the factorial with recursion. Default argument is 1.\n\n### Vectorgebra.permutation(x: int, y: int)\n\nCalculates the _y_ permutations of _x_ elements. Does not utilize\nthe factorial function. Indeed, uses loops to calculate the aimed\nvalue more efficiently.\n\n### Vectorgebra.combination(x: int, y: int)\n\nCalculates _y_ combinations of _x_ elements. Again, this does not\nutilize the factorial function.\n\n### Vectorgebra.multinomial(n: int, *args)\n\nCalculates the multinomial coefficient with n elements, with partitions\ndescribed in \"args\". Does not utilize the factorial.\n\n### Vectorgebra.binomial(n: int, k: int, p: float)\n\nCalculates the probability according to the binomial distribution. n is\nthe maximum number of events, k is the events that p describes, p is the\nprobability of the \"event\" happening.\n\n### Vectorgebra.geometrical(n: int, p: float)\n\nCalculates the probability according to the geometric distribution. n is\nthe number of total events. p is the probability that the event happens.\n\n### Vectorgebra.poisson(k, l)\n\nCalculates the probability according to the Poisson formula. l is the\nlambda factor. k is the \"variable\" on the whatever system this function\nis used to describe.\n\n### Vectorgebra.normal(x, resolution: int = 15)\n\nCalculates the _normal_ gaussian formula given x. \"resolution\" is directly\npassed to the e() function.\n\n### Vectorgebra.gaussian(x, mean, sigma, resolution: int = 15)\n\nCalculates the gaussian given the parameters. \"resolution\" is directly \npassed to the e() function.\n\n### Vectorgebra.laplace(x, sigma, resolution: int = 15)\n\nCalculates the Laplace distribution given the parameters. \"resolution\" is directly \npassed to the e() function.\n\n### Vectorgebra.linear_fit(x, y, rate=0.01, iterations: int = 15)\n\nReturns the b0 and b1 constants for the linear regression of the given data.\nx and y must be one dimensional iterables and their lengths must be equal.\n\"rate\" is the learning rate. \"iterations\" is the total number of iterations\nthat this functions going to update the coefficients.\n\n### Vectorgebra.general_fit(x, y, rate=0.0000002, iterations: int = 15, degree: int = 1)\n\nCalculates the coefficients for at _degree_ polynomial regression. \nDefault _rate_ argument is much much lower because otherwise result \neasily blows up. Returns the coefficients starting from the zeroth \ndegree as a Vector object. \n\nInternally, x and y sets are converted to Vectors if they were not,\nso it is faster to initialize them as Vectors.\n\n### Vectorgebra.kmeans(dataset, k=2, iterations=15, a = 0, b = 10)\n\nApplies the K-means algorithm on the dataset. \"k\" is the number of \npoints to assign data clusters. \"iterations\" is the number of iterations\nthat the algorithm applies. Dataset must be non-empty. Each row of \ndataset is converted to Vectors internally. Predefining them as\nsuch would make the function faster. \n\nEvery element of dataset must be of the same type whether they are\nVectors or not. Type-checking is based on the first row of the dataset.\n\nReturns a 2-element tuple. First element is a list of Vectors which\npoint to the cluster centers. Second element is a list of lists of Vectors\nwhich consist of the initial data. This list has the same length as\nnumber of generated cluster centers. Each internal list corresponds\nto the same indexed center point. So this data is grouped by cluster\ncenters.\n\nInitial guesses are random points whose components are random floats\nbetween a and b.\n\nThis function does not have decimal support yet.\n\n### Trigonometrics\n\nAll are of the format Vectorgebra.name(x, resolution: int).\nCalculates the value of the named trigonometric function via Taylor\nseries. Again, resolution is passed as _power_ to __cumdiv().\n\nInverse trigonometrics(arcsin, arccos) do not use the helper function \n__cumdiv().\n\n### Vectorgebra.__find(...)\n\nThis is a helper function for Math.solve(). Arguments are the same.\nReturns the first zero that it finds and saves it to memory.\n\n### Vectorgebra.solve(f, low, high, search_step, res)\n\nFinds zeroes of function f. It may not be able to find all zeroes,\nbut is pretty precise when it finds some. If the functions derivative\nlarge around its zero, then you should increase resolution to do a\nbetter search.\n\nRetrieves found zeroes from the memory, then clears it. Calling \nmultiple instances of this function at the same time will result\nin errors because of this global memory usage.\n\nThis function is optimized for polynomials. It doesn't matter how many\nzeroes they have since this function utilizes a thread pool. This solver\nis slow when utilized with Taylor series based functions.\n\nThere is an obvious solution to this speed problem though. Just put \nexpanded form as the argument. Not the implicit function form.\n\nExits the main loop if the maximum thread count is reached. This can be used as\na limiter when given b=Infinity(). However, the thread count limit is\nmost likely 4096.\n\n### Vectorgebra.derivative(f, x, h)\n\nTakes the derivative of f around x with h = _h_. There is no algorithm \nhere. It just calculates the derivative.\n\n### Vectorgebra.integrate(f, a, b, delta)\n\nCalculates the integral of f(x) in the interval (a, b) with the specified\ndelta. Default for delta is 0.01. Uses the midpoint rule.\n\n### Vectorgebra.__mul(...)\n\nA helper function to Vectorgebra.matmul(). Threads inside matmul call this\nfunction.\n\n### Vectorgebra.matmul(m1, m2, max=10)\n\nThreaded matrix multiplication. Its speed depends on dimensions of given\nmatrices. Let it be axb and bxc, (a - b) is proportional to this functions\nspeed. Worst case scenario is square matrices. 44x44 (On CPython) is limit \nfor this function to be faster than the normal version of matrix multiplication.\n\nIf b > a, normally this function gets even more slower. But there is a\nway around. Let it be b > a;\n\nA * B = C\n\nB<sup>T</sup> * A<sup>T</sup> = C<sup>T</sup>\n\nAfter taking the transposes, we get a > b again. All we have to do is \nto calculate the matrix C<sup>T</sup> instead of C directly then to\ncalculate the transpose of it.\n\n(I didn't add this function to Matrix class because I have more plans on it.)\n\n### Vectorgebra.findsol(f, x, resolution)\n\nCalculates a single solution of f with Newton's method. x is the starting\nguess. resolution is the number of iterations.\n\n### Vectorgebra.Complex \n\nThis is the complex number class. It has + - / * overloaded.\n\n#### _Vectorgebra.Complex_.conjugate()\n\nReturns the complex conjugate of self.\n\n#### _Vectorgebra.Complex_.length()\n\nReturns the length of self, with treating it as a vector.\n\n#### _Vectorgebra.Complex_.unit()\n\nTreats the complex number as a vector and returns the unit vector.\n\n#### Vectorgebra.Complex.sqrt(arg, resolution: int = 200)\n\nCalculates the square root of the complex number _arg_ and returns it\nagain, as a complex number. Resolution argument is only passed to arcsin\nsince it is the only limiting factor for this functions accuracy. Has an\naverage of 1 degree of error as angle. You may still increase the resolution.\nBut reaching less than half a degree of error requires for it to be at \nleast 600.\n\nThe used algorithm calculates the unit vector as e<sup>i*x</sup>. Then halves\nthe degree, x. Returns the resultant vector at the proper length.\n\n#### _Vectorgebra.Complex_.range(lowreal, highreal, lowimg, highimg, step1, step2)\n\nCreates a complex number range, ranging from complex(lowreal, lowimg)\nto complex(highreal, highimg). Steps are 1 by default. Again this is \na lazy implementation.\n\n#### _Vectorgebra.Complex_.inverse()\n\nReturns 1 / self. This is used in division. If divisor is complex,\nthen this function is applied with multiplication to get the result.\n\n#### _Vectorgebra.Complex_.rotate(angle: int or float)\n\nRotates self by angle.\n\n#### _Vectorgebra.Complex_.rotationFactor(angle: int or float)\n\nReturns e<sup>i*angle</sup> as a complex number.\n\n<hr>\n\n### Vectorgebra.Infinity\n\nThe class of infinities. When initialized, takes one argument describing its sign.\nIf \"True\", the infinity is positive (which is the default). If \"False\", the infinity\nis negative.\n\nLogical and mathematical operations are all overloaded. Operations may return \"Undefined\".\nThis is a special class that has every mathematical and logical operation overloaded.\n\n### Vectorgebra.Undefined\n\nA special class that corresponds to \"undefined\" in mathematics.\n\n## Exceptions\n\n### Vectorgebra.DimensionError\n\nAnything related to dimensions of vectors and matrices. Raised in \nVector class when dimensions of operands don't match or 0 is given\nas a dimension to random vector generating functions.\n\nThis error is raised in Matrix class when non-square matrices are\npassed into inverse calculating functions.\n\n**DimensionError(1) has been changed to RangeError, but is still\nin the code.**\n\n### Vectorgebra.ArgTypeError\n\nAnything related to types of arguments. Can take in a str argument\nflagged as \"hint\".\n\n### Vectorgebra.RangeError\n\nRaised when given arguments are out of required range.\n\n### Vectorgebra.AmountError\n\nRaised when the amount of arguments in a function is wrong.\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A numerical methods tool for python, in python.",
    "version": "3.2.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b2313c773f3778fbe1dd470a81f4b856ef5c30d015f59f4c82b42ca2ecdf4bea",
                "md5": "775651b46a86985abe44ed43ab95d55e",
                "sha256": "378a23d542784978f6373ec949b9c9f00fe86b8909a4422c7acea5b28c541e95"
            },
            "downloads": -1,
            "filename": "vectorgebra-3.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "775651b46a86985abe44ed43ab95d55e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 72183,
            "upload_time": "2024-06-21T21:52:48",
            "upload_time_iso_8601": "2024-06-21T21:52:48.562746Z",
            "url": "https://files.pythonhosted.org/packages/b2/31/3c773f3778fbe1dd470a81f4b856ef5c30d015f59f4c82b42ca2ecdf4bea/vectorgebra-3.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "32bed8d00fe29a82e348c97aa1be1dc06bb11bbd4d1a3931ace4bed3d93e6f61",
                "md5": "5b4c880746601ef2f3d74e0bcfffe540",
                "sha256": "ab5149095ba695bb8cbafc9cd609308acae0431e360aca6f4b0b5557a43154df"
            },
            "downloads": -1,
            "filename": "vectorgebra-3.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "5b4c880746601ef2f3d74e0bcfffe540",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 68957,
            "upload_time": "2024-06-21T21:53:08",
            "upload_time_iso_8601": "2024-06-21T21:53:08.176945Z",
            "url": "https://files.pythonhosted.org/packages/32/be/d8d00fe29a82e348c97aa1be1dc06bb11bbd4d1a3931ace4bed3d93e6f61/vectorgebra-3.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-21 21:53:08",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "vectorgebra"
}
        
Elapsed time: 0.45622s