示例#1
0
 def mergeCovarianceToGF(self):
     """
     merge data covariance (cd) with green function
     """
     # get references for data covariance
     cd_inv = self.dataobs.gcd_inv
     # get a reference for green's function
     green = self.gGF
     # copy from CPU
     green.copy_from_host(source=self.GF)
     # check whether cd is a constant or a matrix
     if isinstance(cd_inv, float):
         green *= cd_inv
     elif isinstance(cd_inv, altar.cuda.matrix):
         # (obsxobs) x (obsxparameters) = (obsxparameters)
         cublas.trmm(cd_inv,
                     green,
                     out=green,
                     side=cublas.SideLeft,
                     uplo=cublas.FillModeUpper,
                     transa=cublas.OpNoTrans,
                     diag=cublas.DiagNonUnit,
                     alpha=1.0,
                     handle=self.cublas_handle)
     # all done
     return
示例#2
0
    def displace(self, displacement):
        """
        Construct a set of displacement vectors for the random walk from a distribution with zero
        mean and my covariance
        """
        # get my decomposed covariance
        Σ_chol = self.gsigma_chol

        # generate gaussian random numbers (samples x parameters)
        altar.cuda.curand.gaussian(out=displacement)

        # multiply by the sigma_cholesky
        cublas.trmm(Σ_chol, displacement, out=displacement,
            alpha=1.0, uplo=cublas.FillModeUpper, side=cublas.SideRight,
            transa = cublas.OpNoTrans, diag=cublas.DiagNonUnit)
        # and return
        return displacement
示例#3
0
文件: cudaL2.py 项目: lijun99/altar
    def cuEvalLikelihood(self,
                         data,
                         constant=0.0,
                         out=None,
                         batch=None,
                         cdinv=None):
        """
        Compute the L2 norm data likelihood of the given data  const - ||x||^2/2
        Arguments:
            data - matrix (samples x observations) 
            batch - number of samples to be computed (first rows)
            constant - normalization constant
            cdinv - inverse covariance matrix (observations x observations) in its Cholesky decomposed form (Upper Triangle)   
        Return:
            out -  data likelihood vector (samples)  
        """

        samples = data.shape[0]
        # no batch provided, compute all samples
        if batch is None or batch > samples:
            batch = samples

        # if output is not pre-allocated, allocate it
        if out is None:
            out = altar.cuda.vector(shape=samples)

        # if covariance matrix is provided
        if cdinv is not None:
            # data [samples][obs] = data[samples][obs] x cdinv[obs][obs]
            cublas.trmm(cdinv,
                        data,
                        out=data,
                        alpha=1.0,
                        uplo=cublas.FillModeUpper,
                        side=cublas.SideRight,
                        transa=cublas.OpNoTrans,
                        diag=cublas.DiagNonUnit)

        # compute the norm
        libcudaaltar.cudaL2_normllk(data.data, out.data, batch, constant)
        # return the result
        return out
示例#4
0
    def prepareGF(self):
        """
        copy green function to gpu and merge cd with green function
        """
        # make a gpu copy
        self.gGF = altar.cuda.matrix(source=self.GF, dtype=self.precision)
        # merge cd with Green's function
        cd_inv = self.dataobs.gcd_inv

        green = self.gGF

        # (obsxobs) x (obsxparameters) = (obsxparameters)
        cublas.trmm(cd_inv,
                    green,
                    out=green,
                    side=cublas.SideLeft,
                    uplo=cublas.FillModeUpper,
                    transa=cublas.OpNoTrans,
                    diag=cublas.DiagNonUnit,
                    alpha=1.0,
                    handle=self.cublas_handle)
        #cublas.gemm(cd_inv, green, out=green)
        return