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


Python numpy.square方法代码示例

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


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

示例1: _evaluate

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import square [as 别名]
def _evaluate(self, x, out, *args, **kwargs):

        # variable names for convenient access
        x1 = x[:, 0]
        x2 = x[:, 1]
        y = x[:, 2]

        # first objectives
        f1 = x1 * anp.sqrt(16 + anp.square(y)) + x2 * anp.sqrt((1 + anp.square(y)))

        # measure which are needed for the second objective
        sigma_ac = 20 * anp.sqrt(16 + anp.square(y)) / (y * x1)
        sigma_bc = 80 * anp.sqrt(1 + anp.square(y)) / (y * x2)

        # take the max
        f2 = anp.max(anp.column_stack((sigma_ac, sigma_bc)), axis=1)

        # define a constraint
        g1 = f2 - self.Smax

        out["F"] = anp.column_stack([f1, f2])
        out["G"] = g1 
开发者ID:msu-coinlab,项目名称:pymoo,代码行数:24,代码来源:truss2d.py

示例2: init_kaf_nn

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import square [as 别名]
def init_kaf_nn(layer_sizes, scale=0.01, rs=np.random.RandomState(0), dict_size=20, boundary=3.0):
    """ 
    Initialize the parameters of a KAF feedforward network.
        - dict_size: the size of the dictionary for every neuron.
        - boundary: the boundary for the activation functions.
    """
    
    # Initialize the dictionary
    D = np.linspace(-boundary, boundary, dict_size).reshape(-1, 1)
    
    # Rule of thumb for gamma
    interval = D[1,0] - D[0,0];
    gamma = 0.5/np.square(2*interval)
    D = D.reshape(1, 1, -1)
    
    # Initialize a list of parameters for the layer
    w = [(rs.randn(insize, outsize) * scale,                # Weight matrix
                     rs.randn(outsize) * scale,             # Bias vector
                     rs.randn(1, outsize, dict_size) * 0.5) # Mixing coefficients
                     for insize, outsize in zip(layer_sizes[:-1], layer_sizes[1:])]
    
    return w, (D, gamma) 
开发者ID:ispamm,项目名称:kernel-activation-functions,代码行数:24,代码来源:kafnets.py

示例3: area_wetted

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import square [as 别名]
def area_wetted(self):
        # Returns the wetted area of a wing.
        area = 0
        for i in range(len(self.xsecs) - 1):
            chord_eff = (self.xsecs[i].chord
                         + self.xsecs[i + 1].chord) / 2
            this_xyz_te = self.xsecs[i].xyz_te()
            that_xyz_te = self.xsecs[i + 1].xyz_te()
            span_le_eff = np.sqrt(
                np.square(self.xsecs[i].xyz_le[1] - self.xsecs[i + 1].xyz_le[1]) +
                np.square(self.xsecs[i].xyz_le[2] - self.xsecs[i + 1].xyz_le[2])
            )
            span_te_eff = np.sqrt(
                np.square(this_xyz_te[1] - that_xyz_te[1]) +
                np.square(this_xyz_te[2] - that_xyz_te[2])
            )
            span_eff = (span_le_eff + span_te_eff) / 2
            area += chord_eff * span_eff
        if self.symmetric:
            area *= 2
        return area 
开发者ID:peterdsharpe,项目名称:AeroSandbox,代码行数:23,代码来源:geometry.py

示例4: central

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import square [as 别名]
def central(f0, ds, w):
  """Apply central difference method to estimate derivatives."""
  f = lambda o: shift(f0, o)
  eye = np.eye(f0.ndim, dtype=int)
  offsets = [-eye[d] for d in ds]

  if not ds:
    return f0
  elif len(ds) == 1:  # First order derivatives.
    i = offsets[0]
    return (f(i) - f(-i)) / (2 * w)
  elif len(ds) == 2:  # Second order derivatives.
    i, j = offsets
    w2 = np.square(w)
    if ds[0] == ds[1]:  # d^2/dxdx
      return (f(i) - 2 * f0 + f(-i)) / w2
    else:  # d^2/dxdy
      return (f(i + j) - f(i - j) - f(j - i) + f(-i - j)) / (4 * w2)
  else:
    raise NotImplementedError(ds) 
开发者ID:google,项目名称:tf-quant-finance,代码行数:22,代码来源:methods.py

示例5: _evaluate

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

示例6: _evaluate

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import square [as 别名]
def _evaluate(self, x, out, *args, **kwargs):
        l = []
        for i in range(2):
            l.append(-10 * anp.exp(-0.2 * anp.sqrt(anp.square(x[:, i]) + anp.square(x[:, i + 1]))))
        f1 = anp.sum(anp.column_stack(l), axis=1)

        f2 = anp.sum(anp.power(anp.abs(x), 0.8) + 5 * anp.sin(anp.power(x, 3)), axis=1)

        out["F"] = anp.column_stack([f1, f2]) 
开发者ID:msu-coinlab,项目名称:pymoo,代码行数:11,代码来源:kursawe.py

示例7: _evaluate

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import square [as 别名]
def _evaluate(self, x, out, *args, **kwargs):
        f1 = x[:, 0]
        f2 = x[:, 1]
        g1 = -(anp.square(x[:, 0]) + anp.square(x[:, 1]) - 1.0 - 0.1 * anp.cos(16.0 * anp.arctan(x[:, 0] / x[:, 1])))
        g2 = 2 * (anp.square(x[:, 0] - 0.5) + anp.square(x[:, 1] - 0.5)) - 1

        out["F"] = anp.column_stack([f1, f2])
        out["G"] = anp.column_stack([g1, g2]) 
开发者ID:msu-coinlab,项目名称:pymoo,代码行数:10,代码来源:tnk.py

示例8: gauss_kernel

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import square [as 别名]
def gauss_kernel(X, D, gamma=1.0):
    """
    Compute the 1D Gaussian kernel between all elements of a 
    NxH matrix and a fixed L-dimensional dictionary, resulting in a NxHxL matrix of kernel
    values.
    """
    return np.exp(- gamma*np.square(X.reshape(-1, X.shape[1], 1) - D)) 
开发者ID:ispamm,项目名称:kernel-activation-functions,代码行数:9,代码来源:kafnets.py

示例9: rosenbrock

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import square [as 别名]
def rosenbrock(x):
  """Rosenbrock function: test function for evaluating algorithms."""
  x = np.array(x)
  x_curr, x_next = x[..., :-1], x[..., 1:]
  terms = 100 * np.square(x_next - np.square(x_curr)) + np.square(1 - x_curr)
  return np.sum(terms, axis=-1) 
开发者ID:google,项目名称:tf-quant-finance,代码行数:8,代码来源:methods.py

示例10: test_square

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import square [as 别名]
def test_square():  unary_ufunc_check(np.square, test_complex=False) 
开发者ID:HIPS,项目名称:autograd,代码行数:3,代码来源:test_systematic.py

示例11: spectral_power

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import square [as 别名]
def spectral_power(ff):
    """ This function computes the spectral power as a function of fill factor
        will autograd/differentiate this with FMD (cevijacobian function)
    """

    # setup FDTD using explicit projection into permittivity
    eps_teeth_proj = projection(teeth_density, (1 - ff), sub_eps, grating_eps)
    eps_total = eps_teeth_proj + eps_base
    F = fdtd(eps_total, dl, [npml, npml, 0])

    # compute fields at each time step at the source above
    # note: we're solving the reciprocal problem of a waveguide -> free space coupler
    measured = []
    print('-> running FDTD within objective function')
    for t_index in range(steps):
        if t_index % 1000 == 0:
            print('   - done with time step {} of {} ({}%)'.format(t_index, steps, int(t_index / steps * 100)))
        fields = F.forward(Jz=source_fn(t_index))
        measured.append(npa.sum(fields['Ez'] * source))

    # get spectral power through FFT
    print('-> computing FFT')
    measured_f = my_fft(npa.array(measured))
    spect_power = npa.square(npa.abs(measured_f)) / source_p
    return spect_power

# evaluate the function at `ff` 
开发者ID:fancompute,项目名称:ceviche,代码行数:29,代码来源:forwardmode_grating_coupler.py

示例12: objective

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import square [as 别名]
def objective(eps_space):
    F.eps_r *= eps_space
    measured = []
    for t_index in range(steps):
        fields = F.forward(Jz=source(t_index))
        measured.append(npa.sum(fields['Ez'] * measure_pos))
    measured_f = my_fft(npa.array(measured))
    spectral_power = npa.square(npa.abs(measured_f))
    return spectral_power 
开发者ID:fancompute,项目名称:ceviche,代码行数:11,代码来源:autograd_fft.py

示例13: Emax

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import square [as 别名]
def Emax(Ex, Ey, eps_r):
    E_mag = npa.sqrt(npa.square(npa.abs(Ex)) + npa.square(npa.abs(Ey)))
    material_density = (eps_r - 1) / (eps_max - 1)
    return npa.max(E_mag * material_density)

# average electric field magnitude in the domain 
开发者ID:fancompute,项目名称:ceviche,代码行数:8,代码来源:optimize_accelerator.py

示例14: Eavg

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import square [as 别名]
def Eavg(Ex, Ey):
    E_mag = npa.sqrt(npa.square(npa.abs(Ex)) + npa.square(npa.abs(Ey)))
    return npa.mean(E_mag)

# defines the acceleration gradient as a function of the relative permittivity grid 
开发者ID:fancompute,项目名称:ceviche,代码行数:7,代码来源:optimize_accelerator.py

示例15: tes1t_Hz_reverse

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import square [as 别名]
def tes1t_Hz_reverse(self):

        print('\ttesting reverse-mode Hz in FDFD')

        f = fdfd_hz(self.omega, self.dL, self.eps_r, self.pml)

        def J_fdfd(eps_arr):

            eps_r = eps_arr.reshape((self.Nx, self.Ny))

            # set the permittivity
            f.eps_r = eps_r

            # set the source amplitude to the permittivity at that point
            Ex, Ey, Hz = f.solve(eps_r * self.source_hz, iterative=True)

            return npa.sum(npa.square(npa.abs(Hz))) \
                 + npa.sum(npa.square(npa.abs(Ex))) \
                 + npa.sum(npa.square(npa.abs(Ey)))

        grad_autograd_rev = jacobian(J_fdfd, mode='reverse')(self.eps_arr)
        grad_numerical = jacobian(J_fdfd, mode='numerical')(self.eps_arr)

        if VERBOSE:
            print('\tobjective function value: ', J_fdfd(self.eps_arr))
            print('\tgrad (auto):  \n\t\t', grad_autograd_rev)
            print('\tgrad (num):   \n\t\t\n', grad_numerical)

        self.check_gradient_error(grad_numerical, grad_autograd_rev) 
开发者ID:fancompute,项目名称:ceviche,代码行数:31,代码来源:test_gradients_fdfd_complex.py


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