def compute_retrospective_loss(self):
        '''
        Compute retrospective loss.

        Returns:
            The tuple data.
            - `np.ndarray` of delta.
            - `np.ndarray` of losses of each batch.
            - float of loss of all batch.

        '''
        observed_arr, encoded_arr, decoded_arr, re_encoded_arr = self.__inferenced_tuple
        batch_size = observed_arr.shape[0]
        if self.__input_neuron_count == self.__hidden_neuron_count:
            target_arr = encoded_arr - np.expand_dims(observed_arr.mean(axis=2), axis=2)
            summary_delta_arr = np.sqrt(np.power(decoded_arr - target_arr, 2))
        else:
            # For each batch, draw a samples from the Uniform distribution.
            if self.__input_neuron_count > self.__hidden_neuron_count:
                all_dim_arr = np.arange(self.__input_neuron_count)
                np.random.shuffle(all_dim_arr)
                choiced_dim_arr = all_dim_arr[:self.__hidden_neuron_count]
                target_arr = encoded_arr - np.expand_dims(observed_arr[:, :, choiced_dim_arr].mean(axis=2), axis=2)
                summary_delta_arr = np.sqrt(np.power(decoded_arr[:, :, choiced_dim_arr] - target_arr, 2))
            else:
                all_dim_arr = np.arange(self.__hidden_neuron_count)
                np.random.shuffle(all_dim_arr)
                choiced_dim_arr = all_dim_arr[:self.__input_neuron_count]
                target_arr = encoded_arr[:, :, choiced_dim_arr] - np.expand_dims(observed_arr.mean(axis=2), axis=2)
                summary_delta_arr = np.sqrt(np.power(decoded_arr - target_arr, 2))

        summary_delta_arr = np.nan_to_num(summary_delta_arr)
        summary_delta_arr = (summary_delta_arr - summary_delta_arr.mean()) / (summary_delta_arr.std() + 1e-08)

        match_delta_arr = np.sqrt(np.power(encoded_arr[:, -1] - re_encoded_arr[:, -1], 2))
        match_delta_arr = np.nan_to_num(match_delta_arr)
        match_delta_arr = (match_delta_arr - match_delta_arr.mean()) / (match_delta_arr.std() + 1e-08)

        other_encoded_delta_arr = np.nansum(
            np.sqrt(
                np.power(
                    np.maximum(
                        0,
                        encoded_arr[:, :-1] - re_encoded_arr[:, -1].reshape(
                            re_encoded_arr[:, -1].shape[0], 
                            1, 
                            re_encoded_arr[:, -1].shape[1]
                        )
                    ),
                    2
                )
            ) + self.__margin_param,
            axis=1
        )
        other_encoded_delta_arr = np.nan_to_num(other_encoded_delta_arr)
        other_encoded_delta_arr = (other_encoded_delta_arr - other_encoded_delta_arr.mean()) / (other_encoded_delta_arr.std() + 1e-08)

        other_re_encoded_delta_arr = np.nansum(
            np.sqrt(
                np.power(
                    np.maximum(
                        0, 
                        encoded_arr[:, -1].reshape(
                            encoded_arr[:, -1].shape[0],
                            1,
                            encoded_arr[:, -1].shape[1]
                        ) - re_encoded_arr[:, :-1], 
                    ),
                    2
                )
            ) + self.__margin_param,
            axis=1
        )
        other_encoded_delta_arr = np.nan_to_num(other_encoded_delta_arr)
        other_re_encoded_delta_arr = (other_re_encoded_delta_arr - other_re_encoded_delta_arr.mean()) / (other_re_encoded_delta_arr.std() + 1e-08)

        mismatch_delta_arr = (match_delta_arr - other_encoded_delta_arr) + (match_delta_arr - other_re_encoded_delta_arr)

        delta_arr = summary_delta_arr + np.expand_dims(self.__retrospective_lambda * match_delta_arr, axis=1) + np.expand_dims(self.__retrospective_eta * mismatch_delta_arr, axis=1)

        v = np.linalg.norm(delta_arr)
        if v > self.__grad_clip_threshold:
            delta_arr = delta_arr * self.__grad_clip_threshold / v

        loss = np.square(delta_arr).mean()
        loss_arr = np.square(delta_arr).sum(axis=1).mean(axis=1)
        return delta_arr, loss_arr, loss
def compute_retrospective_loss ( self ) : observed_arr , encoded_arr , decoded_arr , re_encoded_arr = self . __inferenced_tuple batch_size = observed_arr . shape [ 0 ] if self . __input_neuron_count == self . __hidden_neuron_count : target_arr = encoded_arr - np . expand_dims ( observed_arr . mean ( axis = 2 ) , axis = 2 ) summary_delta_arr = np . sqrt ( np . power ( decoded_arr - target_arr , 2 ) ) else : if self . __input_neuron_count > self . __hidden_neuron_count : all_dim_arr = np . arange ( self . __input_neuron_count ) np . random . shuffle ( all_dim_arr ) choiced_dim_arr = all_dim_arr [ : self . __hidden_neuron_count ] target_arr = encoded_arr - np . expand_dims ( observed_arr [ : , : , choiced_dim_arr ] . mean ( axis = 2 ) , axis = 2 ) summary_delta_arr = np . sqrt ( np . power ( decoded_arr [ : , : , choiced_dim_arr ] - target_arr , 2 ) ) else : all_dim_arr = np . arange ( self . __hidden_neuron_count ) np . random . shuffle ( all_dim_arr ) choiced_dim_arr = all_dim_arr [ : self . __input_neuron_count ] target_arr = encoded_arr [ : , : , choiced_dim_arr ] - np . expand_dims ( observed_arr . mean ( axis = 2 ) , axis = 2 ) summary_delta_arr = np . sqrt ( np . power ( decoded_arr - target_arr , 2 ) ) summary_delta_arr = np . nan_to_num ( summary_delta_arr ) summary_delta_arr = ( summary_delta_arr - summary_delta_arr . mean ( ) ) / ( summary_delta_arr . std ( ) + 1e-08 ) match_delta_arr = np . sqrt ( np . power ( encoded_arr [ : , - 1 ] - re_encoded_arr [ : , - 1 ] , 2 ) ) match_delta_arr = np . nan_to_num ( match_delta_arr ) match_delta_arr = ( match_delta_arr - match_delta_arr . mean ( ) ) / ( match_delta_arr . std ( ) + 1e-08 ) other_encoded_delta_arr = np . nansum ( np . sqrt ( np . power ( np . maximum ( 0 , encoded_arr [ : , : - 1 ] - re_encoded_arr [ : , - 1 ] . reshape ( re_encoded_arr [ : , - 1 ] . shape [ 0 ] , 1 , re_encoded_arr [ : , - 1 ] . shape [ 1 ] ) ) , 2 ) ) + self . __margin_param , axis = 1 ) other_encoded_delta_arr = np . nan_to_num ( other_encoded_delta_arr ) other_encoded_delta_arr = ( other_encoded_delta_arr - other_encoded_delta_arr . mean ( ) ) / ( other_encoded_delta_arr . std ( ) + 1e-08 ) other_re_encoded_delta_arr = np . nansum ( np . sqrt ( np . power ( np . maximum ( 0 , encoded_arr [ : , - 1 ] . reshape ( encoded_arr [ : , - 1 ] . shape [ 0 ] , 1 , encoded_arr [ : , - 1 ] . shape [ 1 ] ) - re_encoded_arr [ : , : - 1 ] , ) , 2 ) ) + self . __margin_param , axis = 1 ) other_encoded_delta_arr = np . nan_to_num ( other_encoded_delta_arr ) other_re_encoded_delta_arr = ( other_re_encoded_delta_arr - other_re_encoded_delta_arr . mean ( ) ) / ( other_re_encoded_delta_arr . std ( ) + 1e-08 ) mismatch_delta_arr = ( match_delta_arr - other_encoded_delta_arr ) + ( match_delta_arr - other_re_encoded_delta_arr ) delta_arr = summary_delta_arr + np . expand_dims ( self . __retrospective_lambda * match_delta_arr , axis = 1 ) + np . expand_dims ( self . __retrospective_eta * mismatch_delta_arr , axis = 1 ) v = np . linalg . norm ( delta_arr ) if v > self . __grad_clip_threshold : delta_arr = delta_arr * self . __grad_clip_threshold / v loss = np . square ( delta_arr ) . mean ( ) loss_arr = np . square ( delta_arr ) . sum ( axis = 1 ) . mean ( axis = 1 ) return delta_arr , loss_arr , loss
Compute retrospective loss.

        Returns:
            The tuple data.
            - `np.ndarray` of delta.
            - `np.ndarray` of losses of each batch.
            - float of loss of all batch.