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


Python numpy.linspace方法代码示例

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


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

示例1: _calc_pareto_front

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import linspace [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

示例2: init_kaf_nn

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import linspace [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: _build_errors_df

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import linspace [as 别名]
def _build_errors_df(name_errors, label):
  """Helper to build errors DataFrame."""
  series = []
  percentiles = np.linspace(0, 100, 21)
  index = percentiles / 100
  for name, errors in name_errors:
    series.append(pd.Series(
        np.nanpercentile(errors, q=percentiles), index=index, name=name))
  df = pd.concat(series, axis=1)
  df.columns.name = 'derivative'
  df.index.name = 'quantile'
  df = df.stack().rename('error').reset_index()
  with np.errstate(divide='ignore'):
    df['log(error)'] = np.log(df['error'])
  if label is not None:
    df['label'] = label
  return df 
开发者ID:google,项目名称:tf-quant-finance,代码行数:19,代码来源:methods.py

示例4: callback

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import linspace [as 别名]
def callback(params):
        print("Log marginal likelihood {}".format(log_marginal_likelihood(params)))

        # Show posterior marginals.
        plot_xs = np.reshape(np.linspace(-5, 5, 300), (300,1))
        pred_mean, pred_cov = combined_predict_fun(params, X, y, plot_xs)
        plot_gp(ax_end_to_end, X, y, pred_mean, pred_cov, plot_xs)
        ax_end_to_end.set_title("X to y")

        layer1_params, layer2_params, hiddens = unpack_all_params(params)
        h_star_mean, h_star_cov = predict_layer_funcs[0](layer1_params, X, hiddens, plot_xs)
        y_star_mean, y_star_cov = predict_layer_funcs[0](layer2_params, np.atleast_2d(hiddens).T, y, plot_xs)

        plot_gp(ax_x_to_h, X, hiddens,                  h_star_mean, h_star_cov, plot_xs)
        ax_x_to_h.set_title("X to hiddens")

        plot_gp(ax_h_to_y, np.atleast_2d(hiddens).T, y, y_star_mean, y_star_cov, plot_xs)
        ax_h_to_y.set_title("hiddens to y")

        plt.draw()
        plt.pause(1.0/60.0)

    # Initialize covariance parameters and hiddens. 
开发者ID:HIPS,项目名称:autograd,代码行数:25,代码来源:deep_gaussian_process.py

示例5: callback

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import linspace [as 别名]
def callback(params, t, g):
        print("Iteration {} lower bound {}".format(t, -objective(params, t)))

        # Sample functions from posterior.
        rs = npr.RandomState(0)
        mean, log_std = unpack_params(params)
        #rs = npr.RandomState(0)
        sample_weights = rs.randn(10, num_weights) * np.exp(log_std) + mean
        plot_inputs = np.linspace(-8, 8, num=400)
        outputs = predictions(sample_weights, np.expand_dims(plot_inputs, 1))

        # Plot data and functions.
        plt.cla()
        ax.plot(inputs.ravel(), targets.ravel(), 'bx')
        ax.plot(plot_inputs, outputs[:, :, 0].T)
        ax.set_ylim([-2, 3])
        plt.draw()
        plt.pause(1.0/60.0)

    # Initialize variational parameters 
开发者ID:HIPS,项目名称:autograd,代码行数:22,代码来源:bayesian_neural_net.py

示例6: create_pf

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import linspace [as 别名]
def create_pf():
    ps = np.linspace(-1/np.sqrt(2),1/np.sqrt(2))
    pf = []
    
    for x1 in ps:
        #generate solutions on the Pareto front:
        x = np.array([x1,x1])
        
        f, f_dx = concave_fun_eval(x)
        pf.append(f)
            
    pf = np.array(pf)
    
    return pf




### optimization method ### 
开发者ID:Xi-L,项目名称:ParetoMTL,代码行数:21,代码来源:run_synthetic_example.py

示例7: curve

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import linspace [as 别名]
def curve(problem, n_points=200):
    X = anp.linspace(problem.xl[0], problem.xu[0], n_points)[:, None]
    F = problem.evaluate(X)
    return anp.column_stack([X, F]) 
开发者ID:msu-coinlab,项目名称:pymoo,代码行数:6,代码来源:multimodal.py

示例8: _calc_pareto_front

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import linspace [as 别名]
def _calc_pareto_front(self, n_points=100):
        x1 = anp.linspace(0, 5, n_points)
        x2 = anp.linspace(0, 5, n_points)
        x2[x1 >= 3] = 3

        X = anp.column_stack([x1, x2])
        return self.evaluate(X, return_values_of=["F"]) 
开发者ID:msu-coinlab,项目名称:pymoo,代码行数:9,代码来源:bnh.py

示例9: cosspace

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import linspace [as 别名]
def cosspace(min=0, max=1, n_points=50):
    mean = (max + min) / 2
    amp = (max - min) / 2

    return mean + amp * np.cos(np.linspace(np.pi, 0, n_points)) 
开发者ID:peterdsharpe,项目名称:AeroSandbox,代码行数:7,代码来源:geometry.py

示例10: linspace_3D

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import linspace [as 别名]
def linspace_3D(start, stop, n_points):
    # Given two points (a start and an end), returns an interpolated array of points on the line between the two.
    # Inputs:
    #   * start: 3D coordinates expressed as a 1D numpy array, shape==(3).
    #   * end: 3D coordinates expressed as a 1D numpy array, shape==(3).
    #   * n_points: Number of points to be interpolated (including endpoints), a scalar.
    # Outputs:
    #   * points: Array of 3D coordinates expressed as a 2D numpy array, shape==(N, 3)
    x = np.linspace(start[0], stop[0], n_points)
    y = np.linspace(start[1], stop[1], n_points)
    z = np.linspace(start[2], stop[2], n_points)

    points = np.column_stack((x, y, z))
    return points 
开发者ID:peterdsharpe,项目名称:AeroSandbox,代码行数:16,代码来源:geometry.py

示例11: grid

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import linspace [as 别名]
def grid(num, ndim, large=False):
  """Build a uniform grid with num points along each of ndim axes."""
  if not large:
    _check_not_too_large(np.power(num, ndim) * ndim)
  x = np.linspace(0, 1, num, dtype='float64')
  w = 1 / (num - 1)
  points = np.stack(
      np.meshgrid(*[x for _ in range(ndim)], indexing='ij'), axis=-1)
  return points, w 
开发者ID:google,项目名称:tf-quant-finance,代码行数:11,代码来源:methods.py

示例12: color_scatter

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import linspace [as 别名]
def color_scatter(ax, xs, ys):
    colors = cm.rainbow(np.linspace(0, 1, len(ys)))
    for x, y, c in zip(xs, ys, colors):
        ax.scatter(x, y, color=c) 
开发者ID:HIPS,项目名称:autograd,代码行数:6,代码来源:ica.py

示例13: build_toy_dataset

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import linspace [as 别名]
def build_toy_dataset(D=1, n_data=20, noise_std=0.1):
    rs = npr.RandomState(0)
    inputs  = np.concatenate([np.linspace(0, 3, num=n_data/2),
                              np.linspace(6, 8, num=n_data/2)])
    targets = (np.cos(inputs) + rs.randn(n_data) * noise_std) / 2.0
    inputs = (inputs - 4.0) / 2.0
    inputs  = inputs.reshape((len(inputs), D))
    return inputs, targets 
开发者ID:HIPS,项目名称:autograd,代码行数:10,代码来源:gaussian_process.py

示例14: callback

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import linspace [as 别名]
def callback(params):
        print("Log likelihood {}".format(-objective(params)))
        plt.cla()

        # Show posterior marginals.
        plot_xs = np.reshape(np.linspace(-7, 7, 300), (300,1))
        pred_mean, pred_cov = predict(params, X, y, plot_xs)
        marg_std = np.sqrt(np.diag(pred_cov))
        ax.plot(plot_xs, pred_mean, 'b')
        ax.fill(np.concatenate([plot_xs, plot_xs[::-1]]),
                np.concatenate([pred_mean - 1.96 * marg_std,
                               (pred_mean + 1.96 * marg_std)[::-1]]),
                alpha=.15, fc='Blue', ec='None')

        # Show samples from posterior.
        rs = npr.RandomState(0)
        sampled_funcs = rs.multivariate_normal(pred_mean, pred_cov, size=10)
        ax.plot(plot_xs, sampled_funcs.T)

        ax.plot(X, y, 'kx')
        ax.set_ylim([-1.5, 1.5])
        ax.set_xticks([])
        ax.set_yticks([])
        plt.draw()
        plt.pause(1.0/60.0)

    # Initialize covariance parameters 
开发者ID:HIPS,项目名称:autograd,代码行数:29,代码来源:gaussian_process.py

示例15: plot_ellipse

# 需要导入模块: from autograd import numpy [as 别名]
# 或者: from autograd.numpy import linspace [as 别名]
def plot_ellipse(ax, mean, cov_sqrt, alpha, num_points=100):
    angles = np.linspace(0, 2*np.pi, num_points)
    circle_pts = np.vstack([np.cos(angles), np.sin(angles)]).T * 2.0
    cur_pts = mean + np.dot(circle_pts, cov_sqrt)
    ax.plot(cur_pts[:, 0], cur_pts[:, 1], '-', alpha=alpha) 
开发者ID:HIPS,项目名称:autograd,代码行数:7,代码来源:gmm.py


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