Partial commit

main
AlessandroBregoli 3 years ago
parent 7e128067d2
commit 9d98c7a6ee
  1. 15
      src/ctbn.rs
  2. 3
      src/network.rs
  3. 8
      src/tools.rs

@ -32,7 +32,7 @@ impl network::Network for CtbnNetwork {
self.network.node_weight(node_idx.clone()).unwrap()
}
fn get_param_index(&self, node: &petgraph::stable_graph::NodeIndex, u: Vec<StateType>) -> usize{
fn get_param_index_parents(&self, node: &petgraph::stable_graph::NodeIndex, u: &Vec<StateType>) -> usize{
self.network.neighbors_directed(node.clone(), Direction::Incoming).zip(u).fold((0, 1), |mut acc, x| {
let n = self.get_node(node);
acc.0 += n.state_to_index(&x.1) * acc.1;
@ -42,4 +42,17 @@ impl network::Network for CtbnNetwork {
}).0
}
fn get_param_index_network(&self, node: &petgraph::stable_graph::NodeIndex, current_state: &Vec<StateType>) -> usize{
self.get_param_index_parents(node, &current_state.iter()
.zip(self.get_node_indices())
.filter_map(|x| {
match self.network.find_edge(x.1, node.clone()) {
Some(_) => Some(x.0.clone()),
None => None
}
}).collect()
)
}
}

@ -13,5 +13,6 @@ pub trait Network {
fn add_edge(&mut self, parent: &petgraph::stable_graph::NodeIndex, child: &petgraph::graph::NodeIndex);
fn get_node_indices(&self) -> petgraph::stable_graph::NodeIndices<node::Node>;
fn get_node(&self, node_idx: &petgraph::stable_graph::NodeIndex) -> &node::Node;
fn get_param_index(&self, node: &petgraph::stable_graph::NodeIndex, u: Vec<params::StateType>) -> usize;
fn get_param_index_parents(&self, node: &petgraph::stable_graph::NodeIndex, u: &Vec<params::StateType>) -> usize;
fn get_param_index_network(&self, node: &petgraph::stable_graph::NodeIndex, current_state: &Vec<params::StateType>) -> usize;
}

@ -35,6 +35,14 @@ pub fn trajectory_generator(net: &Box<dyn network::Network>, n_trajectories: u64
events.push(current_state.clone());
time.push(t.clone());
while t < t_end {
next_transitions.iter_mut().zip(net.get_node_indices()).map(|x| {
if let None = x.0 {
*(x.0) = Some(match net.get_node(&x.1).get_params(){
node::NodeType::DiscreteStatesContinousTime(params) =>
params.get_random_residence_time(x.1, net.get_param_index_network(&x.1, &current_state)).unwrap()
});
}});
}

Loading…
Cancel
Save