Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
80a40cf0
提交
80a40cf0
authored
9月 18, 2008
作者:
Olivier Breuleux
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
RandomKit
上级
b4a75fa6
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
31 行增加
和
40 行删除
+31
-40
tensor_random.py
tensor_random.py
+31
-40
没有找到文件。
tensor_random.py
浏览文件 @
80a40cf0
...
@@ -4,7 +4,7 @@ import tensor
...
@@ -4,7 +4,7 @@ import tensor
import
numpy
import
numpy
import
functools
import
functools
#from compile import State
from
compile
import
SymbolicInputKit
,
SymbolicInput
from
copy
import
copy
from
copy
import
copy
class
RandomFunction
(
gof
.
Op
):
class
RandomFunction
(
gof
.
Op
):
...
@@ -18,7 +18,7 @@ class RandomFunction(gof.Op):
...
@@ -18,7 +18,7 @@ class RandomFunction(gof.Op):
"""
"""
self
.
fn
=
fn
self
.
fn
=
fn
self
.
outtype
=
outtype
self
.
outtype
=
outtype
self
.
args
=
map
(
tensor
.
as_tensor
,
args
)
self
.
args
=
tuple
(
tensor
.
as_tensor
(
arg
)
for
arg
in
args
)
self
.
inplace
=
kwargs
.
pop
(
'inplace'
,
False
)
self
.
inplace
=
kwargs
.
pop
(
'inplace'
,
False
)
if
self
.
inplace
:
if
self
.
inplace
:
self
.
destroy_map
=
{
0
:
[
0
]}
self
.
destroy_map
=
{
0
:
[
0
]}
...
@@ -100,31 +100,6 @@ normal = random_function(RS.normal, 'float64', 0.0, 1.0)
...
@@ -100,31 +100,6 @@ normal = random_function(RS.normal, 'float64', 0.0, 1.0)
random_integers
=
random_function
(
RS
.
random_integers
,
'int64'
,
0
,
1
)
random_integers
=
random_function
(
RS
.
random_integers
,
'int64'
,
0
,
1
)
# T = tensor
# import compile
# x, y = T.matrices('xy')
# r = gof.generic()
# shp = T.make_lvector(2, 2, 2)
# r2, z = uniform(r, shp, x, y)
# f = compile.function([r, x, y], [z])
# print f(numpy.random.RandomState(1000), [[-1, -1], [-10, -10]], [[10, 1], [10, 1]])
# T = tensor
# import compile
# r = gof.generic()
# shp = (2, 7)
# r2, z = binomial(r, shp)
# f = compile.function([r], [z])
# print f(numpy.random.RandomState(1000))
@gof.local_optimizer
@gof.local_optimizer
def
random_make_inplace
(
node
):
def
random_make_inplace
(
node
):
op
=
node
.
op
op
=
node
.
op
...
@@ -132,21 +107,37 @@ def random_make_inplace(node):
...
@@ -132,21 +107,37 @@ def random_make_inplace(node):
return
RandomFunction
(
op
.
fn
,
op
.
outtype
,
*
op
.
args
,
**
dict
(
inplace
=
True
))
.
make_node
(
*
node
.
inputs
)
.
outputs
return
RandomFunction
(
op
.
fn
,
op
.
outtype
,
*
op
.
args
,
**
dict
(
inplace
=
True
))
.
make_node
(
*
node
.
inputs
)
.
outputs
# class RandomState(StateCollection):
import
sys
from
functools
import
partial
# def __init__(self, name = None):
from
collections
import
deque
# self.states = []
# self.name = name
class
RandomKit
(
SymbolicInputKit
):
def
gen
(
self
,
op
,
*
args
,
**
kwargs
):
r
=
gof
.
generic
()
new_r
,
out
=
op
(
r
,
*
args
,
**
kwargs
)
self
.
add_input
(
SymbolicInput
(
r
,
update
=
new_r
))
out
.
rng
=
r
return
out
def
distribute
(
self
,
value
,
indices
,
containers
):
rg
=
partial
(
numpy
.
random
.
RandomState
(
value
)
.
randint
,
sys
.
maxint
)
elems
=
deque
(
zip
(
indices
,
containers
))
i
=
0
while
elems
:
index
,
container
=
elems
.
popleft
()
while
i
<=
index
:
curr
=
rg
()
i
+=
1
rs
=
numpy
.
random
.
RandomState
(
int
(
curr
))
container
.
data
=
rs
def
binomial
(
self
,
*
args
,
**
kwargs
):
return
self
.
gen
(
binomial
,
*
args
,
**
kwargs
)
rk
=
RandomKit
(
'rk'
)
# def gen(self, op, *args, **kwargs):
# r = gof.Generic()
# new_r, out = op(*args, **kwargs)
# state = State(r, new_r)
# self.states.append(state)
# return out
# def make_states(self, init):
# return [Container(numpy.random.RandomState(0)) for state in self.states]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论