fn train(&mut self, sample: &[f64]) {
        let params = &self.params;
        let (nearest, _) = if params.layers.is_empty() {
            nn::nearest_neighbor(sample, &self.weights)
        } else if params.layers.len() == 1 {
            if params.layers[0].categorical {
                nn::nearest_neighbor_tanimoto(sample, &self.weights)
            } else {
                nn::nearest_neighbor(sample, &self.weights)
            }
        } else {
            nn::nearest_neighbor_xyf(sample, &self.weights, &params.layers)
        };
        let (row, col) = self.to_row_col(nearest);

        let alpha = self.params.alpha.get(self.epoch, self.params.epochs);
        let radius = self.params.radius.get(self.epoch, self.params.epochs);
        let neigh = &self.params.neighborhood;
        let radius_inv = 1.0 / radius;
        let search_rad = radius * neigh.radius();
        let search_rad_i = search_rad.floor() as i32;
        //let search_rad_sq = search_rad.powi(2);

        let r_min = cmp::max(0, row as i32 - search_rad_i);
        let r_max = cmp::min(self.nrows as i32 - 1, row as i32 + search_rad_i);
        let c_min = cmp::max(0, col as i32 - search_rad_i);
        let c_max = cmp::min(self.ncols as i32 - 1, col as i32 + search_rad_i);

        for r in r_min..=r_max {
            for c in c_min..=c_max {
                let index = self.to_index(r, c);
                let dist = *self.distances_matrix.get(nearest, index) as f64;
                if dist <= search_rad {
                    let weight = neigh.weight(radius_inv * dist);
                    for (i, smp) in sample.iter().enumerate().take(self.dims) {
                        if !smp.is_nan() {
                            let value = self.weights.get_mut(index, i);
                            *value += weight * alpha * (smp - *value);
                        }
                    }
                }
            }
        }
    }
/// Trains the SOM for a single sample.
Trains the SOM for a single sample.
Trains the SOM for a single sample .
fn train(&mut self, sample: &[f64]) {
        let params = &self.params;
        let (nearest, _) = if params.layers.is_empty() {
            nn::nearest_neighbor(sample, &self.weights)
        } else if params.layers.len() == 1 {
            if params.layers[0].categorical {
                nn::nearest_neighbor_tanimoto(sample, &self.weights)
            } else {
                nn::nearest_neighbor(sample, &self.weights)
            }
        } else {
            nn::nearest_neighbor_xyf(sample, &self.weights, &params.layers)
        };
        let (row, col) = self.to_row_col(nearest);
        let alpha = self.params.alpha.get(self.epoch, self.params.epochs);
        let radius = self.params.radius.get(self.epoch, self.params.epochs);
        let neigh = &self.params.neighborhood;
        let radius_inv = 1.0 / radius;
        let search_rad = radius * neigh.radius();
        let search_rad_i = search_rad.floor() as i32;
        //let search_rad_sq = search_rad.powi(2);
        let r_min = cmp::max(0, row as i32 - search_rad_i);
        let r_max = cmp::min(self.nrows as i32 - 1, row as i32 + search_rad_i);
        let c_min = cmp::max(0, col as i32 - search_rad_i);
        let c_max = cmp::min(self.ncols as i32 - 1, col as i32 + search_rad_i);
        for r in r_min..=r_max {
            for c in c_min..=c_max {
                let index = self.to_index(r, c);
                let dist = *self.distances_matrix.get(nearest, index) as f64;
                if dist <= search_rad {
                    let weight = neigh.weight(radius_inv * dist);
                    for (i, smp) in sample.iter().enumerate().take(self.dims) {
                        if !smp.is_nan() {
                            let value = self.weights.get_mut(index, i);
                            *value += weight * alpha * (smp - *value);
                        }
                    }
                }
            }
        }
    }
fn train ( & mut self , sample : & [ f64 ] ) { let params = & self . params ; let ( nearest , _ ) = if params . layers . is_empty ( ) { nn :: nearest_neighbor ( sample , & self . weights ) } else if params . layers . len ( ) == 1 { if params . layers [ 0 ] . categorical { nn :: nearest_neighbor_tanimoto ( sample , & self . weights ) } else { nn :: nearest_neighbor ( sample , & self . weights ) } } else { nn :: nearest_neighbor_xyf ( sample , & self . weights , & params . layers ) } ; let ( row , col ) = self . to_row_col ( nearest ) ; let alpha = self . params . alpha . get ( self . epoch , self . params . epochs ) ; let radius = self . params . radius . get ( self . epoch , self . params . epochs ) ; let neigh = & self . params . neighborhood ; let radius_inv = 1.0 / radius ; let search_rad = radius * neigh . radius ( ) ; let search_rad_i = search_rad . floor ( ) as i32 ; //let search_rad_sq = search_rad.powi(2); let r_min = cmp :: max ( 0 , row as i32 - search_rad_i ) ; let r_max = cmp :: min ( self . nrows as i32 - 1 , row as i32 + search_rad_i ) ; let c_min = cmp :: max ( 0 , col as i32 - search_rad_i ) ; let c_max = cmp :: min ( self . ncols as i32 - 1 , col as i32 + search_rad_i ) ; for r in r_min ..= r_max { for c in c_min ..= c_max { let index = self . to_index ( r , c ) ; let dist = * self . distances_matrix . get ( nearest , index ) as f64 ; if dist <= search_rad { let weight = neigh . weight ( radius_inv * dist ) ; for ( i , smp ) in sample . iter ( ) . enumerate ( ) . take ( self . dims ) { if ! smp . is_nan ( ) { let value = self . weights . get_mut ( index , i ) ; * value += weight * alpha * ( smp - * value ) ; } } } } } }
Trains the SOM for a single sample.
Trains the SOM for a single sample .
&mut self
sample
&[f64]
&mut self
sample
&[f64]