Struct net_ensembles::ConfigurationModel
source · [−]pub struct ConfigurationModel<T, R>where
T: Node,{ /* private fields */ }
Expand description
Generate networks with a given degree distribution
- the degree of each vertex is fixed (see self.degree_vec), while the actual edges will be drawn randomly
- No self loops allowed
Implementations
sourceimpl<T, R> ConfigurationModel<T, R>where
T: Node,
impl<T, R> ConfigurationModel<T, R>where
T: Node,
sourcepub fn degree_vec(&self) -> &Vec<usize>
pub fn degree_vec(&self) -> &Vec<usize>
Get reference to the degree vector of the vertices,
faster than self.graph().degree_vec()
,
since the former has to construct the vector, while the latter just
returns a reference to an existing vector
sourceimpl<T, R> ConfigurationModel<T, R>where
T: Node,
R: Rng,
impl<T, R> ConfigurationModel<T, R>where
T: Node,
R: Rng,
sourcepub fn from_const(constant: usize, size: usize, rng: R) -> Option<Self>
pub fn from_const(constant: usize, size: usize, rng: R) -> Option<Self>
create configuration model from a constant degree
- drawn graphs will consist of
degree_vec.len()
vertices, where a vertex i will have degreedegree_vec[i]
size
: number of nodes in the resulting graphs- returns
None
if resulting degree vector is invalid
sourcepub fn from_generic_graph<T1, A1>(
generic_graph: &GenericGraph<T1, A1>,
rng: R
) -> Selfwhere
T1: Node,
A1: AdjContainer<T1>,
pub fn from_generic_graph<T1, A1>(
generic_graph: &GenericGraph<T1, A1>,
rng: R
) -> Selfwhere
T1: Node,
A1: AdjContainer<T1>,
create ConfigurationModel from a generic graph
- same as
from_vec_unchecked
, but creates degree vector from a generic graph
sourcepub fn clone_from_generic_graph<A>(
generic_graph: &GenericGraph<T, A>,
rng: R
) -> Selfwhere
T: Clone,
A: AdjContainer<T>,
pub fn clone_from_generic_graph<A>(
generic_graph: &GenericGraph<T, A>,
rng: R
) -> Selfwhere
T: Clone,
A: AdjContainer<T>,
create ConfigurationModel from a generic graph and clones underlying Data
degree_vec
will be extracted fromgeneric_graph
- Data will be cloned from the
generic_graph
- returns
ConfigurationModel
model model.graph()
will have the same topology asgeneric_graph
after this creation. This will of cause change, if you callrandomize
or do markov steps
sourcepub fn from_vec(degree_vec: Vec<usize>, rng: R) -> Option<Self>
pub fn from_vec(degree_vec: Vec<usize>, rng: R) -> Option<Self>
create configuration model from a degree vector
- drawn graphs will consist of
degree_vec.len()
vertices, where a vertex i will have degreedegree_vec[i]
- returns
None
if degree vector is invalid
sourcepub fn from_vec_unchecked(degree_vec: Vec<usize>, rng: R) -> Self
pub fn from_vec_unchecked(degree_vec: Vec<usize>, rng: R) -> Self
create configuration model from a degree vector
- same as
from_vec
, but it does not check if thedegree_vec
is valid - that is on you now
sourcepub fn degree_vec_is_valid(degree_vec: &[usize]) -> bool
pub fn degree_vec_is_valid(degree_vec: &[usize]) -> bool
check if a vector (slice) is a vaild degree distribution
- sum of
degree_vec
needs to be even degree_vec.len()
has to be greater than1
- no entry can request a degree larger than
degree_vec.len()-2
sourcepub fn assert_degree_vec_valid(degree_vec: &[usize])
pub fn assert_degree_vec_valid(degree_vec: &[usize])
asserts, that a vector is a vaild degree distribution
- similar to
degree_vec_is_valid
, but asserts instead - intended for debugging: see why the
degree_vec
is invalid
sourcepub fn swap_degree_vec(&mut self, new_degree_vec: Vec<usize>) -> Vec<usize>
pub fn swap_degree_vec(&mut self, new_degree_vec: Vec<usize>) -> Vec<usize>
Swaps the degree vector for a new one and draws a new network accordingly
Note new_degree_vec.len()
has to be of the same length as self.degree_vec.len()
will panic otherwise
- panics if new_degree_vec is invalid
- returns previous
degree_vec
sourcepub fn swap_degree_vec_unchecked(
&mut self,
new_degree_vec: Vec<usize>
) -> Vec<usize>
pub fn swap_degree_vec_unchecked(
&mut self,
new_degree_vec: Vec<usize>
) -> Vec<usize>
Swaps the degree_vec for a new one and draws a new network accordingly
- same as
swap_degree_vec
but does not assert, that the degree vector is valid - panics if
self.degree_vec.len() != new_degree_vec.len()
(the only thing still checked for, as that check is really really cheap)
sourcepub fn degree_vec_from_generic_graph<T1, A1>(
&mut self,
generic_graph: &GenericGraph<T1, A1>
)where
T1: Node,
A1: AdjContainer<T1>,
pub fn degree_vec_from_generic_graph<T1, A1>(
&mut self,
generic_graph: &GenericGraph<T1, A1>
)where
T1: Node,
A1: AdjContainer<T1>,
Use the degree vector of a generic graph
- asserts, that
generic_graph
andself.graph()
have the same number of vertices - similar to
self.swap_degree_vec_unchecked(generic_graph.degree_vec())
but does not create new vector and as such does not return old degree vector. If you need the old degree vector, you can useself.degree_vec().clone()
before calling this method
Trait Implementations
sourceimpl<T, R> AsRef<GenericGraph<T, NodeContainer<T>>> for ConfigurationModel<T, R>where
T: Node,
impl<T, R> AsRef<GenericGraph<T, NodeContainer<T>>> for ConfigurationModel<T, R>where
T: Node,
sourceimpl<T, R> Borrow<GenericGraph<T, NodeContainer<T>>> for ConfigurationModel<T, R>where
T: Node,
impl<T, R> Borrow<GenericGraph<T, NodeContainer<T>>> for ConfigurationModel<T, R>where
T: Node,
sourceimpl<T: Clone, R: Clone> Clone for ConfigurationModel<T, R>where
T: Node,
impl<T: Clone, R: Clone> Clone for ConfigurationModel<T, R>where
T: Node,
sourcefn clone(&self) -> ConfigurationModel<T, R>
fn clone(&self) -> ConfigurationModel<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 ConfigurationModel<T, R>where
T: Node,
impl<T, R> Contained<T> for ConfigurationModel<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 ConfigurationModel<T, R>where
T: Node,
T: Deserialize<'de>,
R: Deserialize<'de>,
impl<'de, T, R> Deserialize<'de> for ConfigurationModel<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> GraphIteratorsMut<T, GenericGraph<T, NodeContainer<T>>, NodeContainer<T>> for ConfigurationModel<T, R>where
T: Node,
impl<T, R> GraphIteratorsMut<T, GenericGraph<T, NodeContainer<T>>, NodeContainer<T>> for ConfigurationModel<T, R>where
T: Node,
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 ConfigurationModel<T, R>where
T: Node,
R: Rng,
impl<T, R> HasRng<R> for ConfigurationModel<T, R>where
T: Node,
R: Rng,
sourceimpl<T, R> MarkovChain<ConfigurationModelStep, Result<(), UndoStepErrorCM>> for ConfigurationModel<T, R>where
T: Node + SerdeStateConform,
R: Rng,
impl<T, R> MarkovChain<ConfigurationModelStep, Result<(), UndoStepErrorCM>> for ConfigurationModel<T, R>where
T: Node + SerdeStateConform,
R: Rng,
sourcefn m_step(&mut self) -> ConfigurationModelStep
fn m_step(&mut self) -> ConfigurationModelStep
Markov step
- use this to perform a markov step, e.g., to create a markov chain
- result
ConfigurationModelStep
can be used to undo the step withself.undo_step(result)
How it works
- it draws two distinct vertices, weighted with the Vertex degree
- then for each vertex a random edge is drawn from the respective adjacency list. let these edges be edge1 = (n, j) and edge2 = (k, l). These edges are removed and the edges (n, k) and (j, l) are added.
- If the above would result in an invalid topology,
nothing is added or removed and
ConfigurationModelStep::Error
is returned
sourcefn undo_step(
&mut self,
step: &ConfigurationModelStep
) -> Result<(), UndoStepErrorCM>
fn undo_step(
&mut self,
step: &ConfigurationModelStep
) -> Result<(), UndoStepErrorCM>
Undo a markcov step
- adds removed edge and removes added edge, or does nothing
Important:
Restored graph is the same as before the random step except the order of nodes in the adjacency list might be shuffled!
Error
If an error is encountered, this will revert the graph to the state, before trying to undo the step. The returned Error gives a hint for why this did not succeed.
sourcefn undo_step_quiet(&mut self, step: &ConfigurationModelStep)
fn undo_step_quiet(&mut self, step: &ConfigurationModelStep)
Undo a markcov step
- adds removed edge and removes added edge, or does nothing
- as long as you know, that you undo the steps in the correct order, this is the prefered method as this more efficent
- panics if an Error is encountered
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 ConfigurationModel<T, R>where
T: Node,
R: Rng,
impl<T, R> SimpleSample for ConfigurationModel<T, R>where
T: Node,
R: Rng,
sourceimpl<T, R> WithGraph<T, GenericGraph<T, NodeContainer<T>>> for ConfigurationModel<T, R>where
T: Node,
impl<T, R> WithGraph<T, GenericGraph<T, NodeContainer<T>>> for ConfigurationModel<T, R>where
T: Node,
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 ConfigurationModel<T, R>where
R: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, R> Send for ConfigurationModel<T, R>where
R: Send,
T: Send,
impl<T, R> Sync for ConfigurationModel<T, R>where
R: Sync,
T: Sync,
impl<T, R> Unpin for ConfigurationModel<T, R>where
R: Unpin,
T: Unpin,
impl<T, R> UnwindSafe for ConfigurationModel<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