Beispiel #1
0
    def ppf(self, x):
        # convert the parameter to the right format
        if isList(x):
            x = DataVector(x)
        elif isNumerical(x):
            x = DataVector([x])

        # do the transformation
        if self.grid.getStorage().dim() == 1:
            op = createOperationInverseRosenblattTransformation1D(self.grid)
            ans = np.ndarray(len(x))
            for i, xi in enumerate(x.array()):
                ans[i] = op.doTransformation1D(self.alpha, xi)
            if len(ans) == 1:
                return ans[0]
            else:
                return ans
        else:
            if isinstance(x, DataMatrix):
                A = x
                B = DataMatrix(A.getNrows(), A.getNcols())
                B.setAll(0.0)
            elif isinstance(x, DataVector):
                A = DataMatrix(1, len(x))
                A.setRow(0, x)
                B = DataMatrix(1, len(x))
                B.setAll(0)

            # do the transformation
            op = createOperationInverseRosenblattTransformation(self.grid)
            op.doTransformation(self.alpha, A, B)

            # extract the outcome
            if isNumerical(x) or isinstance(x, DataVector):
                return B.get(0, 0)
            elif isinstance(x, DataMatrix):
                return B.array()
Beispiel #2
0
    def ppf(self, x):
        # convert the parameter to the right format
        if isList(x):
            x = DataVector(x)
        elif isNumerical(x):
            x = DataVector([x])

        # do the transformation
        if self.grid.getStorage().dim() == 1:
            op = createOperationInverseRosenblattTransformation1D(self.grid)
            ans = np.ndarray(len(x))
            for i, xi in enumerate(x.array()):
                ans[i] = op.doTransformation1D(self.alpha, xi)
            if len(ans) == 1:
                return ans[0]
            else:
                return ans
        else:
            if isinstance(x, DataMatrix):
                A = x
                B = DataMatrix(A.getNrows(), A.getNcols())
                B.setAll(0.0)
            elif isinstance(x, DataVector):
                A = DataMatrix(1, len(x))
                A.setRow(0, x)
                B = DataMatrix(1, len(x))
                B.setAll(0)

            # do the transformation
            op = createOperationInverseRosenblattTransformation(self.grid)
            op.doTransformation(self.alpha, A, B)

            # extract the outcome
            if isNumerical(x) or isinstance(x, DataVector):
                return B.get(0, 0)
            elif isinstance(x, DataMatrix):
                return B.array()
Beispiel #3
0
    def eval(self, x):
        """
        Evaluate the ANOVA decomposition at the given position
        @param x: coordinates to be evaluated
        """
        if not self.__anova_components:
            raise Exception('Do the decomposition first')

        # type check
        if isNumerical(x):
            x = np.array(x, dtype='float')

        # evaluation function

        # add constant term
        s = self.__E

        # add higher order terms
        for components in self.__anova_components.values():
            s += self.__evalHigherOrderComponent(components, x)

        return s
Beispiel #4
0
    def eval(self, x):
        """
        Evaluate the ANOVA decomposition at the given position
        @param x: coordinates to be evaluated
        """
        if not self.__anova_components:
            raise Exception('Do the decomposition first')

        # type check
        if isNumerical(x):
            x = np.array(x, dtype='float')

        # evaluation function

        # add constant term
        s = self.__E

        # add higher order terms
        for components in self.__anova_components.values():
            s += self.__evalHigherOrderComponent(components, x)

        return s
Beispiel #5
0
    def pdf(self, x):
        # convert the parameter to the right format
        if isList(x):
            x = DataVector(x)
        elif isNumerical(x):
            return evalSGFunction(self.grid, self.alpha, DataVector([x]))

        if isinstance(x, DataMatrix):
            A = x
        elif isinstance(x, DataVector):
            A = DataMatrix(1, len(x))
            A.setRow(0, x)
        else:
            raise AttributeError('data type "%s" is not supported in SGDEdist' % type(x))

        # evaluate the sparse grid density
        fx = evalSGFunctionMulti(self.grid, self.alpha, A)

        # if there is just one value given, extract it from the list
        if len(fx) == 1:
            fx = fx[0]

        return fx
Beispiel #6
0
    def pdf(self, x):
        # convert the parameter to the right format
        if isList(x):
            x = DataVector(x)
        elif isNumerical(x):
            return evalSGFunction(self.grid, self.alpha, DataVector([x]))

        if isinstance(x, DataMatrix):
            A = x
        elif isinstance(x, DataVector):
            A = DataMatrix(1, len(x))
            A.setRow(0, x)
        else:
            raise AttributeError(
                'data type "%s" is not supported in SGDEdist' % type(x))

        # evaluate the sparse grid density
        fx = evalSGFunctionMulti(self.grid, self.alpha, A)

        # if there is just one value given, extract it from the list
        if len(fx) == 1:
            fx = fx[0]

        return fx