pub struct ReplicaExchangeEntropicSampling<Extra, Ensemble, R, Hist, Energy, S, Res> { /* private fields */ }
Expand description
Struct used for entropic sampling with replica exchanges
See this, also for merge functions to create the final probability density functions
Implementations
sourceimpl<Ensemble, R, Hist, Energy, S, Res, Extra> ReplicaExchangeEntropicSampling<Extra, Ensemble, R, Hist, Energy, S, Res>
impl<Ensemble, R, Hist, Energy, S, Res, Extra> ReplicaExchangeEntropicSampling<Extra, Ensemble, R, Hist, Energy, S, Res>
sourcepub fn ensemble_iter(
&self
) -> impl Iterator<Item = RwLockReadGuard<'_, Ensemble>>
pub fn ensemble_iter(
&self
) -> impl Iterator<Item = RwLockReadGuard<'_, Ensemble>>
Iterator over ensembles
If you do not know what RwLockReadGuard<'a, Ensemble>
is - do not worry.
you can just pretend it is &Ensemble
and everything should work out fine,
since it implements Deref
.
Of cause, you can also take a look at RwLockReadGuard
sourcepub fn get_ensemble(&self, index: usize) -> Option<RwLockReadGuard<'_, Ensemble>>
pub fn get_ensemble(&self, index: usize) -> Option<RwLockReadGuard<'_, Ensemble>>
read access to your ensembles
- None if index out of range
- If you do not know what
RwLockReadGuard<Ensemble>
is - do not worry. you can just pretend it is&Ensemble
and everything will work out fine, since it implementsDeref
. Of cause, you can also take a look atRwLockReadGuard
sourcepub unsafe fn get_ensemble_mut(&mut self, index: usize) -> Option<&mut Ensemble>
pub unsafe fn get_ensemble_mut(&mut self, index: usize) -> Option<&mut Ensemble>
mut access to your ensembles
- if possible, prefer
get_ensemble
- unsafe only use this if you know what you are doing
None
ifindex
out of range
Safety
- might panic if a thread is poisened
- it is assumed, that whatever you change has no effect on the Markov Chain, the result of the energy function etc.
sourcepub unsafe fn ensemble_iter_mut(
&mut self
) -> impl Iterator<Item = &mut Ensemble>
pub unsafe fn ensemble_iter_mut(
&mut self
) -> impl Iterator<Item = &mut Ensemble>
Mutable iterator over ensembles
- if possible, prefer
ensemble_iter
Safety
- it is assumed, that whatever you change has no effect on the Markov Chain, the result of the energy function etc.
- might panic if a thread is poisened
sourcepub fn get_hist(&self, index: usize) -> Option<&Hist>
pub fn get_hist(&self, index: usize) -> Option<&Hist>
read access to internal histogram
- None if index out of range
sourcepub fn rewl_roundtrip_iter(&self) -> impl Iterator<Item = usize>
pub fn rewl_roundtrip_iter(&self) -> impl Iterator<Item = usize>
Iterate over the roundtrips done by the REWL
This returns an Iterator which returns the number of roundtrips for each walker. Roundtrips are defined as follows:
If a walker is in the leftest interval, then in the rightest and then in the leftest again (or the other way around) then this is counted as one roundtrip. Note: If only one interval exists, no roundtrips are possible
This iterator will return the roundtrips from the REWL simulation
sourcepub fn rees_roundtrip_iter(&self) -> impl Iterator<Item = usize>
pub fn rees_roundtrip_iter(&self) -> impl Iterator<Item = usize>
Iterator over roundtrips done by REES
- same as rewl_roundtrip_iter just for the rees roundtrips
sourceimpl<Extra, Ensemble, R, Hist, Energy, S, Res> ReplicaExchangeEntropicSampling<Extra, Ensemble, R, Hist, Energy, S, Res>
impl<Extra, Ensemble, R, Hist, Energy, S, Res> ReplicaExchangeEntropicSampling<Extra, Ensemble, R, Hist, Energy, S, Res>
sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Checks threshold
returns true, if all walkers are finished
sourcepub fn num_intervals(&self) -> usize
pub fn num_intervals(&self) -> usize
sourcepub fn num_walkers(&self) -> usize
pub fn num_walkers(&self) -> usize
sourcepub fn walkers_per_interval(&self) -> NonZeroUsize
pub fn walkers_per_interval(&self) -> NonZeroUsize
Returns number of walkers per interval
sourcepub fn walkers(&self) -> &[ReesWalker<R, Hist, Energy, S, Res>]
pub fn walkers(&self) -> &[ReesWalker<R, Hist, Energy, S, Res>]
Returns internal walkers
- access to internal slice of walkers
- the walkers are sorted and neighboring walker are either sampling the same interval, or a neighboring (and if the replica exchange makes any sense overlapping) interval
sourcepub fn change_step_size_of_interval(
&mut self,
n: usize,
step_size: usize
) -> Result<(), ()>
pub fn change_step_size_of_interval(
&mut self,
n: usize,
step_size: usize
) -> Result<(), ()>
Change step size for markov chain of walkers
- changes the step size used in the sweep
- changes step size of all walkers in the nth interval
- returns Err if index out of bounds, i.e., the requested interval does not exist
- interval counting starts at 0, i.e., n=0 is the first interval
sourcepub fn get_step_size_of_interval(&self, n: usize) -> Option<usize>
pub fn get_step_size_of_interval(&self, n: usize) -> Option<usize>
Get step size for markov chain of walkers
- returns
None
if index out of bounds, i.e., the requested interval does not exist - interval counting starts at 0, i.e., n=0 is the first interval
sourcepub fn change_sweep_size_of_interval(
&mut self,
n: usize,
sweep_size: NonZeroUsize
) -> Result<(), ()>
pub fn change_sweep_size_of_interval(
&mut self,
n: usize,
sweep_size: NonZeroUsize
) -> Result<(), ()>
Change sweep size for markov chain of walkers
- changes the sweep size used in the sweep
- changes sweep size of all walkers in the nth interval
- returns Err if index out of bounds, i.e., the requested interval does not exist
- interval counting starts at 0, i.e., n=0 is the first interval
sourcepub fn get_sweep_size_of_interval(&self, n: usize) -> Option<NonZeroUsize>
pub fn get_sweep_size_of_interval(&self, n: usize) -> Option<NonZeroUsize>
Get sweep size for markov chain of walkers
- returns
None
if index out of bounds, i.e., the requested interval does not exist - interval counting starts at 0, i.e., n=0 is the first interval
sourcepub fn extra_slice(&self) -> &[Extra]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
pub fn extra_slice(&self) -> &[Extra]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
sourcepub fn extra_slice_mut(&mut self) -> &mut [Extra]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
pub fn extra_slice_mut(&mut self) -> &mut [Extra]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
sourcepub fn unpack_extra(
self
) -> (ReplicaExchangeEntropicSampling<(), Ensemble, R, Hist, Energy, S, Res>, Vec<Extra, Global>)
pub fn unpack_extra(
self
) -> (ReplicaExchangeEntropicSampling<(), Ensemble, R, Hist, Energy, S, Res>, Vec<Extra, Global>)
Remove extra vector
- returns tuple of Self (without extra, i.e.,
Rees<(), Ensemble, R, Hist, Energy, S, Res>
) and vector of Extra
sourcepub fn swap_extra<Extra2>(
self,
new_extra: Vec<Extra2, Global>
) -> Result<(ReplicaExchangeEntropicSampling<Extra2, Ensemble, R, Hist, Energy, S, Res>, Vec<Extra, Global>), ()>
pub fn swap_extra<Extra2>(
self,
new_extra: Vec<Extra2, Global>
) -> Result<(ReplicaExchangeEntropicSampling<Extra2, Ensemble, R, Hist, Energy, S, Res>, Vec<Extra, Global>), ()>
Swap the extra vector
- Note: len of extra has to be the same as
self.num_walkers()
(which is the same asself.extra_slice().len()
) otherwise an Err is returned
sourceimpl<Ensemble, R, Hist, Energy, S, Res> ReplicaExchangeEntropicSampling<(), Ensemble, R, Hist, Energy, S, Res>
impl<Ensemble, R, Hist, Energy, S, Res> ReplicaExchangeEntropicSampling<(), Ensemble, R, Hist, Energy, S, Res>
sourcepub fn add_extra<Extra>(
self,
extra: Vec<Extra, Global>
) -> Result<ReplicaExchangeEntropicSampling<Extra, Ensemble, R, Hist, Energy, S, Res>, (ReplicaExchangeEntropicSampling<(), Ensemble, R, Hist, Energy, S, Res>, Vec<Extra, Global>)>
pub fn add_extra<Extra>(
self,
extra: Vec<Extra, Global>
) -> Result<ReplicaExchangeEntropicSampling<Extra, Ensemble, R, Hist, Energy, S, Res>, (ReplicaExchangeEntropicSampling<(), Ensemble, R, Hist, Energy, S, Res>, Vec<Extra, Global>)>
Add extra information to your Replica Exchange entropic sampling simulation
- can be used to, e.g., print stuff during the simulation, or write it to a file and so on
sourceimpl<Extra, Ensemble, R, Hist, Energy, S, Res> ReplicaExchangeEntropicSampling<Extra, Ensemble, R, Hist, Energy, S, Res>where
Ensemble: Send + Sync + MarkovChain<S, Res>,
R: Send + Sync + Rng,
Extra: Send + Sync,
Hist: Send + Sync + Histogram + HistogramVal<Energy>,
Energy: Send + Sync + Clone,
S: Send + Sync,
Res: Send + Sync,
impl<Extra, Ensemble, R, Hist, Energy, S, Res> ReplicaExchangeEntropicSampling<Extra, Ensemble, R, Hist, Energy, S, Res>where
Ensemble: Send + Sync + MarkovChain<S, Res>,
R: Send + Sync + Rng,
Extra: Send + Sync,
Hist: Send + Sync + Histogram + HistogramVal<Energy>,
Energy: Send + Sync + Clone,
S: Send + Sync,
Res: Send + Sync,
sourcepub fn refine(&mut self)
pub fn refine(&mut self)
Refine the estimate of the probability density functions
- refines the estimate of all walkers
- does so by calling the walker method refine
sourcepub fn sweep<F, P>(&mut self, energy_fn: F, extra_fn: P)where
F: Fn(&mut Ensemble) -> Option<Energy> + Copy + Send + Sync,
P: Fn(&ReesWalker<R, Hist, Energy, S, Res>, &mut Ensemble, &mut Extra) + Copy + Send + Sync,
pub fn sweep<F, P>(&mut self, energy_fn: F, extra_fn: P)where
F: Fn(&mut Ensemble) -> Option<Energy> + Copy + Send + Sync,
P: Fn(&ReesWalker<R, Hist, Energy, S, Res>, &mut Ensemble, &mut Extra) + Copy + Send + Sync,
Sweep
- Performs one sweep of the Replica exchange entropic sampling simulation
- You can make a complete simulation, by repeatatly calling this method
until
self.is_finished()
returns true
sourcepub fn simulate_until_convergence<F, P>(&mut self, energy_fn: F, extra_fn: P)where
Ensemble: Send + Sync,
R: Send + Sync,
F: Fn(&mut Ensemble) -> Option<Energy> + Copy + Send + Sync,
P: Fn(&ReesWalker<R, Hist, Energy, S, Res>, &mut Ensemble, &mut Extra) + Copy + Send + Sync,
pub fn simulate_until_convergence<F, P>(&mut self, energy_fn: F, extra_fn: P)where
Ensemble: Send + Sync,
R: Send + Sync,
F: Fn(&mut Ensemble) -> Option<Energy> + Copy + Send + Sync,
P: Fn(&ReesWalker<R, Hist, Energy, S, Res>, &mut Ensemble, &mut Extra) + Copy + Send + Sync,
Perform the Replica exchange simulation
- will simulate until all walkers are finished
- extra_fn should be used for example for writing Data to a file
sourcepub fn simulate_while<F, C, P>(&mut self, energy_fn: F, condition: C, extra_fn: P)where
Ensemble: Send + Sync,
R: Send + Sync,
F: Fn(&mut Ensemble) -> Option<Energy> + Copy + Send + Sync,
C: FnMut(&ReplicaExchangeEntropicSampling<Extra, Ensemble, R, Hist, Energy, S, Res>) -> bool,
P: Fn(&ReesWalker<R, Hist, Energy, S, Res>, &mut Ensemble, &mut Extra) + Copy + Send + Sync,
pub fn simulate_while<F, C, P>(&mut self, energy_fn: F, condition: C, extra_fn: P)where
Ensemble: Send + Sync,
R: Send + Sync,
F: Fn(&mut Ensemble) -> Option<Energy> + Copy + Send + Sync,
C: FnMut(&ReplicaExchangeEntropicSampling<Extra, Ensemble, R, Hist, Energy, S, Res>) -> bool,
P: Fn(&ReesWalker<R, Hist, Energy, S, Res>, &mut Ensemble, &mut Extra) + Copy + Send + Sync,
Perform the Replica exchange simulation
- will simulate until all walkers are finished or
- until condition returns false
sourcepub fn check_energy_fn<F>(&mut self, energy_fn: F) -> boolwhere
Energy: PartialEq<Energy>,
F: Fn(&mut Ensemble) -> Option<Energy> + Copy + Send + Sync,
pub fn check_energy_fn<F>(&mut self, energy_fn: F) -> boolwhere
Energy: PartialEq<Energy>,
F: Fn(&mut Ensemble) -> Option<Energy> + Copy + Send + Sync,
Sanity check
- checks if the stored (i.e., last) energy(s) of the system match with the result of energy_fn
sourcepub fn merged_log_prob(&self) -> Result<(Hist, Vec<f64, Global>), HistErrors>where
Hist: HistogramCombine,
👎Deprecated since 0.2.0: will be removed in future releases. Use new method ‘derivative_merged_log_prob_and_aligned’ or consider using ‘average_merged_log_probability_and_align’ instead
pub fn merged_log_prob(&self) -> Result<(Hist, Vec<f64, Global>), HistErrors>where
Hist: HistogramCombine,
Result of the simulations!
This is what we do the simulation for!
It returns the natural logarithm of the normalized (i.e. sum=1 within numerical precision) probability density and the histogram, which contains the corresponding bins.
Failes if the internal histograms (invervals) do not align. Might fail if there is no overlap between neighboring intervals
sourcepub fn merged_log_prob_and_aligned(
&self
) -> Result<(Hist, Vec<f64, Global>, Vec<Vec<f64, Global>, Global>), HistErrors>where
Hist: HistogramCombine,
👎Deprecated since 0.2.0: will be removed in future releases. Use new method ‘derivative_merged_log_prob_and_aligned’ or consider using ‘average_merged_log_probability_and_align’ instead
pub fn merged_log_prob_and_aligned(
&self
) -> Result<(Hist, Vec<f64, Global>, Vec<Vec<f64, Global>, Global>), HistErrors>where
Hist: HistogramCombine,
Results of the simulation
This is what we do the simulation for!
It returns histogram, which contains the corresponding bins and the natural logarithm of the normalized (i.e. sum=1 within numerical precision) probability density. Lastly it returns the vector of the aligned probability estimates (also ln) of the different intervals. This can be used to see, how good the simulation worked, e.g., by plotting them to see, if they match
Notes
Failes if the internal histograms (invervals) do not align. Might fail if there is no overlap between neighboring intervals
sourcepub fn average_merged_log_probability_and_align(
&self
) -> Result<ReplicaGlued<Hist>, HistErrors>where
Hist: HistogramCombine,
pub fn average_merged_log_probability_and_align(
&self
) -> Result<ReplicaGlued<Hist>, HistErrors>where
Hist: HistogramCombine,
Results of the simulation
This is what we do the simulation for!
It returns ReplicaGlued
which allows you to print out the merged probability density function.
It also allows you to switch the base of the logarithm and so on, have a look!
It will use an average based merging algorthim, i.e., it will try to align the intervals and merge them by using the values obtained by averaging in log-space
Notes
Fails if the internal histograms (intervals) do not align. Might fail if there is no overlap between neighboring intervals
sourcepub fn derivative_merged_log_prob_and_aligned(
&self
) -> Result<ReplicaGlued<Hist>, HistErrors>where
Hist: HistogramCombine + Histogram,
pub fn derivative_merged_log_prob_and_aligned(
&self
) -> Result<ReplicaGlued<Hist>, HistErrors>where
Hist: HistogramCombine + Histogram,
Results of the simulation
This is what we do the simulation for!
It returns ReplicaGlued
which allows you to print out the merged probability density function.
It also allows you to switch the base of the logarithm and so on, have a look!
It will use an derivative based merging algorthim, i.e., it will try to align the intervals and merge them by looking at the derivatives of the probability density function. It will search for the (merging-)point where the derivatives are the most similar to each other and glue by using the values of one of the intervals before the merging point and the other interval afterwards. This is repeated for every interval
Notes
Fails if the internal histograms (intervals) do not align. Might fail if there is no overlap between neighboring intervals