Peroxide
Pure Rust numeric library contains linear algebra, numerical analysis, statistics and machine learning tools with R, MATLAB, Python like macros.
Latest README version
Corresponds with 0.7.3
.
Install
- Add next line to your
cargo.toml
= "0.7"
Usage
There is Peroxide Guide written on Jupyter.
Initial Import
extern crate peroxide;
use *;
Module Structure
- src
- bin : For test some libraries
- lib.rs :
mod
andre-export
- ml : For machine learning
- macros : Macro files
- matlab_macro.rs : MATLAB like macro
- mod.rs
- r_macro.rs : R like macro
- numerical : To do numerical things
- operation : To define general operations
- statistics : Statistical Tools
- structure : Fundamental data structures
- dual.rs : Dual number system for automatic differentiation
- matrix.rs : Matrix
- mod.rs
- polynomial.rs : Polynomial
- vector.rs : Extra tools for
Vec<f64>
- util
- mod.rs
- non_macro.rs : Primordial version of macros
- print.rs : To print conveniently
Vec<f64> Declaration
# R
a =
b = # (=c(1,3,5))
// Peroxide
extern crate peroxide;
use *;
Matrix Declaration
# R
a =
// Peroxide (All belows are same)
extern crate peroxide;
use *;
# R
a =
# [,1] [,2]
# [1,] 1 2
# [2,] 3 4
// Peroxide
extern crate peroxide;
use *;
// c[0] c[1]
// r[0] 1 2
// r[1] 3 4
Concatenate
1. Vector + Vector => Vector
# R
a =
b =
c =
# c(1,2,3,4,5,6)
// Peroxide
extern crate peroxide;
use *;
2. Matrix + Matrix => Matrix
# R
# cbind
a =
b =
c =
# [,1] [,2] [,3]
#[1,] 1 3 5
#[2,] 2 4 6
# rbind
a =
b =
c =
# [,1] [,2]
#[1,] 1 2
#[2,] 3 4
#[3,] 5 6
// Peroxide
extern crate peroxide;
use *;
Matrix operation
- If you want to do multiple operations on same matrix, then you should use
clone
because Ruststd::ops
consume value.
# R
a =
b =
// Peroxide
extern crate peroxide;
use *;
LU Decomposition
- Peroxide uses complete pivoting LU decomposition. - Very stable.
- Also there are lots of error handling for LU, so, you should use
Option
// Peroxide
extern crate peroxide;
use *;
Determinant
- Determinant is implemented using by LU decomposition (O(n^3))
// Peroxide
extern crate peroxide;
use *;
Inverse
- Inverse is also implemented using by LU decomposition
- To handle singularity, output type is
Option<Matrix>
- To obtain inverse, you should use
unwrap
or pattern matching
- To obtain inverse, you should use
// Peroxide
extern crate peroxide;
use *;
Extract Column or Row
# R
a =
//Peroxide
extern crate peroxide;
use *;
Functional Programming
// Peroxide
extern crate peroxide;
use *;
// Results
//
// c[0] c[1]
// r[0] 2 3
// r[1] 4 5
//
// c[0] c[1]
// r[0] 0 1
// r[1] 2 3
//
// c[0] c[1]
// r[0] 2 4
// r[1] 6 8
Write to CSV
You can write matrix to csv by two ways.
// Peroxide
extern crate peroxide;
use *;
use process; // for error handling
Read from CSV
You can read matrix with error handling
// Peroxide
extern crate peroxide;
use *;
use process;
Statistics
mean
- Meanvar
- Variancesd
- Standard Deviationcov
- Covariancecor
- Pearson's Coefficient
# R
# Vector Stats
a <-
b <-
# Matrix Stats
m <-
// Peroxide
extern crate peroxide;
use *;
Linear Regression
lm(x, y)
# R
a <-
b <- a +
#Call:
#lm(formula = b ~ a)
#
#Coefficients:
#(Intercept) a
# 0.5076 0.8305
//Peroxide
extern crate peroxide;
use *;
Probability Distributions
Current available distribution
TPDist
: Two parameter distributionsUniform(start, end)
(Wraprand
crate)Normal(mean, std)
(Using ziggurat algorithm)
- Available methods
sample(n: usize) -> Vec<f64>
: extract samplepdf(x: f64) -> Vec<f64>
: calculate probability atx
// Peroxide
extern crate peroxide;
use *;
Polynomial
// Peroxide
extern crate peroxide;
use *;
Interpolation (Beta)
- Lagrange polynomial interpolation
- Chebyshev nodes
// Peroxide
extern crate peroxide;
use *;
Spline (Beta)
- Natural cubic spline
// Peroxide
extern crate peroxide;
use *;
MATLAB like macro
zeros
- zero vector or matrixeye
- identity matrixrand
- random matrix (range from 0 to 1)
Automatic Differentiation
- Implemented AD with dual number structure.
- Available functions
sin, cos, tan
pow, powf
+,-,x,/
exp, ln
extern crate peroxide;
use *;
Jacobian
- Implemented by AD - Exact Jacobian
extern crate peroxide;
use *;
// f(t, x) = 3t^2 * x
Ordinary Differential Equation
- Solve 1st order ODE with various methods
- Explicit Method
RK4
: Runge-Kutta 4th order
- Implicit Method
BDF1
: Backward EulerGL4
: Gauss-Legendre 4th order
Caution
- input function should have form
(Dual, Vec<Dual>) -> Vec<Dual>
// Lotka-Volterra
extern crate peroxide;
use *;
Version Info
To see RELEASES.md
TODO
To see TODO.md