pub fn write_som_units(
        &self,
        som: &Som,
        path: &str,
        class_values: bool,
    ) -> Result<(), Box<dyn Error>> {
        let mut classes: Vec<Option<Vec<String>>> = vec![None; self.layers.len()];
        let mut denorm: Vec<Option<DataFrame>> = (0..self.layers.len()).map(|_| None).collect();

        let mut names: Vec<String> =
            vec!["index".to_string(), "row".to_string(), "col".to_string()];
        let offset = names.len();
        for (idx, layer) in som.params().layers().iter().enumerate() {
            if class_values || !layer.categorical() {
                let result = self.to_denormalized(&som, som.weights(), idx).unwrap();
                names.extend_from_slice(&result.columns());
                denorm[idx] = Some(result);
            }
            if layer.categorical() {
                let (name, cl) = self.to_class(&som, som.weights(), idx).unwrap();
                classes[idx] = Some(cl);
                names.push(name);
            }
        }

        let mut writer = WriterBuilder::new()
            .delimiter(self.csv_options.delimiter)
            .from_path(path)?;

        let mut row = vec!["".to_string(); names.len()];
        writer.write_record(&names)?;
        for index in 0..som.weights().nrows() {
            let (r, c) = som.to_row_col(index);
            row[0] = index.to_string();
            row[1] = r.to_string();
            row[2] = c.to_string();

            for (idx, (layer, start_col)) in som
                .params()
                .layers()
                .iter()
                .zip(som.params().start_columns())
                .enumerate()
            {
                let mut offset_2 = 0;
                if class_values || !layer.categorical() {
                    let df = denorm[idx].as_ref().unwrap();
                    let df_row = df.get_row(index);
                    for i in 0..df_row.len() {
                        let v = df_row[i];
                        row[offset + *start_col + i] = v.to_string();
                    }
                    offset_2 += df_row.len()
                }

                if layer.categorical() {
                    let cls = classes[idx].as_ref().unwrap();
                    let v = &cls[index];
                    row[offset + offset_2 + *start_col] = v.clone();
                }
            }

            writer.write_record(&row)?;
        }

        Ok(())
    }
/// Writes SOM units to CSV file.
Writes SOM units to CSV file.
Writes SOM units to CSV file .
pub fn write_som_units(
        &self,
        som: &Som,
        path: &str,
        class_values: bool,
    ) -> Result<(), Box<dyn Error>> {
        let mut classes: Vec<Option<Vec<String>>> = vec![None; self.layers.len()];
        let mut denorm: Vec<Option<DataFrame>> = (0..self.layers.len()).map(|_| None).collect();
        let mut names: Vec<String> =
            vec!["index".to_string(), "row".to_string(), "col".to_string()];
        let offset = names.len();
        for (idx, layer) in som.params().layers().iter().enumerate() {
            if class_values || !layer.categorical() {
                let result = self.to_denormalized(&som, som.weights(), idx).unwrap();
                names.extend_from_slice(&result.columns());
                denorm[idx] = Some(result);
            }
            if layer.categorical() {
                let (name, cl) = self.to_class(&som, som.weights(), idx).unwrap();
                classes[idx] = Some(cl);
                names.push(name);
            }
        }
        let mut writer = WriterBuilder::new()
            .delimiter(self.csv_options.delimiter)
            .from_path(path)?;
        let mut row = vec!["".to_string(); names.len()];
        writer.write_record(&names)?;
        for index in 0..som.weights().nrows() {
            let (r, c) = som.to_row_col(index);
            row[0] = index.to_string();
            row[1] = r.to_string();
            row[2] = c.to_string();
            for (idx, (layer, start_col)) in som
                .params()
                .layers()
                .iter()
                .zip(som.params().start_columns())
                .enumerate()
            {
                let mut offset_2 = 0;
                if class_values || !layer.categorical() {
                    let df = denorm[idx].as_ref().unwrap();
                    let df_row = df.get_row(index);
                    for i in 0..df_row.len() {
                        let v = df_row[i];
                        row[offset + *start_col + i] = v.to_string();
                    }
                    offset_2 += df_row.len()
                }
                if layer.categorical() {
                    let cls = classes[idx].as_ref().unwrap();
                    let v = &cls[index];
                    row[offset + offset_2 + *start_col] = v.clone();
                }
            }
            writer.write_record(&row)?;
        }
        Ok(())
    }
pub fn write_som_units ( & self , som : & Som , path : & str , class_values : bool , ) -> Result < ( ) , Box < dyn Error > > { let mut classes : Vec < Option < Vec < String > > > = vec ! [ None self layers len ( ) ] ; let mut denorm : Vec < Option < DataFrame > > = ( 0 .. self . layers . len ( ) ) . map ( | _ | None ) . collect ( ) ; let mut names : Vec < String > = vec ! [ " " to_string ( ) " " to_string ( ) " " to_string ( ) ] ; let offset = names . len ( ) ; for ( idx , layer ) in som . params ( ) . layers ( ) . iter ( ) . enumerate ( ) { if class_values || ! layer . categorical ( ) { let result = self . to_denormalized ( & som , som . weights ( ) , idx ) . unwrap ( ) ; names . extend_from_slice ( & result . columns ( ) ) ; denorm [ idx ] = Some ( result ) ; } if layer . categorical ( ) { let ( name , cl ) = self . to_class ( & som , som . weights ( ) , idx ) . unwrap ( ) ; classes [ idx ] = Some ( cl ) ; names . push ( name ) ; } } let mut writer = WriterBuilder :: new ( ) . delimiter ( self . csv_options . delimiter ) . from_path ( path ) ? ; let mut row = vec ! [ " " to_string ( ) names len ( ) ] ; writer . write_record ( & names ) ? ; for index in 0 .. som . weights ( ) . nrows ( ) { let ( r , c ) = som . to_row_col ( index ) ; row [ 0 ] = index . to_string ( ) ; row [ 1 ] = r . to_string ( ) ; row [ 2 ] = c . to_string ( ) ; for ( idx , ( layer , start_col ) ) in som . params ( ) . layers ( ) . iter ( ) . zip ( som . params ( ) . start_columns ( ) ) . enumerate ( ) { let mut offset_2 = 0 ; if class_values || ! layer . categorical ( ) { let df = denorm [ idx ] . as_ref ( ) . unwrap ( ) ; let df_row = df . get_row ( index ) ; for i in 0 .. df_row . len ( ) { let v = df_row [ i ] ; row [ offset + * start_col + i ] = v . to_string ( ) ; } offset_2 += df_row . len ( ) } if layer . categorical ( ) { let cls = classes [ idx ] . as_ref ( ) . unwrap ( ) ; let v = & cls [ index ] ; row [ offset + offset_2 + * start_col ] = v . clone ( ) ; } } writer . write_record ( & row ) ? ; } Ok ( ( ) ) }
Writes SOM units to CSV file.
Writes SOM units to CSV file .
&self
som
&Som
path
&str
class_values
bool
&self
som
&Som
path
&str
class_values
bool