当前位置: 首页>>代码示例>>Python>>正文


Python tensor.std方法代码示例

本文整理汇总了Python中theano.tensor.std方法的典型用法代码示例。如果您正苦于以下问题:Python tensor.std方法的具体用法?Python tensor.std怎么用?Python tensor.std使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在theano.tensor的用法示例。


在下文中一共展示了tensor.std方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: normalize_batch_in_training

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import std [as 别名]
def normalize_batch_in_training(x, gamma, beta,
                                reduction_axes, epsilon=1e-3):
    """Computes mean and std for batch then apply batch_normalization on batch.
    """
    # TODO remove this if statement when Theano without
    # T.nnet.bn.batch_normalization_train is deprecated
    if not hasattr(T.nnet.bn, 'batch_normalization_train'):
        return _old_normalize_batch_in_training(x, gamma, beta, reduction_axes, epsilon)

    if gamma is None:
        if beta is None:
            gamma = ones_like(x)
        else:
            gamma = ones_like(beta)
    if beta is None:
        if gamma is None:
            beta = zeros_like(x)
        beta = zeros_like(gamma)

    normed, mean, stdinv = T.nnet.bn.batch_normalization_train(
        x, gamma, beta, reduction_axes, epsilon)

    return normed, mean, T.inv(stdinv ** 2) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:25,代码来源:theano_backend.py

示例2: truncated_normal

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import std [as 别名]
def truncated_normal(shape, mean=0.0, stddev=1.0, dtype=None, seed=None):
    if dtype is None:
        dtype = floatx()
    if seed is None:
        seed = np.random.randint(1, 10e6)
    rng = RandomStreams(seed=seed)

    try:
        return rng.normal(size=shape, avg=mean, std=stddev, dtype=dtype,
                          truncate=True)
    except TypeError:
        normal_t = rng.normal(size=shape, avg=mean, std=stddev, dtype=dtype)
        # Poor man's truncated normal: we literally clip the tensor
        return T.clip(normal_t, mean - 2 * stddev, mean + 2 * stddev)


# Theano implementation of CTC
# Used with permission from Shawn Tan
# https://github.com/shawntan/
# Note that TensorFlow's native CTC code is significantly
# faster than this 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:23,代码来源:theano_backend.py

示例3: zca_whiten

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import std [as 别名]
def zca_whiten(data, W, batchsize=500, use_gpu=True, verbose=True):
    data = data.astype(np.float32)
    ncases = data.shape[0]
    nbatches = (ncases - 1) / batchsize + 1

    data_white = np.zeros((ncases, data.shape[1]), dtype=np.float32)
    for bidx in range(nbatches):
        start = bidx * batchsize
        end = min((bidx + 1) * batchsize, ncases)
        if use_gpu:
            data[start:end] = theano_subtract_m1(data[start:end])
            data[start:end] = theano_divide_s1(data[start:end])
            data_white[start:end] = theano_dot(data[start:end], W)
        else:
            data[start:end] -= data[start:end].mean(1)[:, None]
            s1 = data[start:end].std(1)[:, None]
            data[start:end] /= s1 + s1.mean()
            data_white[start:end] = np.dot(data[start:end], W)
    return data_white 
开发者ID:saebrahimi,项目名称:Emotion-Recognition-RNN,代码行数:21,代码来源:pca.py

示例4: whiten

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import std [as 别名]
def whiten(data, V, m0, s0, var_fracs, retain_var, nprincomps=0, batchsize=1000, use_gpu=True, verbose=True):
    data = data.astype(np.float32)
    ncases = data.shape[0]
    nbatches = (ncases - 1) / batchsize + 1
    if nprincomps == 0:
        nprincomps = np.where(var_fracs > retain_var)[0][0]
    data_white = np.zeros((ncases, nprincomps), dtype=np.float32)
    for bidx in range(nbatches):
        start = bidx * batchsize
        end = min((bidx + 1) * batchsize, ncases)
        data[start:end] -= data[start:end].mean(1)[:, None]
        s1 = data[start:end].std(1)[:, None]
        data[start:end] /= s1 + s1.mean()
        data[start:end] -= m0
        data[start:end] /= s0
        if use_gpu:
            data_white[start:end] = theano_dot(
                data[start:end], V[:nprincomps].T)
        else:
            data_white[start:end] = np.dot(data[start:end], V[:nprincomps].T)
    return data_white 
开发者ID:saebrahimi,项目名称:Emotion-Recognition-RNN,代码行数:23,代码来源:pca.py

示例5: truncated_normal

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import std [as 别名]
def truncated_normal(shape, mean=0.0, stddev=1.0, dtype=None, seed=None):
    if dtype is None:
        dtype = floatx()
    if seed is None:
        seed = np.random.randint(1, 10e6)
    rng = RandomStreams(seed=seed)
    normal_tensor = rng.normal(size=shape, avg=mean, std=stddev, dtype=dtype)
    # Poor man's truncated normal: we literally clip the tensor
    return T.clip(normal_tensor, mean - 2 * stddev, mean + 2 * stddev)


# Theano implementation of CTC
# Used with permission from Shawn Tan
# https://github.com/shawntan/
# Note that TensorFlow's native CTC code is significantly
# faster than this 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:18,代码来源:theano_backend.py

示例6: normalize_batch_in_training

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import std [as 别名]
def normalize_batch_in_training(x, gamma, beta,
                                reduction_axes, epsilon=0.0001):
    '''Compute mean and std for batch then apply batch_normalization on batch.
    '''
    var = x.var(reduction_axes)
    mean = x.mean(reduction_axes)

    target_shape = []
    for axis in range(ndim(x)):
        if axis in reduction_axes:
            target_shape.append(1)
        else:
            target_shape.append(x.shape[axis])
    target_shape = T.stack(*target_shape)

    broadcast_mean = T.reshape(mean, target_shape)
    broadcast_var = T.reshape(var, target_shape)
    broadcast_beta = T.reshape(beta, target_shape)
    broadcast_gamma = T.reshape(gamma, target_shape)
    normed = batch_normalization(x, broadcast_mean, broadcast_var,
                                 broadcast_beta, broadcast_gamma,
                                 epsilon)
    return normed, mean, var 
开发者ID:GUR9000,项目名称:KerasNeuralFingerprint,代码行数:25,代码来源:theano_backend.py

示例7: truncated_normal

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import std [as 别名]
def truncated_normal(shape, mean=0.0, stddev=1.0, dtype=None, seed=None):
    if dtype is None:
        dtype = floatx()
    if seed is None:
        seed = np.random.randint(1, 10e6)
    rng = RandomStreams(seed=seed)
    normal_tensor = rng.normal(size=shape, avg=mean, std=stddev, dtype=dtype)
    # Poor man's truncated normal: we literally clip the tensor
    return T.clip(normal_tensor, mean - 2 * stddev, mean + 2 * stddev)


# Theano implementation of CTC
# Used with permission from Shawn Tan
# https://github.com/shawntan/
# Note that tensorflow's native CTC code is significantly
# faster than this 
开发者ID:sunilmallya,项目名称:keras-lambda,代码行数:18,代码来源:theano_backend.py

示例8: std

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import std [as 别名]
def std(x, axis=None, keepdims=False):
    return T.std(x, axis=axis, keepdims=keepdims) 
开发者ID:lingluodlut,项目名称:Att-ChemdNER,代码行数:4,代码来源:theano_backend.py

示例9: normalize_batch_in_training

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import std [as 别名]
def normalize_batch_in_training(x, gamma, beta,
                                reduction_axes, epsilon=1e-3):
    '''Computes mean and std for batch then apply batch_normalization on batch.
    '''
    # TODO remove this if statement when Theano without
    # T.nnet.bn.batch_normalization_train is deprecated
    if not hasattr(T.nnet.bn, 'batch_normalization_train'):
        return _old_normalize_batch_in_training(x, gamma, beta, reduction_axes, epsilon)

    normed, mean, stdinv = T.nnet.bn.batch_normalization_train(
        x, gamma, beta, reduction_axes, epsilon)

    return normed, mean, T.inv(stdinv ** 2) 
开发者ID:lingluodlut,项目名称:Att-ChemdNER,代码行数:15,代码来源:theano_backend.py

示例10: _old_normalize_batch_in_training

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import std [as 别名]
def _old_normalize_batch_in_training(x, gamma, beta,
                                     reduction_axes, epsilon=1e-3):
    '''Computes mean and std for batch then apply batch_normalization on batch.
    '''
    dev = theano.config.device
    use_cudnn = ndim(x) < 5 and reduction_axes == [0, 2, 3] and (dev.startswith('cuda') or dev.startswith('gpu'))
    if use_cudnn:
        broadcast_beta = beta.dimshuffle('x', 0, 'x', 'x')
        broadcast_gamma = gamma.dimshuffle('x', 0, 'x', 'x')
        try:
            normed, mean, stdinv = theano.sandbox.cuda.dnn.dnn_batch_normalization_train(
                x, broadcast_gamma, broadcast_beta, 'spatial', epsilon)
            var = T.inv(stdinv ** 2)
            return normed, T.flatten(mean), T.flatten(var)
        except AttributeError:
            pass

    var = x.var(reduction_axes)
    mean = x.mean(reduction_axes)

    target_shape = []
    for axis in range(ndim(x)):
        if axis in reduction_axes:
            target_shape.append(1)
        else:
            target_shape.append(x.shape[axis])
    target_shape = T.stack(*target_shape)

    broadcast_mean = T.reshape(mean, target_shape)
    broadcast_var = T.reshape(var, target_shape)
    broadcast_beta = T.reshape(beta, target_shape)
    broadcast_gamma = T.reshape(gamma, target_shape)
    normed = batch_normalization(x, broadcast_mean, broadcast_var,
                                 broadcast_beta, broadcast_gamma,
                                 epsilon)
    return normed, mean, var


# TODO remove this if statement when Theano without
# T.nnet.bn.batch_normalization_test is deprecated 
开发者ID:lingluodlut,项目名称:Att-ChemdNER,代码行数:42,代码来源:theano_backend.py

示例11: random_normal

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import std [as 别名]
def random_normal(shape, mean=0.0, std=1.0, dtype=None, seed=None):
    if dtype is None:
        dtype = floatx()
    if seed is None:
        seed = np.random.randint(1, 10e6)
    rng = RandomStreams(seed=seed)
    return rng.normal(size=shape, avg=mean, std=std, dtype=dtype) 
开发者ID:lingluodlut,项目名称:Att-ChemdNER,代码行数:9,代码来源:theano_backend.py

示例12: random_normal

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import std [as 别名]
def random_normal(shape, mean=0.0, std=1.0, dtype=_FLOATX, seed=None):
    if seed is None:
        seed = np.random.randint(10e6)
    rng = RandomStreams(seed=seed)
    return rng.normal(size=shape, avg=mean, std=std, dtype=dtype) 
开发者ID:mathDR,项目名称:reading-text-in-the-wild,代码行数:7,代码来源:theano_backend.py

示例13: get_stats

# 需要导入模块: from theano import tensor [as 别名]
# 或者: from theano.tensor import std [as 别名]
def get_stats(input, stat=None):
    """
    Returns a dictionary mapping the name of the statistic to the result on the input.
    Currently gets mean, var, std, min, max, l1, l2.

    Parameters
    ----------
    input : tensor
        Theano tensor to grab stats for.

    Returns
    -------
    dict
        Dictionary of all the statistics expressions {string_name: theano expression}
    """
    stats = {
        'mean': T.mean(input),
        'var': T.var(input),
        'std': T.std(input),
        'min': T.min(input),
        'max': T.max(input),
        'l1': input.norm(L=1),
        'l2': input.norm(L=2),
        #'num_nonzero': T.sum(T.nonzero(input)),
    }
    stat_list = raise_to_list(stat)
    compiled_stats = {}
    if stat_list is None:
        return stats

    for stat in stat_list:
        if isinstance(stat, string_types) and stat in stats:
            compiled_stats.update({stat: stats[stat]})
    return compiled_stats 
开发者ID:vitruvianscience,项目名称:OpenDeep,代码行数:36,代码来源:statistics.py


注:本文中的theano.tensor.std方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。