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


Python numpy.pi方法代码示例

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


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

示例1: __init__

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import pi [as 别名]
def __init__(self, n_var=2, n_constr=1, option="linear"):
        super().__init__(n_var=n_var, n_obj=2, n_constr=n_constr, xl=0, xu=1, type_var=anp.double)

        def g_linear(x):
            return 1 + anp.sum(x, axis=1)

        def g_multimodal(x):
            A = 10
            return 1 + A * x.shape[1] + anp.sum(x ** 2 - A * anp.cos(2 * anp.pi * x), axis=1)

        if option == "linear":
            self.calc_g = g_linear

        elif option == "multimodal":
            self.calc_g = g_multimodal
            self.xl[:, 1:] = -5.12
            self.xu[:, 1:] = 5.12

        else:
            print("Unknown option for CTP single.") 
开发者ID:msu-coinlab,项目名称:pymoo,代码行数:22,代码来源:ctp.py

示例2: _calc_pareto_front

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import pi [as 别名]
def _calc_pareto_front(self, n_points=100, flatten=True):
        regions = [[0, 0.0830015349],
                   [0.182228780, 0.2577623634],
                   [0.4093136748, 0.4538821041],
                   [0.6183967944, 0.6525117038],
                   [0.8233317983, 0.8518328654]]

        pf = []

        for r in regions:
            x1 = anp.linspace(r[0], r[1], int(n_points / len(regions)))
            x2 = 1 - anp.sqrt(x1) - x1 * anp.sin(10 * anp.pi * x1)
            pf.append(anp.array([x1, x2]).T)

        if not flatten:
            pf = anp.concatenate([pf[None,...] for pf in pf])
        else:
            pf = anp.row_stack(pf)

        return pf 
开发者ID:msu-coinlab,项目名称:pymoo,代码行数:22,代码来源:zdt.py

示例3: log_norm

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import pi [as 别名]
def log_norm(self):
        try:
            return self._log_norm
        except AttributeError:
            if self.frame != self.model_frame:
                images_ = self.images[self.slices_for_images]
                weights_ = self.weights[self.slices_for_images]
            else:
                images_ = self.images
                weights_ = self.weights

            # normalization of the single-pixel likelihood:
            # 1 / [(2pi)^1/2 (sigma^2)^1/2]
            # with inverse variance weights: sigma^2 = 1/weight
            # full likelihood is sum over all data samples: pixel in images
            # NOTE: this assumes that all pixels are used in likelihood!
            log_sigma = np.zeros(weights_.shape, dtype=self.weights.dtype)
            cuts = weights_ > 0
            log_sigma[cuts] = np.log(1 / weights_[cuts])
            self._log_norm = (
                    np.prod(images_.shape) / 2 * np.log(2 * np.pi)
                    + np.sum(log_sigma) / 2
            )
        return self._log_norm 
开发者ID:pmelchior,项目名称:scarlet,代码行数:26,代码来源:observation.py

示例4: get_loss

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import pi [as 别名]
def get_loss(self, model):
        """Computes the loss/fidelity of a given model wrt to the observation
        Parameters
        ----------
        model: array
            A model from `Blend`
        Returns
        -------
        loss: float
            Loss of the model
        """
        model_ = self.render(model)
        images_ = self.images
        weights_ = self.weights

        # properly normalized likelihood
        log_sigma = np.zeros(weights_.shape, dtype=weights_.dtype)
        cuts = weights_ > 0
        log_sigma[cuts] = np.log(1 / weights_[cuts])
        log_norm = (
                np.prod(images_.shape) / 2 * np.log(2 * np.pi)
                + np.sum(log_sigma) / 2
        )

        return log_norm + 0.5 * np.sum(weights_ * (model_ - images_) ** 2) 
开发者ID:pmelchior,项目名称:scarlet,代码行数:27,代码来源:observation.py

示例5: black_box_variational_inference

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import pi [as 别名]
def black_box_variational_inference(logprob, D, num_samples):
    """Implements http://arxiv.org/abs/1401.0118, and uses the
    local reparameterization trick from http://arxiv.org/abs/1506.02557"""

    def unpack_params(params):
        # Variational dist is a diagonal Gaussian.
        mean, log_std = params[:D], params[D:]
        return mean, log_std

    def gaussian_entropy(log_std):
        return 0.5 * D * (1.0 + np.log(2*np.pi)) + np.sum(log_std)

    rs = npr.RandomState(0)
    def variational_objective(params, t):
        """Provides a stochastic estimate of the variational lower bound."""
        mean, log_std = unpack_params(params)
        samples = rs.randn(num_samples, D) * np.exp(log_std) + mean
        lower_bound = gaussian_entropy(log_std) + np.mean(logprob(samples, t))
        return -lower_bound

    gradient = grad(variational_objective)

    return variational_objective, gradient, unpack_params 
开发者ID:HIPS,项目名称:autograd,代码行数:25,代码来源:black_box_svi.py

示例6: compute_f

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import pi [as 别名]
def compute_f(theta, lambda0, dL, shape):
    """ Compute the 'vacuum' field vector """

    # get plane wave k vector components (in units of grid cells)
    k0 = 2 * npa.pi / lambda0 * dL
    kx =  k0 * npa.sin(theta)
    ky = -k0 * npa.cos(theta)  # negative because downwards

    # array to write into
    f_src = npa.zeros(shape, dtype=npa.complex128)

    # get coordinates
    Nx, Ny = shape
    xpoints = npa.arange(Nx)
    ypoints = npa.arange(Ny)
    xv, yv = npa.meshgrid(xpoints, ypoints, indexing='ij')

    # compute values and insert into array
    x_PW = npa.exp(1j * xpoints * kx)[:, None]
    y_PW = npa.exp(1j * ypoints * ky)[:, None]

    f_src[xv, yv] = npa.outer(x_PW, y_PW)

    return f_src.flatten() 
开发者ID:fancompute,项目名称:ceviche,代码行数:26,代码来源:sources.py

示例7: multivariate_normal_density

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import pi [as 别名]
def multivariate_normal_density(mean, cov, X):
        """
        Exact density (not log density) of a multivariate Gaussian.
        mean: length-d array
        cov: a dxd covariance matrix
        X: n x d 2d-array
        """
        
        evals, evecs = np.linalg.eigh(cov)
        cov_half_inv = evecs.dot(np.diag(evals**(-0.5))).dot(evecs.T)
    #     print(evals)
        half_evals = np.dot(X-mean, cov_half_inv)
        full_evals = np.sum(half_evals**2, 1)
        unden = np.exp(-0.5*full_evals)
        
        Z = np.sqrt(np.linalg.det(2.0*np.pi*cov))
        den = unden/Z
        assert len(den) == X.shape[0]
        return den 
开发者ID:wittawatj,项目名称:kernel-gof,代码行数:21,代码来源:density.py

示例8: __init__

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import pi [as 别名]
def __init__(self, n_var=2, n_constr=1, option="linear"):
        super().__init__(n_var=n_var, n_obj=2, n_constr=n_constr, xl=0, xu=1, type_var=anp.double)

        def g_linear(x):
            return 1 + anp.sum(x, axis=1)

        def g_multimodal(x):
            A = 10
            return 1 + A * x.shape[1] + anp.sum(x ** 2 - A * anp.cos(2 * anp.pi * x), axis=1)

        if option == "linear":
            self.calc_g = g_linear

        elif option == "multimodal":
            self.calc_g = g_multimodal
            self.xl[:, 1:] = -5.12
            self.xu[:, 1:] = 5.12

        else:
            print("Unknown option for CTP problems.") 
开发者ID:msu-coinlab,项目名称:pymop,代码行数:22,代码来源:ctp.py

示例9: likelihood

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import pi [as 别名]
def likelihood(self, hyp):
        Y = self.Y_batch     
            
        # Encode
        mu_1, Sigma_1 = self.neural_net(Y, self.layers_encoder, hyp[self.idx_encoder]) 
        
        # Reparametrization trick
        epsilon = np.random.randn(self.N_batch,self.Z_dim)        
        z = mu_1 + epsilon*np.sqrt(Sigma_1)
        
        # Decode
        mu_2, Sigma_2 = self.neural_net(z, self.layers_decoder, hyp[self.idx_decoder])
        
        # Log-determinants
        log_det_1 = np.sum(np.log(Sigma_1))
        log_det_2 = np.sum(np.log(Sigma_2))
        
        # KL[q(z|y) || p(z)]
        KL = 0.5*(np.sum(Sigma_1) + np.sum(mu_1**2) - self.Z_dim - log_det_1)
        
        # -log p(y)
        NLML = 0.5*(np.sum((Y-mu_2)**2/Sigma_2) + log_det_2 + np.log(2.*np.pi)*self.Y_dim*self.N_batch)
           
        return NLML + KL 
开发者ID:maziarraissi,项目名称:DeepLearningTutorial,代码行数:26,代码来源:VariationalAutoencoders.py

示例10: _ll

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import pi [as 别名]
def _ll(self, m, p, xn, **kwargs):
        """Computation of log likelihood

        Dimensions
        ----------
        m : n_unique x n_features
        p : n_unique x n_features x n_features
        xn: N x n_features
        """

        samples = xn.shape[0]
        xn = xn.reshape(samples, 1, self.n_features)
        m = m.reshape(1, self.n_unique, self.n_features)

        det = np.linalg.det(np.linalg.inv(p))
        det = det.reshape(1, self.n_unique)
        tem = np.einsum('NUF,UFX,NUX->NU', (xn - m), p, (xn - m))
        res = (-self.n_features/2.0)*np.log(2*np.pi) - 0.5*tem - 0.5*np.log(det)

        return res  # N x n_unique 
开发者ID:mackelab,项目名称:autohmm,代码行数:22,代码来源:tm.py

示例11: g1

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import pi [as 别名]
def g1(self, X_M):
        return 100 * (self.k + anp.sum(anp.square(X_M - 0.5) - anp.cos(20 * anp.pi * (X_M - 0.5)), axis=1)) 
开发者ID:msu-coinlab,项目名称:pymoo,代码行数:4,代码来源:dtlz.py

示例12: obj_func

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import pi [as 别名]
def obj_func(self, X_, g, alpha=1):
        f = []

        for i in range(0, self.n_obj):
            _f = (1 + g)
            _f *= anp.prod(anp.cos(anp.power(X_[:, :X_.shape[1] - i], alpha) * anp.pi / 2.0), axis=1)
            if i > 0:
                _f *= anp.sin(anp.power(X_[:, X_.shape[1] - i], alpha) * anp.pi / 2.0)

            f.append(_f)

        f = anp.column_stack(f)
        return f 
开发者ID:msu-coinlab,项目名称:pymoo,代码行数:15,代码来源:dtlz.py

示例13: _evaluate

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import pi [as 别名]
def _evaluate(self, x, out, *args, **kwargs):
        f = []
        for i in range(0, self.n_obj - 1):
            f.append(x[:, i])
        f = anp.column_stack(f)

        g = 1 + 9 / self.k * anp.sum(x[:, -self.k:], axis=1)
        h = self.n_obj - anp.sum(f / (1 + g[:, None]) * (1 + anp.sin(3 * anp.pi * f)), axis=1)

        out["F"] = anp.column_stack([f, (1 + g) * h]) 
开发者ID:msu-coinlab,项目名称:pymoo,代码行数:12,代码来源:dtlz.py

示例14: __init__

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import pi [as 别名]
def __init__(self, n_var=2, a=20, b=1/5, c=2 * anp.pi):
        super().__init__(n_var=n_var, n_obj=1, n_constr=0, xl=-32.768, xu=+32.768, type_var=anp.double)
        self.a = a
        self.b = b
        self.c = c 
开发者ID:msu-coinlab,项目名称:pymoo,代码行数:7,代码来源:ackley.py

示例15: _evaluate

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import pi [as 别名]
def _evaluate(self, x, out, *args, **kwargs):
        z = anp.power(x, 2) - self.A * anp.cos(2 * anp.pi * x)
        out["F"] = self.A * self.n_var + anp.sum(z, axis=1) 
开发者ID:msu-coinlab,项目名称:pymoo,代码行数:5,代码来源:rastrigin.py


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