当前位置: 首页>>代码示例>>Python>>正文


Python numpy.copy方法代码示例

本文整理汇总了Python中autograd.numpy.copy方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.copy方法的具体用法?Python numpy.copy怎么用?Python numpy.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在autograd.numpy的用法示例。


在下文中一共展示了numpy.copy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: gbrbm_perturb

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import copy [as 别名]
def gbrbm_perturb(var_perturb_B, dx=50, dh=10):
    """
    Get a Gaussian-Bernoulli RBM problem where the first entry of the B matrix
    (the matrix linking the latent and the observation) is perturbed.

    - var_perturb_B: Gaussian noise variance for perturbing B.
    - dx: observed dimension
    - dh: latent dimension

    Return p (density), data source
    """
    with util.NumpySeedContext(seed=10):
        B = np.random.randint(0, 2, (dx, dh))*2 - 1.0
        b = np.random.randn(dx)
        c = np.random.randn(dh)
        p = density.GaussBernRBM(B, b, c)

        B_perturb = np.copy(B)
        if var_perturb_B > 1e-7:
            B_perturb[0, 0] = B_perturb[0, 0] + \
                np.random.randn(1)*np.sqrt(var_perturb_B)
        ds = data.DSGaussBernRBM(B_perturb, b, c, burnin=2000)

    return p, ds 
开发者ID:wittawatj,项目名称:kernel-gof,代码行数:26,代码来源:ex1_vary_n.py

示例2: _set_precision

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import copy [as 别名]
def _set_precision(self, precision_val):
        # new val needs to have dimension (n_unique, n_features, n_features)
        # internally, n_components x 1
        precision_new = \
        np.zeros((self.n_components, self.n_features, self.n_features))
        if precision_val is not None:
            precision_val = \
            precision_val.reshape(self.n_unique, self.n_features, self.n_features)
            if precision_val.shape == \
            (self.n_unique, self.n_features, self.n_features):
                for u in range(self.n_unique):
                    for t in range(self.n_chain):
                        precision_new[u*(self.n_chain)+t] = precision_val[u].copy()
            else:
                raise ValueError("cannot match shape of precision")
        self._precision_ = precision_new 
开发者ID:mackelab,项目名称:autohmm,代码行数:18,代码来源:tm.py

示例3: _set_startprob

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import copy [as 别名]
def _set_startprob(self, startprob):
        if startprob is None:
            startprob = np.tile(1.0 / self.n_components, self.n_components)
        else:
            startprob = np.asarray(startprob, dtype=np.float)

            normalize(startprob)

            if len(startprob) != self.n_components:
                if len(startprob) == self.n_unique:
                    startprob_split = np.copy(startprob) / (1.0+self.n_tied)
                    startprob = np.zeros(self.n_components)
                    for u in range(self.n_unique):
                        for t in range(self.n_chain):
                            startprob[u*(self.n_chain)+t] = \
                                startprob_split[u].copy()
                else:
                    raise ValueError("cannot match shape of startprob")

        if not np.allclose(np.sum(startprob), 1.0):
            raise ValueError('startprob must sum to 1.0')

        self._log_startprob = np.log(np.asarray(startprob).copy()) 
开发者ID:mackelab,项目名称:autohmm,代码行数:25,代码来源:tm.py

示例4: _set_startprob_prior

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import copy [as 别名]
def _set_startprob_prior(self, startprob_prior):
        if startprob_prior is None or startprob_prior == 1.0:
            startprob_prior = np.zeros(self.n_components)
        else:
            startprob_prior = np.asarray(startprob_prior, dtype=np.float)

            if len(startprob_prior) != self.n_components:
                if len(startprob_prior) == self.n_unique:
                    startprob_prior_split = np.copy(startprob_prior) / \
                        (1.0 + self.n_tied)
                    startprob_prior = np.zeros(self.n_components)
                    for u in range(self.n_unique):
                        for t in range(self.n_chain):
                            startprob_prior[u*(self.n_chain)+t] = \
                                startprob_prior_split[u].copy()
                else:
                    raise ValueError("cannot match shape of startprob")

        self.startprob_prior = np.asarray(startprob_prior).copy() 
开发者ID:mackelab,项目名称:autohmm,代码行数:21,代码来源:tm.py

示例5: _set_transmat

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import copy [as 别名]
def _set_transmat(self, transmat_val):
        if transmat_val is None:
            transmat = np.tile(1.0 / self.n_components,
                               (self.n_components, self.n_components))
        else:
            transmat_val[np.isnan(transmat_val)] = 0.0
            normalize(transmat_val, axis=1)

            if (np.asarray(transmat_val).shape == (self.n_components,
                                                   self.n_components)):
                transmat = np.copy(transmat_val)
            elif transmat_val.shape[0] == self.n_unique:
                transmat = self._ntied_transmat(transmat_val)
            else:
                raise ValueError("cannot match shape of transmat")

        if not np.all(np.allclose(np.sum(transmat, axis=1), 1.0)):
            raise ValueError('Rows of transmat must sum to 1.0')
        self._log_transmat = np.log(np.asarray(transmat).copy())
        underflow_idx = np.isnan(self._log_transmat)
        self._log_transmat[underflow_idx] = NEGINF 
开发者ID:mackelab,项目名称:autohmm,代码行数:23,代码来源:tm.py

示例6: _set_transmat_prior

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import copy [as 别名]
def _set_transmat_prior(self, transmat_prior_val):
        # new val needs be n_unique x n_unique
        # internally, n_components x n_components
        # _ntied_transmat_prior is
        # called to get n_components x n_components
        transmat_prior_new = np.zeros((self.n_components, self.n_components))
        if transmat_prior_val is not None:

            if transmat_prior_val.shape == (self.n_unique, self.n_unique):
                transmat_prior_new = \
                np.copy(self._ntied_transmat_prior(transmat_prior_val))

            else:
                raise ValueError("cannot match shape of transmat_prior")


        self.transmat_prior = transmat_prior_new 
开发者ID:mackelab,项目名称:autohmm,代码行数:19,代码来源:tm.py

示例7: clone

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import copy [as 别名]
def clone(self):
        """
        Return a new Data object with a separate copy of each internal 
        variable, and with the same content.
        """
        nX = np.copy(self.X)
        return Data(nX) 
开发者ID:wittawatj,项目名称:kernel-gof,代码行数:9,代码来源:data.py

示例8: __add__

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import copy [as 别名]
def __add__(self, data2):
        """
        Merge the current Data with another one.
        Create a new Data and create a new copy for all internal variables.
        """
        copy = self.clone()
        copy2 = data2.clone()
        nX = np.vstack((copy.X, copy2.X))
        return Data(nX)

### end Data class 
开发者ID:wittawatj,项目名称:kernel-gof,代码行数:13,代码来源:data.py

示例9: __uniform_reference_directions

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import copy [as 别名]
def __uniform_reference_directions(self, ref_dirs, ref_dir, n_partitions, beta, depth):
        if depth == len(ref_dir) - 1:
            ref_dir[depth] = beta / (1.0 * n_partitions)
            ref_dirs.append(ref_dir[None, :])
        else:
            for i in range(beta + 1):
                ref_dir[depth] = 1.0 * i / (1.0 * n_partitions)
                self.__uniform_reference_directions(ref_dirs, anp.copy(ref_dir), n_partitions, beta - i,
                                                    depth + 1) 
开发者ID:msu-coinlab,项目名称:pymop,代码行数:11,代码来源:util.py

示例10: _calc_pareto_front

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import copy [as 别名]
def _calc_pareto_front(self, n_pareto_points=100):
        x1 = anp.linspace(0, 5, n_pareto_points)
        x2 = anp.copy(x1)
        x2[x1 >= 3] = 3
        return anp.vstack((4 * anp.square(x1) + 4 * anp.square(x2), anp.square(x1 - 5) + anp.square(x2 - 5))).T 
开发者ID:msu-coinlab,项目名称:pymop,代码行数:7,代码来源:bnh.py

示例11: _set_mu

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import copy [as 别名]
def _set_mu(self, mu_val):
        # new val needs to be of shape (n_uniqe, n_features)
        # internally, (n_components x n_features)
        mu_new = np.zeros((self.n_components, self.n_features))
        if mu_val is not None:
            mu_val = mu_val.reshape(self.n_unique, self.n_features)
            if mu_val.shape == (self.n_unique, self.n_features):
                for u in range(self.n_unique):
                    for t in range(self.n_chain):
                        mu_new[u*(self.n_chain)+t] = mu_val[u].copy()
            else:
                raise ValueError("cannot match shape of mu")
        self._mu_ = mu_new 
开发者ID:mackelab,项目名称:autohmm,代码行数:15,代码来源:tm.py

示例12: _set_mu_prior

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import copy [as 别名]
def _set_mu_prior(self, mu_prior):
        if mu_prior is None:
            self._mu_prior_ = np.zeros((self.n_components, self.n_features))
        else:
            mu_prior = np.asarray(mu_prior)
            mu_prior = mu_prior.reshape(self.n_unique, self.n_features)
            if mu_prior.shape == (self.n_unique, self.n_features):
                for u in range(self.n_unique):
                    for t in range(self.n_chain):
                        self._mu_prior[u*(self.n_chain)+t] = mu_prior[u].copy()

            else:
                raise ValueError("cannot match shape of mu_prior") 
开发者ID:mackelab,项目名称:autohmm,代码行数:15,代码来源:tm.py

示例13: _obj_grad

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import copy [as 别名]
def _obj_grad(self, wrt, m, p, a, xn, xln, gn, entries='all', **kwargs):
        m = m.reshape(self.n_unique, self.n_features, 1)  # tm

        if wrt == 'm':
            wrt_num = 0
        elif wrt == 'p':
            wrt_num = 1
        elif wrt == 'a':
            wrt_num = 2
        else:
            raise ValueError('unknown parameter')
        res = grad(self._obj, wrt_num)(m, p, a, xn, xln, gn)

        if wrt == 'p' and self.n_features > 1:
            if entries == 'diag':
                res_new = \
                np.zeros((self.n_unique, self.n_features, self.n_features))
                for u in range(self.n_unique):
                    for f in range(self.n_features):
                        res_new[u,f,f] = res[u,f,f]
                res = np.copy(res_new)

            elif entries == 'offdiag':
                for u in range(self.n_unique):
                    for f in range(self.n_features):
                        res[u,f,f] = 0.

        res = np.array([res])
        return res 
开发者ID:mackelab,项目名称:autohmm,代码行数:31,代码来源:ar.py

示例14: _set_alpha

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import copy [as 别名]
def _set_alpha(self, alpha_val):
        # new val needs to have a 1st dim of length n_unique x n_lags
        # if shared_alpha is true, a shape of 1 x n_lags is possible, too
        # internally, n_components x n_lags
        alpha_new = np.zeros((self.n_components, self.n_lags))

        if alpha_val is not None:
            if alpha_val.ndim == 1:
                alpha_val = alpha_val.reshape(-1, 1)  # make sure 2nd dim exists

            if alpha_val.shape[1] != self.n_lags:
                raise ValueError("shape[1] does not match n_lags")

            if self.shared_alpha == False:
                # alpha is not shared
                if alpha_val.shape[0] != self.n_unique:
                    raise ValueError("shape[0] does not match n_unique")
                for u in range(self.n_unique):
                    for t in range(1+self.n_tied):
                        alpha_new[u*(1+self.n_tied)+t, :] = alpha_val[u, :].copy()
            else:
                # alpha is shared ...
                if alpha_val.shape[0] != self.n_unique and \
                  alpha_val.shape[0] != 1:
                    # ... the shape should either be 1 x L or U x L
                    raise ValueError("shape[0] is neither 1 nor does it match n_unique")
                if alpha_val.shape[0] == self.n_unique and \
                  not (alpha_val == alpha_val[0,:]).all():
                    # .. in case of U x L the rows need to be identical
                    raise ValueError("rows not identical (shared_alpha)")
                for u in range(self.n_unique):
                    for t in range(1+self.n_tied):
                        alpha_new[u*(1+self.n_tied)+t, :] = alpha_val[0, :].copy()

        self._alpha_ = alpha_new 
开发者ID:mackelab,项目名称:autohmm,代码行数:37,代码来源:ar.py

示例15: match

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import copy [as 别名]
def match(self, model_frame, diff_kernels=None, convolution="fft"):
        """Match the frame of `Blend` to the frame of this observation.

        The method sets up the mappings in spectral and spatial coordinates,
        which includes a spatial selection, computing PSF difference kernels
        and filter transformations.

        Parameters
        ---------
        model_frame: a `scarlet.Frame` instance
            The frame of `Blend` to match
        diff_kernels: array
            The difference kernel for each band.
            If `diff_kernels` is `None` then they are
            calculated automatically.
        convolution: str
            The type of convolution to use.
            - `real`: Use a real space convolution and gradient
            - `fft`: Use a DFT to do the convolution and gradient

        Returns
        -------
        None
        """
        self.model_frame = model_frame
        if model_frame.channels is not None and self.frame.channels is not None:
            channel_origin = list(model_frame.channels).index(self.frame.channels[0])
            self.frame.origin = (channel_origin, *self.frame.origin[1:])

        slices = overlapped_slices(self.frame, model_frame)
        self.slices_for_images = slices[0] # Slice of images to match the model
        self.slices_for_model = slices[1] #  Slice of model that overlaps with the observation

        # check dtype consistency
        if self.frame.dtype != model_frame.dtype:
            self.frame.dtype = model_frame.dtype
            self.images = self.images.copy().astype(model_frame.dtype)
            if type(self.weights) is np.ndarray:
                self.weights = self.weights.copy().astype(model_frame.dtype)

        # constrcut diff kernels
        if diff_kernels is None:
            self._diff_kernels = None
            if self.frame.psf is not model_frame.psf:
                assert self.frame.psf is not None and model_frame.psf is not None
                psf = fft.Fourier(self.frame.psf.update_dtype(model_frame.dtype).image)
                model_psf = fft.Fourier(
                    model_frame.psf.update_dtype(model_frame.dtype).image
                )
                self._diff_kernels = fft.match_psfs(psf, model_psf)
        else:
            if not isinstance(diff_kernels, fft.Fourier):
                diff_kernels = fft.Fourier(diff_kernels)
            self._diff_kernels = diff_kernels

        # initialize the filter window
        assert convolution in ["real", "fft"], "`convolution` must be either 'real' or 'fft'"
        self.convolution = convolution
        return self 
开发者ID:pmelchior,项目名称:scarlet,代码行数:61,代码来源:observation.py


注:本文中的autograd.numpy.copy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。