Example #1
0
    def update(self, grid, alphas, gpi, params, *args, **kws):
        gs = grid.getStorage()
        # get maximum coefficient of ancestors
        vi = 0.0
        for _, gpp in parents(grid, gpi):
            if gs.isContaining(gpp):
                ix = gs.getSequenceNumber(gpp)
                vi = max(vi, np.abs(alphas[ix]))

        p = DataVector(gs.getDimension())
        gs.getCoordinates(gpi, p)

        # get joint distribution
        ap = params.activeParams()
        U = ap.getIndependentJointDistribution()
        T = ap.getJointTransformation()
        q = T.unitToProbabilistic(p.array())

        # scale surplus by probability density
        return np.abs(vi) * U.pdf(q)
Example #2
0
    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))