Struct net_ensembles::er_m::ErEnsembleM
source · [−]pub struct ErEnsembleM<T: Node, R> { /* private fields */ }
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;
use std::io::{BufWriter, BufReader};
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");
let buf_writer = BufWriter::new(er_m_file);
// or serde_json::to_writer(buf_writer, &er_ensemble);
serde_json::to_writer_pretty(buf_writer, &er_ensemble);
// loading ensemble from file:
let read = File::open("store_ER_m.dat")
.expect("Unable to open file");
let mut buf_reader = BufReader::new(read);
let er: ErEnsembleM::<EmptyNode, Pcg64> = serde_json::from_reader(buf_reader).unwrap();
}
Implementations
sourceimpl<T, R> ErEnsembleM<T, R>where
T: Node + SerdeStateConform,
R: Rng,
impl<T, R> ErEnsembleM<T, R>where
T: Node + SerdeStateConform,
R: Rng,
sourcepub fn new(n: usize, m: usize, rng: R) -> Self
pub fn new(n: usize, m: usize, rng: R) -> Self
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
sourceimpl<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,
sourceimpl<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,
sourceimpl<T: Clone + Node, R: Clone> Clone for ErEnsembleM<T, R>
impl<T: Clone + Node, R: Clone> Clone for ErEnsembleM<T, R>
sourcefn clone(&self) -> ErEnsembleM<T, R>
fn clone(&self) -> ErEnsembleM<T, R>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresourceimpl<T, R> Contained<T> for ErEnsembleM<T, R>where
T: Node,
impl<T, R> Contained<T> for ErEnsembleM<T, R>where
T: Node,
sourcefn get_contained(&self, index: usize) -> Option<&T>
fn get_contained(&self, index: usize) -> Option<&T>
Returns a reference to the element stored in the specified node or
None
if out of Boundssourcefn get_contained_mut(&mut self, index: usize) -> Option<&mut T>
fn get_contained_mut(&mut self, index: usize) -> Option<&mut T>
Returns a mutable reference to the element stored in the specified node or
None
if out of Boundssourceunsafe fn get_contained_unchecked(&self, index: usize) -> &T
unsafe fn get_contained_unchecked(&self, index: usize) -> &T
For a save alternative see get_contained Read more
sourceunsafe fn get_contained_unchecked_mut(&mut self, index: usize) -> &mut T
unsafe fn get_contained_unchecked_mut(&mut self, index: usize) -> &mut T
Returns a mutable reference to the element stored in the specified node Read more
sourceimpl<'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>,
sourcefn 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
sourceimpl<T, R> Dot for ErEnsembleM<T, R>where
T: Node,
impl<T, R> Dot for ErEnsembleM<T, R>where
T: Node,
sourcefn dot_from_indices<F, W, S1, S2>(
&self,
writer: W,
dot_options: S1,
f: F
) -> Result<(), Error>where
S1: AsRef<str>,
S2: AsRef<str>,
W: Write,
F: FnMut(usize) -> S2,
fn dot_from_indices<F, W, S1, S2>(
&self,
writer: W,
dot_options: S1,
f: F
) -> Result<(), Error>where
S1: AsRef<str>,
S2: AsRef<str>,
W: Write,
F: FnMut(usize) -> S2,
f
to create labels depending on the indexdot_options
use dot_options!
macro and take a look at module dot_constants
sourcefn dot<S, W>(&self, writer: W, dot_options: S) -> Result<(), Error>where
S: AsRef<str>,
W: Write,
fn dot<S, W>(&self, writer: W, dot_options: S) -> Result<(), Error>where
S: AsRef<str>,
W: Write,
sourcefn dot_string<S>(&self, dot_options: S) -> Stringwhere
S: AsRef<str>,
fn dot_string<S>(&self, dot_options: S) -> Stringwhere
S: AsRef<str>,
self.dot()
, but returns a String insteadsourcefn dot_string_from_indices<F, S1, S2>(&self, dot_options: S1, f: F) -> Stringwhere
S1: AsRef<str>,
S2: AsRef<str>,
F: FnMut(usize) -> S2,
fn dot_string_from_indices<F, S1, S2>(&self, dot_options: S1, f: F) -> Stringwhere
S1: AsRef<str>,
S2: AsRef<str>,
F: FnMut(usize) -> S2,
self.dot_from_indices
but returns String insteadsourcefn dot_string_with_indices<S>(&self, dot_options: S) -> Stringwhere
S: AsRef<str>,
fn dot_string_with_indices<S>(&self, dot_options: S) -> Stringwhere
S: AsRef<str>,
self.dot_with_indices
but returns String insteadsourceimpl<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,
sourcefn contained_iter_neighbors_mut(
&mut self,
index: usize
) -> NContainedIterMut<'_, T, NodeContainer<T>, IterWrapper<'_>>ⓘNotable traits for NContainedIterMut<'a, T, A, I>impl<'a, T, A, I> Iterator for NContainedIterMut<'a, T, A, I>where
T: 'a,
A: AdjContainer<T>,
I: Iterator<Item = &'a usize> + 'a, type Item = &'a mut T;
fn contained_iter_neighbors_mut(
&mut self,
index: usize
) -> NContainedIterMut<'_, T, NodeContainer<T>, IterWrapper<'_>>ⓘNotable traits for NContainedIterMut<'a, T, A, I>impl<'a, T, A, I> Iterator for NContainedIterMut<'a, T, A, I>where
T: 'a,
A: AdjContainer<T>,
I: Iterator<Item = &'a usize> + 'a, type Item = &'a mut T;
T: 'a,
A: AdjContainer<T>,
I: Iterator<Item = &'a usize> + 'a, type Item = &'a mut T;
index
&mut T
sort_adj
will affect the ordersourcefn 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);
T: 'a + Node,
A: AdjContainer<T>, type Item = (usize, &'a mut T);
index
(index_neighbor: usize, neighbor: &mut T)
sort_adj
will affect the ordersourcefn 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;
T: 'a + Node,
A: AdjContainer<T>, type Item = &'a mut T;
Node
(for example EmptyNode
or whatever you used)sourceimpl<T, R> HasRng<R> for ErEnsembleM<T, R>where
T: Node,
R: Rng,
impl<T, R> HasRng<R> for ErEnsembleM<T, R>where
T: Node,
R: Rng,
sourcefn rng(&mut self) -> &mut R
fn rng(&mut self) -> &mut R
Access RNG
If, for some reason, you want access to the internal random number generator: Here you go
sourcefn swap_rng(&mut self, rng: &mut R)
fn swap_rng(&mut self, rng: &mut R)
Swap random number generator
- returns old internal rng
sourceimpl<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,
sourcefn undo_step(&mut self, step: &ErStepM) -> ErStepM
fn undo_step(&mut self, step: &ErStepM) -> ErStepM
- undo a markov step, return result-state
- if you want to undo more than one step
see
undo_steps
sourcefn undo_step_quiet(&mut self, step: &ErStepM)
fn undo_step_quiet(&mut self, step: &ErStepM)
- undo a markov step, panic on invalid result state
- for undoing multiple steps see
undo_steps_quiet
sourcefn m_step(&mut self) -> ErStepM
fn m_step(&mut self) -> ErStepM
Markov step
- use this to perform a markov step
- for doing multiple mc steps at once, use
m_steps
sourcefn m_steps_quiet(&mut self, count: usize)
fn m_steps_quiet(&mut self, count: usize)
Markov steps without return Read more
sourcefn m_step_acc<Acc, AccFn>(&mut self, acc: &mut Acc, acc_fn: AccFn) -> Swhere
AccFn: FnMut(&Self, &S, &mut Acc),
fn m_step_acc<Acc, AccFn>(&mut self, acc: &mut Acc, acc_fn: AccFn) -> Swhere
AccFn: FnMut(&Self, &S, &mut Acc),
Accumulating markov step Read more
sourcefn m_steps_acc<Acc, AccFn>(
&mut self,
count: usize,
steps: &mut Vec<S, Global>,
acc: &mut Acc,
acc_fn: AccFn
)where
AccFn: FnMut(&Self, &S, &mut Acc),
fn m_steps_acc<Acc, AccFn>(
&mut self,
count: usize,
steps: &mut Vec<S, Global>,
acc: &mut Acc,
acc_fn: AccFn
)where
AccFn: FnMut(&Self, &S, &mut Acc),
Accumulating markov steps Read more
sourcefn m_steps_acc_quiet<Acc, AccFn>(
&mut self,
count: usize,
acc: &mut Acc,
acc_fn: AccFn
)where
AccFn: FnMut(&Self, &S, &mut Acc),
fn m_steps_acc_quiet<Acc, AccFn>(
&mut self,
count: usize,
acc: &mut Acc,
acc_fn: AccFn
)where
AccFn: FnMut(&Self, &S, &mut Acc),
Accumulating markov steps Read more
sourcefn undo_steps_quiet(&mut self, steps: &[S])
fn undo_steps_quiet(&mut self, steps: &[S])
Undo markov steps Read more
sourcefn steps_accepted(&mut self, _steps: &[S])
fn steps_accepted(&mut self, _steps: &[S])
Function called whenever the steps are accepted. Read more
sourcefn steps_rejected(&mut self, _steps: &[S])
fn steps_rejected(&mut self, _steps: &[S])
Function called whenever the steps are rejected. Read more
sourceimpl<T, R> SimpleSample for ErEnsembleM<T, R>where
T: Node + SerdeStateConform,
R: Rng,
impl<T, R> SimpleSample for ErEnsembleM<T, R>where
T: Node + SerdeStateConform,
R: Rng,
sourcefn randomize(&mut self)
fn randomize(&mut self)
Randomizes self according to model
- this is intended for creation of initial sample
- used in
simple_sample
andsimple_sample_vec
sourceimpl<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,
sourcefn sort_adj(&mut self)
fn sort_adj(&mut self)
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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
fn cast_trunc(self) -> T
fn cast_trunc(self) -> T
Cast to integer, truncating Read more
fn cast_nearest(self) -> T
fn cast_nearest(self) -> T
Cast to the nearest integer Read more
fn cast_floor(self) -> T
fn cast_floor(self) -> T
Cast the floor to an integer Read more
fn try_cast_trunc(self) -> Result<T, Error>
fn try_cast_trunc(self) -> Result<T, Error>
Try converting to integer with truncation Read more
fn try_cast_nearest(self) -> Result<T, Error>
fn try_cast_nearest(self) -> Result<T, Error>
Try converting to the nearest integer Read more
fn try_cast_floor(self) -> Result<T, Error>
fn try_cast_floor(self) -> Result<T, Error>
Try converting the floor to an integer Read more
fn try_cast_ceil(self) -> Result<T, Error>
fn try_cast_ceil(self) -> Result<T, Error>
Try convert the ceiling to an integer Read more