本文整理汇总了Python中theano.tensor.outer方法的典型用法代码示例。如果您正苦于以下问题:Python tensor.outer方法的具体用法?Python tensor.outer怎么用?Python tensor.outer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类theano.tensor
的用法示例。
在下文中一共展示了tensor.outer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: perform
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import outer [as 别名]
def perform(self, node, inputs, outputs):
# Kalbfleisch and Lawless, J. Am. Stat. Assoc. 80 (1985) Equation 3.4
# Kind of... You need to do some algebra from there to arrive at
# this expression.
(A, gA) = inputs
(out,) = outputs
w, V = scipy.linalg.eig(A, right=True)
U = scipy.linalg.inv(V).T
exp_w = numpy.exp(w)
X = numpy.subtract.outer(exp_w, exp_w) / numpy.subtract.outer(w, w)
numpy.fill_diagonal(X, exp_w)
Y = U.dot(V.T.dot(gA).dot(U) * X).dot(V.T)
with warnings.catch_warnings():
warnings.simplefilter("ignore", numpy.ComplexWarning)
out[0] = Y.astype(A.dtype)
示例2: compute_kernel
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import outer [as 别名]
def compute_kernel(lls, lsf, x, z):
ls = T.exp(lls)
sf = T.exp(lsf)
if x.ndim == 1:
x = x[ None, : ]
if z.ndim == 1:
z = z[ None, : ]
lsre = T.outer(T.ones_like(x[ :, 0 ]), ls)
r2 = T.outer(T.sum(x * x / lsre, 1), T.ones_like(z[ : , 0 : 1 ])) - np.float32(2) * \
T.dot(x / lsre, T.transpose(z)) + T.dot(np.float32(1.0) / lsre, T.transpose(z)**2)
k = sf * T.exp(-np.float32(0.5) * r2)
return k
示例3: compute_kernel_numpy
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import outer [as 别名]
def compute_kernel_numpy(lls, lsf, x, z):
ls = np.exp(lls)
sf = np.exp(lsf)
if x.ndim == 1:
x= x[ None, : ]
if z.ndim == 1:
z= z[ None, : ]
lsre = np.outer(np.ones(x.shape[ 0 ]), ls)
r2 = np.outer(np.sum(x * x / lsre, 1), np.ones(z.shape[ 0 ])) - 2 * np.dot(x / lsre, z.T) + np.dot(1.0 / lsre, z.T **2)
k = sf * np.exp(-0.5*r2)
return k
##
# xmean and xvar can be vectors of input points
#
# This is the expected value of the kernel
#
示例4: compute_psi1
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import outer [as 别名]
def compute_psi1(lls, lsf, xmean, xvar, z):
if xmean.ndim == 1:
xmean = xmean[ None, : ]
ls = T.exp(lls)
sf = T.exp(lsf)
lspxvar = ls + xvar
constterm1 = ls / lspxvar
constterm2 = T.prod(T.sqrt(constterm1), 1)
r2_psi1 = T.outer(T.sum(xmean * xmean / lspxvar, 1), T.ones_like(z[ : , 0 : 1 ])) \
- np.float32(2) * T.dot(xmean / lspxvar, T.transpose(z)) + \
T.dot(np.float32(1.0) / lspxvar, T.transpose(z)**2)
psi1 = sf * T.outer(constterm2, T.ones_like(z[ : , 0 : 1 ])) * T.exp(-np.float32(0.5) * r2_psi1)
return psi1
示例5: sample
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import outer [as 别名]
def sample(self, n_samples):
'''
Inspired by jbornschein's implementation.
'''
z0 = T.zeros((n_samples, self.dim,)).astype(floatX) + T.shape_padleft(self.b)
rs = self.trng.uniform((self.dim, n_samples), dtype=floatX)
def _step_sample(i, W_i, r_i, z):
p_i = T.nnet.sigmoid(z[:, i]) * 0.9999 + 0.000005
x_i = (r_i <= p_i).astype(floatX)
z = z + T.outer(x_i, W_i)
return z, x_i
seqs = [T.arange(self.dim), self.W, rs]
outputs_info = [z0, None]
non_seqs = []
(zs, x), updates = scan(_step_sample, seqs, outputs_info, non_seqs,
self.dim)
return x.T, updates
示例6: __init__
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import outer [as 别名]
def __init__(self,dataset,dictionary_size=50000,embedding_size=50,skip_window=5,learning_rate=0.1,negative_sampling=25):
self.ds = dictionary_size
self.es = embedding_size
self.sw = skip_window
self.lr = learning_rate
self.ns = negative_sampling
self._tokenize(dataset)
#nn architecture
self.input = T.matrix()
self.w1 = theano.shared((np.random.rand(self.ds,self.es).astype(theano.config.floatX)-0.5),borrow=True)
self.activeidx = T.ivector()
self.activew1 = T.take(self.w1, self.activeidx, axis=0)
self.l1out = T.dot(self.input,self.activew1)
self.w2 = theano.shared((np.random.rand(self.es,self.ds).astype(theano.config.floatX)-0.5),borrow=True)
self.sampidx = T.ivector()
self.sampw2 = T.take(self.w2, self.sampidx, axis=1)
self.l2out = T.nnet.softmax(T.dot(self.l1out,self.sampw2))
self.target = T.matrix()
#nn functions
self.z = (self.l2out - self.target).T
self.w1update = T.set_subtensor(self.w1[self.activeidx,:], self.w1[self.activeidx,:] - T.dot(self.sampw2, self.z).flatten()*self.lr)
self.w2update = T.set_subtensor(self.w2[:,self.sampidx], self.w2[:,self.sampidx] - T.outer(self.z, self.l1out).T*self.lr)
self.propogate = theano.function([self.input,self.target,self.activeidx,self.sampidx],\
updates = [(self.w1,self.w1update),(self.w2,self.w2update)],allow_input_downcast=True)
示例7: grad
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import outer [as 别名]
def grad(self, inputs, cost_grad):
"""
In defining the gradient, the Finite Fourier Transform is viewed as
a complex-differentiable function of a complex variable
"""
a = inputs[0]
n = inputs[1]
axis = inputs[2]
grad = cost_grad[0]
if not isinstance(axis, tensor.TensorConstant):
raise NotImplementedError('%s: gradient is currently implemented'
' only for axis being a Theano constant'
% self.__class__.__name__)
axis = int(axis.data)
# notice that the number of actual elements in wrto is independent of
# possible padding or truncation:
elem = tensor.arange(0, tensor.shape(a)[axis], 1)
# accounts for padding:
freq = tensor.arange(0, n, 1)
outer = tensor.outer(freq, elem)
pow_outer = tensor.exp(((-2 * math.pi * 1j) * outer) / (1. * n))
res = tensor.tensordot(grad, pow_outer, (axis, 0))
# This would be simpler but not implemented by theano:
# res = tensor.switch(tensor.lt(n, tensor.shape(a)[axis]),
# tensor.set_subtensor(res[...,n::], 0, False, False), res)
# Instead we resort to that to account for truncation:
flip_shape = list(numpy.arange(0, a.ndim)[::-1])
res = res.dimshuffle(flip_shape)
res = tensor.switch(tensor.lt(n, tensor.shape(a)[axis]),
tensor.set_subtensor(res[n::, ], 0, False, False),
res)
res = res.dimshuffle(flip_shape)
# insures that gradient shape conforms to input shape:
out_shape = list(numpy.arange(0, axis)) + [a.ndim - 1] +\
list(numpy.arange(axis, a.ndim - 1))
res = res.dimshuffle(*out_shape)
return [res, None, None]
示例8: test_outer
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import outer [as 别名]
def test_outer(self):
f = self.function([self.x, self.y], T.outer(self.x, self.y))
self.assertFunctionContains(f, self.ger_destructive)
f(numpy.random.rand(5).astype(self.dtype),
numpy.random.rand(4).astype(self.dtype))
示例9: test_A_plus_outer
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import outer [as 别名]
def test_A_plus_outer(self):
f = self.function([self.A, self.x, self.y],
self.A + T.outer(self.x, self.y))
self.assertFunctionContains(f, self.ger)
f(numpy.random.rand(5, 4).astype(self.dtype),
numpy.random.rand(5).astype(self.dtype),
numpy.random.rand(4).astype(self.dtype))
f(numpy.random.rand(5, 4).astype(self.dtype)[::-1, ::-1],
numpy.random.rand(5).astype(self.dtype),
numpy.random.rand(4).astype(self.dtype))
示例10: test_A_plus_scaled_outer
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import outer [as 别名]
def test_A_plus_scaled_outer(self):
f = self.function([self.A, self.x, self.y],
self.A + 0.1 * T.outer(self.x, self.y))
self.assertFunctionContains(f, self.ger)
f(numpy.random.rand(5, 4).astype(self.dtype),
numpy.random.rand(5).astype(self.dtype),
numpy.random.rand(4).astype(self.dtype))
f(numpy.random.rand(5, 4).astype(self.dtype)[::-1, ::-1],
numpy.random.rand(5).astype(self.dtype),
numpy.random.rand(4).astype(self.dtype))
示例11: test_scaled_A_plus_scaled_outer
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import outer [as 别名]
def test_scaled_A_plus_scaled_outer(self):
f = self.function([self.A, self.x, self.y],
numpy.asarray(0.2, self.dtype) * self.A +
numpy.asarray(0.1, self.dtype) * T.outer(
self.x, self.y))
# Why gemm? This make the graph simpler did we test that it
# make it faster?
self.assertFunctionContains(f, self.gemm)
f(numpy.random.rand(5, 4).astype(self.dtype),
numpy.random.rand(5).astype(self.dtype),
numpy.random.rand(4).astype(self.dtype))
f(numpy.random.rand(5, 4).astype(self.dtype)[::-1, ::-1],
numpy.random.rand(5).astype(self.dtype),
numpy.random.rand(4).astype(self.dtype))
示例12: test_inplace
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import outer [as 别名]
def test_inplace(self):
A = self.shared(numpy.random.rand(4, 5).astype(self.dtype))
f = self.function([self.x, self.y], [],
updates=[(A, A + T.constant(0.1, dtype=self.dtype) *
T.outer(self.x, self.y))])
self.assertFunctionContains(f, self.ger_destructive)
f(numpy.random.rand(4).astype(self.dtype),
numpy.random.rand(5).astype(self.dtype))
A.set_value(
A.get_value(borrow=True, return_internal_type=True)[::-1, ::-1],
borrow=True)
f(numpy.random.rand(4).astype(self.dtype),
numpy.random.rand(5).astype(self.dtype))
示例13: test_optimization_pipeline
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import outer [as 别名]
def test_optimization_pipeline(self):
f = self.function([self.x, self.y], tensor.outer(self.x, self.y))
self.assertFunctionContains(f, CGer(destructive=True))
f(self.xval, self.yval) # DebugMode tests correctness
示例14: test_optimization_pipeline_float
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import outer [as 别名]
def test_optimization_pipeline_float(self):
self.setUp('float32')
f = self.function([self.x, self.y], tensor.outer(self.x, self.y))
self.assertFunctionContains(f, CGer(destructive=True))
f(self.xval, self.yval) # DebugMode tests correctness
示例15: test_int_fails
# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import outer [as 别名]
def test_int_fails(self):
self.setUp('int32')
f = self.function([self.x, self.y], tensor.outer(self.x, self.y))
self.assertFunctionContains0(f, CGer(destructive=True))
self.assertFunctionContains0(f, CGer(destructive=False))