pub fn test(
    input: &Vec<Sample>,
    hidden_weights: &DMatrix<f64>,
    output_weights: &DMatrix<f64>,
) -> (f64, Vec<Vec<usize>>) {
    let mut num_correct = 0.0;
    let total = input.len();
    let mut confusion_matrix = vec![vec![0; 10]; 10];

    for sample in input.iter() {
        let hidden: DVector<f64> = (hidden_weights.transpose() * &sample.input)
            .map(sigmoid)
            .insert_row(0, 1.0); // insert the bias
        let output = (output_weights.transpose() * hidden).map(sigmoid);

        let class = output
            .iter()
            .enumerate()
            .fold(
                (0, 0.0),
                |acc, (label, val)| {
                    if *val > acc.1 {
                        (label, *val)
                    } else {
                        acc
                    }
                },
            );

        if class.0 == sample.label {
            num_correct += 1.0;
        }

        confusion_matrix[sample.label][class.0] += 1;
    }

    (num_correct / total as f64, confusion_matrix)
}
/* Tests a network and returns the accuracy value with a confusion matrix */
Tests a network and returns the accuracy value with a confusion matrix
Tests a network and returns the accuracy value with a confusion matrix
pub fn test(
    input: &Vec<Sample>,
    hidden_weights: &DMatrix<f64>,
    output_weights: &DMatrix<f64>,
) -> (f64, Vec<Vec<usize>>) {
    let mut num_correct = 0.0;
    let total = input.len();
    let mut confusion_matrix = vec![vec![0; 10]; 10];
    for sample in input.iter() {
        let hidden: DVector<f64> = (hidden_weights.transpose() * &sample.input)
            .map(sigmoid)
            .insert_row(0, 1.0); // insert the bias
        let output = (output_weights.transpose() * hidden).map(sigmoid);
        let class = output
            .iter()
            .enumerate()
            .fold(
                (0, 0.0),
                |acc, (label, val)| {
                    if *val > acc.1 {
                        (label, *val)
                    } else {
                        acc
                    }
                },
            );
        if class.0 == sample.label {
            num_correct += 1.0;
        }
        confusion_matrix[sample.label][class.0] += 1;
    }
    (num_correct / total as f64, confusion_matrix)
}
pub fn test ( input : & Vec < Sample > , hidden_weights : & DMatrix < f64 > , output_weights : & DMatrix < f64 > , ) -> ( f64 , Vec < Vec < usize > > ) { let mut num_correct = 0.0 ; let total = input . len ( ) ; let mut confusion_matrix = vec ! [ vec [ 0 10 ] 10 ] ; for sample in input . iter ( ) { let hidden : DVector < f64 > = ( hidden_weights . transpose ( ) * & sample . input ) . map ( sigmoid ) . insert_row ( 0 , 1.0 ) ; // insert the bias let output = ( output_weights . transpose ( ) * hidden ) . map ( sigmoid ) ; let class = output . iter ( ) . enumerate ( ) . fold ( ( 0 , 0.0 ) , | acc , ( label , val ) | { if * val > acc . 1 { ( label , * val ) } else { acc } } , ) ; if class . 0 == sample . label { num_correct += 1.0 ; } confusion_matrix [ sample . label ] [ class . 0 ] += 1 ; } ( num_correct / total as f64 , confusion_matrix ) }
Tests a network and returns the accuracy value with a confusion matrix
Tests a network and returns the accuracy value with a confusion matrix
input
&Vec<Sample>
hidden_weights
&DMatrix<f64>
output_weights
&DMatrix<f64>
input
&Vec<Sample>
hidden_weights
&DMatrix<f64>
output_weights
&DMatrix<f64>