[−][src]Struct net_ensembles::er_m::ErEnsembleM
Implements Erdős-Rényi graph ensemble
Constant number of edges
- Note simple sampling of this ensemble is somewhat inefficient right now - I might change it in the future, though that will change the results of the simple sampling (Not on average of cause)
- for simple sampling look at
SimpleSample
trait - for markov steps look at
MarkovChain
trait
Other
- for topology functions look at
GenericGraph
- to access underlying topology or manipulate additional data look at
WithGraph
trait - to use or swap the random number generator, look at
HasRng
trait
Save and load example
- only works if feature
"serde_support"
is enabled - Note:
"serde_support"
is enabled by default - I need the
#[cfg(feature = "serde_support")]
to ensure the example does compile if - you can do not have to use
serde_json
, look here for more info you opt out of the default feature
use net_ensembles::traits::*; // I recommend always using this use serde_json; use rand_pcg::Pcg64; use net_ensembles::{ErEnsembleM, EmptyNode, rand::SeedableRng}; use std::fs::File; let rng = Pcg64::seed_from_u64(95); // create Erdős-Rényi ensemble with 200 vertices and 600 edges let er_ensemble = ErEnsembleM::<EmptyNode, Pcg64>::new(200, 600, rng); #[cfg(feature = "serde_support")] { // storing the ensemble in a file: let er_m_file = File::create("store_ER_m.dat") .expect("Unable to create file"); // or serde_json::to_writer(er_m_file, &er_ensemble); serde_json::to_writer_pretty(er_m_file, &er_ensemble); // loading ensemble from file: let mut read = File::open("store_ER_m.dat") .expect("Unable to open file"); let er: ErEnsembleM::<EmptyNode, Pcg64> = serde_json::from_reader(read).unwrap(); }
Implementations
impl<T, R> ErEnsembleM<T, R> where
T: Node + SerdeStateConform,
R: Rng,
[src]
T: Node + SerdeStateConform,
R: Rng,
pub fn new(n: usize, m: usize, rng: R) -> Self
[src]
Initialize
create new ErEnsembleM graph with:
n
verticesm
edgesrng
is consumed and used as random number generator in the following- internally uses
Graph<T>::new(n)
- generates random edges according to ER model
pub fn get_m(&self) -> usize
[src]
Return total number of edges
pub fn sort_adj(&mut self)
[src]
Sort adjecency lists
If you depend on the order of the adjecency lists, you can sort them
Performance
- internally uses pattern-defeating quicksort as long as that is the standard
- sorts an adjecency list with length
d
in worst-case:O(d log(d))
- is called for each adjecency list, i.e.,
self.vertex_count()
times
Trait Implementations
impl<T, R> AsRef<GenericGraph<T, NodeContainer<T>>> for ErEnsembleM<T, R> where
T: Node,
R: Rng,
[src]
T: Node,
R: Rng,
impl<T, R> Borrow<GenericGraph<T, NodeContainer<T>>> for ErEnsembleM<T, R> where
T: Node,
R: Rng,
[src]
T: Node,
R: Rng,
impl<T: Clone + Node, R: Clone + Rng> Clone for ErEnsembleM<T, R> where
T: Node,
R: Rng,
[src]
T: Node,
R: Rng,
fn clone(&self) -> ErEnsembleM<T, R>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T: Debug + Node, R: Debug + Rng> Debug for ErEnsembleM<T, R> where
T: Node,
R: Rng,
[src]
T: Node,
R: Rng,
impl<'de, T: Node, R: Rng> Deserialize<'de> for ErEnsembleM<T, R> where
T: Node,
R: Rng,
T: Deserialize<'de>,
R: Deserialize<'de>,
[src]
T: Node,
R: Rng,
T: Deserialize<'de>,
R: Deserialize<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl<T, R> GraphIteratorsMut<T, GenericGraph<T, NodeContainer<T>>, NodeContainer<T>> for ErEnsembleM<T, R> where
T: Node + SerdeStateConform,
R: Rng,
[src]
T: Node + SerdeStateConform,
R: Rng,
fn contained_iter_neighbors_mut(
&mut self,
index: usize
) -> NContainedIterMut<T, NodeContainer<T>>
[src]
&mut self,
index: usize
) -> NContainedIterMut<T, NodeContainer<T>>
fn contained_iter_neighbors_mut_with_index(
&mut self,
index: usize
) -> INContainedIterMut<T, NodeContainer<T>>
[src]
&mut self,
index: usize
) -> INContainedIterMut<T, NodeContainer<T>>
fn contained_iter_mut(&mut self) -> ContainedIterMut<T, NodeContainer<T>>
[src]
impl<T, R> HasRng<R> for ErEnsembleM<T, R> where
T: Node,
R: Rng,
[src]
T: Node,
R: Rng,
fn rng(&mut self) -> &mut R
[src]
Access RNG
If, for some reason, you want access to the internal random number generator: Here you go
fn swap_rng(&mut self, rng: R) -> R
[src]
Swap random number generator
- returns old internal rng
impl<T, R> MarkovChain<ErStepM, ErStepM> for ErEnsembleM<T, R> where
T: Node + SerdeStateConform,
R: Rng,
[src]
T: Node + SerdeStateConform,
R: Rng,
fn undo_step(&mut self, step: ErStepM) -> ErStepM
[src]
- undo a markov step, return result-state
- if you want to undo more than one step
see
undo_steps
fn undo_step_quiet(&mut self, step: ErStepM)
[src]
- undo a markov step, panic on invalid result state
- for undoing multiple steps see
undo_steps_quiet
fn m_step(&mut self) -> ErStepM
[src]
Markov step
- use this to perform a markov step
- for doing multiple mc steps at once, use
m_steps
fn m_steps(&mut self, count: usize) -> Vec<S>
[src]
fn undo_steps(&mut self, steps: Vec<S>) -> Vec<Res>
[src]
fn undo_steps_quiet(&mut self, steps: Vec<S>)
[src]
impl<T: Node, R: Rng> Serialize for ErEnsembleM<T, R> where
T: Node,
R: Rng,
T: Serialize,
R: Serialize,
[src]
T: Node,
R: Rng,
T: Serialize,
R: Serialize,
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl<T, R> SimpleSample for ErEnsembleM<T, R> where
T: Node + SerdeStateConform,
R: Rng,
[src]
T: Node + SerdeStateConform,
R: Rng,
fn randomize(&mut self)
[src]
Randomizes self according to model
- this is intended for creation of initial sample
- used in
simple_sample
andsimple_sample_vec
fn simple_sample<F>(&mut self, times: usize, f: F) where
F: FnMut(&Self),
[src]
F: FnMut(&Self),
fn simple_sample_vec<F, G>(&mut self, times: usize, f: F) -> Vec<G> where
F: FnMut(&Self) -> G,
[src]
F: FnMut(&Self) -> G,
impl<T, R> WithGraph<T, GenericGraph<T, NodeContainer<T>>> for ErEnsembleM<T, R> where
T: Node + SerdeStateConform,
R: Rng,
[src]
T: Node + SerdeStateConform,
R: Rng,
Auto Trait Implementations
impl<T, R> RefUnwindSafe for ErEnsembleM<T, R> where
R: RefUnwindSafe,
T: RefUnwindSafe,
R: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, R> Send for ErEnsembleM<T, R> where
R: Send,
T: Send,
R: Send,
T: Send,
impl<T, R> Sync for ErEnsembleM<T, R> where
R: Sync,
T: Sync,
R: Sync,
T: Sync,
impl<T, R> Unpin for ErEnsembleM<T, R> where
R: Unpin,
T: Unpin,
R: Unpin,
T: Unpin,
impl<T, R> UnwindSafe for ErEnsembleM<T, R> where
R: UnwindSafe,
T: UnwindSafe,
R: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<S, Res, A> Metropolis<S, Res> for A where
A: MarkovChain<S, Res>,
[src]
A: MarkovChain<S, Res>,
fn metropolis<Rng, F, G, H>(
&mut self,
rng: Rng,
temperature: f64,
stepsize: usize,
steps: usize,
valid_self: F,
energy: G,
measure: H
) -> MetropolisState<Rng> where
F: FnMut(&mut Self) -> bool,
G: FnMut(&mut Self) -> f64,
H: FnMut(&mut Self, usize, f64, bool),
Rng: Rng,
[src]
&mut self,
rng: Rng,
temperature: f64,
stepsize: usize,
steps: usize,
valid_self: F,
energy: G,
measure: H
) -> MetropolisState<Rng> where
F: FnMut(&mut Self) -> bool,
G: FnMut(&mut Self) -> f64,
H: FnMut(&mut Self, usize, f64, bool),
Rng: Rng,
fn metropolis_while<Rng, F, G, H, B>(
&mut self,
rng: Rng,
temperature: f64,
stepsize: usize,
steps: usize,
valid_self: F,
energy: G,
measure: H,
brake_if: B
) -> MetropolisState<Rng> where
F: FnMut(&mut Self) -> bool,
G: FnMut(&mut Self) -> f64,
H: FnMut(&mut Self, usize, f64, bool),
B: FnMut(&Self, usize) -> bool,
Rng: Rng,
[src]
&mut self,
rng: Rng,
temperature: f64,
stepsize: usize,
steps: usize,
valid_self: F,
energy: G,
measure: H,
brake_if: B
) -> MetropolisState<Rng> where
F: FnMut(&mut Self) -> bool,
G: FnMut(&mut Self) -> f64,
H: FnMut(&mut Self, usize, f64, bool),
B: FnMut(&Self, usize) -> bool,
Rng: Rng,
fn continue_metropolis_while<R, F, G, H, B>(
&mut self,
state: MetropolisState<R>,
ignore_energy_missmatch: bool,
valid_self: F,
energy: G,
measure: H,
brake_if: B
) -> MetropolisState<R> where
F: FnMut(&mut Self) -> bool,
G: FnMut(&mut Self) -> f64,
H: FnMut(&mut Self, usize, f64, bool),
B: FnMut(&Self, usize) -> bool,
R: Rng,
[src]
&mut self,
state: MetropolisState<R>,
ignore_energy_missmatch: bool,
valid_self: F,
energy: G,
measure: H,
brake_if: B
) -> MetropolisState<R> where
F: FnMut(&mut Self) -> bool,
G: FnMut(&mut Self) -> f64,
H: FnMut(&mut Self, usize, f64, bool),
B: FnMut(&Self, usize) -> bool,
R: Rng,
fn continue_metropolis<Rng, F, G, H>(
&mut self,
state: MetropolisState<Rng>,
ignore_energy_missmatch: bool,
valid_self: F,
energy: G,
measure: H
) -> MetropolisState<Rng> where
F: FnMut(&mut Self) -> bool,
G: FnMut(&mut Self) -> f64,
H: FnMut(&mut Self, usize, f64, bool),
Rng: Rng,
[src]
&mut self,
state: MetropolisState<Rng>,
ignore_energy_missmatch: bool,
valid_self: F,
energy: G,
measure: H
) -> MetropolisState<Rng> where
F: FnMut(&mut Self) -> bool,
G: FnMut(&mut Self) -> f64,
H: FnMut(&mut Self, usize, f64, bool),
Rng: Rng,
impl<T> SerdeStateConform for T where
T: Serialize,
[src]
T: Serialize,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,