本文整理汇总了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
示例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)
示例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
示例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.
示例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
示例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 ###
示例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])
示例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"])
示例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))
示例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
示例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
示例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)
示例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
示例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
示例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)