提交 3f596d97 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Add multinomial to raw_random and RandomStream

Changed RandomStream.perform so it casts the shape into a tuple, to work around a bug in numpy.
上级 512651f6
......@@ -182,3 +182,10 @@ class RandomStreams(Component):
"""
return self.gen(raw_random.permutation, *args, **kwargs)
def multinomial(self, *args, **kwargs):
"""Return a symbolic multinomial sample
This is a shortcut for a call to `self.gen`
"""
return self.gen(raw_random.multinomial, *args, **kwargs)
......@@ -171,7 +171,7 @@ class RandomFunction(gof.Op):
if not self.inplace:
r = copy(r)
rout[0] = r
rval = self.fn(r, *(args + [shape]))
rval = self.fn(r, *(args + [tuple(shape)]))
if not isinstance(rval, numpy.ndarray) \
or str(rval.dtype) != node.outputs[1].type.dtype:
out[0] = numpy.asarray(rval, dtype = node.outputs[1].type.dtype)
......@@ -301,6 +301,12 @@ Usage: permutation(random_state, size, n)
Returns a permutation of the integers between 0 and n-1.
"""
multinomial = random_function('multinomial', 'float64', 1, [0.5, 0.5])
multinomial.__doc__ = """
Usage: multinomial(random_state, size, n, pvals)
Sample from a multinomial distribution defined by probabilities pvals.
"""
@gof.local_optimizer([None])
def random_make_inplace(node):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论