csta_derive

Crates.iocsta_derive
lib.rscsta_derive
version1.0.0
sourcesrc
created_at2024-03-12 16:14:47.271116
updated_at2024-03-12 16:14:47.271116
descriptionMacro implementation of #[derive(Randomizable)]
homepage
repository
max_upload_size
id1170775
size14,688
Carlettos (Carlettos1)

documentation

README

CSTA

A personal statistics library, with montecarlo support.

Usage

Add csta to Cargo.toml.

[dependencies]
csta = "1.0.0"
csta_derive = version = "1.0.0"
rand = "0.8.5"

Histogram

let mut hist = Hist::with_buckets(0.0, 6.0, 6);
let mut rng = thread_rng();

for _ in 0..1000 {
    let x = rng.gen_range(0.0..6.0);
    hist.add(&x);
}

println!("avg: {}, sd: {}", hist.average(), hist.variance().sqrt());

For saving the histogram, the struct contains a save function.

hist.save("./histogram");

As a convenience function, there is save numpy, which makes the plotting using matplotlib easier.

hist.save_numpy("./histogram");
import matplotlib.pyplot as plt
import numpy as np

[counts, bins] = np.loadtxt("histogram", delimiter=",")
# the first count is a filler, so we remove it
counts = counts[1:]
plt.stairs(counts, bins, fill=True)
plt.show()

A more complete example is on this file. And here the code of the plotter in python.

Randomizable and Montecarlo

Randomizable is a derivable trait to produce a struct with random values.

#[derive(Debug, Randomizable)]
struct Dice<const N: usize>(#[rng(range(1..=N))] usize);

Any randomizable can be used in a Montecarlo iterator.

MonteCarlo::default()
    .into_iter()
    .take(10)
    .for_each(|dice: Dice<6> /* type anotations needed */| {
        println!("dice: {:?}", dice);
    });

Any tuple of randomizables is randomizable, f64 is randomizable. To see more about the Randomizable derive and montecarlo, go to this file.

Indexing

Provides indexing utilities, used in the ising system.

Markov

Markov chain system. Used in ising and within the Lennard-Jones in particles

Prelude

Commonly used types for easier usage of the library.

Commit count: 0

cargo fmt