Hi,

While slowly learning DeepChem infrustructure I came across GAN examples from model/test section.

I have modified the code to more closely resemble outdated Tutorial part 16 example. Unfortunately, I am not able to obtained even closely similar results. Could you let me know if I am doing something wrong.

This is my sample code:

```
#GENERATE SAMPLE DATA
n_classes = 4
class_centers = np.random.uniform(-4, 4, (n_classes, 2))
class_transforms = []
for i in range(n_classes):
xscale = np.random.uniform(0.5, 2)
yscale = np.random.uniform(0.5, 2)
angle = np.random.uniform(0, np.pi)
m = [[xscale*np.cos(angle), -yscale*np.sin(angle)],
[xscale*np.sin(angle), yscale*np.cos(angle)]]
class_transforms.append(m)
class_transforms = np.array(class_transforms)
def generate_data(n_points):
classes = np.random.randint(n_classes, size=n_points)
r = np.random.random(n_points)
angle = 2*np.pi*np.random.random(n_points)
points = (r*np.array([np.cos(angle), np.sin(angle)])).T
points = np.einsum('ijk,ik->ij', class_transforms[classes], points)
points += class_centers[classes]
return classes, points
%matplotlib inline
import matplotlib.pyplot as plot
classes, points = generate_data(10000)
plot.scatter(x=points[:,0], y=points[:,1], c=classes)
#(plot shown at the end)
#CREATE EXAMPLE WGAN CLASS
class DWGAN(dc.models.WGAN):
def get_noise_input_shape(self):
return (2,)
#modified from original to contain x and y data
def get_data_input_shapes(self):
return [(2,)]
#will be used for classes
def get_conditional_input_shapes(self):
return [(1,)]
def create_generator(self):
noise_input = Input(self.get_noise_input_shape())
conditional_input = Input(self.get_conditional_input_shapes()[0])
inputs = [noise_input, conditional_input]
gen_in = Concatenate(axis=1)(inputs)
#modified from original test example to accomodate 2d data
output = Dense(2)(gen_in)
return tf.keras.Model(inputs=inputs, outputs=output)
def create_discriminator(self):
data_input = Input(self.get_data_input_shapes()[0])
conditional_input = Input(self.get_conditional_input_shapes()[0])
inputs = [data_input, conditional_input]
discrim_in = Concatenate(axis=1)(inputs)
dense = Dense(10, activation=tf.nn.relu)(discrim_in)
#modified from original test example to accomodate 2d data
output = Dense(2)(dense)
return tf.keras.Model(inputs=inputs, outputs=output)
#GENERATE INPUT DATA
def get2DData(gan):
batch = {gan.data_inputs[0]: points, gan.conditional_inputs[0]: classes}
yield batch
#CREATE NEW MODEL
gan = DWGAN(learning_rate=0.01, gradient_penalty=0.1, batch_size=10000)
#TRAIN MODEL
gan.fit_gan(
get2DData(gan),
generator_steps=0.1,
checkpoint_interval=0)
#PREDICT NEW VALUES AND PLOT THEM
new_values = gan.predict_gan_generator(conditional_inputs=[classes])
plot.scatter(x=new_values[:,0], y=new_values[:,1], c=classes)
plot.show()
```

Result:

I have run it several times and all of them look almost identical.

I wonder if I am using the code in a wrong way and how to use properly.

I would assume that the model will try to predict x,y values for each class, with similar distribution in matching training set.

Cheers,

Milosz