Struct net_ensembles::er_m::ErEnsembleM [−][src]
pub struct ErEnsembleM<T: Node, R> { /* fields omitted */ }
Expand description
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
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
Trait Implementations
impl<T, R> AsRef<GenericGraph<T, NodeContainer<T>>> for ErEnsembleM<T, R> where
T: Node,
R: Rng,
impl<T, R> AsRef<GenericGraph<T, NodeContainer<T>>> for ErEnsembleM<T, R> where
T: Node,
R: Rng,
impl<T, R> Borrow<GenericGraph<T, NodeContainer<T>>> for ErEnsembleM<T, R> where
T: Node,
R: Rng,
impl<T, R> Borrow<GenericGraph<T, NodeContainer<T>>> for ErEnsembleM<T, R> where
T: Node,
R: Rng,
Returns a reference to the element stored in the specified node or None
if out of Bounds
Returns a mutable reference to the element stored in the specified node or None
if out of Bounds
For a save alternative see get_contained Read more
Returns a mutable reference to the element stored in the specified node Read more
impl<'de, T: Node, R> Deserialize<'de> for ErEnsembleM<T, R> where
T: Deserialize<'de>,
R: Deserialize<'de>,
impl<'de, T: Node, R> Deserialize<'de> for ErEnsembleM<T, R> where
T: Deserialize<'de>,
R: Deserialize<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
f
to create labels depending on the indexdot_options
use dot_options!
macro and take a look at module dot_constants
self.dot()
, but returns a String instead
self.dot_from_indices
but returns String instead
self.dot_with_indices
but returns String insteadimpl<T, R> GraphIteratorsMut<T, GenericGraph<T, NodeContainer<T>>, NodeContainer<T>> for ErEnsembleM<T, R> where
T: Node + SerdeStateConform,
R: Rng,
impl<T, R> GraphIteratorsMut<T, GenericGraph<T, NodeContainer<T>>, NodeContainer<T>> for ErEnsembleM<T, R> where
T: Node + SerdeStateConform,
R: Rng,
fn contained_iter_neighbors_mut(
&mut self,
index: usize
) -> NContainedIterMut<'_, T, NodeContainer<T>>ⓘNotable traits for NContainedIterMut<'a, T, A>impl<'a, T, A> Iterator for NContainedIterMut<'a, T, A> where
T: 'a + Node,
A: AdjContainer<T>, type Item = &'a mut T;
fn contained_iter_neighbors_mut(
&mut self,
index: usize
) -> NContainedIterMut<'_, T, NodeContainer<T>>ⓘNotable traits for NContainedIterMut<'a, T, A>impl<'a, T, A> Iterator for NContainedIterMut<'a, T, A> where
T: 'a + Node,
A: AdjContainer<T>, type Item = &'a mut T;
impl<'a, T, A> Iterator for NContainedIterMut<'a, T, A> where
T: 'a + Node,
A: AdjContainer<T>, type Item = &'a mut T;
index
&mut T
sort_adj
will affect the orderfn contained_iter_neighbors_mut_with_index(
&mut self,
index: usize
) -> INContainedIterMut<'_, T, NodeContainer<T>>ⓘNotable traits for INContainedIterMut<'a, T, A>impl<'a, T, A> Iterator for INContainedIterMut<'a, T, A> where
T: 'a + Node,
A: AdjContainer<T>, type Item = (usize, &'a mut T);
fn contained_iter_neighbors_mut_with_index(
&mut self,
index: usize
) -> INContainedIterMut<'_, T, NodeContainer<T>>ⓘNotable traits for INContainedIterMut<'a, T, A>impl<'a, T, A> Iterator for INContainedIterMut<'a, T, A> where
T: 'a + Node,
A: AdjContainer<T>, type Item = (usize, &'a mut T);
impl<'a, T, A> Iterator for INContainedIterMut<'a, T, A> where
T: 'a + Node,
A: AdjContainer<T>, type Item = (usize, &'a mut T);
index
(index_neighbor: usize, neighbor: &mut T)
sort_adj
will affect the orderfn contained_iter_mut(&mut self) -> ContainedIterMut<'_, T, NodeContainer<T>>ⓘNotable traits for ContainedIterMut<'a, T, A>impl<'a, T, A> Iterator for ContainedIterMut<'a, T, A> where
T: 'a + Node,
A: AdjContainer<T>, type Item = &'a mut T;
fn contained_iter_mut(&mut self) -> ContainedIterMut<'_, T, NodeContainer<T>>ⓘNotable traits for ContainedIterMut<'a, T, A>impl<'a, T, A> Iterator for ContainedIterMut<'a, T, A> where
T: 'a + Node,
A: AdjContainer<T>, type Item = &'a mut T;
impl<'a, T, A> Iterator for ContainedIterMut<'a, T, A> where
T: 'a + Node,
A: AdjContainer<T>, type Item = &'a mut T;
Node
(for example EmptyNode
or whatever you used)Access RNG
If, for some reason, you want access to the internal random number generator: Here you go
Swap random number generator
- returns old internal rng
impl<T, R> MarkovChain<ErStepM, ErStepM> for ErEnsembleM<T, R> where
T: Node + SerdeStateConform,
R: Rng,
impl<T, R> MarkovChain<ErStepM, ErStepM> for ErEnsembleM<T, R> where
T: Node + SerdeStateConform,
R: Rng,
- undo a markov step, return result-state
- if you want to undo more than one step
see
undo_steps
- undo a markov step, panic on invalid result state
- for undoing multiple steps see
undo_steps_quiet
Markov step
- use this to perform a markov step
- for doing multiple mc steps at once, use
m_steps
Markov steps without return Read more
Accumulating markov step Read more
Accumulating markov steps Read more
Accumulating markov steps Read more
Undo markov steps Read more
Randomizes self according to model
- this is intended for creation of initial sample
- used in
simple_sample
andsimple_sample_vec
do the following times
times: Read more
impl<T, R> WithGraph<T, GenericGraph<T, NodeContainer<T>>> for ErEnsembleM<T, R> where
T: Node + SerdeStateConform,
R: Rng,
impl<T, R> WithGraph<T, GenericGraph<T, NodeContainer<T>>> for ErEnsembleM<T, R> where
T: Node + SerdeStateConform,
R: Rng,
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
Auto Trait Implementations
impl<T, R> RefUnwindSafe for ErEnsembleM<T, R> where
R: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, R> Send for ErEnsembleM<T, R> where
R: Send,
T: Send,
impl<T, R> Sync for ErEnsembleM<T, R> where
R: Sync,
T: Sync,
impl<T, R> Unpin for ErEnsembleM<T, R> where
R: Unpin,
T: Unpin,
impl<T, R> UnwindSafe for ErEnsembleM<T, R> where
R: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn cast_trunc(self) -> T
pub fn cast_trunc(self) -> T
Cast to integer, truncating Read more
pub fn cast_nearest(self) -> T
pub fn cast_nearest(self) -> T
Cast to the nearest integer Read more
pub fn cast_floor(self) -> T
pub fn cast_floor(self) -> T
Cast the floor to an integer Read more
pub fn try_cast_trunc(self) -> Result<T, Error>
pub fn try_cast_trunc(self) -> Result<T, Error>
Try converting to integer with truncation Read more
pub fn try_cast_nearest(self) -> Result<T, Error>
pub fn try_cast_nearest(self) -> Result<T, Error>
Try converting to the nearest integer Read more
pub fn try_cast_floor(self) -> Result<T, Error>
pub fn try_cast_floor(self) -> Result<T, Error>
Try converting the floor to an integer Read more
pub fn try_cast_ceil(self) -> Result<T, Error>
pub fn try_cast_ceil(self) -> Result<T, Error>
Try convert the ceiling to an integer Read more