def __init__(self, ndim_x=28 * 28, ndim_y=10, ndim_z=10, ndim_h=1000):
        super(Model, self).__init__()
        self.ndim_x = ndim_x
        self.ndim_y = ndim_y
        self.ndim_z = ndim_z
        self.ndim_h = ndim_h
        with self.init_scope():
            decoder = nn.Module(
                # nn.BatchNormalization(ndim_h),
                nn.Linear(ndim_h, ndim_h),
                nn.ReLU(),
                # nn.BatchNormalization(ndim_h),
                nn.Linear(ndim_h, ndim_x),
                nn.Tanh(),
            )
            decoder.merge_y = nn.Linear(ndim_y, ndim_h, nobias=True)
            decoder.merge_z = nn.Linear(ndim_z, ndim_h, nobias=True)
            decoder.merge_bias = nn.Bias(shape=(ndim_h, ))
            self.decoder = decoder

            encoder = nn.Module(
                nn.Linear(ndim_x, ndim_h),
                nn.ReLU(),
                # nn.BatchNormalization(ndim_h),
                nn.Linear(ndim_h, ndim_h),
                nn.ReLU(),
            )
            encoder.head_y = nn.Linear(ndim_h, ndim_y)
            encoder.head_z = nn.Linear(ndim_h, ndim_z)
            self.encoder = encoder

            self.discriminator_z = nn.Module(
                nn.GaussianNoise(std=0.3),
                nn.Linear(ndim_z, ndim_h),
                nn.ReLU(),
                # nn.BatchNormalization(ndim_h),
                nn.Linear(ndim_h, ndim_h),
                nn.ReLU(),
                # nn.BatchNormalization(ndim_h),
                nn.Linear(ndim_h, 2),
            )

            self.discriminator_y = nn.Module(
                nn.GaussianNoise(std=0.3),
                # nn.GaussianNoise(0, 0.3),
                nn.Linear(ndim_y, ndim_h),
                nn.ReLU(),
                # nn.BatchNormalization(ndim_h),
                nn.Linear(ndim_h, ndim_h),
                nn.ReLU(),
                # nn.BatchNormalization(ndim_h),
                nn.Linear(ndim_h, 2),
            )

        for param in self.params():
            if param.name == "W":
                param.data[...] = np.random.normal(0, 0.01, param.data.shape)
Beispiel #2
0
	def __init__(self, ndim_x=28*28, ndim_y=20, ndim_z=2, ndim_h=1000, cluster_head_distance_threshold=2):
		super(Model, self).__init__()
		self.ndim_x = ndim_x
		self.ndim_y = ndim_y
		self.ndim_z = ndim_z
		self.ndim_h = ndim_h
		self.cluster_head_distance_threshold = cluster_head_distance_threshold

		with self.init_scope():
			self.decoder = nn.Module(
				nn.Linear(ndim_z, ndim_h),
				nn.ReLU(),
				# nn.BatchNormalization(ndim_h),
				nn.Linear(ndim_h, ndim_h),
				nn.ReLU(),
				# nn.BatchNormalization(ndim_h),
				nn.Linear(ndim_h, ndim_x),
				nn.Tanh(),
			)

			encoder = nn.Module(
				nn.Linear(ndim_x, ndim_h),
				nn.ReLU(),
				# nn.BatchNormalization(ndim_h),
				nn.Linear(ndim_h, ndim_h),
				nn.ReLU(),
			)
			encoder.head_y = nn.Linear(ndim_h, ndim_y)
			encoder.head_z = nn.Linear(ndim_h, ndim_z)
			self.encoder = encoder

			self.discriminator_z = nn.Module(
				nn.GaussianNoise(std=0.3),
				nn.Linear(ndim_z, ndim_h),
				nn.ReLU(),
				# nn.BatchNormalization(ndim_h),
				nn.Linear(ndim_h, ndim_h),
				nn.ReLU(),
				# nn.BatchNormalization(ndim_h),
				nn.Linear(ndim_h, 2),
			)

			self.discriminator_y = nn.Module(
				nn.GaussianNoise(std=0.3),
				# nn.GaussianNoise(0, 0.3),
				nn.Linear(ndim_y, ndim_h),
				nn.ReLU(),
				# nn.BatchNormalization(ndim_h),
				nn.Linear(ndim_h, ndim_h),
				nn.ReLU(),
				# nn.BatchNormalization(ndim_h),
				nn.Linear(ndim_h, 2),
			)

			self.cluster_head = nn.Linear(ndim_y, ndim_z, nobias=True)

		for param in self.params():
			if param.name == "W":
				param.data[...] = np.random.normal(0, 0.01, param.data.shape)

		for param in self.cluster_head.params():
			if param.name == "W":
				param.data[...] = np.random.normal(0, 1, param.data.shape)