提交 d6780ea5 authored 作者: Olivier Delalleau's avatar Olivier Delalleau

Just moved the code for normal closer to uniform since they are very similar

上级 3b806177
......@@ -418,6 +418,27 @@ def uniform(random_state, size=None, low=0.0, high=1.0, ndim=None, dtype='floatX
tensor.TensorType(dtype=out_dtype, broadcastable=bcast) )
return op(random_state, size, low, high)
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
the specified standard deviation (std).
If the size argument is ambiguous on the number of dimensions, ndim
may be a plain integer to supplement the missing information.
If size is None, the output shape will be determined by the shapes
of avg and std.
"""
avg = tensor.as_tensor_variable(avg)
std = tensor.as_tensor_variable(std)
ndim, size, bcast = _infer_ndim_bcast(ndim, size, avg, std)
dtype = tensor.scal.upcast(dtype, avg.dtype, std.dtype)
op = RandomFunction('normal',
tensor.TensorType(dtype=dtype, broadcastable=bcast))
return op(random_state, size, avg, std)
def binomial(random_state, size=None, n=1, p=0.5, ndim=None, dtype='int64', prob=None):
"""
Sample n times with probability of success prob for each trial,
......@@ -446,25 +467,6 @@ def binomial(random_state, size=None, n=1, p=0.5, ndim=None, dtype='int64', prob
tensor.TensorType(dtype = dtype, broadcastable = (False,)*ndim) )
return op(random_state, size, n, p)
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
the specified standard deviation (std).
If the size argument is ambiguous on the number of dimensions, ndim
may be a plain integer to supplement the missing information.
If size is None, the output shape will be determined by the shapes
of avg and std.
"""
avg = tensor.as_tensor_variable(avg)
std = tensor.as_tensor_variable(std)
ndim, size, bcast = _infer_ndim_bcast(ndim, size, avg, std)
dtype = tensor.scal.upcast(dtype, avg.dtype, std.dtype)
op = RandomFunction('normal',
tensor.TensorType(dtype=dtype, broadcastable=bcast))
return op(random_state, size, avg, std)
def random_integers_helper(random_state, low, high, size):
'''
Helper function to draw random integers.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论