diff --git a/reCTBN/src/lib.rs b/reCTBN/src/lib.rs index 8feddfb..1997fa6 100644 --- a/reCTBN/src/lib.rs +++ b/reCTBN/src/lib.rs @@ -6,7 +6,7 @@ extern crate approx; pub mod parameter_learning; pub mod params; pub mod process; -pub mod reward_function; +pub mod reward; pub mod sampling; pub mod structure_learning; pub mod tools; diff --git a/reCTBN/src/reward.rs b/reCTBN/src/reward.rs new file mode 100644 index 0000000..114ba03 --- /dev/null +++ b/reCTBN/src/reward.rs @@ -0,0 +1,41 @@ +pub mod reward_function; + +use crate::process; + +/// Instantiation of reward function and instantaneous reward +/// +/// +/// # Arguments +/// +/// * `transition_reward`: reward obtained transitioning from one state to another +/// * `instantaneous_reward`: reward per unit of time obtained staying in a specific state + +#[derive(Debug, PartialEq)] +pub struct Reward { + pub transition_reward: f64, + pub instantaneous_reward: f64, +} + +/// The trait RewardFunction describe the methods that all the reward functions must satisfy + +pub trait RewardFunction { + /// Given the current state and the previous state, it compute the reward. + /// + /// # Arguments + /// + /// * `current_state`: the current state of the network represented as a `process::NetworkProcessState` + /// * `previous_state`: an optional argument representing the previous state of the network + + fn call( + &self, + current_state: process::NetworkProcessState, + previous_state: Option, + ) -> Reward; + + /// Initialize the RewardFunction internal accordingly to the structure of a NetworkProcess + /// + /// # Arguments + /// + /// * `p`: any structure that implements the trait `process::NetworkProcess` + fn initialize_from_network_process(p: &T) -> Self; +} diff --git a/reCTBN/src/reward_function.rs b/reCTBN/src/reward/reward_function.rs similarity index 72% rename from reCTBN/src/reward_function.rs rename to reCTBN/src/reward/reward_function.rs index 35e15c8..ae94ff1 100644 --- a/reCTBN/src/reward_function.rs +++ b/reCTBN/src/reward/reward_function.rs @@ -3,46 +3,10 @@ use crate::{ params::{self, ParamsTrait}, process, + reward::{Reward, RewardFunction}, }; -use ndarray; - -/// Instantiation of reward function and instantaneous reward -/// -/// -/// # Arguments -/// -/// * `transition_reward`: reward obtained transitioning from one state to another -/// * `instantaneous_reward`: reward per unit of time obtained staying in a specific state - -#[derive(Debug, PartialEq)] -pub struct Reward { - pub transition_reward: f64, - pub instantaneous_reward: f64, -} - -/// The trait RewardFunction describe the methods that all the reward functions must satisfy -pub trait RewardFunction { - /// Given the current state and the previous state, it compute the reward. - /// - /// # Arguments - /// - /// * `current_state`: the current state of the network represented as a `process::NetworkProcessState` - /// * `previous_state`: an optional argument representing the previous state of the network - - fn call( - &self, - current_state: process::NetworkProcessState, - previous_state: Option, - ) -> Reward; - - /// Initialize the RewardFunction internal accordingly to the structure of a NetworkProcess - /// - /// # Arguments - /// - /// * `p`: any structure that implements the trait `process::NetworkProcess` - fn initialize_from_network_process(p: &T) -> Self; -} +use ndarray; /// Reward function over a factored state space /// diff --git a/reCTBN/tests/reward_function.rs b/reCTBN/tests/reward_function.rs index dcc5e69..03f2ab7 100644 --- a/reCTBN/tests/reward_function.rs +++ b/reCTBN/tests/reward_function.rs @@ -2,7 +2,7 @@ mod utils; use ndarray::*; use utils::generate_discrete_time_continous_node; -use reCTBN::{process::{NetworkProcess, ctbn::*, NetworkProcessState}, reward_function::*, params}; +use reCTBN::{process::{NetworkProcess, ctbn::*, NetworkProcessState}, reward::{*, reward_function::*}, params}; #[test]