Beispiel #1
0
 def add(self, x, y, update=True):
     assert x.shape[0] == y.shape[0]
     assert x.shape[1] == self.d
     assert y.shape[1] == 1
     x = np.asmatrix(x)
     y = np.asmatrix(y)
     if x.shape[0] > 0:
         self.x = np.concatenate((self.x, x))
         self.y = np.concatenate((self.y, y))
     if update:
         self._update()
Beispiel #2
0
def permutation_matrix(dim):
    '''
    Generate haar permuation matrix.
    '''
    I = M.eye(dim, dim)
    return M.concatenate((I[::2][:],
                          I[1::2][:]))
Beispiel #3
0
def threedize_phi_angles(data, view, cameraposor, laserpos, lasertheta):
    """Call threedize on each element of data.  Data is a list of pairs whose first
element is phi and whose second element is an array of x--y pairs.  phi is
combined with laserpos and lasertheta to create laserposor."""
    per_angles = [threedize(xys, view,
                            cameraposor,
                            Posor(laserpos, lasertheta, phi, 0))
                  for (phi, xys) in data]
    return np.concatenate(per_angles)
Beispiel #4
0
 def grid(self, ngrid=30):
     x1 = np.linspace(self.lim['x1'][0], self.lim['x1'][1], ngrid)
     x2 = np.linspace(self.lim['x2'][0], self.lim['x2'][1], ngrid)
     (x1, x2) = np.meshgrid(x1, x2)
     x1r = x1.reshape((-1, 1));
     x2r = x2.reshape((-1, 1));
     x = np.concatenate((x1r, x2r), 1)
     if self.type == 'fun':
         y = self.fun.eval(x)
     else:
         y = self.model.sample(x)
     y = y.reshape((ngrid, ngrid))
     return (x1, x2, y)
Beispiel #5
0
 def grid(self, ngrid=30):
     x1 = np.linspace(self.lim['x1'][0], self.lim['x1'][1], ngrid)
     x2 = np.linspace(self.lim['x2'][0], self.lim['x2'][1], ngrid)
     (x1, x2) = np.meshgrid(x1, x2)
     x1r = x1.reshape((-1, 1))
     x2r = x2.reshape((-1, 1))
     x = np.concatenate((x1r, x2r), 1)
     if self.type == 'fun':
         y = self.fun.eval(x)
     else:
         y = self.model.sample(x)
     y = y.reshape((ngrid, ngrid))
     return (x1, x2, y)
	def fit(self, X):
		self.X = X
		if self.ivalues is None:
			self._set_ivalues()

		converged = False
		iteration = 0
		d = self.X.shape[1]
		while not converged and iteration < self.max_iterations:
			priors = concatenate([self._prior(component) for component in range(self.components)], axis=1)
			set_trace()
			new_priors = np.asarray([np.sum(priors[:,component])/self.X.shape[0] for component in range(self.components)])
			new_mus = np.asarray([np.sum(priors[:,[component]] * self.X, axis=0)/np.sum(priors[:,component]) for component in range(self.components)])
			new_sigmas = concatenate([sum(np.reshape((np.dot((self.X[[n],:] - self.mus[[component],:]).transpose(), (self.X[[n],:] - self.mus[[component],:]))*priors[n,component]),(d,d,1)) for n in range(X.shape[0])) for component in range(self.components)],axis=2)

			# converged = np.abs(self._log_likelihood(self.X, new_mus, new_sigmas, new_priors) - self._log_likelihood(self.X, self.mus, self.sigmas, self.priors)) < self.tolerance

			self.priors = new_priors
			self.mus = new_mus
			self.sigmas = new_sigmas

			iteration+=1
Beispiel #7
0
 def add(self, x, y, update=True):
     x = np.asmatrix(x)
     y = np.asmatrix(y)
     if x.shape[1] != self.d:
         if x.shape[0] == self.d:
             x = x.T
         else:
             raise Exception('Invalid train-set (x) dimension -- '
                             'expected d = ' + str(self.d) + '.')
     if y.shape[1] != 1:
         if y.shape[0] == 1:
             y = y.T
         else:
             raise Exception('Invalid train-set (y) dimension -- '
                             'expected d = 1.')
     if y.shape[0] != x.shape[0]:
         raise Exception('Incompatible train-set (x, y) lengths.')
     x = np.asmatrix(x)
     y = np.asmatrix(y)
     if x.shape[0] > 0:
         self.x = np.concatenate((self.x, x))
         self.y = np.concatenate((self.y, y))
     if update:
         self._update()
def permutation_matrix(dim):
    '''
    Generate haar permuation matrix.
    '''
    I = M.eye(dim, dim)
    return M.concatenate((I[::2][:], I[1::2][:]))