资源简介
用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支持库
- Python-BDD100K大规模多样化驾驶视频数据
- Instant Pygame for Python Game Development How
- Biopython Tutorial
- Think Python 2nd
- 一个小小的表白程序(python)
- Python课堂笔记(高淇400集第一季)
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
评论
共有 条评论