Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
fea13d01
提交
fea13d01
authored
2月 17, 2010
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add keyword arg "dtype" to random functions.
上级
28e1bd43
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
24 行增加
和
24 行删除
+24
-24
raw_random.py
theano/tensor/raw_random.py
+24
-24
没有找到文件。
theano/tensor/raw_random.py
浏览文件 @
fea13d01
...
@@ -51,7 +51,7 @@ class RandomFunction(gof.Op):
...
@@ -51,7 +51,7 @@ class RandomFunction(gof.Op):
"""
"""
def
__init__
(
self
,
fn
,
outtype
,
inplace
=
False
,
ndim_added
=
0
):
def
__init__
(
self
,
fn
,
outtype
,
inplace
=
False
,
ndim_added
=
0
):
"""
"""
:param fn: a member function of numpy.RandomState
:param fn: a member function of numpy.RandomState
Technically, any function with a signature like the ones in
Technically, any function with a signature like the ones in
...
@@ -306,7 +306,7 @@ def _generate_broadcasting_indices(out_shape, *shapes):
...
@@ -306,7 +306,7 @@ def _generate_broadcasting_indices(out_shape, *shapes):
return
ret_indices
return
ret_indices
def
uniform
(
random_state
,
size
=
None
,
low
=
0.0
,
high
=
1.0
,
ndim
=
None
):
def
uniform
(
random_state
,
size
=
None
,
low
=
0.0
,
high
=
1.0
,
ndim
=
None
,
dtype
=
theano
.
config
.
floatX
):
"""
"""
Sample from a uniform distribution between low and high.
Sample from a uniform distribution between low and high.
...
@@ -320,10 +320,10 @@ def uniform(random_state, size=None, low=0.0, high=1.0, ndim=None):
...
@@ -320,10 +320,10 @@ def uniform(random_state, size=None, low=0.0, high=1.0, ndim=None):
high
=
tensor
.
as_tensor_variable
(
high
)
high
=
tensor
.
as_tensor_variable
(
high
)
ndim
,
size
=
_infer_ndim
(
ndim
,
size
,
low
,
high
)
ndim
,
size
=
_infer_ndim
(
ndim
,
size
,
low
,
high
)
op
=
RandomFunction
(
'uniform'
,
op
=
RandomFunction
(
'uniform'
,
tensor
.
TensorType
(
dtype
=
'float64'
,
broadcastable
=
(
False
,)
*
ndim
)
)
tensor
.
TensorType
(
dtype
=
dtype
,
broadcastable
=
(
False
,)
*
ndim
)
)
return
op
(
random_state
,
size
,
low
,
high
)
return
op
(
random_state
,
size
,
low
,
high
)
def
binomial
(
random_state
,
size
=
None
,
n
=
1
,
prob
=
0.5
,
ndim
=
None
):
def
binomial
(
random_state
,
size
=
None
,
n
=
1
,
prob
=
0.5
,
ndim
=
None
,
dtype
=
'int64'
):
"""
"""
Sample n times with probability of success prob for each trial,
Sample n times with probability of success prob for each trial,
return the number of successes.
return the number of successes.
...
@@ -338,10 +338,10 @@ def binomial(random_state, size=None, n=1, prob=0.5, ndim=None):
...
@@ -338,10 +338,10 @@ def binomial(random_state, size=None, n=1, prob=0.5, ndim=None):
prob
=
tensor
.
as_tensor_variable
(
prob
)
prob
=
tensor
.
as_tensor_variable
(
prob
)
ndim
,
size
=
_infer_ndim
(
ndim
,
size
,
n
,
prob
)
ndim
,
size
=
_infer_ndim
(
ndim
,
size
,
n
,
prob
)
op
=
RandomFunction
(
'binomial'
,
op
=
RandomFunction
(
'binomial'
,
tensor
.
TensorType
(
dtype
=
'int64'
,
broadcastable
=
(
False
,)
*
ndim
)
)
tensor
.
TensorType
(
dtype
=
dtype
,
broadcastable
=
(
False
,)
*
ndim
)
)
return
op
(
random_state
,
size
,
n
,
prob
)
return
op
(
random_state
,
size
,
n
,
prob
)
def
normal
(
random_state
,
size
=
None
,
avg
=
0.0
,
std
=
1.0
,
ndim
=
None
):
def
normal
(
random_state
,
size
=
None
,
avg
=
0.0
,
std
=
1.0
,
ndim
=
None
,
dtype
=
theano
.
config
.
floatX
):
"""
"""
Sample from a normal distribution centered on avg with
Sample from a normal distribution centered on avg with
the specified standard deviation (std).
the specified standard deviation (std).
...
@@ -356,7 +356,7 @@ def normal(random_state, size=None, avg=0.0, std=1.0, ndim=None):
...
@@ -356,7 +356,7 @@ def normal(random_state, size=None, avg=0.0, std=1.0, ndim=None):
std
=
tensor
.
as_tensor_variable
(
std
)
std
=
tensor
.
as_tensor_variable
(
std
)
ndim
,
size
=
_infer_ndim
(
ndim
,
size
,
avg
,
std
)
ndim
,
size
=
_infer_ndim
(
ndim
,
size
,
avg
,
std
)
op
=
RandomFunction
(
'normal'
,
op
=
RandomFunction
(
'normal'
,
tensor
.
TensorType
(
dtype
=
'float64'
,
broadcastable
=
(
False
,)
*
ndim
)
)
tensor
.
TensorType
(
dtype
=
dtype
,
broadcastable
=
(
False
,)
*
ndim
)
)
return
op
(
random_state
,
size
,
avg
,
std
)
return
op
(
random_state
,
size
,
avg
,
std
)
def
random_integers_helper
(
random_state
,
low
,
high
,
size
):
def
random_integers_helper
(
random_state
,
low
,
high
,
size
):
...
@@ -401,7 +401,7 @@ def random_integers_helper(random_state, low, high, size):
...
@@ -401,7 +401,7 @@ def random_integers_helper(random_state, low, high, size):
return
out
return
out
def
random_integers
(
random_state
,
size
=
None
,
low
=
0
,
high
=
1
,
ndim
=
None
):
def
random_integers
(
random_state
,
size
=
None
,
low
=
0
,
high
=
1
,
ndim
=
None
,
dtype
=
'int64'
):
"""
"""
Sample a random integer between low and high, both inclusive.
Sample a random integer between low and high, both inclusive.
...
@@ -415,7 +415,7 @@ def random_integers(random_state, size=None, low=0, high=1, ndim=None):
...
@@ -415,7 +415,7 @@ def random_integers(random_state, size=None, low=0, high=1, ndim=None):
high
=
tensor
.
as_tensor_variable
(
high
)
high
=
tensor
.
as_tensor_variable
(
high
)
ndim
,
size
=
_infer_ndim
(
ndim
,
size
,
low
,
high
)
ndim
,
size
=
_infer_ndim
(
ndim
,
size
,
low
,
high
)
op
=
RandomFunction
(
random_integers_helper
,
op
=
RandomFunction
(
random_integers_helper
,
tensor
.
TensorType
(
dtype
=
'int64'
,
broadcastable
=
(
False
,)
*
ndim
)
)
tensor
.
TensorType
(
dtype
=
dtype
,
broadcastable
=
(
False
,)
*
ndim
)
)
return
op
(
random_state
,
size
,
low
,
high
)
return
op
(
random_state
,
size
,
low
,
high
)
def
permutation_helper
(
random_state
,
n
,
shape
):
def
permutation_helper
(
random_state
,
n
,
shape
):
...
@@ -448,7 +448,7 @@ def permutation_helper(random_state, n, shape):
...
@@ -448,7 +448,7 @@ def permutation_helper(random_state, n, shape):
#print 'RETURNING', out.shape
#print 'RETURNING', out.shape
return
out
return
out
def
permutation
(
random_state
,
size
=
None
,
n
=
1
,
ndim
=
None
):
def
permutation
(
random_state
,
size
=
None
,
n
=
1
,
ndim
=
None
,
dtype
=
'int64'
):
"""
"""
Returns permutations of the integers between 0 and n-1, as many times
Returns permutations of the integers between 0 and n-1, as many times
as required by size. For instance, if size=(p,q), p*q permutations
as required by size. For instance, if size=(p,q), p*q permutations
...
@@ -465,7 +465,7 @@ def permutation(random_state, size=None, n=1, ndim=None):
...
@@ -465,7 +465,7 @@ def permutation(random_state, size=None, n=1, ndim=None):
ndim
,
size
=
_infer_ndim
(
ndim
,
size
)
ndim
,
size
=
_infer_ndim
(
ndim
,
size
)
#print "NDIM", ndim, size
#print "NDIM", ndim, size
op
=
RandomFunction
(
permutation_helper
,
op
=
RandomFunction
(
permutation_helper
,
tensor
.
TensorType
(
dtype
=
'int64'
,
broadcastable
=
(
False
,)
*
(
ndim
+
1
)),
tensor
.
TensorType
(
dtype
=
dtype
,
broadcastable
=
(
False
,)
*
(
ndim
+
1
)),
ndim_added
=
1
)
ndim_added
=
1
)
return
op
(
random_state
,
size
,
n
)
return
op
(
random_state
,
size
,
n
)
...
@@ -517,7 +517,7 @@ def multinomial_helper(random_state, n, pvals, size):
...
@@ -517,7 +517,7 @@ def multinomial_helper(random_state, n, pvals, size):
out
[
mi
]
=
random_state
.
multinomial
(
n
=
n
[
ni
],
pvals
=
pvals
[
pi
])
out
[
mi
]
=
random_state
.
multinomial
(
n
=
n
[
ni
],
pvals
=
pvals
[
pi
])
return
out
return
out
def
multinomial
(
random_state
,
size
=
None
,
n
=
1
,
pvals
=
[
0.5
,
0.5
],
ndim
=
None
):
def
multinomial
(
random_state
,
size
=
None
,
n
=
1
,
pvals
=
[
0.5
,
0.5
],
ndim
=
None
,
dtype
=
'int64'
):
"""
"""
Sample n times from a multinomial distribution defined by
Sample n times from a multinomial distribution defined by
probabilities pvals, as many times as required by size. For
probabilities pvals, as many times as required by size. For
...
@@ -554,7 +554,7 @@ optdb.register('random_make_inplace', opt.in2out(random_make_inplace, ignore_new
...
@@ -554,7 +554,7 @@ optdb.register('random_make_inplace', opt.in2out(random_make_inplace, ignore_new
class
RandomStreamsBase
(
object
):
class
RandomStreamsBase
(
object
):
def
binomial
(
self
,
size
=
None
,
n
=
1
,
prob
=
0.5
,
ndim
=
None
):
def
binomial
(
self
,
size
=
None
,
n
=
1
,
prob
=
0.5
,
ndim
=
None
,
dtype
=
'int64'
):
"""
"""
Sample n times with probability of success prob for each trial,
Sample n times with probability of success prob for each trial,
return the number of successes.
return the number of successes.
...
@@ -563,9 +563,9 @@ class RandomStreamsBase(object):
...
@@ -563,9 +563,9 @@ class RandomStreamsBase(object):
ndim may be a plain integer to supplement the missing
ndim may be a plain integer to supplement the missing
information.
information.
"""
"""
return
self
.
gen
(
binomial
,
size
,
n
,
prob
,
ndim
=
ndim
)
return
self
.
gen
(
binomial
,
size
,
n
,
prob
,
ndim
=
ndim
,
dtype
=
dtype
)
def
uniform
(
self
,
size
=
None
,
low
=
0.0
,
high
=
1.0
,
ndim
=
None
):
def
uniform
(
self
,
size
=
None
,
low
=
0.0
,
high
=
1.0
,
ndim
=
None
,
dtype
=
theano
.
config
.
floatX
):
"""
"""
Sample a tensor of given size whose element from a uniform
Sample a tensor of given size whose element from a uniform
distribution between low and high.
distribution between low and high.
...
@@ -574,9 +574,9 @@ class RandomStreamsBase(object):
...
@@ -574,9 +574,9 @@ class RandomStreamsBase(object):
ndim may be a plain integer to supplement the missing
ndim may be a plain integer to supplement the missing
information.
information.
"""
"""
return
self
.
gen
(
uniform
,
size
,
low
,
high
,
ndim
=
ndim
)
return
self
.
gen
(
uniform
,
size
,
low
,
high
,
ndim
=
ndim
,
dtype
=
dtype
)
def
normal
(
self
,
size
=
None
,
avg
=
0.0
,
std
=
1.0
,
ndim
=
None
):
def
normal
(
self
,
size
=
None
,
avg
=
0.0
,
std
=
1.0
,
ndim
=
None
,
dtype
=
theano
.
config
.
floatX
):
"""
"""
Sample from a normal distribution centered on avg with
Sample from a normal distribution centered on avg with
the specified standard deviation (std).
the specified standard deviation (std).
...
@@ -585,9 +585,9 @@ class RandomStreamsBase(object):
...
@@ -585,9 +585,9 @@ class RandomStreamsBase(object):
ndim may be a plain integer to supplement the missing
ndim may be a plain integer to supplement the missing
information.
information.
"""
"""
return
self
.
gen
(
normal
,
size
,
avg
,
std
,
ndim
=
ndim
)
return
self
.
gen
(
normal
,
size
,
avg
,
std
,
ndim
=
ndim
,
dtype
=
dtype
)
def
random_integers
(
self
,
size
=
None
,
low
=
0
,
high
=
1
,
ndim
=
None
):
def
random_integers
(
self
,
size
=
None
,
low
=
0
,
high
=
1
,
ndim
=
None
,
dtype
=
'int64'
):
"""
"""
Sample a random integer between low and high, both inclusive.
Sample a random integer between low and high, both inclusive.
...
@@ -595,9 +595,9 @@ class RandomStreamsBase(object):
...
@@ -595,9 +595,9 @@ class RandomStreamsBase(object):
ndim may be a plain integer to supplement the missing
ndim may be a plain integer to supplement the missing
information.
information.
"""
"""
return
self
.
gen
(
random_integers
,
size
,
low
,
high
,
ndim
=
ndim
)
return
self
.
gen
(
random_integers
,
size
,
low
,
high
,
ndim
=
ndim
,
dtype
=
dtype
)
def
permutation
(
self
,
size
=
None
,
n
=
1
,
ndim
=
None
):
def
permutation
(
self
,
size
=
None
,
n
=
1
,
ndim
=
None
,
dtype
=
'int64'
):
"""
"""
Returns permutations of the integers between 0 and n-1, as many times
Returns permutations of the integers between 0 and n-1, as many times
as required by size. For instance, if size=(p,q), p*q permutations
as required by size. For instance, if size=(p,q), p*q permutations
...
@@ -611,9 +611,9 @@ class RandomStreamsBase(object):
...
@@ -611,9 +611,9 @@ class RandomStreamsBase(object):
.. note::
.. note::
Note that the output will then be of dimension ndim+1.
Note that the output will then be of dimension ndim+1.
"""
"""
return
self
.
gen
(
permutation
,
size
,
n
,
ndim
=
ndim
)
return
self
.
gen
(
permutation
,
size
,
n
,
ndim
=
ndim
,
dtype
=
dtype
)
def
multinomial
(
self
,
size
=
None
,
n
=
1
,
pvals
=
[
0.5
,
0.5
],
ndim
=
None
):
def
multinomial
(
self
,
size
=
None
,
n
=
1
,
pvals
=
[
0.5
,
0.5
],
ndim
=
None
,
dtype
=
'int64'
):
"""
"""
Sample n times from a multinomial distribution defined by
Sample n times from a multinomial distribution defined by
probabilities pvals, as many times as required by size. For
probabilities pvals, as many times as required by size. For
...
@@ -627,7 +627,7 @@ class RandomStreamsBase(object):
...
@@ -627,7 +627,7 @@ class RandomStreamsBase(object):
.. note::
.. note::
Note that the output will then be of dimension ndim+1.
Note that the output will then be of dimension ndim+1.
"""
"""
return
self
.
gen
(
multinomial
,
size
,
n
,
pvals
,
ndim
=
ndim
)
return
self
.
gen
(
multinomial
,
size
,
n
,
pvals
,
ndim
=
ndim
,
dtype
=
dtype
)
def
shuffle_row_elements
(
self
,
input
):
def
shuffle_row_elements
(
self
,
input
):
"""Return a variable with every row (rightmost index) shuffled.
"""Return a variable with every row (rightmost index) shuffled.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论