A (very) basic Linear Algebra, Statistics, and Machine Learning library written from scratch and without dependencies
The following is the list of functions implemented so far
add(v []f64, w []f64) []f64: Adds two vectorsaandb:(a + b)subtract(v []f64, w []f64) []f64: Subtracts two vectorsaandb:(a - b)vector_sum(vector_list [][]f64) []f64: Sums a list of vectors, example:vector_sum([[f64(1),2],[3,4]]) => [4.0, 6.0]scalar_multiply(c f64, v []f64) []f64: Multiplies an scalar valuecto each element of a vectorvvector_mean(vector_list [][]f64) []f64: Calculates 1/n sum_j (v[j])dot(v []f64, w []f64) f64: Dot product ofvandwsum_of_squares(v []f64) f64: Squares each term of a vector, example: [1,2,3]^2 = [1^2, 2^2, 3^2]magnitude(v []f64) f64: Module of a vector, example: || [3,4] || = 5squared_distance(v []f64, w []f64) f64: Calculates sqrt[(v1-w1)^2 + (v2-w2)^2...]distance(v []f64, w []f64) f64: Calculates the distance betweenvandw
shape(a [][]f64) (int, int): Returns the shape of a matrix (rows, columns)get_row(a [][]f64, i int) []f64: Gets the i-th row of a matrix as a vectorget_column(a [][]f64, j int) []f64: Gets the j-th column of a matrix as a vectormake_matrix(num_rows int, num_cols int, op fn (int, int) f64) [][]f64: Makes a matrix using a formula given by functionopidentity_matrix(n int) [][]f64: Returns a n-identity matrixmatmul(a [][]f64, b [][]f64) [][]f64: Multuplies matrixawithb
beta_function(x f64, y f64) f64normal_cdf(x f64, mu f64, sigma f64) f64inverse_normal_cdf(p f64, mu f64, sigma f64, dp DistribParams) f64bernoulli_pdf(x f64, p f64) f64bernoulli_cdf(x f64, p f64) f64binomial_pdf(k int, n int, p f64) f64poisson_pdf(k int, lambda f64) f64poisson_cdf(k int, lambda f64) f64exponential_pdf(x f64, lambda f64) f64exponential_cdf(x f64, lambda f64) f64gamma_pdf(x f64, k f64, theta f64) f64chi_squared_pdf(x f64, df int) f64students_t_pdf(x f64, df int) f64f_distribution_pdf(x f64, d1 int, d2 int) f64beta_pdf(x f64, alpha f64, beta f64) f64uniform_pdf(x f64, a f64, b f64) f64uniform_cdf(x f64, a f64, b f64) f64negative_binomial_pdf(k int, r int, p f64) f64negative_binomial_cdf(k int, r int, p f64) f64multinomial_pdf(x []int, p []f64) f64expectation(x []f64, p []f64) f64
sum(x []f64) f64mean(x []f64) f64median(x []f64) f64quantile(x []f64, p f64) f64mode(x []f64) []f64data_range(x []f64) f64dev_mean(x []f64) []f64variance(x []f64) f64standard_deviation(x []f64) f64interquartile_range(x []f64) f64covariance(x []f64, y []f64) f64correlation(x []f64, y []f64) f64
difference_quotient(f fn (f64) f64, x f64, h f64) f64partial_difference_quotient(f fn([]f64) f64, v []f64, i int, h f64) f64gradient(f fn([]f64) f64, v []f64, h f64) []f64gradient_step(v []f64, gradient_vector []f64, step_size f64) []f64sum_of_squares_gradient(v []f64) []f64
- This was written as an exercise to get V closer to Data Analytics and Machine Learning tasks
- Heavily inspired by the book from Joel Grus "Data Science from Scratch: First principles with Python"
- It is not optimized in any way (at least for now)
- Documentation es an ongoing effort
- Add more optimization algorithms
- Complete Hypothesis testing module
- Complete Machine Learning module
- Complete Neural Network module
- Symbolic calculation
Pull requests are welcome!