Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monte carlo block added #113

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
aae3e29
Monte carlo block added (excluding configurability)
Aug 16, 2023
76ec567
MonteCarlo updates input on forward_backward step
Aug 17, 2023
9648feb
Same order of methods applied in BlockMonteCarlo as in BlockTrait
Aug 17, 2023
ac76305
Seed-ed random Xoshiro256Plus random number generator used in BlockMo…
Aug 17, 2023
357434c
Configurability of FFM MonteCarlo added
Aug 17, 2023
e702de9
Test added for MonteCarlo
Aug 18, 2023
d177241
Prediction statistics exposed via FFI
Aug 20, 2023
62029cb
FFI naming made consistent
Aug 20, 2023
cc5b02f
Merge branch 'main' of github.com:outbrain/fwumious_wabbit into monte…
Aug 21, 2023
35ab593
Monte Carlo test corrected after incorrect merge
Aug 21, 2023
a447cf8
Limit monte carlo blocks to more then 0 iterations
Aug 21, 2023
636318b
Merge branch 'main' of github.com:outbrain/fwumious_wabbit into monte…
Aug 23, 2023
6d276ad
Merge branch 'main' of github.com:outbrain/fwumious_wabbit into monte…
Aug 29, 2023
1b3859f
First iteration of Monte Carlo block executes run without masking
Aug 29, 2023
69b7573
Handle 0 iteration of Monte Carlo in a more consise way
Sep 11, 2023
8c131a2
ffm_mc_iteration_count and ffm_mc_dropout_rate exposed via cli
Sep 11, 2023
2b9be62
Merge branch 'main' of github.com:outbrain/fwumious_wabbit into monte…
Sep 14, 2023
6709501
Merge branch 'main' of github.com:outbrain/fwumious_wabbit into monte…
Sep 24, 2023
ff9cf33
Merge branch 'main' of github.com:outbrain/fwumious_wabbit into monte…
Sep 25, 2023
def777c
Moving monte carlo block before triangle
Oct 11, 2023
bd8911f
Small correction
Oct 11, 2023
63033c6
Remove println
Oct 11, 2023
540ead4
Merge branch 'main' of github.com:outbrain/fwumious_wabbit into monte…
Oct 11, 2023
f022467
Merge branch 'main' of github.com:outbrain/fwumious_wabbit into monte…
Oct 12, 2023
a763bac
Merge branch 'main' of github.com:outbrain/fwumious_wabbit into monte…
Nov 2, 2023
fd5394f
Processing review comments
Nov 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Test added for MonteCarlo
ggaspersic committed Aug 18, 2023
commit e702de98eac9b86ec83d571f33ae1b059da60023
58 changes: 58 additions & 0 deletions src/block_monte_carlo.rs
Original file line number Diff line number Diff line change
@@ -218,3 +218,61 @@ impl BlockMonteCarlo {
});
}
}

mod tests {
use crate::assert_epsilon;
use crate::block_helpers::{slearn2, spredict2};
use crate::block_misc::Observe;
use crate::block_monte_carlo::new_monte_carlo_block;
use crate::graph::BlockGraph;
use crate::model_instance::ModelInstance;
use crate::{block_misc, feature_buffer::FeatureBuffer};

fn fb_vec() -> FeatureBuffer {
FeatureBuffer {
label: 0.0,
example_importance: 1.0,
example_number: 0,
lr_buffer: Vec::new(),
ffm_buffer: Vec::new(),
}
}

#[test]
fn test_monte_carlo_block() {
let mut mi = ModelInstance::new_empty().unwrap();
let mut bg = BlockGraph::new();
let input_block = block_misc::new_const_block(&mut bg, vec![2.0, 4.0, 4.0, 5.0]).unwrap();
let observe_block_backward =
block_misc::new_observe_block(&mut bg, input_block, Observe::Backward, None).unwrap();
let triangle_block =
new_monte_carlo_block(&mut bg, observe_block_backward, 3, 0.3).unwrap();
let observe_block_forward =
block_misc::new_observe_block(&mut bg, triangle_block, Observe::Forward, None).unwrap();
block_misc::new_sink_block(
&mut bg,
observe_block_forward,
block_misc::SinkType::Untouched,
)
.unwrap();
bg.finalize();
bg.allocate_and_init_weights(&mi);

let mut pb = bg.new_port_buffer();
let fb = fb_vec();
slearn2(&mut bg, &fb, &mut pb, true);
assert_eq!(pb.observations, [2.0, 4.0, 4.0, 5.0, 2.0, 4.0, 4.0, 5.0]);

spredict2(&mut bg, &fb, &mut pb, false);
let expected_observations = [2.0, 4.0, 0.0, 5.0, 0.0, 4.0, 4.0, 5.0, 2.0, 4.0, 4.0, 0.0, 2.0, 4.0, 4.0, 5.0];
assert_eq!(pb.observations.len(), expected_observations.len());
assert_eq!(pb.observations, expected_observations);

assert_ne!(pb.monte_carlo_stats, None);

let monte_carlo_stats = pb.monte_carlo_stats.unwrap();
assert_epsilon!(monte_carlo_stats.mean, 11.333333);
assert_epsilon!(monte_carlo_stats.variance, 302.88885);
assert_epsilon!(monte_carlo_stats.standard_deviation, 17.403702);
}
}
2 changes: 1 addition & 1 deletion src/port_buffer.rs
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ pub struct PortBuffer {
pub monte_carlo_stats: Option<MonteCarloStats>,
}

#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq)]
pub struct MonteCarloStats {
pub mean: f32,
pub variance: f32,