pub trait MonteCarloDefault<State, const D: usize>where
State: LatticeState<D>,{
type Error;
// Required method
fn potential_next_element<Rng>(
&mut self,
state: &State,
rng: &mut Rng
) -> Result<State, Self::Error>
where Rng: Rng + ?Sized;
// Provided methods
fn probability_of_replacement(old_state: &State, new_state: &State) -> Real { ... }
fn next_element_default<Rng>(
&mut self,
state: State,
rng: &mut Rng
) -> Result<State, Self::Error>
where Rng: Rng + ?Sized { ... }
}
Expand description
Some times it is easier to just implement a potential next element, the rest is done automatically using an McWrapper
.
To get an MonteCarlo
use the wrapper McWrapper
.
Example
use lattice_qcd_rs::error::ImplementationError;
use lattice_qcd_rs::simulation::{
LatticeState, LatticeStateDefault, McWrapper, MetropolisHastingsDiagnostic, MonteCarlo,
};
use rand::SeedableRng;
let rng = rand::rngs::StdRng::seed_from_u64(0); // change with your seed
let mh = MetropolisHastingsDiagnostic::new(1, 0.1_f64)
.ok_or(ImplementationError::OptionWithUnexpectedNone)?;
let mut wrapper = McWrapper::new(mh, rng);
// Realistically you want more steps than 10
let mut state = LatticeStateDefault::<3>::new_cold(1_f64, 6_f64, 4)?;
for _ in 0..100 {
state = state.monte_carlo_step(&mut wrapper)?;
println!(
"probability of acceptance during last step {}, does it accepted the change ? {}",
mh.prob_replace_last(),
mh.has_replace_last()
);
// or state.monte_carlo_step(&mut wrapper)?;
// operation to track the progress or the evolution
}
// operation at the end of the simulation
let (_, rng) = wrapper.deconstruct(); // get the rng back
// continue with further operation using the same rng ...
Required Associated Types§
Required Methods§
Provided Methods§
sourcefn probability_of_replacement(old_state: &State, new_state: &State) -> Real
fn probability_of_replacement(old_state: &State, new_state: &State) -> Real
probability of the next element to replace the current one.
by default it is Exp(-H_old) / Exp(-H_new).