Struct ReplicaExchangeEntropicSampling

Source
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§

Source§

impl<Ensemble, R, Hist, Energy, S, Res, Extra> ReplicaExchangeEntropicSampling<Extra, Ensemble, R, Hist, Energy, S, Res>

Source

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

Source

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 implements Deref. Of cause, you can also take a look at RwLockReadGuard
Source

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 if index out of range
§Safety
  • might panic if a thread is poisoned
  • it is assumed, that whatever you change has no effect on the Markov Chain, the result of the energy function etc.
Source

pub unsafe fn ensemble_iter_mut( &mut self, ) -> impl Iterator<Item = &mut Ensemble>

§Mutable iterator over ensembles
§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 poisoned
Source

pub fn hists(&self) -> Vec<&Hist>

§read access to the internal histograms used by the walkers
Source

pub fn get_hist(&self, index: usize) -> Option<&Hist>

§read access to internal histogram
  • None if index out of range
Source

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

Source

pub fn rees_roundtrip_iter(&self) -> impl Iterator<Item = usize> + '_

§Iterator over roundtrips done by REES
Source§

impl<Extra, Ensemble, R, Hist, Energy, S, Res> ReplicaExchangeEntropicSampling<Extra, Ensemble, R, Hist, Energy, S, Res>

Source

pub fn is_finished(&self) -> bool

§Checks threshold

returns true, if all walkers are finished

Source

pub fn num_intervals(&self) -> usize

§Get the number of intervals present
Source

pub fn num_walkers(&self) -> usize

§How many walkers are there in total?
Source

pub fn walkers_per_interval(&self) -> NonZeroUsize

Returns number of walkers per interval

Source

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
Source

pub fn change_step_size_of_interval( &mut self, n: usize, step_size: usize, ) -> Outcome

§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 Failure 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
Source

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
Source

pub fn change_sweep_size_of_interval( &mut self, n: usize, sweep_size: NonZeroUsize, ) -> Outcome

§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 Failure 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
Source

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
Source

pub fn extra_slice(&self) -> &[Extra]

§Read access to your extra information
Source

pub fn extra_slice_mut(&mut self) -> &mut [Extra]

§Write access to your extra information
Source

pub fn unpack_extra( self, ) -> (Rees<(), Ensemble, R, Hist, Energy, S, Res>, Vec<Extra>)

§Remove extra vector
  • returns tuple of Self (without extra, i.e., Rees<(), Ensemble, R, Hist, Energy, S, Res>) and vector of Extra
Source

pub fn swap_extra<Extra2>( self, new_extra: Vec<Extra2>, ) -> Option<(Rees<Extra2, Ensemble, R, Hist, Energy, S, Res>, Vec<Extra>)>

§Swap the extra vector
  • Note: len of extra has to be the same as self.num_walkers() (which is the same as self.extra_slice().len()), otherwise swapping will fail
  • If swap was successful, new Rees is returned, and the old Extra as well, in case you want to do something with it
Source§

impl<Ensemble, R, Hist, Energy, S, Res> ReplicaExchangeEntropicSampling<(), Ensemble, R, Hist, Energy, S, Res>

Source

pub fn add_extra<Extra>( self, extra: Vec<Extra>, ) -> Result<Rees<Extra, Ensemble, R, Hist, Energy, S, Res>, (Self, Vec<Extra>)>

§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
Source§

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,

Source

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
Source

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 repeatedly calling this method until self.is_finished() returns true
Source

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
Source

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(&Self) -> 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
Source

pub fn check_energy_fn<F>(&mut self, energy_fn: F) -> bool
where Energy: PartialEq, 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
Source

pub fn merged_log_prob_rees(&self) -> Result<(Hist, Vec<f64>), 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
§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.

Fails if the internal histograms (intervals) do not align. Might fail if there is no overlap between neighboring intervals

Source

pub fn average_merged_log_probability_and_align( &self, ) -> Result<Glued<Hist, Energy>, HistErrors>
where Hist: HistogramCombine,

§Results of the simulation

This is what we do the simulation for!

It returns Glued 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 algorithm, 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

Source

pub fn derivative_merged_log_prob_and_aligned( &self, ) -> Result<Glued<Hist, Energy>, HistErrors>

§Results of the simulation

This is what we do the simulation for!

It returns Glued 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 algorithm, 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

Trait Implementations§

Source§

impl<Extra: Debug, Ensemble: Debug, R: Debug, Hist: Debug, Energy: Debug, S: Debug, Res: Debug> Debug for ReplicaExchangeEntropicSampling<Extra, Ensemble, R, Hist, Energy, S, Res>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de, Extra, Ensemble, R, Hist, Energy, S, Res> Deserialize<'de> for ReplicaExchangeEntropicSampling<Extra, Ensemble, R, Hist, Energy, S, Res>
where Extra: Deserialize<'de>, Ensemble: Deserialize<'de>, R: Deserialize<'de>, Hist: Deserialize<'de>, Energy: Deserialize<'de>, S: Deserialize<'de>, Res: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<Extra, Ensemble, R, Hist, Energy, S, Res> GlueAble<Hist> for ReplicaExchangeEntropicSampling<Extra, Ensemble, R, Hist, Energy, S, Res>
where Hist: Clone + Histogram,

Source§

fn push_glue_entry_ignoring( &self, job: &mut GlueJob<Hist>, ignore_idx: &[usize], )

Add selfto the GlueJob, but ignore some indices
Source§

fn push_glue_entry(&self, job: &mut GlueJob<H>)

Add self to the GlueJob
Source§

impl<Extra, Ensemble, R, Hist, Energy, S, Res> Serialize for ReplicaExchangeEntropicSampling<Extra, Ensemble, R, Hist, Energy, S, Res>
where Extra: Serialize, Ensemble: Serialize, R: Serialize, Hist: Serialize, Energy: Serialize, S: Serialize, Res: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<Extra, Ensemble, R, Hist, Energy, S, Res> Freeze for ReplicaExchangeEntropicSampling<Extra, Ensemble, R, Hist, Energy, S, Res>

§

impl<Extra, Ensemble, R, Hist, Energy, S, Res> RefUnwindSafe for ReplicaExchangeEntropicSampling<Extra, Ensemble, R, Hist, Energy, S, Res>

§

impl<Extra, Ensemble, R, Hist, Energy, S, Res> Send for ReplicaExchangeEntropicSampling<Extra, Ensemble, R, Hist, Energy, S, Res>
where Extra: Send, Ensemble: Send, R: Send, Hist: Send, Energy: Send, Res: Send, S: Send,

§

impl<Extra, Ensemble, R, Hist, Energy, S, Res> Sync for ReplicaExchangeEntropicSampling<Extra, Ensemble, R, Hist, Energy, S, Res>
where Extra: Sync, Ensemble: Send + Sync, R: Sync, Hist: Sync, Energy: Sync, Res: Sync, S: Sync,

§

impl<Extra, Ensemble, R, Hist, Energy, S, Res> Unpin for ReplicaExchangeEntropicSampling<Extra, Ensemble, R, Hist, Energy, S, Res>
where Extra: Unpin, R: Unpin, Hist: Unpin, Energy: Unpin, Ensemble: Unpin, Res: Unpin, S: Unpin,

§

impl<Extra, Ensemble, R, Hist, Energy, S, Res> UnwindSafe for ReplicaExchangeEntropicSampling<Extra, Ensemble, R, Hist, Energy, S, Res>
where Extra: UnwindSafe, R: UnwindSafe, Hist: UnwindSafe, Energy: UnwindSafe, Res: UnwindSafe, S: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,