Code Monkey home page Code Monkey logo

peroxide's Introduction

Peroxide

On crates.io On docs.rs DOI github

maintenance

Rust numeric library contains linear algebra, numerical analysis, statistics and machine learning tools with R, MATLAB, Python like macros.

Table of Contents

Why Peroxide?

1. Customize features

Peroxide provides various features.

  • default - Pure Rust (No dependencies of architecture - Perfect cross compilation)
  • O3 - BLAS & LAPACK (Perfect performance but little bit hard to set-up - Strongly recommend to look Peroxide with BLAS)
  • plot - With matplotlib of python, we can draw any plots.
  • nc - To handle netcdf file format with DataFrame
  • csv - To handle csv file format with Matrix or DataFrame
  • parquet - To handle parquet file format with DataFrame
  • serde - serialization with Serde.

If you want to do high performance computation and more linear algebra, then choose O3 feature. If you don't want to depend C/C++ or Fortran libraries, then choose default feature. If you want to draw plot with some great templates, then choose plot feature.

You can choose any features simultaneously.

2. Easy to optimize

Peroxide uses a 1D data structure to represent matrices, making it straightforward to integrate with BLAS (Basic Linear Algebra Subprograms). This means that Peroxide can guarantee excellent performance for linear algebraic computations by leveraging the optimized routines provided by BLAS.

3. Friendly syntax

For users familiar with numerical computing libraries like NumPy, MATLAB, or R, Rust's syntax might seem unfamiliar at first. This can make it more challenging to learn and use Rust libraries that heavily rely on Rust's unique features and syntax.

However, Peroxide aims to bridge this gap by providing a syntax that resembles the style of popular numerical computing environments. With Peroxide, you can perform complex computations using a syntax similar to that of R, NumPy, or MATLAB, making it easier for users from these backgrounds to adapt to Rust and take advantage of its performance benefits.

For example,

#[macro_use]
extern crate peroxide;
use peroxide::prelude::*;

fn main() {
    // MATLAB like matrix constructor
    let a = ml_matrix("1 2;3 4");

    // R like matrix constructor (default)
    let b = matrix(c!(1,2,3,4), 2, 2, Row);

    // Or use zeros
    let mut z = zeros(2, 2);
    z[(0,0)] = 1.0;
    z[(0,1)] = 2.0;
    z[(1,0)] = 3.0;
    z[(1,1)] = 4.0;

    // Simple but effective operations
    let c = a * b; // Matrix multiplication (BLAS integrated)

    // Easy to pretty print
    c.print();
    //       c[0] c[1]
    // r[0]     1    3
    // r[1]     2    4

    // Easy to do linear algebra
    c.det().print();
    c.inv().print();

    // and etc.
}

4. Can choose two different coding styles.

In peroxide, there are two different options.

  • prelude: To simple use.
  • fuga: To choose numerical algorithms explicitly.

For examples, let's see norm.

In prelude, use norm is simple: a.norm(). But it only uses L2 norm for Vec<f64>. (For Matrix, Frobenius norm.)

#[macro_use]
extern crate peroxide;
use peroxide::prelude::*;

fn main() {
    let a = c!(1, 2, 3);
    let l2 = a.norm();      // L2 is default vector norm

    assert_eq!(l2, 14f64.sqrt());
}

In fuga, use various norms. But you should write a little bit longer than prelude.

#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = c!(1, 2, 3);
    let l1 = a.norm(Norm::L1);
    let l2 = a.norm(Norm::L2);
    let l_inf = a.norm(Norm::LInf);
    assert_eq!(l1, 6f64);
    assert_eq!(l2, 14f64.sqrt());
    assert_eq!(l_inf, 3f64);
}

5. Batteries included

Peroxide can do many things.

  • Linear Algebra
    • Effective Matrix structure
    • Transpose, Determinant, Diagonal
    • LU Decomposition, Inverse matrix, Block partitioning
    • QR Decomposition (O3 feature)
    • Singular Value Decomposition (SVD) (O3 feature)
    • Cholesky Decomposition (O3 feature)
    • Reduced Row Echelon form
    • Column, Row operations
    • Eigenvalue, Eigenvector
  • Functional Programming
    • Easier functional programming with Vec<f64>
    • For matrix, there are three maps
      • fmap : map for all elements
      • col_map : map for column vectors
      • row_map : map for row vectors
  • Automatic Differentiation
    • Taylor mode Forward AD - for nth order AD
    • Exact jacobian
    • Real trait to constrain for f64 and AD (for ODE)
  • Numerical Analysis
    • Lagrange interpolation
    • Splines
      • Cubic Spline
      • Cubic Hermite Spline
        • Estimate slope via Akima
        • Estimate slope via Quadratic interpolation
    • Non-linear regression
      • Gradient Descent
      • Levenberg Marquardt
    • Ordinary Differential Equation
      • Trait based ODE solver (after v0.36.0)
      • Explicit integrator
        • Ralston's 3rd order
        • Runge-Kutta 4th order
        • Ralston's 4th order
        • Runge-Kutta 5th order
      • Embedded integrator
        • Bogacki-Shampine 3(2)
        • Runge-Kutta-Fehlberg 4(5)
        • Dormand-Prince 5(4)
        • Tsitouras 5(4)
      • Implicit integrator
        • Gauss-Legendre 4th order
    • Numerical Integration
      • Newton-Cotes Quadrature
      • Gauss-Legendre Quadrature (up to 30 order)
      • Gauss-Kronrod Quadrature (Adaptive)
        • G7K15, G10K21, G15K31, G20K41, G25K51, G30K61
      • Gauss-Kronrod Quadrature (Relative tolerance)
        • G7K15R, G10K21R, G15K31R, G20K41R, G25K51R, G30K61R
    • Root Finding
      • Trait based root finding (after v0.37.0)
      • Bisection
      • False Position
      • Secant
      • Newton
      • Broyden
  • Statistics
    • More easy random with rand crate
    • Ordered Statistics
      • Median
      • Quantile (Matched with R quantile)
    • Probability Distributions
      • Bernoulli
      • Uniform
      • Binomial
      • Normal
      • Gamma
      • Beta
      • Student's-t
      • Weighted Uniform
    • RNG algorithms
      • Acceptance Rejection
      • Marsaglia Polar
      • Ziggurat
      • Wrapper for rand-dist crate
      • Piecewise Rejection Sampling
    • Confusion Matrix & Metrics
  • Special functions
    • Wrapper for puruspe crate (pure rust)
  • Utils
    • R-like macro & functions
    • Matlab-like macro & functions
    • Numpy-like macro & functions
    • Julia-like macro & functions
  • Plotting
    • With pyo3 & matplotlib
  • DataFrame
    • Support various types simultaneously
    • Read & Write csv files (csv feature)
    • Read & Write netcdf files (nc feature)
    • Read & Write parquet files (parquet feature)

6. Compatible with Mathematics

After 0.23.0, peroxide is compatible with mathematical structures. Matrix, Vec<f64>, f64 are considered as inner product vector spaces. And Matrix, Vec<f64> are linear operators - Vec<f64> to Vec<f64> and Vec<f64> to f64. For future, peroxide will include more & more mathematical concepts. (But still practical.)

7. Written in Rust

Rust provides a strong type system, ownership concepts, borrowing rules, and other features that enable developers to write safe and efficient code. It also offers modern programming techniques like trait-based abstraction and convenient error handling. Peroxide is developed to take full advantage of these strengths of Rust.

The example code demonstrates how Peroxide can be used to simulate the Lorenz attractor and visualize the results. It showcases some of the powerful features provided by Rust, such as the ? operator for streamlined error handling and the ODEProblem trait for abstracting ODE problems.

use peroxide::fuga::*;

fn main() -> Result<(), Box<dyn Error>> {
    let rkf45 = RKF45::new(1e-4, 0.9, 1e-6, 1e-2, 100);
    let basic_ode_solver = BasicODESolver::new(rkf45);
    let (_, y_vec) = basic_ode_solver.solve(
        &Lorenz,
        (0f64, 100f64),
        1e-2,
    )?; // Error handling with `?` - can check constraint violation and etc.
    let y_mat = py_matrix(y_vec);
    let y0 = y_mat.col(0);
    let y2 = y_mat.col(2);

    // Simple but effective plotting
    let mut plt = Plot2D::new();
    plt
        .set_domain(y0)
        .insert_image(y2)
        .set_xlabel(r"$y_0$")
        .set_ylabel(r"$y_2$")
        .set_style(PlotStyle::Nature)
        .tight_layout()
        .set_dpi(600)
        .set_path("example_data/lorenz_rkf45.png")
        .savefig()?;

    Ok(())
}

struct Lorenz;

impl ODEProblem for Lorenz {
    fn initial_conditions(&self) -> Vec<f64> {
        vec![10f64, 1f64, 1f64]
    }

    fn rhs(&self, t: f64, y: &[f64], dy: &mut [f64]) -> anyhow::Result<()> {
        dy[0] = 10f64 * (y[1] - y[0]);
        dy[1] = 28f64 * y[0] - y[1] - y[0] * y[2];
        dy[2] = -8f64 / 3f64 * y[2] + y[0] * y[1];
        Ok(())
    }
}

Running the code produces the following visualization of the Lorenz attractor:

lorenz_rkf45.png

Peroxide strives to leverage the benefits of the Rust language while providing a user-friendly interface for numerical computing and scientific simulations.

How's that? Let me know if there's anything else you'd like me to improve!

Latest README version

Corresponding to 0.37.1

Pre-requisite

  • For O3 feature - Need OpenBLAS
  • For plot feature - Need matplotlib and optional scienceplots (for publication quality)
  • For nc feature - Need netcdf

Install

  • Run below commands in your project directory
  1. Default

    cargo add peroxide
  2. OpenBLAS

    cargo add peroxide --features O3
  3. Plot

    cargo add peroxide --features plot
  4. NetCDF dependency for DataFrame

    cargo add peroxide --features nc
  5. CSV dependency for DataFrame

    cargo add peroxide --features csv
  6. Parquet dependency for DataFrame

    cargo add peroxide --features parquet
  7. Serialize or Deserialize with Matrix or polynomial

    cargo add peroxide --features serde
  8. All features

    cargo add peroxide --features "O3 plot nc csv parquet serde"

Useful tips for features

  • If you want to use QR, SVD, or Cholesky Decomposition, you should use the O3 feature. These decompositions are not implemented in the default feature.

  • If you want to save your numerical results, consider using the parquet or nc features, which correspond to the parquet and netcdf file formats, respectively. These formats are much more efficient than csv and json.

  • For plotting, it is recommended to use the plot feature. However, if you require more customization, you can use the parquet or nc feature to export your data in the parquet or netcdf format and then use Python to create the plots.

    • To read parquet files in Python, you can use the pandas and pyarrow libraries.

    • A template for Python code that works with netcdf files can be found in the Socialst repository.

Module Structure

Documentation

  • On docs.rs

Examples

Release Info

To see RELEASES.md

Contributes Guide

See CONTRIBUTES.md

LICENSE

Peroxide is licensed under dual licenses - Apache License 2.0 and MIT License.

TODO

To see TODO.md

Cite Peroxide

Hey there! If you're using Peroxide in your research or project, you're not required to cite us. But if you do, we'd be really grateful! ๐Ÿ˜Š

To make citing Peroxide easy, we've created a DOI through Zenodo. Just click on this badge:

DOI

This will take you to the Zenodo page for Peroxide. At the bottom, you'll find the citation information in various formats like BibTeX, RIS, and APA.

So, if you want to acknowledge the work we've put into Peroxide, citing us would be a great way to do it! Thanks for considering it, we appreciate your support! ๐Ÿ‘

peroxide's People

Contributors

adamnemecek avatar axect avatar gcomitini avatar koute avatar mulimoen avatar nateckert avatar rdavis120 avatar relastle avatar russellb23 avatar samnaughtonb avatar schrieveslaach avatar tchamelot avatar thettasch avatar

Stargazers

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

Watchers

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

peroxide's Issues

Taylor mode automatic differentiation

Peroxide has two AD methods - Dual, HyperDual. But these are only 1st and 2nd order methods, and they are distinct. So, we need not only higher order AD but also generic.

  • Struct AD
    • fmt::Display
    • Copy?
    • From<T>
  • std::ops for AD
    • Add, Sub, Neg
    • Mul
    • Div
  • PowOps for AD
    • powi
    • powf
    • pow
  • TrigOps for AD
    • sin, cos, tan
    • asin, acos, atan
    • sinh, cosh, tanh
    • asinh, acosh, atanh
    • sin_cos, sinh_cosh
  • ExpLogOps for AD
    • exp, ln
    • log, log2, log10
  • std::ops with f64
    • Add, Sub
    • Mul, Div
  • Change the structure - proc_macro to Enum (to reduce compile time)
  • Generic AD function - ADFn
  • Apply to numerical things
    • numerical/root
    • numerical/ode
    • numerical/optimize
    • numerical/utils

puruspe and statrs integration

Hi there!!

Thank you very much for your great work!!

I am using Rust for numerical computations and was wondering about the best place to take special functions from.

I came across the module statrs::function and saw that you use the puruspe (by the way, in the README.md there is an extra "r", it says "pururspe").

So, my question is: Would it not be better to join efforts and have and have the "best" source for special functions in one place?

Of course, there is always a trade-off between accuracy and velocity, but joining efforts hopefully leads to the best solution or documented solutions.

LM Algorithm: Unbounded lambda

I have some optimisations which appear to get caught in a local minimum so that chi = chi_2 and as a result rho = 0. In the current setup, the algorithm doubles lambda until there is some improvement, this seems to lead to divergence and the algorithm failing for some optimisation problems. A simple fix might be to have the algorithm halt when lambda exceeds a meaningful value.

Uniform random generator behaviour

I am not sure whether it is intended or not but

Uniform(0,1) has type TPDist and
Uniform(0,1).sample(10) type generates random integers between [0, 1), so only zeros

However,
Normal(0,1) has the same type TPDist and
Nomral(0,1).sample(10) genrates random floats from the distribution

Cholesky decomposition

Hey, thanks for the library, it's a pleasure to use.

I was wondering whether there are any plans to implement Cholesky decomposition? I understand it's probably not a high priority as LU decomposition is already implemented, but would be cool to have some additional speed there!

Thanks,
Andrew

New general DataFrame

Peroxide already supported dataframe feature, but it is only for f64 data type.
So, our new general DataFrame should have following features :

  • Various data types Series
    • Integer (usize, u8, u16, u32, u64, isize, i8, i16, i32, i64)
    • Float (f32, f64)
    • String
    • bool
    • char
  • Type casting
    • Series type casting
    • DataFrame type casting
  • Unified DataFrame
    • Index<usize>
    • Index<&str>
    • IndexMut<usize>
    • IndexMut<&str>
  • Pretty print
    • Series
    • DataFrame
  • Support various format IO
    • CSV (Additional feature)
    • JSON (Additional feature)
    • HDF5 (Additional feature)
    • NetCDF (Additional feature)
    • Apache arrow IPC (Additional feature)
    • Apache parquet (Additional feature)
  • Vector-like methods
    • Implement Vector for numeric type Series
    • Matrix from Series directly
  • Functional programming for Series
    • map, mut_map
    • fold, filter, zip_with
    • take, skip, take_while, skip_while
  • Translate macros to functions (to reduce compile time)

And other convenient features can be added.

Native implementation of QR, SVD

QR, SVD were already implemented in O3 feature, but not natively.
Since O3 feature require blas-family, we can't use QR and SVD in portable environments.
So, we need native implementation of QR and SVD.

  • QR decomposition
  • SVD decomposition

Multivariate Automatic Differentiation

To calculate exact Hessian via Taylor-mode AD, we should need multivariate formula.

  • New structure for Multivariate AD - ADM (temporary name)
  • std::ops for ADM
    • Neg, Add, Sub
    • Mul, Div
  • PowOps
  • ExpLogOps
  • TrigOps

Blas linkage

As it stands now, Peroxide enforces use of OpenBLAS even though all the libraries and apis it uses are agnostic to the BLAS library variant. In order to use a different BLAS implementation, one must delete Peroxide's build.rs, everything works fine otherwise. Especially as this tutorial page is linked in the README, I think it should be expected that the user should be the one to include the linkage lines in their build.rs.

Realistically, I think there are a few good ways of changing this:

  1. Just remove Peroxide's build.rsand leave it to the user to include the right libraries (I believe this is the best course of action)
  2. Add a "no explicit linkage" feature that disables Peroxide's build.rs
  3. Change the linkage from openblas to blas - many distros/package managers will have libblas symlinked to the installed BLAS implementation, OpenBLAS included.
  4. Add links tag to Cargo.toml to allow for explicit overriding

Regardless, Peroxide explicitly linking to OpenBLAS is undesirable due to the plethora of other BLAS implementations (including open source ones like ClBlast) that can be used with no source code changes.

Make `fuga` and rewrite functions' front-end

Description

After Ver 0.23.0, peroxide will use two different main modules - prelude and fuga.

  • prelude: Contains all simplified functions. (ex: a.norm(), integrate(f, (a,b)))
  • fuga: Contains all customizable functions. (ex: a.norm(L2), integrate(f, (a,b), GaussLegendre(15)))

Fuga list

  • Norm
    • Vector norm
    • Matrix norm
  • Solve
    • LU
    • WAZ
    • QR
  • Integrate
  • Spline
  • ODE

Print in ODE when stop condition is reached

Hello, thank your for this nice crate.
I have a minor issue that is not blocking or whatever. In the ODE method integrate there are printl when the stop condition is reached. I can understand why for debug purpose but when calling this method a lot of time, this end up making a lot of noise and slowing down the process.
For example, my use case is a physical model being simulated several times to find the best parameters for a PID controller through black box optimization (differential evolution). The stop condition is used to eliminate parameters that do not satisfy the physical limits of my model (a motor that spins faster than the maximum angular speed allowed by the voltage supply for example). I end up with thousands of line printed by the stop condition which slow the process and make the interesting output difficult to identify.
I would be up to write a small patch to fix this but i do not know how yet.

The print is at this line:

println!("Reach the stop condition!");

More Numerical Integrations

More numerical integrations are needed for convenience & accuracy.

  • Newton-Cotes Quadrature
  • Gauss-Legendre Quadrature (1 ~ 30)
  • Gauss-Kronrod Quadrature
    • G7K15
    • G10K21
    • G15K31
    • G20K41
    • G25K51
    • G30K61
  • Clenshaw-Curtis Quadrature
  • Tanh-sinh Quadrature (Double Exponential)

Increase usability of `Real` trait

This is not a bug, but just rather feature request for some future version. As far as I understand, this feature would be a breaking change, so understandably the necessity of this request should be considered. (I am also a newbie, so I may think things wrong too.)

Real trait is sweet, because functions can be made generic over type, and the function can be easily passed to automatic differentiation. Now in my case the Real type is practically f64 or Number. However, many numeric traits that are implemented for Number, are not trait bounds on Real. For example Neg and PartialOrd are missing.

Also, binary operands f:f64 and r: Real can be written only as r @ f but not f @ r, where @ is one of operators {+, -, *, /}. This also makes function writing a bit more cumbersome.

This is probably a breaking change, because it may be technically possible that somebody have implemented Real for some own type. (So should Real be also locked, so that it can not be implemented outside the crate?)

Support Complex number

Still peroxide supports only real number. But for many cases, complex number, vector & matrix should be required.

  • Integrate num_complex::Complex<F>
  • Complex vector
    • Re-design Vector traits
    • crate::traits::math::{Vector, Normed, InnerProduct, LinearOp, VectorProduct}
    • crate::traits::fp::FPVector
  • Complex matrix
    • Implement almost all of Matrix
    • Integrates LAPACK complex subroutines

Length bug in `linspace`

If end - start is too small, then linspace may not guarantee the length of output.
For example, below code generates error.

use peroxide::fuga::*;

fn main() {
    let x = linspace(435482956799564540_f64, 435482956800000000, 101);
    assert_eq!(x.len(), 101);
}

This error is caused from seq - seq does not guarantee the length.
Thus, linspace should not depend on implementation of seq.

Optimization after refactoring to AD in 0.30 - example failing

Hi, thanks a lot for the great library.

I tried running the example in optimization.rs in 0.30.6 and it does not optimize, keeping the initial value in p output. Using 0.29.1 - its example (i.e. before refactoring from numbers to AD) works OK.

Thanks a lot,

Pavel.

Add support of root-finding

I use Peroxide for some number cruching. For example, my code interpolates a measurement series of an analogue-digital converter with a spline and it analyzes the first and second derivatives. Therefore, I need to find the root of these derivatives.

However, there is no bisection or any other numerical root-find method in Peroxide and I have to use the rootfind crate but this crate is not actively maintained. Additionally, if root finding is provided by Peroxide, this would reduce the number of crate in my dependencies.

Optimization with uncertainties

Is there a way to use Optimizer with weights? It would be very useful if your data include uncertainties sigma, a user can easily found weights as 1 / sigma^2.

If there is no such way, would you accept a PR where loss function is sum (f_i - y(x_i))^2 / sigma_i^2, Optimizer has additional field weight: Optional<Vec<f64>> and Optimizer::new accepts two or three column data (additional optional column is weight)?

Support for Windows?

Hello,

I am trying my very first steps in Rust. Actually Peroxide is my first dependency I tried to include into my project. So, it may be a beginners mistake, but I really cannot make it work.

Here is what I did:

  • Included the dependency like:
[dependencies.peroxide]
version = "0.21"
default-features = false
features = ["dataframe"]
  • Compiled (without problems). Cargo build fails with:

= note: LINK : fatal error LNK1181: cannot open input file 'netcdf.lib'

  • Downloaded+Installed netcdf from

https://www.unidata.ucar.edu/software/netcdf/docs/winbin.html

  • Built again, same problem
  • Added lib folder of netcdf manually to PATH
  • Double checked its availability
> where netcdf.lib
>> C:\Program Files\netCDF 4.7.4\lib\netcdf.lib
  • Cleaned the build (cargo clean)
  • built from scratch
  • Dependencies built again fine, particularly:

Compiling netcdf v0.2.0

  • Linker still fails on
error: linking with `link.exe` failed: exit code: 1181
  |
  = note: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.25.28610\\bin\\HostX64\\x64\\link.exe" "/NOLOGO" "/NXCOMPAT" "/LIBPATH:C:\\Users\\username\\.rustup\\toolchains\\stable-x86_6
4-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\username\\Dropbox\\dev\\hdtree_rust\\target\\debug\\deps\\hdtree_rust.30i0fylwf8h8ulnx.rcgu.o" "C:\\Users\\username\\Dropbox\\dev\\hdtree_rust\\target
\\debug\\deps\\hdtree_rust.3le9awyzz0gyzza3.rcgu.o" "C:\\Users\\username\\Dropbox\\dev\\hdtree_rust\\target\\debug\\deps\\hdtree_rust.3mz25962q1j46fjg.rcgu.o" "C:\\Users\\username\\Dropbox\\dev\\hdtree_rust\\target\\debug\\d
eps\\hdtree_rust.4g9p2kmszo5plezg.rcgu.o" "C:\\Users\\username\\Dropbox\\dev\\hdtree_rust\\target\\debug\\deps\\hdtree_rust.4idues0eeqlb3xz9.rcgu.o" "C:\\Users\\username\\Dropbox\\dev\\hdtree_rust\\target\\debug\\deps\\hdtre
e_rust.5f0n4k1xtlm3wg9l.rcgu.o" "C:\\Users\\username\\Dropbox\\dev\\hdtree_rust\\target\\debug\\deps\\hdtree_rust.5ga6ebzlel6xoxwm.rcgu.o" "C:\\Users\\username\\Dropbox\\dev\\hdtree_rust\\target\\debug\\deps\\hdtree_rust.zvd
o8rmrsj7qkqr.rcgu.o" "/OUT:C:\\Users\\username\\Dropbox\\dev\\hdtree_rust\\target\\debug\\deps\\hdtree_rust.exe" "C:\\Users\\username\\Dropbox\\dev\\hdtree_rust\\target\\debug\\deps\\hdtree_rust.29ih15nz8vqrgzu1.rcgu.o" "/OP
T:REF,NOICF" "/DEBUG" "/NATVIS:C:\\Users\\username\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:C:\\Users\\username\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\l
ib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:C:\\Users\\username\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" "/NATVIS:C:\\Users\\username\\.rustup\\toolchains\\stable-x86_64-pc-wind
ows-msvc\\lib\\rustlib\\etc\\libstd.natvis" "/LIBPATH:C:\\Users\\username\\Dropbox\\dev\\hdtree_rust\\target\\debug\\deps" "/LIBPATH:C:\\Users\\username\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_
64-pc-windows-msvc\\lib" "C:\\Users\\username\\Dropbox\\dev\\hdtree_rust\\target\\debug\\deps\\libperoxide-24bf80c4ddf588c5.rlib" "C:\\Users\\username\\Dropbox\\dev\\hdtree_rust\\target\\debug\\deps\\libcsv-2b6c3aeb6abeb573.
rlib" "C:\\Users\\username\\Dropbox\\dev\\hdtree_rust\\target\\debug\\deps\\libryu-d56761e067164813.rlib" "C:\\Users\\username\\Dropbox\\dev\\hdtree_rust\\target\\debug\\deps\\libitoa-d7c651340e327dcf.rlib" "C:\\Users\\Richa
rd\\Dropbox\\dev\\hdtree_rust\\target\\debug\\deps\\libcsv_core-102be63259463331.rlib" "C:\\Users\\username\\Dropbox\\dev\\hdtree_rust\\target\\debug\\deps\\libbstr-d02df58ca68799e4.rlib" "C:\\Users\\username\\Dropbox\\dev\\
hdtree_rust\\target\\debug\\deps\\libregex_automata-0dd02774b7688856.rlib" "C:\\Users\\username\\Dropbox\\dev\\hdtree_rust\\target\\debug\\deps\\libbyteorder-6de9b9e550938e5e.rlib" "C:\\Users\\username\\Dropbox\\dev\\hdtree_
rust\\target\\debug\\deps\\libmemchr-e69b91a3f49b729c.rlib" "C:\\Users\\username\\Dropbox\\dev\\hdtree_rust\\target\\debug\\deps\\libserde-490de0045ee1405b.rlib" "C:\\Users\\username\\Dropbox\\dev\\hdtree_rust\\target\\debug
\\deps\\librand_distr-f3f2a9aeaf547929.rlib" "C:\\Users\\username\\Dropbox\\dev\\hdtree_rust\\target\\debug\\deps\\libmatrixmultiply-0a35a7d21257890c.rlib" "C:\\Users\\username\\Dropbox\\dev\\hdtree_rust\\target\\debug\\deps
\\librawpointer-c36da0366a5028e9.rlib" "C:\\Users\\username\\Dropbox\\dev\\hdtree_rust\\target\\debug\\deps\\libpuruspe-b3f6429c5fb8c975.rlib" "C:\\Users\\username\\Dropbox\\dev\\hdtree_rust\\target\\debug\\deps\\liborder_st
at-216e1fa5f5fd6ba9.rlib" "C:\\Users\\username\\Dropbox\\dev\\hdtree_rust\\target\\debug\\deps\\libjson-00767a04bcc14eb6.rlib" "C:\\Users\\username\\Dropbox\\dev\\hdtree_rust\\target\\debug\\deps\\libnetcdf-ab3a9c03658592ea.
rlib" "C:\\Users\\username\\Dropbox\\dev\\hdtree_rust\\target\\debug\\deps\\libnetcdf_sys-cae9d15dc48a360f.rlib" "C:\\Users\\username\\Dropbox\\dev\\hdtree_rust\\target\\debug\\deps\\liblazy_static-14780178ad1d3bd0.rlib" "C:
\\Users\\username\\Dropbox\\dev\\hdtree_rust\\target\\debug\\deps\\libindexmap-bdaf8fd585f4cea4.rlib" "C:\\Users\\username\\Dropbox\\dev\\hdtree_rust\\target\\debug\\deps\\librand-f1a6813f03c05795.rlib" "C:\\Users\\username\\
Dropbox\\dev\\hdtree_rust\\target\\debug\\deps\\librand_chacha-511b7d3a4fe8a2e2.rlib" "C:\\Users\\username\\Dropbox\\dev\\hdtree_rust\\target\\debug\\deps\\libppv_lite86-0a2ecd567e7881db.rlib" "C:\\Users\\username\\Dropbox\\
dev\\hdtree_rust\\target\\debug\\deps\\librand_core-5b1cbcc69748ae95.rlib" "C:\\Users\\username\\Dropbox\\dev\\hdtree_rust\\target\\debug\\deps\\libgetrandom-e0be2fffb9b435da.rlib" "C:\\Users\\username\\Dropbox\\dev\\hdtree_
rust\\target\\debug\\deps\\libcfg_if-46d5a3a2d2fb8986.rlib" "C:\\Users\\username\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-93a5cbf3214e1635.rlib" "C:\\Users\\Rich
ard\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-bc497f38bc14ea36.rlib" "C:\\Users\\username\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustl
ib\\x86_64-pc-windows-msvc\\lib\\libhashbrown-cff6a81a38e24acd.rlib" "C:\\Users\\username\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_alloc-2fcb3fe3
0807f5cb.rlib" "C:\\Users\\username\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libbacktrace-916d55fe59b6e45e.rlib" "C:\\Users\\username\\.rustup\\toolchains\\stable-x86_64
-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_demangle-7f1beeb3aa6031c7.rlib" "C:\\Users\\username\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libu
nwind-0f8323184fc867ad.rlib" "C:\\Users\\username\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcfg_if-451043412713beed.rlib" "C:\\Users\\username\\.rustup\\toolchains\\st
able-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-e9eb82ffd1eb284e.rlib" "C:\\Users\\username\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\lib
alloc-8a93a70731c0c815.rlib" "C:\\Users\\username\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_core-6fc8e09b7aa39aaf.rlib" "C:\\Users\\username\\.rust
up\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-05a61bb76241250f.rlib" "C:\\Users\\username\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-wind
ows-msvc\\lib\\libcompiler_builtins-9e67ceffec35e0af.rlib" "netcdf.lib" "netcdf.lib" "advapi32.lib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "msvcrt.lib"
  = note: LINK : fatal error LNK1181: cannot open input file 'netcdf.lib'
  • Notice the double quoted entries at the end of the command like "netcdf.lib" "netcdf.lib" (which also appear for some reason twice?!)
    • At this point there are too many questions: What is generating the link command?
    • is it supposed to find the paths correctly alone?
    • why some entries are duplicated?
    • am I supposed to install the libs by hand at all?
    • if yes: how am I expected to exactly know which versions those should be?
    • how can I make cargo actually recognize them?
  • Too many questions -> Gave up and came here.

Versions:

cargo --version
cargo 1.42.0 (86334295e 2020-01-31)

rustc --version
rustc 1.42.0 (b8cedc004 2020-03-09)

(Windows 10)

Faster polynomial multiplication

The current polynomial multiplication has a runtime of O(n^2). This is fine for some cases (especially lower degree polynomials), but is suboptimal, as it is relatively easy to reduce the runtime using a Fast Fourier Transformation to O(n log n). This would be a considerable speedup for higher degree polynomials.

I think it would be best to perhaps use the currrent algorithm for polynomials of low degree, as it is undoubtedly faster for these kinds, but for higher degree polynomials switch to the more complex, but asymptotically faster FFT. The switching point should of course be determined by the implementation details.

If this is something worth considering, I think there would be three ways to go about using this method:

  1. Use an existing FFT crate which is significantly faster than what would be used in this crate, which in turn significantly improve the runtime of many things using polynomials.
  2. Create a custom implementation of the FFT algorithm. This would mean that the crate has less dependencies, and would therefore be more portable.
  3. You could also possibly use a feature flag to indicate use of an external FFT library, which would include the best of both worlds: It would allow for people who need an efficient implementation to use the external library for the multiplication, and those who care more about portability to use the slower version.

If you think that the second option sounds appealing, I would be willing to write an implementation of the algorithm.

`quantile` may panic

#![feature(drain_filter)]

#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;
use peroxide::statistics::*;

use std::{env, ops::Index};

fn main() -> Result<(), Box<dyn Error>> {
    let data = vec![0f64; 7592];
    let q = quantile(&data, QType::Type1);
    println!("{:?}", q);
    Ok(())
}

Panics with the following:

   Running `target\debug\o2ring.exe C:\Users\asm19\OneDrive\zettlekasten\o2ring\2021-03-28.csv`
thread 'main' panicked at 'index out of bounds: the len is 7592 but the index is 7592', C:\Users\asm19\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\core\src\slice\mod.rs:566:36
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597\/library\std\src\panicking.rs:493
   1: core::panicking::panic_fmt
             at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597\/library\core\src\panicking.rs:92
   2: core::panicking::panic_bounds_check
             at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597\/library\core\src\panicking.rs:69
   3: core::slice::{{impl}}::swap<f64>
             at C:\Users\asm19\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\slice\mod.rs:566
   4: order_stat::floyd_rivest::select_<f64,closure-0>
             at C:\Users\asm19\.cargo\registry\src\github.com-1ecc6299db9ec823\order-stat-0.1.3\src\floyd_rivest.rs:37
   5: order_stat::floyd_rivest::select_<f64,closure-0>
             at C:\Users\asm19\.cargo\registry\src\github.com-1ecc6299db9ec823\order-stat-0.1.3\src\floyd_rivest.rs:32
   6: order_stat::floyd_rivest::select<f64,closure-0>
             at C:\Users\asm19\.cargo\registry\src\github.com-1ecc6299db9ec823\order-stat-0.1.3\src\floyd_rivest.rs:8
   7: order_stat::kth_by<f64,closure-0>
             at C:\Users\asm19\.cargo\registry\src\github.com-1ecc6299db9ec823\order-stat-0.1.3\src\lib.rs:192
   8: peroxide::statistics::stat::quantile_mut
             at C:\Users\asm19\.cargo\registry\src\github.com-1ecc6299db9ec823\peroxide-0.30.5\src\statistics\stat.rs:504
   9: peroxide::statistics::stat::{{impl}}::quantiles
             at C:\Users\asm19\.cargo\registry\src\github.com-1ecc6299db9ec823\peroxide-0.30.5\src\statistics\stat.rs:485
  10: peroxide::statistics::stat::quantile
             at C:\Users\asm19\.cargo\registry\src\github.com-1ecc6299db9ec823\peroxide-0.30.5\src\statistics\stat.rs:527
  11: o2ring::main
             at .\src\main.rs:12
  12: core::ops::function::FnOnce::call_once<fn() -> core::result::Result<tuple<>, alloc::boxed::Box<Error, alloc::alloc::Global>>,tuple<>>
             at C:\Users\asm19\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ops\function.rs:227
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Whole new numerical computations

There will be huge update in 0.31.0 - Algebraic Syntax Tree based Automatic Differentiation.
Therefore, there will be significant changes in the numerical calculation API accordingly.

  1. Optimize (numeric/optimize.rs)
    • API Change
    • Documentation
    1. Zeroth order (Not relate to AD)
      • Bracket minimum
      • Shubert-Piyavskii
      • Fibonacci
      • Golden Section
      • Quadratic Fit
    2. First Order (Use ADScalarFn)
      • Bisection
      • Gradient Descent
      • Conjugate Gradient
      • Momentum
      • Nesterov Momentum
      • Adagrad
      • RMSprop
      • Adadelta
      • Adam
      • Hypergradient
  2. Regression (numeric/reg.rs)
    • API Change
    • Documentation
    1. Linear Regression
      • Ordinary Least Square
      • Ridge
      • LASSO
      • Principal Component Regression
    2. Nonlinear Regression
      • Gradient Descent
      • Gauss-Newton
      • Levenberg-Marquardt
  3. Root Finding (numeric/root.rs)
    • API Change
    • Documentation
    1. Bracketing
      • Bisection
      • False Position
      • Secant
    2. First Order
      • Newton-Raphson

Adaptive Differential Equation Solvers

Hey,

Thanks for the wonderful library. Do you have plans of putting in adaptive solvers of differential equations? Would that require considerable changes to the current framework?

Best,
Amartya

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.