コード例 #1
0
class WeightedL2BFRanking(Ranking):

    def __init__(self):
        super(self.__class__, self).__init__()
        self._estimationStrategy = AnalyticEstimationStrategy()
        self.initialized = False

    def update(self, grid, v, gpi, params, *args, **kws):
        """
        Compute ranking for variance estimation

        \argmax_{i \in \A} |v_i| \sqrt{E[\varphi_i^2]}

        @param grid: Grid grid
        @param v: numpy array coefficients
        """
        # update the quadrature operations
        if not self.initialized:
            self._estimationStrategy.initQuadratureStrategy(grid)
            U = params.getIndependentJointDistribution()
            T = params.getJointTransformation()
            self.vol, self.W, self.D = self._estimationStrategy._extractPDFforMomentEstimation(U, T)
            self.initialized = True

        # get maximum coefficient of ancestors
        vi = 0.0
        gs = grid.getStorage()
        for _, gpp in parents(grid, gpi):
            if gs.isContaining(gpp):
                ix = gs.getSequenceNumber(gpp)
                vi = max(vi, np.abs(v[ix]))

        # prepare data
        basisi = getBasis(grid)

        # compute the second moment for the current grid point
        secondMoment, _ = self._estimationStrategy.computeSystemMatrixForVarianceList(gs,
                                                                                      [gpi], basisi,
                                                                                      [gpi], basisi,
                                                                                      self.W, self.D)
        secondMoment = max(0.0, self.vol * secondMoment[0])

        # update the ranking
        return np.abs(vi * np.sqrt(secondMoment))
コード例 #2
0
ファイル: RefinementStrategy.py プロジェクト: SGpp/SGpp
class ExpectationValueOptRanking(Ranking):
    def __init__(self):
        super(self.__class__, self).__init__()
        self._estimationStrategy = AnalyticEstimationStrategy()
        self.initialized = False

        self._linearForm = LinearGaussQuadratureStrategy()

    def compute_mean_phii(self, gs, gpi, basisi):
        mean_phii, _ = self._estimationStrategy.computeSystemMatrixForMeanList(
            gs, [gpi], basisi, self.W, self.D)
        return mean_phii[0]

    def update(self, grid, v, gpi, params, *args, **kws):
        """
        Compute ranking for variance estimation

        \argmax_{i \in \A} | |v_i| E(\varphi_i)

        @param grid: Grid grid
        @param v: numpy array coefficients
        @param admissibleSet: AdmissibleSet
        """
        # update the quadrature operations
        if not self.initialized:
            self._estimationStrategy.initQuadratureStrategy(grid)
            U = params.getIndependentJointDistribution()
            T = params.getJointTransformation()
            self.vol, self.W, self.D = self._estimationStrategy._extractPDFforMomentEstimation(
                U, T)
            self.initialized = True

        # prepare data
        gs = grid.getStorage()

        # compute stiffness matrix for next run
        basis = getBasis(grid)
        ix = gs.getSequenceNumber(gpi)

        mean_phii = self.compute_mean_phii(gs, gpi, basis)

        return np.abs(v[ix]) * mean_phii
コード例 #3
0
ファイル: RefinementStrategy.py プロジェクト: SGpp/SGpp
class VarianceOptRanking(Ranking):
    def __init__(self):
        super(self.__class__, self).__init__()
        self._estimationStrategy = AnalyticEstimationStrategy()
        self.initialized = False

    def compute_mean_uwi_phii(self, gs, gpswi, w, gpi, basis):
        A, _ = self._estimationStrategy.computeSystemMatrixForVarianceList(
            gs, gpswi, basis, [gpi], basis, self.W, self.D)
        return np.dot(w, A)

    def compute_mean_uwi(self, gs, gpswi, w, basis):
        b, _ = self._estimationStrategy.computeSystemMatrixForMeanList(
            gs, gpswi, basis, self.W, self.D)
        return np.dot(w, b)

    def compute_mean_phii(self, gs, gpi, basisi):
        mean_phii, _ = self._estimationStrategy.computeSystemMatrixForMeanList(
            gs, [gpi], basisi, self.W, self.D)
        return mean_phii[0]

    def compute_var_phii(self, gs, gpi, basisi, mean_phii):
        A_var, _ = self._estimationStrategy.computeSystemMatrixForVarianceList(
            gs, [gpi], basisi, [gpi], basisi, self.W, self.D)
        return A_var[0, 0] - mean_phii**2

    def update(self, grid, v, gpi, params, *args, **kws):
        """
        Compute ranking for variance estimation

        \argmax_{i \in \A} | -v_i^2 V(\varphi_i) - 2 v_i Cov(u_indwli \varphi_i)|

        @param grid: Grid grid
        @param v: numpy array coefficients
        @param admissibleSet: AdmissibleSet
        """
        # update the quadrature operations
        if not self.initialized:
            self._estimationStrategy.initQuadratureStrategy(grid)
            U = params.getIndependentJointDistribution()
            T = params.getJointTransformation()
            self.vol, self.W, self.D = self._estimationStrategy._extractPDFforMomentEstimation(
                U, T)
            self.initialized = True

        # prepare data
        gs = grid.getStorage()
        basis = getBasis(grid)

        # load coefficients and vectors and matrices for variance and mean
        # estimation
        w = np.ndarray(gs.getSize() - 1)
        ix = gs.getSequenceNumber(gpi)

        # prepare list of grid points
        gpswi = []
        jx = 0
        for j in range(gs.getSize()):
            gpj = gs.getPoint(j)
            if gpi.getHash() != gpj.getHash():
                gpswi.append(gpj)
                w[jx] = v[j]
                jx += 1

        # compute the covariance
        mean_uwi_phii = self.compute_mean_uwi_phii(gs, gpswi, w, gpi, basis)
        mean_phii = self.compute_mean_phii(gs, gpi, basis)
        mean_uwi = self.compute_mean_uwi(gs, gpswi, w, basis)

        cov_uwi_phii = mean_uwi_phii - mean_phii * mean_uwi

        # compute the variance of phi_i
        var_phii = self.compute_var_phii(gs, gpi, basis, mean_phii)

        # update the ranking
        return np.abs(-v[ix]**2 * var_phii - 2 * v[ix] * cov_uwi_phii)