Struct net_ensembles::er_c::ErEnsembleC
source · [−]pub struct ErEnsembleC<T, R>where
T: Node,{ /* private fields */ }
Expand description
Implements Erdős-Rényi graph ensemble
- variable number of edges
- targets a connectivity
Sampling
- 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
Implementations
sourceimpl<T, R> ErEnsembleC<T, R>where
T: Node + SerdeStateConform,
R: Rng,
impl<T, R> ErEnsembleC<T, R>where
T: Node + SerdeStateConform,
R: Rng,
sourcepub fn new(n: usize, c_target: f64, rng: R) -> Self
pub fn new(n: usize, c_target: f64, rng: R) -> Self
Initialize
create new ErEnsembleC
with:
n
vertices- target connectivity
c_target
rng
is consumed and used as random number generator in the following- internally uses
Graph<T>::new(n)
- generates random edges according to ER model
sourcepub fn make_connected(&mut self)
pub fn make_connected(&mut self)
Experimental! Connect the connected components
- adds edges, to connect the connected components
- panics if no vertices are in the graph
- intended as starting point for a markov chain, if you require connected graphs
- do not use this to independently (simple-) sample connected networks, as this will skew the statistics
- This is still experimental, this member might change the internal functionallity resulting in different connected networks, without prior notice
- This member might be removed in braking releases
sourcepub fn target_connectivity(&self) -> f64
pub fn target_connectivity(&self) -> f64
returns target connectivity
Explanation
The target connectivity c_target
is used to
calculate the probability p
, that any two vertices i
and j
(where i != j
)
are connected.
p = c_target / (N - 1)
where N
is the number of vertices in the graph
sourcepub fn set_target_connectivity(&mut self, c_target: f64)
pub fn set_target_connectivity(&mut self, c_target: f64)
- set new value for target connectivity
Note
- will only set the value (and probability), which will be used from now on
- if you also want to create a new sample, call
randomize
afterwards
Trait Implementations
sourceimpl<T, R> AsRef<GenericGraph<T, NodeContainer<T>>> for ErEnsembleC<T, R>where
T: Node,
R: Rng,
impl<T, R> AsRef<GenericGraph<T, NodeContainer<T>>> for ErEnsembleC<T, R>where
T: Node,
R: Rng,
sourceimpl<T, R> Borrow<GenericGraph<T, NodeContainer<T>>> for ErEnsembleC<T, R>where
T: Node,
R: Rng,
impl<T, R> Borrow<GenericGraph<T, NodeContainer<T>>> for ErEnsembleC<T, R>where
T: Node,
R: Rng,
sourceimpl<T: Clone, R: Clone> Clone for ErEnsembleC<T, R>where
T: Node,
impl<T: Clone, R: Clone> Clone for ErEnsembleC<T, R>where
T: Node,
sourcefn clone(&self) -> ErEnsembleC<T, R>
fn clone(&self) -> ErEnsembleC<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 ErEnsembleC<T, R>where
T: Node,
impl<T, R> Contained<T> for ErEnsembleC<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, R> Deserialize<'de> for ErEnsembleC<T, R>where
T: Node,
T: Deserialize<'de>,
R: Deserialize<'de>,
impl<'de, T, R> Deserialize<'de> for ErEnsembleC<T, R>where
T: Node,
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 ErEnsembleC<T, R>where
T: Node,
impl<T, R> Dot for ErEnsembleC<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 ErEnsembleC<T, R>where
T: Node + SerdeStateConform,
R: Rng,
impl<T, R> GraphIteratorsMut<T, GenericGraph<T, NodeContainer<T>>, NodeContainer<T>> for ErEnsembleC<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 ErEnsembleC<T, R>where
T: Node,
R: Rng,
impl<T, R> HasRng<R> for ErEnsembleC<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<ErStepC, ErStepC> for ErEnsembleC<T, R>where
T: Node + SerdeStateConform,
R: Rng,
impl<T, R> MarkovChain<ErStepC, ErStepC> for ErEnsembleC<T, R>where
T: Node + SerdeStateConform,
R: Rng,
sourcefn m_step(&mut self) -> ErStepC
fn m_step(&mut self) -> ErStepC
Markov step
- use this to perform a markov step, e.g., to create a markov chain
- result
ErStepC
can be used to undo the step withself.undo_step(result)
sourcefn undo_step(&mut self, step: &ErStepC) -> ErStepC
fn undo_step(&mut self, step: &ErStepC) -> ErStepC
Undo a markcov step
- adds removed edge, or removes added edge, or does nothing
- if it returns an Err value, you probably used the function wrong
Important:
Restored graph is the same as before the random step except the order of nodes in the adjacency list might be shuffled!
sourcefn undo_step_quiet(&mut self, step: &ErStepC)
fn undo_step_quiet(&mut self, step: &ErStepC)
Undo a markov step
- adds removed edge, or removes added edge, or does nothing
- if it returns an Err value, you probably used the function wrong
Important:
Restored graph is the same as before the random step except the order of nodes in the adjacency list might be shuffled!
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 ErEnsembleC<T, R>where
T: Node + SerdeStateConform,
R: Rng,
impl<T, R> SimpleSample for ErEnsembleC<T, R>where
T: Node + SerdeStateConform,
R: Rng,
sourcefn randomize(&mut self)
fn randomize(&mut self)
Randomizes the edges according to Er probabilities
- this is used by
ErEnsembleC::new
to create the initial topology - you can use this for sampling the ensemble
- runs in
O(vertices * vertices)
sourceimpl<T, R> WithGraph<T, GenericGraph<T, NodeContainer<T>>> for ErEnsembleC<T, R>where
T: Node + SerdeStateConform,
R: Rng,
impl<T, R> WithGraph<T, GenericGraph<T, NodeContainer<T>>> for ErEnsembleC<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 ErEnsembleC<T, R>where
R: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, R> Send for ErEnsembleC<T, R>where
R: Send,
T: Send,
impl<T, R> Sync for ErEnsembleC<T, R>where
R: Sync,
T: Sync,
impl<T, R> Unpin for ErEnsembleC<T, R>where
R: Unpin,
T: Unpin,
impl<T, R> UnwindSafe for ErEnsembleC<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