def gen_xz(self, x, z, n_batch):
        
        x, z = ndict.ordereddicts((x, z))
        
        A = np.ones((1, n_batch)).astype(np.float32)
        for i in z: z[i] = z[i].astype(np.float32)
        for i in x: x[i] = x[i].astype(np.float32)
        
        _z = {}

        # If x['x'] was given but not z['z']: generate z ~ q(z|x)
        if x.has_key('x') and x.has_key('y') and not z.has_key('z'):

            q_mean, q_logvar = self.dist_qz['z'](*([x['x'], x['y']] + [A]))
            _z['mean'] = q_mean
            _z['logvar'] = q_logvar
            
            # Require epsilon
            if not z.has_key('eps'):
                eps = self.gen_eps(n_batch)['eps']
            
            z['z'] = q_mean + np.exp(0.5 * q_logvar) * eps
            
        else:
            if not z.has_key('z'):
                if ['gaussian','gaussianmarg'] in self.type_pz:
                    z['z'] = np.random.standard_normal(size=(self.n_z, n_batch)).astype(np.float32)
                elif self.type_pz == 'laplace':
                    z['z'] = np.random.laplace(size=(self.n_z, n_batch)).astype(np.float32)
                elif self.type_pz == 'studentt':
                    z['z'] = np.random.standard_t(np.dot(np.exp(self.w['logv'].get_value()), A)).astype(np.float32)
                elif self.type_pz == 'mog':
                    i = np.random.randint(self.n_mixture)
                    loc = np.dot(self.w['mog_mean'+str(i)].get_value(), A)
                    scale = np.dot(np.exp(.5*self.w['mog_logvar'+str(i)].get_value()), A)
                    z['z'] = np.random.normal(loc=loc, scale=scale).astype(np.float32)
                else:
                    raise Exception('Unknown type_pz')
            if not x.has_key('y'):
                py = self.dist_px['y'](*([A]))
                _z['y'] = py
                x['y'] = np.zeros(py.shape)
                # np.random.multinomial requires loop. Faster possible?
                for i in range(py.shape[1]):
                    x['y'][:,i] = np.random.multinomial(n=1, pvals=py[:,i])
                
        # Generate from p(x|z)
        
        if self.type_px == 'bernoulli':
            p = self.dist_px['x'](*([x['y'], z['z']] + [A]))
            _z['x'] = p
            if not x.has_key('x'):
                x['x'] = np.random.binomial(n=1,p=p)
        elif self.type_px == 'laplace':
            x_mean, x_logvar = self.dist_px['x'](*([x['y'], z['z']] + [A]))
            _z['x'] = x_mean
            if not x.has_key('x'):
                x['x'] = np.random.laplace(x_mean, np.exp(0.5 * x_logvar))
        elif self.type_px == 'bounded01' or self.type_px == 'gaussian':
            x_mean, x_logvar = self.dist_px['x'](*([x['y'], z['z']] + [A]))
            _z['x'] = x_mean
            if not x.has_key('x'):
                x['x'] = np.random.normal(x_mean, np.exp(x_logvar/2))
                if self.type_px == 'bounded01':
                    x['x'] = np.maximum(np.zeros(x['x'].shape), x['x'])
                    x['x'] = np.minimum(np.ones(x['x'].shape), x['x'])
        
        else: raise Exception("")
        
        return x, z, _z
dataset/ETHPy150Open dpkingma/nips14-ssl/anglepy/models/GPUVAE_YZ_X.py/GPUVAE_YZ_X.gen_xz/swapped operands of `in`