def _check_cost(self):
        """Check cost function

        This method tests the cost function for convergence in the specified
        interval of iterations using the last n (test_range) cost values

        Returns
        -------
        bool result of the convergence test

        """

        # Add current cost value to the test list
        self._test_list.append(self.cost)

        # Check if enough cost values have been collected
        if len(self._test_list) == self._test_range:

            # The mean of the first half of the test list
            t1 = np.mean(self._test_list[len(self._test_list) // 2:], axis=0)
            # The mean of the second half of the test list
            t2 = np.mean(self._test_list[:len(self._test_list) // 2], axis=0)
            # Calculate the change across the test list
            if not np.around(t1, decimals=16):
                cost_diff = 0.0
            else:
                cost_diff = (np.linalg.norm(t1 - t2) / np.linalg.norm(t1))
            # Reset the test list
            self._test_list = []

            if self._verbose:
                print(' - CONVERGENCE TEST - ')
                print(' - CHANGE IN COST:', cost_diff)
                print('')

            # Check for convergence
            return cost_diff <= self._tolerance

        else:

            return False
Check cost function

        This method tests the cost function for convergence in the specified
        interval of iterations using the last n (test_range) cost values

        Returns
        -------
        bool result of the convergence test