models/dense_net.py
def self_constructing_var2(self, epoch, accuracy):
        """
        A step of the self-constructing algorithm (variant #2) for one
        training epoch.
        Adds new layers to the last block depending on parameters.
        Returns True if training should continue, False otherwise.

        This algorithm consists in a succession of two stages:
        - Ascension: add one layer every asc_thresh training epochs, break the
          loop (end the stage) when a layer settles (its layer cs for sources
          is == 1), or after std_window epochs or more if accuracy hasn't
          changed much.
        - Improvement: countdown of patience_param epochs until the stage ends;
          if another layer settles, add a layer and restart the countdown.

        Args:
            epoch: `int`, current training epoch (since adding the last block);
            accuracy: `float`, accuracy for this epoch.
        """
        continue_training = True
        cs, lcs_dst, lcs_src = self.process_block_filters(
            self.total_blocks-1, epoch)

        # calculate number of settled layers (layers with lcs_src == 1)
        settled_layers = 0
        for src in range(1, len(lcs_src)):
            if lcs_src[src] >= 1:
                settled_layers += 1

        # stage #0 = ascension stage
        if self.algorithm_stage == 0:
            # the ascension stage uses a FIFO list of past accuracies.
            self.accuracy_FIFO.append(accuracy)
            # after std_window ascension stage epochs, end the stage if the
            # accuracy didn't change much in a while.
            if (len(self.accuracy_FIFO) == self.std_window and
                    np.std(self.accuracy_FIFO) < self.std_tolerance):
                self.algorithm_stage += 1
                # max_n_ep is used to estimate completion time
                self.max_n_ep = epoch + self.patience_param + 1
            # else follow the usual protocol based on settled layers.
            else:
                if settled_layers > 0 and self.layer_num_list[-1] > 2:
                    self.settled_layers_ceil = settled_layers
                    self.algorithm_stage += 1
                    # max_n_ep is used to estimate completion time
                    self.max_n_ep = epoch + self.patience_param + 1
                elif (epoch-1) % self.asc_thresh == 0:
                    self._new_layer(self.growth_rate)

        # stage #1 = improvement stage
        if self.algorithm_stage == 1:
            if self.patience_cntdwn <= 0:
                # stop algorithm and reset everything
                continue_training = False
                self.algorithm_stage = 0
                self.patience_cntdwn = self.patience_param
            elif settled_layers > self.settled_layers_ceil:
                # if a layer settles, add a layer and restart the countdown
                self.settled_layers_ceil = settled_layers
                self._new_layer(self.growth_rate)
                self.patience_cntdwn = self.patience_param
                # max_n_ep is used to estimate completion time
                self.max_n_ep = epoch + self.patience_param + 1
            else:
                self.patience_cntdwn -= 1

        return continue_training

        A step of the self-constructing algorithm (variant #2) for one
        training epoch.
        Adds new layers to the last block depending on parameters.
        Returns True if training should continue, False otherwise.

        This algorithm consists in a succession of two stages:
        - Ascension: add one layer every asc_thresh training epochs, break the
          loop (end the stage) when a layer settles (its layer cs for sources
          is == 1), or after std_window epochs or more if accuracy hasn't
          changed much.
        - Improvement: countdown of patience_param epochs until the stage ends;
          if another layer settles, add a layer and restart the countdown.

        Args:
            epoch: `int`, current training epoch (since adding the last block);
            accuracy: `float`, accuracy for this epoch.
        
A step of the self-constructing algorithm (variant #2) for one
training epoch.
Adds new layers to the last block depending on parameters.
Returns True if training should continue, False otherwise.

This algorithm consists in a succession of two stages:
Ascension: add one layer every asc_thresh training epochs, break the
loop (end the stage) when a layer settles (its layer cs for sources
is == 1), or after std_window epochs or more if accuracy hasn't
changed much.
Improvement: countdown of patience_param epochs until the stage ends;
if another layer settles, add a layer and restart the countdown.
A step of the self - constructing algorithm ( variant #2 ) for one training epoch . Adds new layers to the last block depending on parameters . Returns True if training should continue False otherwise . This algorithm consists in a succession of two stages : Ascension : add one layer every asc_thresh training epochs break the loop ( end the stage ) when a layer settles ( its layer cs for sources is == 1 ) or after std_window epochs or more if accuracy hasn ' t changed much . Improvement : countdown of patience_param epochs until the stage ends ; if another layer settles add a layer and restart the countdown .
def self_constructing_var2(self, epoch, accuracy):
        continue_training = True
        cs, lcs_dst, lcs_src = self.process_block_filters(
            self.total_blocks-1, epoch)
        settled_layers = 0
        for src in range(1, len(lcs_src)):
            if lcs_src[src] >= 1:
                settled_layers += 1
        if self.algorithm_stage == 0:
            self.accuracy_FIFO.append(accuracy)
            if (len(self.accuracy_FIFO) == self.std_window and
                    np.std(self.accuracy_FIFO) < self.std_tolerance):
                self.algorithm_stage += 1
                self.max_n_ep = epoch + self.patience_param + 1
            else:
                if settled_layers > 0 and self.layer_num_list[-1] > 2:
                    self.settled_layers_ceil = settled_layers
                    self.algorithm_stage += 1
                    self.max_n_ep = epoch + self.patience_param + 1
                elif (epoch-1) % self.asc_thresh == 0:
                    self._new_layer(self.growth_rate)
        if self.algorithm_stage == 1:
            if self.patience_cntdwn <= 0:
                continue_training = False
                self.algorithm_stage = 0
                self.patience_cntdwn = self.patience_param
            elif settled_layers > self.settled_layers_ceil:
                self.settled_layers_ceil = settled_layers
                self._new_layer(self.growth_rate)
                self.patience_cntdwn = self.patience_param
                self.max_n_ep = epoch + self.patience_param + 1
            else:
                self.patience_cntdwn -= 1
        return continue_training
def self_constructing_var2 ( self , epoch , accuracy ) : continue_training = True cs , lcs_dst , lcs_src = self . process_block_filters ( self . total_blocks - 1 , epoch ) settled_layers = 0 for src in range ( 1 , len ( lcs_src ) ) : if lcs_src [ src ] >= 1 : settled_layers += 1 if self . algorithm_stage == 0 : self . accuracy_FIFO . append ( accuracy ) if ( len ( self . accuracy_FIFO ) == self . std_window and np . std ( self . accuracy_FIFO ) < self . std_tolerance ) : self . algorithm_stage += 1 self . max_n_ep = epoch + self . patience_param + 1 else : if settled_layers > 0 and self . layer_num_list [ - 1 ] > 2 : self . settled_layers_ceil = settled_layers self . algorithm_stage += 1 self . max_n_ep = epoch + self . patience_param + 1 elif ( epoch - 1 ) % self . asc_thresh == 0 : self . _new_layer ( self . growth_rate ) if self . algorithm_stage == 1 : if self . patience_cntdwn <= 0 : continue_training = False self . algorithm_stage = 0 self . patience_cntdwn = self . patience_param elif settled_layers > self . settled_layers_ceil : self . settled_layers_ceil = settled_layers self . _new_layer ( self . growth_rate ) self . patience_cntdwn = self . patience_param self . max_n_ep = epoch + self . patience_param + 1 else : self . patience_cntdwn -= 1 return continue_training
A step of the self-constructing algorithm (variant #2) for one
training epoch.
A step of the self - constructing algorithm ( variant #2 ) for one training epoch .
"""
        A step of the self-constructing algorithm (variant #2) for one
        training epoch.
        Adds new layers to the last block depending on parameters.
        Returns True if training should continue, False otherwise.

        This algorithm consists in a succession of two stages:
        - Ascension: add one layer every asc_thresh training epochs, break the
          loop (end the stage) when a layer settles (its layer cs for sources
          is == 1), or after std_window epochs or more if accuracy hasn't
          changed much.
        - Improvement: countdown of patience_param epochs until the stage ends;
          if another layer settles, add a layer and restart the countdown.

        Args:
            epoch: `int`, current training epoch (since adding the last block);
            accuracy: `float`, accuracy for this epoch.
        """ # calculate number of settled layers (layers with lcs_src == 1) # stage #0 = ascension stage # the ascension stage uses a FIFO list of past accuracies. # after std_window ascension stage epochs, end the stage if the # accuracy didn't change much in a while. # max_n_ep is used to estimate completion time # else follow the usual protocol based on settled layers. # max_n_ep is used to estimate completion time # stage #1 = improvement stage # stop algorithm and reset everything # if a layer settles, add a layer and restart the countdown # max_n_ep is used to estimate completion time
self
epoch
`int`, current training epoch (since adding the last block).
` int ` current training epoch ( since adding the last block ) .
accuracy
`float`, accuracy for this epoch.
` float ` accuracy for this epoch .