Skip to content

Commit

Permalink
remove halving option and make it default
Browse files Browse the repository at this point in the history
  • Loading branch information
jirigav committed Sep 28, 2023
1 parent bd715bc commit cd80849
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 27 deletions.
6 changes: 1 addition & 5 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub(crate) struct Args {
pub(crate) block_size: usize,

/// Number of explored pattern branches.
#[arg(short, long, default_value_t = 10)]
#[arg(short, long, default_value_t = 100)]
pub(crate) k: usize,

/// Minimal difference between expected and actual count of a given pattern in data.
Expand All @@ -32,10 +32,6 @@ pub(crate) struct Args {
#[arg(short, long, default_value_t = 2)]
pub(crate) base_pattern_size: usize,

/// Option whether the input data should be halved into training and testing data.
#[arg(long)]
pub(crate) halving: bool,

/// Option whether the input data should be divided into training, validation and testing data.
#[arg(long, short)]
pub(crate) validation_and_testing_split: bool,
Expand Down
36 changes: 14 additions & 22 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn results(
mut final_patterns: Vec<Pattern>,
start: Instant,
training_data: &Data,
testing_data_option: Option<&Data>,
testing_data: &Data,
patterns_combined: usize,
hist: bool,
) {
Expand All @@ -34,10 +34,12 @@ fn results(

println!("trained in {:.2?}", start.elapsed());

println!("z-score: {}", best_mp.z_score.unwrap());
println!("training z-score: {}", best_mp.z_score.unwrap());
println!("best multi-pattern: {best_mp:?}");

if let Some(testing_data) = testing_data_option {
if hist {
hist_result(final_patterns, training_data, testing_data);
} else {
let z_score = evaluate_distinguisher(&mut best_mp, testing_data);
let p_value = p_value(
best_mp.get_count(),
Expand All @@ -46,17 +48,9 @@ fn results(
);
print_results(p_value, z_score);
}
if hist {
hist_result(final_patterns, training_data, testing_data_option);
}
}

fn hist_result(
final_patterns: Vec<Pattern>,
training_data: &Data,
testing_data_option: Option<&Data>,
) {
println!("\n-- histograms --\n");
fn hist_result(final_patterns: Vec<Pattern>, training_data: &Data, testing_data: &Data) {
let bits = final_patterns[0].bits.clone();

println!("number of bits: {}", bits.len());
Expand All @@ -68,25 +62,23 @@ fn hist_result(

let hist = Histogram::get_hist(&bits, training_data);

println!("z-score: {}", hist.z_score);
println!("training z-score: {}", hist.z_score);

if let Some(testing_data) = testing_data_option {
let count = hist.evaluate(testing_data);
let prob = 2.0_f64.powf(-(hist.bits.len() as f64)) * (hist.best_division as f64);
let count = hist.evaluate(testing_data);
let prob = 2.0_f64.powf(-(hist.bits.len() as f64)) * (hist.best_division as f64);

let z = z_score(testing_data.num_of_blocks, count, prob);
let p_val = p_value(count, testing_data.num_of_blocks, prob);
let z = z_score(testing_data.num_of_blocks, count, prob);
let p_val = p_value(count, testing_data.num_of_blocks, prob);

print_results(p_val, z);
}
print_results(p_val, z);
}

fn run_bottomup(args: Args) {
let s = Instant::now();
let (training_data, validation_data_option, testing_data_option) = prepare_data(
&args.data_source,
args.block_size,
args.halving,
true,
args.validation_and_testing_split,
);
println!("data loaded in: {:?}", s.elapsed());
Expand All @@ -97,7 +89,7 @@ fn run_bottomup(args: Args) {
final_patterns.clone(),
start,
&training_data,
testing_data_option.as_ref(),
&testing_data_option.unwrap(),
args.patterns_combined,
args.hist,
);
Expand Down

0 comments on commit cd80849

Please sign in to comment.