File tree Expand file tree Collapse file tree 2 files changed +5
-10
lines changed Expand file tree Collapse file tree 2 files changed +5
-10
lines changed Original file line number Diff line number Diff line change 71
71
# :math:`D` and :math:`G` play a minimax game in which :math:`D` tries to
72
72
# maximize the probability it correctly classifies reals and fakes
73
73
# (:math:`logD(x)`), and :math:`G` tries to minimize the probability that
74
- # :math:`D` will predict its outputs are fake (:math:`log(1-D(G(x )))`).
74
+ # :math:`D` will predict its outputs are fake (:math:`log(1-D(G(z )))`).
75
75
# From the paper, the GAN loss function is
76
76
#
77
77
# .. math:: \underset{G}{\text{min}} \underset{D}{\text{max}}V(D,G) = \mathbb{E}_{x\sim p_{data}(x)}\big[logD(x)\big] + \mathbb{E}_{z\sim p_{z}(z)}\big[log(1-D(G(z)))\big]
Original file line number Diff line number Diff line change 63
63
import numpy as np
64
64
import matplotlib
65
65
import matplotlib .pyplot as plt
66
- from collections import namedtuple
66
+ from collections import namedtuple , deque
67
67
from itertools import count
68
68
from PIL import Image
69
69
115
115
class ReplayMemory (object ):
116
116
117
117
def __init__ (self , capacity ):
118
- self .capacity = capacity
119
- self .memory = []
120
- self .position = 0
118
+ self .memory = deque ([],maxlen = capacity )
121
119
122
120
def push (self , * args ):
123
- """Saves a transition."""
124
- if len (self .memory ) < self .capacity :
125
- self .memory .append (None )
126
- self .memory [self .position ] = Transition (* args )
127
- self .position = (self .position + 1 ) % self .capacity
121
+ """Save a transition"""
122
+ self .memory .append (Transition (* args ))
128
123
129
124
def sample (self , batch_size ):
130
125
return random .sample (self .memory , batch_size )
You can’t perform that action at this time.
0 commit comments