本文整理汇总了Python中pylearn2.space.VectorSpace类的典型用法代码示例。如果您正苦于以下问题:Python VectorSpace类的具体用法?Python VectorSpace怎么用?Python VectorSpace使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VectorSpace类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_np_format_as_vector2conv2D
def test_np_format_as_vector2conv2D():
vector_space = VectorSpace(dim=8*8*3, sparse=False)
conv2d_space = Conv2DSpace(shape=(8,8), num_channels=3,
axes=('b','c',0,1))
data = np.arange(5*8*8*3).reshape(5, 8*8*3)
rval = vector_space.np_format_as(data, conv2d_space)
assert np.all(rval == data.reshape((5,3,8,8)))
开发者ID:Alienfeel,项目名称:pylearn2,代码行数:7,代码来源:test_space.py
示例2: test_vector_to_conv_c01b_invertible
def test_vector_to_conv_c01b_invertible():
"""
Tests that the format_as methods between Conv2DSpace
and VectorSpace are invertible for the ('c', 0, 1, 'b')
axis format.
"""
rng = np.random.RandomState([2013, 5, 1])
batch_size = 3
rows = 4
cols = 5
channels = 2
conv = Conv2DSpace([rows, cols], channels = channels, axes = ('c', 0, 1, 'b'))
vec = VectorSpace(conv.get_total_dimension())
X = conv.make_batch_theano()
Y = conv.format_as(X, vec)
Z = vec.format_as(Y, conv)
A = vec.make_batch_theano()
B = vec.format_as(A, conv)
C = conv.format_as(B, vec)
f = function([X, A], [Z, C])
X = rng.randn(*(conv.get_origin_batch(batch_size).shape)).astype(X.dtype)
A = rng.randn(*(vec.get_origin_batch(batch_size).shape)).astype(A.dtype)
Z, C = f(X,A)
np.testing.assert_allclose(Z, X)
np.testing.assert_allclose(C, A)
开发者ID:Alienfeel,项目名称:pylearn2,代码行数:35,代码来源:test_space.py
示例3: inv_prop
def inv_prop(self, state_above):
if not isinstance(state_above, tuple):
expected_space = VectorSpace(self.output_space.get_total_dimension())
state_above = expected_space.format_as(state_above, self.output_space)
self.output_space.validate(state_above)
return tuple(layer.inv_prop(state) for layer,state in safe_zip(self.layers, state_above))
开发者ID:mdenil,项目名称:parameter_prediction,代码行数:7,代码来源:mlp.py
示例4: __init__
def __init__(self, nvis, nhid, hidden_transition_model, irange=0.05,
non_linearity='sigmoid', use_ground_truth=True):
allowed_non_linearities = {'sigmoid': T.nnet.sigmoid,
'tanh': T.tanh}
self.nvis = nvis
self.nhid = nhid
self.hidden_transition_model = hidden_transition_model
self.use_ground_truth = use_ground_truth
self.alpha = sharedX(1)
self.alpha_decrease_rate = 0.999
assert non_linearity in allowed_non_linearities
self.non_linearity = allowed_non_linearities[non_linearity]
# Space initialization
self.input_space = VectorSpace(dim=self.nvis)
self.hidden_space = VectorSpace(dim=self.nhid)
self.output_space = VectorSpace(dim=1)
self.input_source = 'features'
self.target_source = 'targets'
# Features-to-hidden matrix
W_value = numpy.random.uniform(low=-irange, high=irange,
size=(self.nvis, self.nhid))
self.W = sharedX(W_value, name='W')
# Hidden biases
b_value = numpy.zeros(self.nhid)
self.b = sharedX(b_value, name='b')
# Hidden-to-out matrix
U_value = numpy.random.uniform(low=-irange, high=irange,
size=(self.nhid, 1))
self.U = sharedX(U_value, name='U')
# Output bias
c_value = numpy.zeros(1)
self.c = sharedX(c_value, name='c')
开发者ID:amoliu,项目名称:research,代码行数:35,代码来源:rnn.py
示例5: simulate
def simulate(inputs, model):
space = VectorSpace(inputs.shape[1])
X = space.get_theano_batch()
Y = model.fprop(space.format_as(X, model.get_input_space()))
f = theano.function([X], Y)
result = []
for x in xrange(0, len(inputs), 100):
result.extend(f(inputs[x:x + 100]))
return result
开发者ID:dsanno,项目名称:pylearn2_mnist,代码行数:9,代码来源:test_result.py
示例6: test_np_format_as_conv2d_vector_conv2d
def test_np_format_as_conv2d_vector_conv2d():
conv2d_space1 = Conv2DSpace(shape=(8, 8), num_channels=3,
axes=('c', 'b', 1, 0))
vector_space = VectorSpace(dim=8*8*3, sparse=False)
conv2d_space0 = Conv2DSpace(shape=(8, 8), num_channels=3,
axes=('b', 'c', 0, 1))
data = np.arange(5*8*8*3).reshape(5, 3, 8, 8)
vecval = conv2d_space0.np_format_as(data, vector_space)
rval1 = vector_space.np_format_as(vecval, conv2d_space1)
rval2 = conv2d_space0.np_format_as(data, conv2d_space1)
assert np.allclose(rval1, rval2)
nval = data.transpose(1, 0, 3, 2)
assert np.allclose(nval, rval1)
开发者ID:AlexArgus,项目名称:pylearn2,代码行数:15,代码来源:test_space.py
示例7: test_np_format_as_vector2conv2D
def test_np_format_as_vector2conv2D():
vector_space = VectorSpace(dim=8*8*3, sparse=False)
conv2d_space = Conv2DSpace(shape=(8, 8), num_channels=3,
axes=('b', 'c', 0, 1))
data = np.arange(5*8*8*3).reshape(5, 8*8*3)
rval = vector_space.np_format_as(data, conv2d_space)
# Get data in a Conv2DSpace with default axes
new_axes = conv2d_space.default_axes
axis_to_shape = {'b': 5, 'c': 3, 0: 8, 1: 8}
new_shape = tuple([axis_to_shape[ax] for ax in new_axes])
nval = data.reshape(new_shape)
# Then transpose
nval = nval.transpose(*[new_axes.index(ax) for ax in conv2d_space.axes])
assert np.all(rval == nval)
开发者ID:alouisos,项目名称:pylearn2,代码行数:15,代码来源:test_space.py
示例8: __init__
def __init__(self,
nvis,
bias_from_marginals = None):
"""
nvis: the dimension of the space
bias_from_marginals: a dataset, whose marginals are used to
initialize the visible biases
"""
self.__dict__.update(locals())
del self.self
# Don't serialize the dataset
del self.bias_from_marginals
self.space = VectorSpace(nvis)
self.input_space = self.space
origin = self.space.get_origin()
if bias_from_marginals is None:
init_bias = np.zeros((nvis,))
else:
# data is in [-1, 1], but want biases for a sigmoid
init_bias = init_sigmoid_bias_from_array(bias_from_marginals.X / 2. + 0.5)
# init_bias =
self.boltzmann_bias = sharedX(init_bias, 'visible_bias')
开发者ID:Alienfeel,项目名称:pylearn2,代码行数:26,代码来源:ising.py
示例9: set_input_space
def set_input_space(self, space):
self.input_space = space
if not isinstance(space, Space):
raise TypeError("Expected Space, got "+
str(space)+" of type "+str(type(space)))
self.input_dim = space.get_total_dimension()
self.needs_reformat = not isinstance(space, VectorSpace)
desired_dim = self.input_dim
self.desired_space = VectorSpace(desired_dim)
if not self.needs_reformat:
assert self.desired_space == self.input_space
rng = self.mlp.rng
self._params = []
V = np.zeros((self.n_classes, self.input_dim),dtype=np.float32)
self.V = sharedX(V, self.layer_name + "_V" )
U = np.identity( self.input_dim)
self.U = sharedX(U, self.layer_name + "_U")
Q = np.zeros((self.input_dim, self.input_dim),dtype=np.float32)
self.Q = sharedX(Q, self.layer_name + "_Q")
Ui = np.identity(self.input_dim,dtype=np.float32)
self.Ui = sharedX(Ui, self.layer_name + "_Ui")
self._params = [ self.U, self.Ui, self.V, self.Q]
开发者ID:tomsbergmanis,项目名称:pylearn2speech,代码行数:32,代码来源:factorized_layers.py
示例10: __init__
def __init__(self,
nvis,
bias_from_marginals = None):
"""
nvis: the dimension of the space
bias_from_marginals: a dataset, whose marginals are used to
initialize the visible biases
"""
self.__dict__.update(locals())
del self.self
# Don't serialize the dataset
del self.bias_from_marginals
self.space = VectorSpace(nvis)
self.input_space = self.space
origin = self.space.get_origin()
if bias_from_marginals is None:
init_bias = np.zeros((nvis,))
else:
X = bias_from_marginals.get_design_matrix()
assert X.max() == 1.
assert X.min() == 0.
assert not np.any( (X > 0.) * (X < 1.) )
mean = X.mean(axis=0)
mean = np.clip(mean, 1e-7, 1-1e-7)
init_bias = inverse_sigmoid_numpy(mean)
self.bias = sharedX(init_bias, 'visible_bias')
开发者ID:deigen,项目名称:pylearn,代码行数:34,代码来源:dbm.py
示例11: set_input_space
def set_input_space(self, space):
self.input_space = space
if not isinstance(space, Space):
raise TypeError("Expected Space, got "+
str(space)+" of type "+str(type(space)))
self.input_dim = space.get_total_dimension()
self.needs_reformat = not isinstance(space, VectorSpace)
self.desired_space = VectorSpace(self.input_dim)
if not self.needs_reformat:
assert self.desired_space == self.input_space
rng = self.dbm.rng
if self.irange is not None:
assert self.sparse_init is None
W = rng.uniform(-self.irange,self.irange, (self.input_dim,self.n_classes))
else:
assert self.sparse_init is not None
W = np.zeros((self.input_dim, self.n_classes))
for i in xrange(self.n_classes):
for j in xrange(self.sparse_init):
idx = rng.randint(0, self.input_dim)
while W[idx, i] != 0.:
idx = rng.randint(0, self.input_dim)
W[idx, i] = rng.randn()
self.W = sharedX(W, 'softmax_W' )
self._params = [ self.b, self.W ]
开发者ID:deigen,项目名称:pylearn,代码行数:33,代码来源:dbm.py
示例12: set_input_space
def set_input_space(self, space):
self.input_space = space
if not isinstance(space, Space):
raise TypeError("Expected Space, got "+
str(space)+" of type "+str(type(space)))
self.input_dim = space.get_total_dimension()
self.needs_reformat = not isinstance(space, VectorSpace)
if self.no_affine:
desired_dim = self.n_classes
assert self.input_dim == desired_dim
else:
desired_dim = self.input_dim
self.desired_space = VectorSpace(desired_dim)
if not self.needs_reformat:
assert self.desired_space == self.input_space
rng = self.mlp.rng
if self.irange is not None:
assert self.istdev is None
assert self.sparse_init is None
W = rng.uniform(-self.irange,self.irange, (self.input_dim,self.n_groups,self.n_classes))
elif self.istdev is not None:
assert self.sparse_init is None
W = rng.randn(self.input_dim,self.n_groups,self.n_classes) * self.istdev
else:
raise NotImplementedError()
self.W = sharedX(W, 'softmax_W' )
self._params = [ self.b, self.W ]
开发者ID:nicholas-leonard,项目名称:hps,代码行数:35,代码来源:test1.py
示例13: set_input_space
def set_input_space(self, space):
""" Note: this resets parameters! """
self.input_space = space
if isinstance(space, VectorSpace):
self.requires_reformat = False
self.input_dim = space.dim
else:
self.requires_reformat = True
self.input_dim = space.get_total_dimension()
self.desired_space = VectorSpace(self.input_dim)
self.output_space = VectorSpace(self.dim)
rng = self.dbm.rng
if self.irange is not None:
assert self.sparse_init is None
W = rng.uniform(-self.irange,
self.irange,
(self.input_dim, self.dim)) * \
(rng.uniform(0.,1., (self.input_dim, self.dim))
< self.include_prob)
else:
assert self.sparse_init is not None
W = np.zeros((self.input_dim, self.dim))
W *= self.sparse_stdev
W = sharedX(W)
W.name = self.layer_name + '_W'
self.transformer = MatrixMul(W)
W ,= self.transformer.get_params()
assert W.name is not None
开发者ID:Alienfeel,项目名称:pylearn2,代码行数:35,代码来源:ising.py
示例14: __init__
def __init__(self, shape, axes=None):
"""
The arguments describe how the data is laid out in the design matrix.
Parameters
----------
shape : tuple
A tuple of 4 ints, describing the shape of each datum.
This is the size of each axis in <axes>, excluding the 'b' axis.
axes : tuple
A tuple of the following elements in any order:
'b' batch axis
's' stereo axis
0 image axis 0 (row)
1 image axis 1 (column)
'c' channel axis
"""
shape = tuple(shape)
if not all(isinstance(s, int) for s in shape):
raise TypeError("Shape must be a tuple/list of ints")
if len(shape) != 4:
raise ValueError("Shape array needs to be of length 4, got %s." %
shape)
datum_axes = list(axes)
datum_axes.remove('b')
if shape[datum_axes.index('s')] != 2:
raise ValueError("Expected 's' axis to have size 2, got %d.\n"
" axes: %s\n"
" shape: %s" %
(shape[datum_axes.index('s')],
axes,
shape))
self.shape = shape
self.set_axes(axes)
def make_conv2d_space(shape, axes):
shape_axes = list(axes)
shape_axes.remove('b')
image_shape = tuple(shape[shape_axes.index(axis)]
for axis in (0, 1))
conv2d_axes = list(axes)
conv2d_axes.remove('s')
return Conv2DSpace(shape=image_shape,
num_channels=shape[shape_axes.index('c')],
axes=conv2d_axes,
dtype=None)
conv2d_space = make_conv2d_space(shape, axes)
self.topo_space = CompositeSpace((conv2d_space, conv2d_space))
self.storage_space = VectorSpace(dim=numpy.prod(shape))
开发者ID:allansp84,项目名称:pylearn2,代码行数:55,代码来源:new_norb.py
示例15: __init__
def __init__(self,
layer_name,
num_gates,
irange = 0.05,
routing_protocol = 'nearest'
):
self.__dict__.update(locals())
del self.self
self.output_space = VectorSpace(self.num_gates)
开发者ID:nicholas-leonard,项目名称:ift6085,代码行数:11,代码来源:gate.py
示例16: __init__
def __init__(self, mlp, input_condition_space, condition_distribution, noise_dim=100, *args, **kwargs):
super(ConditionalGenerator, self).__init__(mlp, *args, **kwargs)
self.noise_dim = noise_dim
self.noise_space = VectorSpace(dim=self.noise_dim)
self.condition_space = input_condition_space
self.condition_distribution = condition_distribution
self.input_space = CompositeSpace([self.noise_space, self.condition_space])
self.mlp.set_input_space(self.input_space)
开发者ID:hit-computer,项目名称:adversarial,代码行数:11,代码来源:__init__.py
示例17: get_weights_topo
def get_weights_topo(self):
"""
Returns a topological view of the weights, the first half
corresponds to wxf and the second half to wyf.
Returns
-------
weights : ndarray
Same as the return value of `get_weights` but formatted as a 4D
tensor with the axes being (hidden/factor units, rows, columns,
channels).The the number of channels is either 1 or 3
(because they will be visualized as grayscale or RGB color).
At the moment the function only supports factors whose sqrt
is exact.
"""
if not isinstance(self.input_space.components[0], Conv2DSpace) or not isinstance(
self.input_space.components[1], Conv2DSpace
):
raise NotImplementedError()
wxf = self.wxf.get_value(borrow=False).T
wyf = self.wyf.get_value(borrow=False).T
convx = self.input_space.components[0]
convy = self.input_space.components[1]
vecx = VectorSpace(self.nvisx)
vecy = VectorSpace(self.nvisy)
wxf_view = vecx.np_format_as(
wxf, Conv2DSpace(convx.shape, num_channels=convx.num_channels, axes=("b", 0, 1, "c"))
)
wyf_view = vecy.np_format_as(
wyf, Conv2DSpace(convy.shape, num_channels=convy.num_channels, axes=("b", 0, 1, "c"))
)
h = int(numpy.ceil(numpy.sqrt(self.nfac)))
new_weights = numpy.zeros(
(wxf_view.shape[0] * 2, wxf_view.shape[1], wxf_view.shape[2], wxf_view.shape[3]), dtype=wxf_view.dtype
)
t = 0
while t < (self.nfac // h):
filter_pair = numpy.concatenate((wxf_view[h * t : h * (t + 1), ...], wyf_view[h * t : h * (t + 1), ...]), 0)
new_weights[h * 2 * t : h * 2 * (t + 1), ...] = filter_pair
t += 1
return new_weights
开发者ID:CandyPythonFlow,项目名称:pylearn2,代码行数:41,代码来源:gated_autoencoder.py
示例18: set_input_space
def set_input_space(self, space):
self.input_space = space
if not isinstance(space, Space):
raise TypeError("Expected Space, got "+
str(space)+" of type "+str(type(space)))
self.input_dim = space.get_total_dimension()
self.needs_reformat = not isinstance(space, VectorSpace)
if self.no_affine:
desired_dim = self.n_classes
assert self.input_dim == desired_dim
else:
desired_dim = self.input_dim
self.desired_space = VectorSpace(desired_dim)
if not self.needs_reformat:
assert self.desired_space == self.input_space
rng = self.mlp.rng
if self.no_affine:
self._params = []
else:
if self.irange is not None:
assert self.istdev is None
assert self.sparse_init is None
W_cluster = rng.uniform(-self.irange,self.irange, (self.input_dim, self.n_clusters))
W_class = rng.uniform(-self.irange,self.irange, (self.n_clusters, self.input_dim, self.n_classes))
elif self.istdev is not None:
assert self.sparse_init is None
W_cluster = rng.randn(self.input_dim, self.n_clusters) * self.istdev
W_class = rng.randn(self.n_clusters, self.input_dim, self.n_classes) * self.istdev
else:
raise NotImplementedError()
# set the extra dummy weights to 0
for key in self.clusters_scope.keys():
#print key
#should probably be reverse
W_class[int(key), :, :self.clusters_scope[key]] = 0.
self.W_class = sharedX(W_class, 'softmax_W_class' )
self.W_cluster = sharedX(W_cluster, 'softmax_W_cluster' )
self._params = [self.b_class, self.W_class, self.b_cluster, self.W_cluster]
开发者ID:rahul003,项目名称:pylearn2,代码行数:46,代码来源:backup+with+nll.py
示例19: VectorSpaceConverter
class VectorSpaceConverter(mlp.Layer):
def __init__(self, layer_name):
self.layer_name = layer_name
self._params = []
def set_input_space(self, space):
self.input_space = space
self.output_space = VectorSpace(space.get_total_dimension())
def fprop(self, state_below):
return self.input_space.format_as(state_below, self.output_space)
def inv_prop(self, state_above):
return self.output_space.format_as(state_above, self.input_space)
def get_weight_decay(self, coeff):
return 0.0
def get_l1_weight_decay(self, coeff):
return 0.0
开发者ID:mdenil,项目名称:parameter_prediction,代码行数:20,代码来源:mlp.py
示例20: __init__
def __init__(self, shape, axes=None):
shape = tuple(shape)
if not all(isinstance(s, int) for s in shape):
raise TypeError("Shape must be a tuple/list of ints")
if len(shape) != 4:
raise ValueError("Shape array needs to be of length 4, got %s." %
shape)
datum_axes = list(axes)
datum_axes.remove('b')
if shape[datum_axes.index('s')] != 2:
raise ValueError("Expected 's' axis to have size 2, got %d.\n"
" axes: %s\n"
" shape: %s" %
(shape[datum_axes.index('s')],
axes,
shape))
self.shape = shape
self.set_axes(axes)
def make_conv2d_space(shape, axes):
shape_axes = list(axes)
shape_axes.remove('b')
image_shape = tuple(shape[shape_axes.index(axis)]
for axis in (0, 1))
conv2d_axes = list(axes)
conv2d_axes.remove('s')
return Conv2DSpace(shape=image_shape,
num_channels=shape[shape_axes.index('c')],
axes=conv2d_axes)
conv2d_space = make_conv2d_space(shape, axes)
self.topo_space = CompositeSpace((conv2d_space, conv2d_space))
self.storage_space = VectorSpace(dim=numpy.prod(shape))
开发者ID:HALLAB-Halifax,项目名称:pylearn2,代码行数:36,代码来源:norb.py
注:本文中的pylearn2.space.VectorSpace类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论