资源简介
用python语言,利用对抗抗神经网络(GAN神经)生成一维数据,用python语言,利用对抗抗神经网络(GAN神经)生成一维数据。
代码片段和文件信息
import argparse
import numpy as np
from scipy.stats import norm
import tensorflow as tf
import matplotlib.pyplot as plt
from matplotlib import animation
import seaborn as sns
sns.set(color_codes=True)
seed = 42
np.random.seed(seed)
tf.set_random_seed(seed)
class DataDistribution(object):
def __init__(self):
self.mu = 4
self.sigma = 0.5
def sample(self N):
samples = np.random.normal(self.mu self.sigma N)
samples.sort()
return samples
class GeneratorDistribution(object):
def __init__(self range):
self.range = range
def sample(self N):
return np.linspace(-self.range self.range N) + \
np.random.random(N) * 0.01
def linear(input output_dim scope=None stddev=1.0):
norm = tf.random_normal_initializer(stddev=stddev)
const = tf.constant_initializer(0.0)
with tf.variable_scope(scope or ‘linear‘):
w = tf.get_variable(‘w‘ [input.get_shape()[1] output_dim] initializer=norm)
b = tf.get_variable(‘b‘ [output_dim] initializer=const)
return tf.matmul(input w) + b
def generator(input h_dim):
h0 = tf.nn.softplus(linear(input h_dim ‘g0‘))
h1 = linear(h0 1 ‘g1‘)
return h1
def discriminator(input h_dim):
h0 = tf.tanh(linear(input h_dim * 2 ‘d0‘))
h1 = tf.tanh(linear(h0 h_dim * 2 ‘d1‘))
h2 = tf.tanh(linear(h1 h_dim * 2 scope=‘d2‘))
h3 = tf.sigmoid(linear(h2 1 scope=‘d3‘))
return h3
def optimizer(loss var_list initial_learning_rate):
decay = 0.95
num_decay_steps = 150
batch = tf.Variable(0)
learning_rate = tf.train.exponential_decay(
initial_learning_rate
batch
num_decay_steps
decay
staircase=True
)
optimizer = tf.train.GradientDescentOptimizer(learning_rate).minimize(
loss
global_step=batch
var_list=var_list
)
return optimizer
class GAN(object):
def __init__(self data gen num_steps batch_size log_every):
self.data = data
self.gen = gen
self.num_steps = num_steps
self.batch_size = batch_size
self.log_every = log_every
self.mlp_hidden_size = 4
self.learning_rate = 0.03
self._create_model()
def _create_model(self):
with tf.variable_scope(‘D_pre‘):
self.pre_input = tf.placeholder(tf.float32 shape=(self.batch_size 1))
self.pre_labels = tf.placeholder(tf.float32 shape=(self.batch_size 1))
D_pre = discriminator(self.pre_input self.mlp_hidden_size)
self.pre_loss = tf.reduce_mean(tf.square(D_pre - self.pre_labels))
self.pre_opt = optimizer(self.pre_loss None self.learning_rate)
# This defines the generator network - it takes samples from a noise
# distribution as input and passes them through an MLP.
with tf.variable_scope(‘Gen‘):
self.z = tf.placeholder(tf.float32 shape=(self
- 上一篇:python小波阈值去噪
- 下一篇:python3.0 爬虫小说
相关资源
- python实现SGBM图像匹配算法
- python实现灰度直方图均衡化
- scrapy_qunar_one
- Python学习全系列教程永久可用
- python简明教程.chm
- 抽奖大转盘python的图形化界面
- 双边滤波器实验报告及代码python
- python +MYSQL+HTML实现21蛋糕网上商城
- Python-直播答题助手自动检测出题搜索
- OpenCV入门教程+OpenCV官方教程中文版
- Python 串口工具源码+.exe文件
- Python开发的全栈股票系统.zip
- Python操作Excel表格并将其中部分数据写
- python书籍 PDF
- 利用python绘制散点图
- python+labview+No1.vi
- 老男孩python项目实战
- python源码制作whl文件.rar
- python3.5可用的scipy
- PYTHON3 经典50案例.pptx
- 计算机科学导论-python.pdf
- python模拟鼠标点击屏幕
- windows鼠标自动点击py脚本
- 鱼c小甲鱼零基础学python全套课后题和
- Python 练习题100道
- Practical Programming 2nd Edition
- wxPython Application Development Cookbook
- python 3.6
- Python 3.5.2 中文文档 互联网唯一CHM版本
- python3.5.2.chm官方文档
评论
共有 条评论