def get_K(self, t): with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=PendingDeprecationWarning) K = np.linalg.inv(np.matlib.eye(self.A.shape[0]) - t * self.A) return np.array(np.log(K))
def get_K(self, t): with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=PendingDeprecationWarning) K = _KernelR.mat_exp(t * self.A) return np.array(np.log(K))
def make_legitimate_covariance_matrix(ndim=3, lo=2, hi=15) -> list: from numpy import zeros, int16 from numpy.random import multivariate_normal, randint from numpy import warnings n = ndim for _ in range(100000): mx = zeros(shape=(n, n), dtype=int16) for i in range(n): for j in range(i, n): mx[i, j:] = randint(lo, hi, size=len(mx[i, j:])) cm = mx | mx.transpose() with warnings.catch_warnings(): warnings.filterwarnings('error') try: mx = multivariate_normal(mean=[ 0, ] * n, cov=cm, size=200) print(cm) return cm.tolist() break except RuntimeWarning: continue else: from warnings import warn warn("failed to find a covariance matrix. try again", Warning) return None
def my_read_array(f): with warnings.catch_warnings(): # prevent numpy from outputting empty array warning warnings.simplefilter("ignore") res = np.loadtxt(f) if np.array_equal(np.round(res),res): return res.astype(int) else: return res
def my_read_array(f): with warnings.catch_warnings( ): # prevent numpy from outputting empty array warning warnings.simplefilter("ignore") res = np.loadtxt(f) if np.array_equal(np.round(res), res): return res.astype(int) else: return res
def get_K(self, t): with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=PendingDeprecationWarning) K = _KernelR.mat_exp(-t * self.Ll, n=50) if np.any(K < 0): # logging.info(t, "K < 0") return None return np.array(np.log(K))
def get_K(self, alpha): with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=PendingDeprecationWarning) K = np.linalg.inv(self.D - alpha * self.A) if np.any(K < 0): # logging.info(alpha, "K < 0") return None return np.array(np.log(K))
def get_K(self, beta): with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=PendingDeprecationWarning) K = np.linalg.inv(np.matlib.eye(self.A.shape[0]) + beta * self.L) if np.any(K < 0): # logging.info(beta, "K < 0") return None return np.array(np.log(K))
def make_multidim_blobs(n_blobs=3, n_points=100, n_dim=3, range=100, relative_dispersion=10): import builtins from numpy import zeros, float16, warnings, diag, abs, uint8, argsort from numpy.random import randint, multivariate_normal m = n_points // n_blobs working_range = 100 σ2 = (working_range / (n_blobs + 1)**(1 / n_dim) / relative_dispersion)**2 σ2 = int(σ2 * 0.5), int(σ2 * 1.5) X = zeros(shape=(m * n_blobs, n_dim), dtype=float16) y = zeros(shape=X.shape[0], dtype=uint8) with warnings.catch_warnings(): warnings.filterwarnings("error") for i in builtins.range(n_blobs): while True: diagonal = randint(*σ2, size=n_dim) mx = diag(diagonal) [ mx.__setitem__([i, slice(0, i, None)], randint(-1, 1, size=n_dim)[:i]) for i in builtins.range(n_dim) ] Σ = mx | mx.T μ = randint(0, working_range, size=n_dim) try: mx = multivariate_normal(mean=μ, cov=Σ, size=m) break except RuntimeWarning: continue X[i * m:i * m + m, :] = mx y[i * m:i * m + m] = i #the last touches X += abs(X.min()) X *= range / X.max() nx = argsort(X[:, 0]) X = X[nx] y = y[nx] return X, y
def _update_actor(self): number_of_points = self._vtk_points.GetNumberOfPoints() cells = hstack((ones((number_of_points, 1), dtype=int64), arange(number_of_points).reshape(-1, 1))) cells = ascontiguousarray(cells, dtype=int64) with warnings.catch_warnings(): #see issue #8 warnings.simplefilter("ignore", FutureWarning) cell_array = numpy_support.numpy_to_vtk( num_array=cells, deep=True, array_type=VTK_ID_TYPE) vtk_cells = vtkCellArray() vtk_cells.SetCells(number_of_points, cell_array) vtk_poly = vtkPolyData() vtk_poly.SetPoints(self._vtk_points) vtk_poly.SetVerts(vtk_cells) vtk_mapper = vtkPolyDataMapper() vtk_mapper.SetInputData(vtk_poly) self.actor.SetMapper(vtk_mapper)