The state generation is now seedable

pull/33/head
Meliurwen 3 years ago
parent 185e1756ca
commit 9316fcee30
  1. 4
      src/params.rs
  2. 1
      src/tools.rs
  3. 4
      tests/params.rs

@ -40,7 +40,7 @@ pub trait ParamsTrait {
/// Randomly generate a possible state for the given node taking into account the node state /// Randomly generate a possible state for the given node taking into account the node state
/// and its parent set. /// and its parent set.
fn get_random_state(&self, state: usize, u: usize) -> Result<StateType, ParamsError>; fn get_random_state(&self, state: usize, u: usize, rng: &mut ChaCha8Rng) -> Result<StateType, ParamsError>;
/// Used by childern of the node described by this parameters to reserve spaces in their CIMs. /// Used by childern of the node described by this parameters to reserve spaces in their CIMs.
fn get_reserved_space_as_parent(&self) -> usize; fn get_reserved_space_as_parent(&self) -> usize;
@ -160,7 +160,7 @@ impl ParamsTrait for DiscreteStatesContinousTimeParams {
} }
} }
fn get_random_state(&self, state: usize, u: usize) -> Result<StateType, ParamsError> { fn get_random_state(&self, state: usize, u: usize, rng: &mut ChaCha8Rng) -> Result<StateType, ParamsError> {
// Generate a random transition given the current state of the node and its parent set. // Generate a random transition given the current state of the node and its parent set.
// The method used is described in: // The method used is described in:
// https://en.wikipedia.org/wiki/Multinomial_distribution#Sampling_from_a_multinomial_distribution // https://en.wikipedia.org/wiki/Multinomial_distribution#Sampling_from_a_multinomial_distribution

@ -84,6 +84,7 @@ pub fn trajectory_generator<T: network::Network>(
.params .params
.state_to_index(&current_state[next_node_transition]), .state_to_index(&current_state[next_node_transition]),
net.get_param_index_network(next_node_transition, &current_state), net.get_param_index_network(next_node_transition, &current_state),
&mut rng,
) )
.unwrap(); .unwrap();

@ -42,8 +42,10 @@ fn test_random_generation_state() {
let param = create_ternary_discrete_time_continous_param(); let param = create_ternary_discrete_time_continous_param();
let mut states = Array1::<usize>::zeros(10000); let mut states = Array1::<usize>::zeros(10000);
let mut rng = ChaCha8Rng::seed_from_u64(123456);
states.mapv_inplace(|_| { states.mapv_inplace(|_| {
if let StateType::Discrete(val) = param.get_random_state(1, 0).unwrap() { if let StateType::Discrete(val) = param.get_random_state(1, 0, &mut rng).unwrap() {
val val
} else { } else {
panic!() panic!()

Loading…
Cancel
Save