/// Prepares everything for running F-BLEAU, and runs a forward
/// estimation strategy.
Prepares everything for running F-BLEAU, and runs a forward
estimation strategy.
Prepares everything for running F - BLEAU and runs a forward estimation strategy .
pub fn run_fbleau(
    train_x: Array2<f64>,
    train_y: Array1<Label>,
    test_x: Array2<f64>,
    test_y: Array1<Label>,
    estimate: Estimate,
    knn_strategy: Option<KNNStrategy>,
    distance: Option<String>,
    error_logger: &mut Option<Logger<f64>>,
    individual_error_logger: &mut Option<Logger<bool>>,
    delta: Option<f64>,
    qstop: Option<usize>,
    absolute: bool,
    scale: bool,
) -> (f64, f64, f64) {
    // Check label's indexes, and scale data if required.
    let (train_x, train_y, test_x, test_y, nlabels) =
        prepare_data(train_x, train_y, test_x, test_y, scale);
    // Convergence with (delta, q)-convergence checker.
    let convergence_checker = if let Some(delta) = delta {
        let q = match qstop {
            Some(q) => q,
            None => (train_x.len() as f64 * 0.1) as usize,
        };
        println!("will stop when (delta={}, q={})-converged", delta, q);
        Some(ForwardChecker::new(&[delta], q, !absolute))
    } else if qstop.is_some() {
        panic!("--qstop should only be specified with --delta");
    } else {
        // No convergence checker (i.e., run for all training data).
        None
    };
    // Random guessing error.
    let random_guessing = estimate_random_guessing(&test_y.view());
    println!("Random guessing error: {}", random_guessing);
    println!("Estimating leakage measures...");
    // Distance for k-NN (defaults to Euclidean).
    let distance = match distance.as_ref().map(String::as_ref) {
        Some("euclidean") => euclidean_distance,
        Some("levenshtein") => levenshtein_distance,
        _ => euclidean_distance,
    };
    // Init estimator and run.
    let (min_error, last_error) = match estimate {
        Estimate::Frequentist => {
            if !has_integer_support(&train_x) || !has_integer_support(&test_x) {
                println!("Warning: frequentist discouraged for continuous observations!");
            }
            let estimator = FrequentistEstimator::new(nlabels, &test_x.view(), &test_y.view());
            run_forward_strategy(
                estimator,
                convergence_checker,
                error_logger,
                individual_error_logger,
                train_x,
                train_y,
            )
        }
        Estimate::NN => {
            if !has_integer_support(&train_x) || !has_integer_support(&test_x) {
                println!("Warning: NN discouraged for continuous observations!");
            }
            let estimator = KNNEstimator::new(
                &test_x.view(),
                &test_y.view(),
                train_x.nrows(),
                distance,
                KNNStrategy::NN,
            );
            run_forward_strategy(
                estimator,
                convergence_checker,
                error_logger,
                individual_error_logger,
                train_x,
                train_y,
            )
        }
        Estimate::KNN => {
            let estimator = KNNEstimator::new(
                &test_x.view(),
                &test_y.view(),
                train_x.nrows(),
                distance,
                knn_strategy.expect("Specify a k-NN strategy."),
            );
            run_forward_strategy(
                estimator,
                convergence_checker,
                error_logger,
                individual_error_logger,
                train_x,
                train_y,
            )
        }
        Estimate::NNBound => {
            let estimator =
                NNBoundEstimator::new(&test_x.view(), &test_y.view(), distance, nlabels);
            run_forward_strategy(
                estimator,
                convergence_checker,
                error_logger,
                individual_error_logger,
                train_x,
                train_y,
            )
        }
    };
    (min_error, last_error, random_guessing)
}
pub fn run_fbleau ( train_x : Array2 < f64 > , train_y : Array1 < Label > , test_x : Array2 < f64 > , test_y : Array1 < Label > , estimate : Estimate , knn_strategy : Option < KNNStrategy > , distance : Option < String > , error_logger : & mut Option < Logger < f64 > > , individual_error_logger : & mut Option < Logger < bool > > , delta : Option < f64 > , qstop : Option < usize > , absolute : bool , scale : bool , ) -> ( f64 , f64 , f64 ) { // Check label's indexes, and scale data if required. let ( train_x , train_y , test_x , test_y , nlabels ) = prepare_data ( train_x , train_y , test_x , test_y , scale ) ; // Convergence with (delta, q)-convergence checker. let convergence_checker = if let Some ( delta ) = delta { let q = match qstop { Some ( q ) => q , None => ( train_x . len ( ) as f64 * 0.1 ) as usize , } ; println ! ( " " delta q ) ; Some ( ForwardChecker :: new ( & [ delta ] , q , ! absolute ) ) } else if qstop . is_some ( ) { panic ! ( " " ) ; } else { // No convergence checker (i.e., run for all training data). None } ; // Random guessing error. let random_guessing = estimate_random_guessing ( & test_y . view ( ) ) ; println ! ( " " random_guessing ) ; println ! ( " " ) ; // Distance for k-NN (defaults to Euclidean). let distance = match distance . as_ref ( ) . map ( String :: as_ref ) { Some ( " " ) => euclidean_distance , Some ( " " ) => levenshtein_distance , _ => euclidean_distance , } ; // Init estimator and run. let ( min_error , last_error ) = match estimate { Estimate :: Frequentist => { if ! has_integer_support ( & train_x ) || ! has_integer_support ( & test_x ) { println ! ( " " ) ; } let estimator = FrequentistEstimator :: new ( nlabels , & test_x . view ( ) , & test_y . view ( ) ) ; run_forward_strategy ( estimator , convergence_checker , error_logger , individual_error_logger , train_x , train_y , ) } Estimate :: NN => { if ! has_integer_support ( & train_x ) || ! has_integer_support ( & test_x ) { println ! ( " " ) ; } let estimator = KNNEstimator :: new ( & test_x . view ( ) , & test_y . view ( ) , train_x . nrows ( ) , distance , KNNStrategy :: NN , ) ; run_forward_strategy ( estimator , convergence_checker , error_logger , individual_error_logger , train_x , train_y , ) } Estimate :: KNN => { let estimator = KNNEstimator :: new ( & test_x . view ( ) , & test_y . view ( ) , train_x . nrows ( ) , distance , knn_strategy . expect ( " " ) , ) ; run_forward_strategy ( estimator , convergence_checker , error_logger , individual_error_logger , train_x , train_y , ) } Estimate :: NNBound => { let estimator = NNBoundEstimator :: new ( & test_x . view ( ) , & test_y . view ( ) , distance , nlabels ) ; run_forward_strategy ( estimator , convergence_checker , error_logger , individual_error_logger , train_x , train_y , ) } } ; ( min_error , last_error , random_guessing ) }
Prepares everything for running F-BLEAU, and runs a forward
estimation strategy.
Prepares everything for running F - BLEAU and runs a forward estimation strategy .
train_x
Array2<f64>
train_y
Array1<Label>
test_x
Array2<f64>
test_y
Array1<Label>
estimate
Estimate
knn_strategy
Option<KNNStrategy>
distance
Option<String>
error_logger
&mut Option<Logger<f64>>
individual_error_logger
&mut Option<Logger<bool>>
delta
Option<f64>
qstop
Option<usize>
absolute
bool
scale
bool