#coding=utf8
import numpy as np
import sklearn.preprocessing as prep
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
def xavier_init(fan_in, fan_out, constant = 1): # 泽威尔初始化
low = -constant * np.sqrt(6.0 / (fan_in + fan_out))
high = constant * np.sqrt(6.0 / (fan_in + fan_out))
return tf.random_uniform((fan_in, fan_out),minval = low, maxval = high,dtype = tf.float32) # 均值为0,方差为2/(n_in + n_out)的均匀分布
class AdditiveGaussianNoiseAutoencoder(object): # 加性高斯噪声自编码器
def __init__(self, n_input, n_hidden, transfer_function = tf.nn.softplus, optimizer = tf.train.AdamOptimizer(),
scale = 0.1):
'''
n_input: 输入变量数
n_hidden: 隐含层节点数
transfer_function: 隐含层激活函数
optimizer: 优化器
scale: 高斯噪声系数
'''
self.n_input = n_input
self.n_hidden = n_hidden
self.transfer = transfer_function
self.scale = tf.placeholder(tf.float32)
self.training_scale = scale
network_weights = self._initialize_weights()
self.weights = network_weights
# model
self.x = tf.placeholder(tf.float32, [None, self.n_input])
self.hidden = self.transfer(tf.add(tf.matmul(self.x + scale * tf.random_normal((n_input,)),
self.weights['w1']),
self.weights['b1']))
# (x + s * n) * w1 + b1 ,噪声n是 tf.random_normal((n_input,)),如果写出 tf.random_norma
【tensorflow】加性高斯噪声AutoEncoder
最新推荐文章于 2019-07-18 12:02:24 发布
本文介绍了如何利用TensorFlow实战中的方法,构建一个加性高斯噪声AutoEncoder模型。通过引入高斯噪声,该模型能增强对输入数据的鲁棒性。

最低0.47元/天 解锁文章
3028

被折叠的 条评论
为什么被折叠?



