Ejemplo n.º 1
0
    def generate_affine_backtransformation(self):
        """ Generate synthetic examples and test them to determine transformation

        This is the key method!
        """
        if type(self.example) == FeatureVector:
            testsample = FeatureVector.replace_data(
                self.example, numpy.zeros(self.example.shape))
            self.offset = numpy.longdouble(self._execute(testsample))
            self.trafo = FeatureVector.replace_data(
                self.example, numpy.zeros(self.example.shape))
            for j in range(len(self.example.feature_names)):
                testsample = FeatureVector.replace_data(
                    self.example, numpy.zeros(self.example.shape))
                testsample[0][j] = 1.0
                self.trafo[0][j] = \
                    numpy.longdouble(self._execute(testsample) - self.offset)
        elif type(self.example) == TimeSeries:
            testsample = TimeSeries.replace_data(
                self.example, numpy.zeros(self.example.shape))
            self.offset = numpy.longdouble(
                numpy.squeeze(self._execute(testsample)))
            self.trafo = TimeSeries.replace_data(
                self.example, numpy.zeros(self.example.shape))
            for i in range(self.example.shape[0]):
                for j in range(self.example.shape[1]):
                    testsample = TimeSeries.replace_data(
                        self.example, numpy.zeros_like(self.example))
                    testsample[i][j] = 1.0
                    self.trafo[i][j] = \
                        numpy.longdouble(numpy.squeeze(self._execute(testsample))
                                       - self.offset)
Ejemplo n.º 2
0
    def generate_affine_backtransformation(self):
        """ Generate synthetic examples and test them to determine transformation

        This is the key method!
        """
        if type(self.example) == FeatureVector:
            testsample = FeatureVector.replace_data(
                self.example, numpy.zeros(self.example.shape))
            self.offset = numpy.longdouble(self._execute(testsample))
            self.trafo = FeatureVector.replace_data(
                self.example, numpy.zeros(self.example.shape))
            for j in range(len(self.example.feature_names)):
                testsample = FeatureVector.replace_data(
                    self.example,
                    numpy.zeros(self.example.shape))
                testsample[0][j] = 1.0
                self.trafo[0][j] = \
                    numpy.longdouble(self._execute(testsample) - self.offset)
        elif type(self.example) == TimeSeries:
            testsample = TimeSeries.replace_data(
                self.example, numpy.zeros(self.example.shape))
            self.offset = numpy.longdouble(numpy.squeeze(
                self._execute(testsample)))
            self.trafo = TimeSeries.replace_data(
                self.example, numpy.zeros(self.example.shape))
            for i in range(self.example.shape[0]):
                for j in range(self.example.shape[1]):
                    testsample = TimeSeries.replace_data(
                        self.example, numpy.zeros_like(self.example))
                    testsample[i][j] = 1.0
                    self.trafo[i][j] = \
                        numpy.longdouble(numpy.squeeze(self._execute(testsample))
                                       - self.offset)
 def test_replace_data(self):
   data = FeatureVector.replace_data(self.f2,[10,20,30,40,50,60])
   self.assertFalse((data.view(numpy.ndarray)-[10,20,30,40,50,60]).any())
   self.assertEqual(data.feature_names, ['a','b','c','d','e','f'])
   self.assertEqual(data.tag, 'Tag of f2')
   
   data2 = FeatureVector.replace_data(self.f1, [4,5,6,7,8,9],
                                      feature_names=['m','n','o','p','q','r'])
   self.assertFalse((data2.view(numpy.ndarray)-[4,5,6,7,8,9]).any())
   self.assertEqual(data2.feature_names, ['m','n','o','p','q','r'])
   self.assertEqual(data2.tag, None)
Ejemplo n.º 4
0
    def test_replace_data(self):
        data = FeatureVector.replace_data(self.f2, [10, 20, 30, 40, 50, 60])
        self.assertFalse(
            (data.view(numpy.ndarray) - [10, 20, 30, 40, 50, 60]).any())
        self.assertEqual(data.feature_names, ['a', 'b', 'c', 'd', 'e', 'f'])
        self.assertEqual(data.tag, 'Tag of f2')

        data2 = FeatureVector.replace_data(
            self.f1, [4, 5, 6, 7, 8, 9],
            feature_names=['m', 'n', 'o', 'p', 'q', 'r'])
        self.assertFalse(
            (data2.view(numpy.ndarray) - [4, 5, 6, 7, 8, 9]).any())
        self.assertEqual(data2.feature_names, ['m', 'n', 'o', 'p', 'q', 'r'])
        self.assertEqual(data2.tag, None)
Ejemplo n.º 5
0
    def normalization(self, sample):
        """ normalizes the results of the transformation to the same norm as the input

        **Principle**

        The function first computes the norm of the input and then applies the same norm to
        the self.trafo variable such that the results will be on the same scale

        .. note::

            If either the input or the derivative have not been computed already
            the node will will raise an IOError.
        """
        if self.trafo is None:
            raise IOError(
                "The derivative has not be computed. Cannot perform normalization."
            )
        if sample is None:
            raise IOError(
                "The initial sample has not been given. Cannot perform normalization."
            )
        initial = sample.view(numpy.ndarray)
        a = initial[0, :]
        norm_a = numpy.linalg.norm(a)
        if norm_a == 0:
            norm_a = 1

        initial = self.trafo.view(numpy.ndarray)
        b = initial[0, :]
        norm_b = numpy.linalg.norm(b)
        if norm_b == 0:
            norm_b = 1

        self.trafo = FeatureVector.replace_data(self.trafo,
                                                b * norm_a / norm_b)
Ejemplo n.º 6
0
    def normalization(self, sample):
        """ normalizes the results of the transformation to the same norm as the input

        **Principle**

        The function first computes the norm of the input and then applies the same norm to
        the self.trafo variable such that the results will be on the same scale

        .. note::

            If either the input or the derivative have not been computed already
            the node will will raise an IOError.
        """
        if self.trafo is None:
            raise IOError("The derivative has not be computed. Cannot perform normalization.")
        if sample is None:
            raise IOError("The initial sample has not been given. Cannot perform normalization.")
        initial = sample.view(numpy.ndarray)
        a = initial[0,:]
        norm_a = numpy.linalg.norm(a)
        if norm_a == 0:
            norm_a = 1

        initial = self.trafo.view(numpy.ndarray)
        b = initial[0,:]
        norm_b = numpy.linalg.norm(b)
        if norm_b == 0:
            norm_b = 1

        self.trafo = FeatureVector.replace_data(self.trafo, b*norm_a/norm_b)
Ejemplo n.º 7
0
    def _execute(self, x):
        """ General description of algorithm maybe followed by further details

        E.g. log "Hello" during first call and if P2 is set to True,
        always multiply data with P1 and in the other case forward the data.

        Logging is done using
        :func:`~pySPACE.missions.nodes.base_node.BaseNode._log`:

        .. code-block:: python

            self._log(self.P3, level=logging.DEBUG)

        To access only the data array and not the attached meta data, use
        `data = x.view(numpy.ndarray)` for preparation.
        """
        if self.P3:
            self._log(self.P3, level=logging.DEBUG)
            self.P3 = False
        data = x.view(numpy.ndarray)
        if self.P2:
            data = self.P1 * data
            x = FeatureVector.replace_data(x, data)
        return x
Ejemplo n.º 8
0
    def _execute(self, x):
        """ General description of algorithm maybe followed by further details

        E.g. log "Hello" during first call and if P2 is set to True,
        always multiply data with P1 and in the other case forward the data.

        Logging is done using
        :func:`~pySPACE.missions.nodes.base_node.BaseNode._log`:

        .. code-block:: python

            self._log(self.P3, level=logging.DEBUG)

        To access only the data array and not the attached meta data, use
        `data = x.view(numpy.ndarray)` for preparation.
        """
        if self.P3:
            self._log(self.P3, level=logging.DEBUG)
            self.P3 = False
        data = x.view(numpy.ndarray)
        if self.P2:
            data = self.P1 * data
            x = FeatureVector.replace_data(x, data)
        return x
Ejemplo n.º 9
0
 def feature_vector_conversion(self, data):
     good_data = numpy.nan_to_num(data.get_data())
     return FeatureVector.replace_data(data, good_data)
Ejemplo n.º 10
0
    def central_difference_with_halfstep_method(self, sample):
        """ implementation of the central difference method with a half step

        **Principle**

        The principle applied by the central difference method with a half step is

        .. math::

            f'(x)=\\frac{f(x-h)-8f(x-\\frac{h}{2})+8f(x+\\frac{h}{2})-f(x-h)}{6h}

        where :math:`h` is the step of the differentiation that is computed
        as :math:`h(x)=\sqrt{\\varepsilon} \\cdot x` for :math:`x \\neq 0` and
        :math:`h(0)=\\sqrt{\\varepsilon}` for :math:`x=0`.

        **Parameters**

            :sample:
                the initial value used for the derivation

        .. note::

            This method is the most accurate differentiation method but also
            has the greatest overhead.
        """
        if type(sample) == FeatureVector:
            self.trafo = FeatureVector.replace_data(
                    self.example, numpy.zeros(self.example.shape))
            for j in range(len(sample.feature_names)):
                positive_offset = copy.deepcopy(sample)
                negative_offset = copy.deepcopy(sample)
                half_positive_offset = copy.deepcopy(sample)
                half_negative_offset = copy.deepcopy(sample)

                if positive_offset[0][j] == 0.:
                    diff = numpy.sqrt(self.eps)
                else:
                    diff = numpy.sqrt(self.eps)*positive_offset[0][j]
                positive_offset[0][j] += diff
                negative_offset[0][j] -= diff
                half_positive_offset[0][j] += diff/2.
                half_negative_offset[0][j] -= diff/2.
                
                diff = (positive_offset[0][j]-negative_offset[0][j])/2.

                positive_vector = FeatureVector.replace_data(
                    sample,
                    positive_offset
                )
                negative_vector = FeatureVector.replace_data(
                    sample,
                    negative_offset
                )
                half_positive_vector = FeatureVector.replace_data(
                    sample,
                    half_positive_offset
                )
                half_negative_vector = FeatureVector.replace_data(
                    sample,
                    half_negative_offset
                )
                self.trafo[0][j] = \
                    numpy.longdouble((self._execute(negative_vector) -
                                    8*self._execute(half_negative_vector) +
                                    8*self._execute(half_positive_vector) -
                                    self._execute(positive_vector))/(6.*diff))
        elif type(sample) == TimeSeries:
            self.trafo = TimeSeries.replace_data(
                self.example, numpy.zeros(self.example.shape))
            for i in range(sample.shape[0]):
                for j in range(sample.shape[1]):
                    positive_offset = copy.deepcopy(sample)
                    negative_offset = copy.deepcopy(sample)
                    half_positive_offset = copy.deepcopy(sample)
                    half_negative_offset = copy.deepcopy(sample)

                    if positive_offset[i][j] == 0.:
                        diff = numpy.sqrt(self.eps)
                    else:
                        diff = numpy.sqrt(self.eps)*positive_offset[i][j]
                    positive_offset[i][j] += diff
                    negative_offset[i][j] -= diff
                    half_positive_offset[i][j] += diff/2.
                    half_negative_offset[i][j] -= diff/2.
                    
                    diff = (positive_offset[i][j]-negative_offset[i][j])/2.

                    positive_series = TimeSeries.replace_data(
                        sample,
                        positive_offset
                    )
                    negative_series = TimeSeries.replace_data(
                        sample,
                        negative_offset
                    )
                    half_positive_series = TimeSeries.replace_data(
                        sample,
                        half_positive_offset
                    )
                    half_negative_series = TimeSeries.replace_data(
                        sample,
                        half_negative_offset
                    )
                    self.trafo[i][j] = \
                        numpy.longdouble((self._execute(negative_series) -
                                        8*self._execute(half_negative_series) +
                                        8*self._execute(half_positive_series) -
                                        self._execute(positive_series))/(6.*diff))
Ejemplo n.º 11
0
 def feature_vector_conversion(self, data):
     good_data = numpy.nan_to_num(data.get_data())
     return FeatureVector.replace_data(data, good_data)
Ejemplo n.º 12
0
    def forward_difference_method(self, sample):
        """ implementation of the forward difference method

        **Principle**

        The principle applied by this method of numerical differentiation is

        .. math::

            f'(x)=\\frac{f(x+h)-f(x)}{h}

        where :math:`h` is the step of the differentiation that is computed
        as :math:`h(x)=\sqrt{\\varepsilon} \\cdot x` for :math:`x \\neq 0` and
        :math:`h(0)=\\sqrt{\\varepsilon}` for :math:`x=0`.

        The differentiation method distinguishes between ``FeatureVector`` and
        ``TimeSeries`` inputs and applies the derivative according to the
        input type.

        **Parameters**

            :sample:
                the initial value used for the derivation

        .. note::

            Out of the three numerical differentiation methods, this one has the
            least overhead. Nonetheless, this method is less accurate than the
            half step method.
        """
        initial_value = self._execute(sample)
        if type(sample) == FeatureVector:
            self.trafo = FeatureVector.replace_data(
                    self.example, numpy.zeros(self.example.shape))
            for j in range(len(sample.feature_names)):
                data_with_offset = copy.deepcopy(sample)
                if data_with_offset[0][j] == 0.:
                    diff = numpy.sqrt(self.eps)
                else:
                    diff = numpy.sqrt(self.eps)*data_with_offset[0][j]
                orig = data_with_offset[0][j]
                data_with_offset[0][j] += diff
                diff = data_with_offset[0][j] - orig
                new_feature_vector = FeatureVector.replace_data(
                    sample,
                    data_with_offset
                )
                self.trafo[0][j] = \
                    numpy.longdouble((self._execute(new_feature_vector) -
                                   initial_value)/diff)
        elif type(sample) == TimeSeries:
            self.trafo = TimeSeries.replace_data(
                self.example, numpy.zeros(self.example.shape))
            for i in range(sample.shape[0]):
                for j in range(sample.shape[1]):
                    data_with_offset = copy.deepcopy(sample)
                    if data_with_offset[i][j] == 0.:
                        diff = numpy.sqrt(self.eps)
                    else:
                        diff = numpy.sqrt(self.eps)*data_with_offset[0][j]
                    data_with_offset[i][j] += diff
                    new_time_series = TimeSeries.replace_data(
                        sample,
                        data_with_offset)
                    self.trafo[i][j] = \
                        numpy.longdouble((numpy.squeeze(self._execute(new_time_series))
                                       - numpy.squeeze(initial_value))/diff)
Ejemplo n.º 13
0
    def central_difference_method(self, sample):
        """ implementation of the central difference method

        **Principle**

        The principle applied by the central difference method is

        .. math::

            f'(x)=\\frac{f(x+h)-f(x-h)}{2h}

        where :math:`h` is the step of the differentiation that is computed
        as :math:`h(x)=\sqrt{\\varepsilon} \\cdot x` for :math:`x \\neq 0` and
        :math:`h(0)=\\sqrt{\\varepsilon}` for :math:`x=0`.

        **Parameters**

            :sample:
                the initial value used for the derivation
        """
        if type(sample) == FeatureVector:
            self.trafo = FeatureVector.replace_data(
                    sample, numpy.zeros(sample.shape))
            for j in range(len(sample.feature_names)):
                positive_offset = copy.deepcopy(sample)
                negative_offset = copy.deepcopy(sample)
                if positive_offset[0][j] == 0.:
                    diff = numpy.sqrt(self.eps)
                else:
                    diff = numpy.sqrt(self.eps)*positive_offset[0][j]
                positive_offset[0][j] += diff
                negative_offset[0][j] -= diff
                diff = (positive_offset[0][j]-negative_offset[0][j])/2.

                positive_vector = FeatureVector.replace_data(
                    sample,
                    positive_offset
                )
                negative_vector = FeatureVector.replace_data(
                    sample,
                    negative_offset
                )
                self.trafo[0][j] = \
                    numpy.longdouble((self._execute(positive_vector) -
                                   self._execute(negative_vector))/(2.*diff))
        elif type(sample) == TimeSeries:
            self.trafo = TimeSeries.replace_data(
                self.example, numpy.zeros(self.example.shape))
            for i in range(sample.shape[0]):
                for j in range(sample.shape[1]):
                    positive_offset = copy.deepcopy(sample)
                    negative_offset = copy.deepcopy(sample)
                    if positive_offset[i][j] == 0.:
                        diff = numpy.sqrt(self.eps)
                    else:
                        diff = numpy.sqrt(self.eps)*positive_offset[i][j]

                    positive_offset[i][j] += diff
                    negative_offset[i][j] -= diff
                    diff = (positive_offset[i][j]-negative_offset[i][j])/2.

                    positive_series = TimeSeries.replace_data(
                        sample,
                        positive_offset
                    )
                    negative_series = TimeSeries.replace_data(
                        sample,
                        negative_offset
                    )
                    self.trafo[i][j] = \
                        numpy.longdouble((self._execute(positive_series) -
                                       self._execute(negative_series))/(2.*diff))
Ejemplo n.º 14
0
 def feature_vector_conversion(self, data):
     float_data = data.get_data().astype(self.type)
     return FeatureVector.replace_data(data, float_data)
Ejemplo n.º 15
0
    def forward_difference_method(self, sample):
        """ implementation of the forward difference method

        **Principle**

        The principle applied by this method of numerical differentiation is

        .. math::

            f'(x)=\\frac{f(x+h)-f(x)}{h}

        where :math:`h` is the step of the differentiation that is computed
        as :math:`h(x)=\sqrt{\\varepsilon} \\cdot x` for :math:`x \\neq 0` and
        :math:`h(0)=\\sqrt{\\varepsilon}` for :math:`x=0`.

        The differentiation method distinguishes between ``FeatureVector`` and
        ``TimeSeries`` inputs and applies the derivative according to the
        input type.

        **Parameters**

            :sample:
                the initial value used for the derivation

        .. note::

            Out of the three numerical differentiation methods, this one has the
            least overhead. Nonetheless, this method is less accurate than the
            half step method.
        """
        initial_value = self._execute(sample)
        if type(sample) == FeatureVector:
            self.trafo = FeatureVector.replace_data(
                self.example, numpy.zeros(self.example.shape))
            for j in range(len(sample.feature_names)):
                data_with_offset = copy.deepcopy(sample)
                if data_with_offset[0][j] == 0.:
                    diff = numpy.sqrt(self.eps)
                else:
                    diff = numpy.sqrt(self.eps) * data_with_offset[0][j]
                orig = data_with_offset[0][j]
                data_with_offset[0][j] += diff
                diff = data_with_offset[0][j] - orig
                new_feature_vector = FeatureVector.replace_data(
                    sample, data_with_offset)
                self.trafo[0][j] = \
                    numpy.longdouble((self._execute(new_feature_vector) -
                                   initial_value)/diff)
        elif type(sample) == TimeSeries:
            self.trafo = TimeSeries.replace_data(
                self.example, numpy.zeros(self.example.shape))
            for i in range(sample.shape[0]):
                for j in range(sample.shape[1]):
                    data_with_offset = copy.deepcopy(sample)
                    if data_with_offset[i][j] == 0.:
                        diff = numpy.sqrt(self.eps)
                    else:
                        diff = numpy.sqrt(self.eps) * data_with_offset[0][j]
                    data_with_offset[i][j] += diff
                    new_time_series = TimeSeries.replace_data(
                        sample, data_with_offset)
                    self.trafo[i][j] = \
                        numpy.longdouble((numpy.squeeze(self._execute(new_time_series))
                                       - numpy.squeeze(initial_value))/diff)
Ejemplo n.º 16
0
 def feature_vector_conversion(self, data):
     float_data = data.get_data().astype(self.type)
     return FeatureVector.replace_data(data, float_data)
Ejemplo n.º 17
0
    def central_difference_with_halfstep_method(self, sample):
        """ implementation of the central difference method with a half step

        **Principle**

        The principle applied by the central difference method with a half step is

        .. math::

            f'(x)=\\frac{f(x-h)-8f(x-\\frac{h}{2})+8f(x+\\frac{h}{2})-f(x-h)}{6h}

        where :math:`h` is the step of the differentiation that is computed
        as :math:`h(x)=\sqrt{\\varepsilon} \\cdot x` for :math:`x \\neq 0` and
        :math:`h(0)=\\sqrt{\\varepsilon}` for :math:`x=0`.

        **Parameters**

            :sample:
                the initial value used for the derivation

        .. note::

            This method is the most accurate differentiation method but also
            has the greatest overhead.
        """
        if type(sample) == FeatureVector:
            self.trafo = FeatureVector.replace_data(
                self.example, numpy.zeros(self.example.shape))
            for j in range(len(sample.feature_names)):
                positive_offset = copy.deepcopy(sample)
                negative_offset = copy.deepcopy(sample)
                half_positive_offset = copy.deepcopy(sample)
                half_negative_offset = copy.deepcopy(sample)

                if positive_offset[0][j] == 0.:
                    diff = numpy.sqrt(self.eps)
                else:
                    diff = numpy.sqrt(self.eps) * positive_offset[0][j]
                positive_offset[0][j] += diff
                negative_offset[0][j] -= diff
                half_positive_offset[0][j] += diff / 2.
                half_negative_offset[0][j] -= diff / 2.

                diff = (positive_offset[0][j] - negative_offset[0][j]) / 2.

                positive_vector = FeatureVector.replace_data(
                    sample, positive_offset)
                negative_vector = FeatureVector.replace_data(
                    sample, negative_offset)
                half_positive_vector = FeatureVector.replace_data(
                    sample, half_positive_offset)
                half_negative_vector = FeatureVector.replace_data(
                    sample, half_negative_offset)
                self.trafo[0][j] = \
                    numpy.longdouble((self._execute(negative_vector) -
                                    8*self._execute(half_negative_vector) +
                                    8*self._execute(half_positive_vector) -
                                    self._execute(positive_vector))/(6.*diff))
        elif type(sample) == TimeSeries:
            self.trafo = TimeSeries.replace_data(
                self.example, numpy.zeros(self.example.shape))
            for i in range(sample.shape[0]):
                for j in range(sample.shape[1]):
                    positive_offset = copy.deepcopy(sample)
                    negative_offset = copy.deepcopy(sample)
                    half_positive_offset = copy.deepcopy(sample)
                    half_negative_offset = copy.deepcopy(sample)

                    if positive_offset[i][j] == 0.:
                        diff = numpy.sqrt(self.eps)
                    else:
                        diff = numpy.sqrt(self.eps) * positive_offset[i][j]
                    positive_offset[i][j] += diff
                    negative_offset[i][j] -= diff
                    half_positive_offset[i][j] += diff / 2.
                    half_negative_offset[i][j] -= diff / 2.

                    diff = (positive_offset[i][j] - negative_offset[i][j]) / 2.

                    positive_series = TimeSeries.replace_data(
                        sample, positive_offset)
                    negative_series = TimeSeries.replace_data(
                        sample, negative_offset)
                    half_positive_series = TimeSeries.replace_data(
                        sample, half_positive_offset)
                    half_negative_series = TimeSeries.replace_data(
                        sample, half_negative_offset)
                    self.trafo[i][j] = \
                        numpy.longdouble((self._execute(negative_series) -
                                        8*self._execute(half_negative_series) +
                                        8*self._execute(half_positive_series) -
                                        self._execute(positive_series))/(6.*diff))
Ejemplo n.º 18
0
    def central_difference_method(self, sample):
        """ implementation of the central difference method

        **Principle**

        The principle applied by the central difference method is

        .. math::

            f'(x)=\\frac{f(x+h)-f(x-h)}{2h}

        where :math:`h` is the step of the differentiation that is computed
        as :math:`h(x)=\sqrt{\\varepsilon} \\cdot x` for :math:`x \\neq 0` and
        :math:`h(0)=\\sqrt{\\varepsilon}` for :math:`x=0`.

        **Parameters**

            :sample:
                the initial value used for the derivation
        """
        if type(sample) == FeatureVector:
            self.trafo = FeatureVector.replace_data(sample,
                                                    numpy.zeros(sample.shape))
            for j in range(len(sample.feature_names)):
                positive_offset = copy.deepcopy(sample)
                negative_offset = copy.deepcopy(sample)
                if positive_offset[0][j] == 0.:
                    diff = numpy.sqrt(self.eps)
                else:
                    diff = numpy.sqrt(self.eps) * positive_offset[0][j]
                positive_offset[0][j] += diff
                negative_offset[0][j] -= diff
                diff = (positive_offset[0][j] - negative_offset[0][j]) / 2.

                positive_vector = FeatureVector.replace_data(
                    sample, positive_offset)
                negative_vector = FeatureVector.replace_data(
                    sample, negative_offset)
                self.trafo[0][j] = \
                    numpy.longdouble((self._execute(positive_vector) -
                                   self._execute(negative_vector))/(2.*diff))
        elif type(sample) == TimeSeries:
            self.trafo = TimeSeries.replace_data(
                self.example, numpy.zeros(self.example.shape))
            for i in range(sample.shape[0]):
                for j in range(sample.shape[1]):
                    positive_offset = copy.deepcopy(sample)
                    negative_offset = copy.deepcopy(sample)
                    if positive_offset[i][j] == 0.:
                        diff = numpy.sqrt(self.eps)
                    else:
                        diff = numpy.sqrt(self.eps) * positive_offset[i][j]

                    positive_offset[i][j] += diff
                    negative_offset[i][j] -= diff
                    diff = (positive_offset[i][j] - negative_offset[i][j]) / 2.

                    positive_series = TimeSeries.replace_data(
                        sample, positive_offset)
                    negative_series = TimeSeries.replace_data(
                        sample, negative_offset)
                    self.trafo[i][j] = \
                        numpy.longdouble((self._execute(positive_series) -
                                       self._execute(negative_series))/(2.*diff))