/// Forward strategy for estimation.
///
/// Estimates security measures with a forward strategy: the estimator
/// is trained with an increasing number of examples, and its estimate
/// is progressively logged.
/// This function returns:
///     - smallest estimate
///     - final estimate (i.e., the estimate when all the training data was
///       available).
Forward strategy for estimation.
Estimates security measures with a forward strategy: the estimator
is trained with an increasing number of examples, and its estimate
is progressively logged.
This function returns:
smallest estimate
final estimate .
Forward strategy for estimation . Estimates security measures with a forward strategy : the estimator is trained with an increasing number of examples and its estimate is progressively logged . This function returns : smallest estimate final estimate .
fn run_forward_strategy<E>(
    mut estimator: E,
    mut convergence_checker: Option<ForwardChecker>,
    error_logger: &mut Option<Logger<f64>>,
    individual_error_logger: &mut Option<Logger<bool>>,
    train_x: Array2<f64>,
    train_y: Array1<Label>,
) -> (f64, f64)
where
    E: BayesEstimator,
{
    // Init logfile, if specified.
    if let Some(ref mut logger) = error_logger {
        if let Logger::LogFile(file) = logger {
            writeln!(file, "n, error-count, estimate").expect("Could not write to log file");
        }
    }
    // We keep track both of the minimum and of the last estimate.
    let mut min_error = 1.0;
    let mut last_error = 1.0;
    let mut min_individual_errors = vec![];
    for (n, (x, y)) in train_x.outer_iter().zip(train_y.iter()).enumerate() {
        // Compute error.
        estimator
            .add_example(&x, *y)
            .expect("Could not add more examples.");
        last_error = estimator.get_error();
        if min_error > last_error {
            min_error = last_error;
            min_individual_errors = estimator.get_individual_errors();
        }
        // Log current error.
        if let Some(ref mut logger) = error_logger {
            match logger {
                Logger::LogFile(file) => writeln!(
                    file,
                    "{}, {}, {}",
                    n,
                    estimator.get_error_count(),
                    last_error
                )
                .expect("Could not write to log file"),
                Logger::LogVec(v) => v.push(last_error),
            }
        }
        // Should we stop because of (delta, q)-convergence?
        if let Some(ref mut checker) = convergence_checker {
            checker.add_estimate(last_error);
            if checker.all_converged() {
                break;
            }
        }
    }
    // Log individual test errors.
    if let Some(logger) = individual_error_logger {
        match logger {
            Logger::LogFile(file) => {
                writeln!(file, "{:?}", min_individual_errors).expect("Could not write to log file")
            }
            Logger::LogVec(v) => v.extend(min_individual_errors.iter().cloned()),
        }
    }
    (min_error, last_error)
}
fn run_forward_strategy < E > ( mut estimator : E , mut convergence_checker : Option < ForwardChecker > , error_logger : & mut Option < Logger < f64 > > , individual_error_logger : & mut Option < Logger < bool > > , train_x : Array2 < f64 > , train_y : Array1 < Label > , ) -> ( f64 , f64 ) where E : BayesEstimator , { // Init logfile, if specified. if let Some ( ref mut logger ) = error_logger { if let Logger :: LogFile ( file ) = logger { writeln ! ( file " " ) . expect ( " " ) ; } } // We keep track both of the minimum and of the last estimate. let mut min_error = 1.0 ; let mut last_error = 1.0 ; let mut min_individual_errors = vec ! [ ] ; for ( n , ( x , y ) ) in train_x . outer_iter ( ) . zip ( train_y . iter ( ) ) . enumerate ( ) { // Compute error. estimator . add_example ( & x , * y ) . expect ( " " ) ; last_error = estimator . get_error ( ) ; if min_error > last_error { min_error = last_error ; min_individual_errors = estimator . get_individual_errors ( ) ; } // Log current error. if let Some ( ref mut logger ) = error_logger { match logger { Logger :: LogFile ( file ) => writeln ! ( file " " n estimator get_error_count ( ) last_error ) . expect ( " " ) , Logger :: LogVec ( v ) => v . push ( last_error ) , } } // Should we stop because of (delta, q)-convergence? if let Some ( ref mut checker ) = convergence_checker { checker . add_estimate ( last_error ) ; if checker . all_converged ( ) { break ; } } } // Log individual test errors. if let Some ( logger ) = individual_error_logger { match logger { Logger :: LogFile ( file ) => { writeln ! ( file " " min_individual_errors ) . expect ( " " ) } Logger :: LogVec ( v ) => v . extend ( min_individual_errors . iter ( ) . cloned ( ) ) , } } ( min_error , last_error ) }
Forward strategy for estimation.
Forward strategy for estimation .
estimator
E
convergence_checker
Option<ForwardChecker>
error_logger
&mut Option<Logger<f64>>
individual_error_logger
&mut Option<Logger<bool>>
train_x
Array2<f64>
train_y
Array1<Label>