-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Hashmaps, vector preallocation and avoid cloning [Rust] (#250)
* get hashmap without match statements * preallocate vectors * avoid cloning
- Loading branch information
1 parent
e32e331
commit c4ab757
Showing
7 changed files
with
87 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use rshgf::model::Network; | ||
|
||
fn main() { | ||
|
||
// initialize network | ||
let mut network = Network::new(); | ||
|
||
// create a network with two exponential family state nodes | ||
network.add_nodes( | ||
"exponential-state", | ||
None, | ||
None, | ||
None, | ||
None | ||
); | ||
|
||
// belief propagation | ||
let input_data = vec![1.0, 1.3, 1.5, 1.7]; | ||
network.set_update_sequence(); | ||
network.input_data(input_data); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use crate::{utils::function_pointer::FnType, model::Network, updates::observations::observation_update}; | ||
|
||
/// Single time slice belief propagation. | ||
/// | ||
/// # Arguments | ||
/// * `observations` - A vector of values, each value is one new observation associated | ||
/// with one node. | ||
pub fn belief_propagation(network: &mut Network, observations_set: Vec<f64>, predictions: & Vec<(usize, FnType)>, updates: & Vec<(usize, FnType)>) { | ||
|
||
// 1. prediction steps | ||
for (idx, step) in predictions.iter() { | ||
step(network, *idx); | ||
} | ||
|
||
// 2. observation steps | ||
for (i, observations) in observations_set.iter().enumerate() { | ||
let idx = network.inputs[i]; | ||
observation_update(network, idx, *observations); | ||
} | ||
|
||
// 3. update steps | ||
for (idx, step) in updates.iter() { | ||
step(network, *idx); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod set_sequence; | ||
pub mod function_pointer; | ||
pub mod function_pointer; | ||
pub mod beliefs_propagation; |