def sample(self, N): """Sample N samples from the model. If N, n are both specified, then generate N samples, but only keep n of them""" N = int(N) # Get a random permutation of N elements perm = permutation(N) # Sample the number of samples from each view cnts = multinomial(N, self.weights) # Generate Xs xs = multivariate_normal(self.mean, self.sigma, N) ys = zeros((N, )) cnt_ = 0 for i in xrange(self.k): cnt = cnts[i] # Generate a bunch of points for each mean beta = self.betas.T[i] perm_ = perm[cnt_:cnt_ + cnt] ys[perm_] = xs[perm_].dot(beta) cnt_ += cnt return xs, ys
def sample(self, N, n = -1): """Sample N samples from the model. If N, n are both specified, then generate N samples, but only keep n of them""" if n <= 0: n = N shape = (n, self.d) #X = self._allocate_samples("X", shape) X = zeros(shape) # Get a random permutation of N elements perm = permutation(N) # Sample the number of samples from each view cnts = multinomial(N, self.weights) cnt_ = 0 for i in xrange(self.k): cnt = cnts[i] # Generate a bunch of points for each mean mean, sigma = self.means.T[ i ], self.sigmas[ i ] perm_ = perm[cnt_ : cnt_ + cnt] X[perm_] = multivariate_normal(mean, sigma, cnt) cnt_ += cnt #X.flush() return X
def sample(self, N): """Sample N samples from the model. If N, n are both specified, then generate N samples, but only keep n of them""" N = int(N) # Get a random permutation of N elements perm = permutation(N) # Sample the number of samples from each view cnts = multinomial(N, self.weights) # Generate Xs xs = multivariate_normal(self.mean, self.sigma, N) ys = zeros((N,)) cnt_ = 0 for i in xrange(self.k): cnt = cnts[i] # Generate a bunch of points for each mean beta = self.betas.T[i] perm_ = perm[cnt_ : cnt_ + cnt] ys[perm_] = xs[perm_].dot(beta) cnt_ += cnt return xs, ys
def sample(self, N): """Sample N samples from the model. If N, n are both specified, then generate N samples, but only keep n of them""" shape = (N, self.d, 3) X = zeros(shape) # Get a random permutation of N elements perm = permutation(N) # Sample the number of samples from each view cnts = multinomial(N, self.weights) cnt_ = 0 for i in xrange(self.k): cnt = cnts[i] # Generate a bunch of points for each mean mean = self.means.T[i] perm_ = perm[cnt_ : cnt_ + cnt] X[perm_,:,0] = multinomial(1, mean, size=int(cnt)) X[perm_,:,1] = multinomial(1, mean, size=int(cnt)) X[perm_,:,2] = multinomial(1, mean, size=int(cnt)) cnt_ += cnt return X