Crates.io | rugfield |
lib.rs | rugfield |
version | 0.2.2 |
source | src |
created_at | 2024-03-19 02:28:07.802077 |
updated_at | 2024-05-15 08:05:55.178842 |
description | A Rust library for generating Gaussian Random Fields using the circulant embedding method |
homepage | |
repository | https://github.com/axect/Rugfield |
max_upload_size | |
id | 1178704 |
size | 29,298 |
Rugfield is a Rust library for generating Gaussian Random Fields (GRFs) using the circulant embedding method. It provides an efficient and easy-to-use implementation for simulating GRFs with various kernel functions.
SquaredExponential
Matern
LocalPeriodic
RationalQuadratic
rustfft
libraryserde
featureAdd the following to your Cargo.toml
file:
[dependencies]
rugfield = "0.2.2"
Here's a simple example of how to use Rugfield to generate a GRF with a squared exponential kernel:
use rugfield::{grf, Kernel};
fn main() {
let n = 100;
let kernel = Kernel::SquaredExponential(0.1);
let grf_data = grf(n, kernel);
// Plot the GRF data
// ...
}
This code generates a GRF with a squared exponential kernel and a length scale of 0.1. The resulting GRF data is stored in the grf_data
vector.
For a complete example, see the examples/squared_exponential.rs
file:
use peroxide::fuga::*;
use rugfield::{grf, Kernel::SquaredExponential};
fn main() -> Result<(), Box<dyn Error>> {
let x_max = 100.0;
let x_min = 0.0;
let sigma = 0.1;
let n = 1000;
let samples = 8;
let kernel = SquaredExponential(sigma);
let x = linspace_with_precision(x_min, x_max, n, 2);
let grfs = (0..samples).map(|_| grf(n, kernel)).collect::<Vec<_>>();
// Plot the GRF data
// ...
Ok(())
}
With a specific random number generator:
use peroxide::fuga::*;
use rugfield::{grf_with_rng, Kernel::SquaredExponential};
fn main() -> Result<(), Box<dyn Error>> {
let n = 100;
let kernel = SquaredExponential(0.1);
let mut rng = stdrng_from_seed(42);
let grf_data = grf_with_rng(&mut rng, n, kernel);
// ...
}
The above code generates multiple GRFs with a squared exponential kernel and plots the resulting data. Here's an example output:
For detailed documentation and API reference, please refer to the Rustdoc documentation.
Rugfield is licensed under the MIT License.
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request on the GitHub repository.
Rugfield was inspired by the paper "An Effective Method for Simulating Gaussian Random Fields" by Grace Chan (1999).
We would like to express our gratitude to the authors of the rustfft
library for their excellent work, which has been instrumental in the development of Rugfield.