Crates.io | exp_root_log |
lib.rs | exp_root_log |
version | 0.1.2 |
source | src |
created_at | 2025-05-06 03:18:20.813451+00 |
updated_at | 2025-05-06 03:42:25.164628+00 |
description | Fast and interpretable function approximation with exp-root-log basis |
homepage | |
repository | |
max_upload_size | |
id | 1661829 |
size | 18,335 |
ExpRoot+Log is a fast and interpretable function approximation method based on a hybrid linear basis. It combines exponential square-root, polynomial, and logarithmic terms to efficiently approximate a wide range of functions, including smooth, discontinuous, and decaying ones.
The full write‑up (motivation, math derivation, and numeric experiments) is available on dev.to:
👉 ExpRoot + Log: A Linear and Universal Basis for Function Approximation
https://dev.to/andysay/exprootlog-a-linear-and-universal-basis-for-function-approximation-2e9d
Cargo.toml
:[dependencies]
exp_root_log = "0.1.0"
examples/demo.rs
:use exp_root_log::approx_exp_root_log;
fn main() {
// Generate test data
let x: Vec<f64> = (0..100).map(|i| i as f64 / 100.0).collect();
let y: Vec<f64> = x.iter().map(|&x| (2.0 * std::f64::consts::PI * x).sin()).collect();
// Create the approximation function using ExpRoot+Log
let approx_fn = approx_exp_root_log(
&x,
&y,
&[0.5, 2.0, 5.0, 10.0, 20.0], // b_i
5, // x^5
&[1.0, 5.0, 10.0, 20.0], // log params
);
// Evaluate the approximation
let y_pred: Vec<f64> = x.iter().map(|&xi| approx_fn(xi)).collect();
// Print the result
println!("Approximated values: {:?}", y_pred);
}
Function | ExpRoot + Log ▪ MSE |
Polynomial deg 10 ▪ MSE |
Take‑away |
---|---|---|---|
Sin |
3.67 × 10⁻⁸ | 1.34 × 10⁻¹¹ | Poly‑10 is a hair better on a pure sine; ExpRoot + Log is still < 10⁻⁷. |
ExpDecay |
1.46 × 10⁻¹³ | 1.14 × 10⁻¹⁵ | Both are essentially machine‑precision; ExpRoot + Log keeps up. |
Step |
1.52 × 10⁻² | 1.51 × 10⁻² | Equal accuracy on a hard discontinuity, no Gibbs ringing. |
Spike |
4.23 × 10⁻³ | 2.55 × 10⁻³ | Narrow Gaussian spike: poly‑10 wins on raw MSE, but ExpRoot + Log is ~2× better than a 6‑knot cubic spline. |
⏱ Average runtime on 2 000 points (Apple M1,
cargo run --example benchmark
):
ExpRoot + Log ≈ 47 ms | Poly deg 10 ≈ 32 ms
Two SVDs of comparable size; speed improves proportionally if you reduce basis size or enable rayon.
git clone https://github.com/andysay1/exp_root_log
cd exp_root_log
cargo run --example benchmark