def random_uniform(shape, minval=0, maxval=None, dtype=dtypes.float32, seed=None, name=None): """Outputs random values from a uniform distribution. The generated values follow a uniform distribution in the range `[minval, maxval)`. The lower bound `minval` is included in the range, while the upper bound `maxval` is excluded. For floats, the default range is `[0, 1)`. For ints, at least `maxval` must be specified explicitly. In the integer case, the random integers are slightly biased unless `maxval - minval` is an exact power of two. The bias is small for values of `maxval - minval` significantly smaller than the range of the output (either `2**32` or `2**64`). Args: shape: A 1-D integer Tensor or Python array. The shape of the output tensor. minval: A 0-D Tensor or Python value of type `dtype`. The lower bound on the range of random values to generate. Defaults to 0. maxval: A 0-D Tensor or Python value of type `dtype`. The upper bound on the range of random values to generate. Defaults to 1 if `dtype` is floating point. dtype: The type of the output: 'float16`, `float32`, `float64`, `int32`, or `int64`. seed: A Python integer. Used to create a random seed for the distribution. See @{tf.set_random_seed} for behavior. name: A name for the operation (optional). Returns: A tensor of the specified shape filled with random uniform values. Raises: ValueError: If `dtype` is integral and `maxval` is not specified. """ dtype = dtypes.as_dtype(dtype) if dtype not in (dtypes.float16, dtypes.float32, dtypes.float64, dtypes.int32, dtypes.int64): raise ValueError("Invalid dtype %r" % dtype) if maxval is None: if dtype.is_integer: raise ValueError("Must specify maxval for integer dtype %r" % dtype) maxval = 1 with ops.name_scope(name, "random_uniform", [shape, minval, maxval]) as name: shape = _ShapeTensor(shape) minval = ops.convert_to_tensor(minval, dtype=dtype, name="min") maxval = ops.convert_to_tensor(maxval, dtype=dtype, name="max") seed1, seed2 = random_seed.get_seed(seed) if dtype.is_integer: return gen_random_ops._random_uniform_int( shape, minval, maxval, seed=seed1, seed2=seed2, name=name) else: rnd = gen_random_ops._random_uniform( shape, dtype, seed=seed1, seed2=seed2) return math_ops.add(rnd * (maxval - minval), minval, name=name)
def make_chain_minmax(length, node_mbs=1): """Creates chain of nodes alternating minimum/maximum.""" tf.reset_default_graph() tf_dev = tf.device('/cpu:0') tf_dev.__enter__() n = node_mbs * 250000 dtype = tf.float32 upper = gen_random_ops._random_uniform((n, ), dtype, name="u") y = gen_random_ops._random_uniform((n, ), dtype, name="x") min_nodes = [] max_nodes = [] nodes = [y] for i in range(length): y = tf.maximum(upper, y, name="cl") max_nodes.append(y) nodes.append(y) y = tf.minimum(upper, y, name="cu") min_nodes.append(y) nodes.append(y) return nodes
def make_chain_minmax(length, node_mbs=1): """Creates chain of nodes alternating minimum/maximum.""" tf.reset_default_graph() tf_dev = tf.device('/cpu:0') tf_dev.__enter__() n = node_mbs * 250000 dtype = tf.float32 upper = gen_random_ops._random_uniform((n,), dtype, name="u") y = gen_random_ops._random_uniform((n,), dtype, name="x") min_nodes = [] max_nodes = [] nodes = [y] for i in range(length): y = tf.maximum(upper, y, name="cl") max_nodes.append(y) nodes.append(y) y = tf.minimum(upper, y, name="cu") min_nodes.append(y) nodes.append(y) return nodes
def random_uniform(shape, minval=0.0, maxval=1.0, dtype=types.float32, seed=None, name=None): """Outputs random values from a uniform distribution. The generated values follow a uniform distribution in the range `[minval, maxval)`. The lower bound `minval` is included in the range, while the upper bound `maxval` is excluded. Args: shape: A 1-D integer Tensor or Python array. The shape of the output tensor. minval: A 0-D Tensor or Python value of type `dtype`. The lower bound on the range of random values to generate. maxval: A 0-D Tensor or Python value of type `dtype`. The upper bound on the range of random values to generate. dtype: The type of the output. seed: A Python integer. Used to create a random seed for the distribution. See [`set_random_seed`](../../api_docs/python/constant_op.md#set_random_seed) for behavior. name: A name for the operation (optional). Returns: A tensor of the specified shape filled with random uniform values. """ with ops.op_scope([shape, minval, maxval], name, "random_uniform") as name: shape_tensor = _ShapeTensor(shape) min_tensor = ops.convert_to_tensor(minval, dtype=dtype, name="min") range_tensor = ops.convert_to_tensor(maxval - minval, dtype=dtype, name="range") seed1, seed2 = random_seed.get_seed(seed) rnd = gen_random_ops._random_uniform(shape_tensor, dtype, seed=seed1, seed2=seed2) mul = rnd * range_tensor value = math_ops.add(mul, min_tensor, name=name) return value
def random_uniform(shape, minval=0.0, maxval=1.0, dtype=types.float32, seed=None, name=None): """Outputs random values from a uniform distribution. The generated values follow a uniform distribution in the range `[minval, maxval)`. The lower bound `minval` is included in the range, while the upper bound `maxval` is excluded. Args: shape: A 1-D integer Tensor or Python array. The shape of the output tensor. minval: A 0-D Tensor or Python value of type `dtype`. The lower bound on the range of random values to generate. maxval: A 0-D Tensor or Python value of type `dtype`. The upper bound on the range of random values to generate. dtype: The type of the output. seed: A Python integer. Used to create a random seed for the distribution. See [`set_random_seed`](../../api_docs/python/constant_op.md#set_random_seed) for behavior. name: A name for the operation (optional). Returns: A tensor of the specified shape filled with random uniform values. """ with ops.op_scope([shape, minval, maxval], name, "random_uniform") as name: shape_tensor = _ShapeTensor(shape) min_tensor = ops.convert_to_tensor(minval, dtype=dtype, name="min") range_tensor = ops.convert_to_tensor( maxval - minval, dtype=dtype, name="range") seed1, seed2 = random_seed.get_seed(seed) rnd = gen_random_ops._random_uniform(shape_tensor, dtype, seed=seed1, seed2=seed2) mul = rnd * range_tensor value = math_ops.add(mul, min_tensor, name=name) return value
def make_leaf(i): name = "leaf"+str(i) val = gen_random_ops._random_uniform((n2, n2), dtype, name=name) return val
def make_leaf(i): name = "leaf" + str(i) val = gen_random_ops._random_uniform((n2, n2), dtype, name=name) return val