本文整理汇总了Python中minpy.numpy.zeros函数的典型用法代码示例。如果您正苦于以下问题:Python zeros函数的具体用法?Python zeros怎么用?Python zeros使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zeros函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: main
def main(args):
# Create model.
model = RNNNet(args)
for k, v in model.param_configs.items():
model.params[k] = np.zeros(v['shape'])
data = np.zeros((args.batch_size, args.input_size)) # Data of only one time step.
label = np.zeros((args.batch_size,), dtype=np.int)
for l in range(args.num_loops):
if l == num_cold:
start = time.time()
def loss_func(*params):
f = model.forward(data, 'train')
return model.loss(f, label)
if args.only_forward:
loss = loss_func()
loss.asnumpy()
else:
param_arrays = list(model.params.values())
param_keys = list(model.params.keys())
grad_and_loss_func = core.grad_and_loss(
loss_func, argnum=range(len(param_arrays)))
grad_arrays, loss = grad_and_loss_func(*param_arrays)
dur = time.time() - start
print('Per Loop Time: %.6f' % (dur / (args.num_loops - num_cold)))开发者ID:HrWangChengdu,项目名称:minpy,代码行数:26,代码来源:rnn_minpy_cpu.py
示例2: lstm_temporal
def lstm_temporal(x, h0, Wx, Wh, b):
"""
Forward pass for an LSTM over an entire sequence of data. We assume an input
sequence composed of T vectors, each of dimension D. The LSTM uses a hidden
size of H, and we work over a minibatch containing N sequences. After running
the LSTM forward, we return the hidden states for all timesteps.
Note that the initial cell state is passed as input, but the initial cell
state is set to zero. Also note that the cell state is not returned; it is
an internal variable to the LSTM and is not accessed from outside.
Inputs:
- x: Input data of shape (N, T, D)
- h0: Initial hidden state of shape (N, H)
- Wx: Weights for input-to-hidden connections, of shape (D, 4H)
- Wh: Weights for hidden-to-hidden connections, of shape (H, 4H)
- b: Biases of shape (4H,)
Returns a tuple of:
- h: Hidden states for all timesteps of all sequences, of shape (N, T, H)
"""
N, T, D = x.shape
_, H = h0.shape
c = np.zeros([N, 0, H])
h = np.zeros([N, 0, H])
for t in xrange(T):
h_step, c_step = lstm_step(
x[:, t, :], h[:, t-1, :] if t > 0 else h0, c[:, t-1, :] if t > 0 else np.zeros((N, H)), Wx, Wh, b)
h_step = h_step.reshape(N, 1, H)
c_step = c_step.reshape(N, 1, H)
h = np.append(h, h_step, axis=1)
c = np.append(c, c_step, axis=1)
return h开发者ID:ZihengJiang,项目名称:minpy,代码行数:33,代码来源:layers.py
示例3: __init__
def __init__(self,
input_dim=3 * 32 * 32,
hidden_dim=100,
num_classes=10,
weight_scale=1e-3,
reg=0.0,
conv_mode='lazy',
dtype=py_np.float64):
"""
Initialize a new network.
Inputs:
- input_dim: An integer giving the size of the input
- hidden_dim: An integer giving the size of the hidden layer
- num_classes: An integer giving the number of classes to classify
- dropout: Scalar between 0 and 1 giving dropout strength.
- weight_scale: Scalar giving the standard deviation for random
initialization of the weights.
- reg: Scalar giving L2 regularization strength.
"""
super(TwoLayerNet, self).__init__(conv_mode)
self.params = {}
self.reg = reg
self.params['W1'] = random.randn(input_dim, hidden_dim) * weight_scale
self.params['b1'] = np.zeros((hidden_dim))
self.params['W2'] = random.randn(hidden_dim, num_classes) * weight_scale
self.params['b2'] = np.zeros((num_classes))开发者ID:colinsongf,项目名称:minpy,代码行数:28,代码来源:fc_net_minpy.py
示例4: main
def main(args):
# Create model.
model = TwoLayerNet(args)
for k, v in model.param_configs.items():
model.params[k] = np.zeros(v['shape'])
img = np.zeros((args.batch_size, 784))
label = np.zeros((args.batch_size,))
start = time.time()
for l in range(num_loops):
def loss_func(*params):
f = model.forward(img, 'train')
return model.loss(f, label)
if args.only_forward:
loss_func()
loss.asnumpy()
else:
param_arrays = list(model.params.values())
param_keys = list(model.params.keys())
grad_and_loss_func = minpy.core.grad_and_loss(
loss_func, argnum=range(len(param_arrays)))
grad_arrays, loss = grad_and_loss_func(*param_arrays)
for g in grad_arrays:
g.get_data(minpy.array_variants.ArrayType.MXNET).wait_to_read()
dur = time.time() - start
print('Per Loop Time: %.6f' % (dur / num_loops))开发者ID:ZihengJiang,项目名称:minpy,代码行数:27,代码来源:mlp_minpy_gpu.py
示例5: gaussian_cluster_generator
def gaussian_cluster_generator(num_samples=10000, num_features=500, num_classes=5):
mu = np.random.rand(num_classes, num_features)
sigma = np.ones((num_classes, num_features)) * 0.1
num_cls_samples = int(num_samples / num_classes)
x = np.zeros((num_samples, num_features))
y = np.zeros((num_samples, num_classes))
for i in range(num_classes):
cls_samples = np.random.normal(mu[i,:], sigma[i,:], (num_cls_samples, num_features))
x[i*num_cls_samples:(i+1)*num_cls_samples] = cls_samples
y[i*num_cls_samples:(i+1)*num_cls_samples,i] = 1
return x, y开发者ID:lryta,项目名称:minpy,代码行数:11,代码来源:test_policy.py
示例6: forward
def forward(self, X, mode):
seq_len = X.shape[1]
batch_size = X.shape[0]
hidden_size = self.params['Wh'].shape[0]
h = np.zeros((batch_size, hidden_size))
c = np.zeros((batch_size, hidden_size))
for t in xrange(seq_len):
h, c = layers.lstm_step(X[:, t, :], h, c, self.params['Wx'], self.params['Wh'],
self.params['b'])
y = layers.affine(h, self.params['Wa'], self.params['ba'])
return y开发者ID:lryta,项目名称:minpy,代码行数:11,代码来源:lstm.py
示例7: softmax_cross_entropy
def softmax_cross_entropy(prob, label):
"""
Computes the cross entropy for softmax activation.
Inputs:
- prob: Probability, of shape (N, C) where x[i, j] is the probability for the jth class
for the ith input.
- label: Either of the followings:
- One hot encoding of labels, of shape (N, C)
- Label index of shape (N, ), each y[i] is the label of i^th example
(0 |