def __init__(self): app.Canvas.__init__(self, position=(50, 50), keys='interactive') ps = self.pixel_scale # Load the Iris dataset and normalize. iris = load_iris() position = iris['data'].astype(np.float32) n, ndim = position.shape position -= position.mean() position /= np.abs(position).max() v_position = position * .75 v_color = ColorArray(['orange', 'magenta', 'darkblue']) v_color = v_color.rgb[iris['group'], :].astype(np.float32) v_color *= np.random.uniform(.5, 1.5, (n, 3)) v_color = np.clip(v_color, 0, 1) v_size = np.random.uniform(2 * ps, 12 * ps, (n, 1)).astype(np.float32) self.program = gloo.Program(VERT_SHADER, FRAG_SHADER) self.program['a_position'] = gloo.VertexBuffer(v_position) self.program['a_color'] = gloo.VertexBuffer(v_color) self.program['a_size'] = gloo.VertexBuffer(v_size) self.program['u_pan'] = (0., 0.) self.program['u_scale'] = (1., 1.) self.program['u_vec1'] = (1., 0., 0., 0.) self.program['u_vec2'] = (0., 1., 0., 0.) # Circulant matrix. circ = np.diagflat(np.ones(ndim - 1), 1) circ[-1, 0] = -1 if ndim % 2 == 0 else 1 self.logcirc = logm(circ) # We will solve the equation dX/dt = log(circ) * X in real time # to compute the matrix exponential expm(t*log(circ)). self.mat = np.eye(ndim) self.dt = .001 gloo.set_state(clear_color=(1, 1, 1, 1), blend=True, blend_func=('src_alpha', 'one_minus_src_alpha')) gloo.set_viewport(0, 0, *self.physical_size) self._timer = app.Timer('auto', connect=self.on_timer, start=True) self.show()
def __init__(self): app.Canvas.__init__(self, position=(50, 50), keys='interactive') ps = self.pixel_scale # Load the Iris dataset and normalize. iris = load_iris() position = iris['data'].astype(np.float32) n, ndim = position.shape position -= position.mean() position /= np.abs(position).max() v_position = position*.75 v_color = ColorArray(['orange', 'magenta', 'darkblue']) v_color = v_color.rgb[iris['group'], :].astype(np.float32) v_color *= np.random.uniform(.5, 1.5, (n, 3)) v_color = np.clip(v_color, 0, 1) v_size = np.random.uniform(2*ps, 12*ps, (n, 1)).astype(np.float32) self.program = gloo.Program(VERT_SHADER, FRAG_SHADER) self.program['a_position'] = gloo.VertexBuffer(v_position) self.program['a_color'] = gloo.VertexBuffer(v_color) self.program['a_size'] = gloo.VertexBuffer(v_size) self.program['u_pan'] = (0., 0.) self.program['u_scale'] = (1., 1.) self.program['u_vec1'] = (1., 0., 0., 0.) self.program['u_vec2'] = (0., 1., 0., 0.) # Circulant matrix. circ = np.diagflat(np.ones(ndim-1), 1) circ[-1, 0] = -1 if ndim % 2 == 0 else 1 self.logcirc = logm(circ) # We will solve the equation dX/dt = log(circ) * X in real time # to compute the matrix exponential expm(t*log(circ)). self.mat = np.eye(ndim) self.dt = .001 gloo.set_state(clear_color=(1, 1, 1, 1), blend=True, blend_func=('src_alpha', 'one_minus_src_alpha')) gloo.set_viewport(0, 0, *self.physical_size) self._timer = app.Timer('auto', connect=self.on_timer, start=True) self.show()
# -*- coding: utf-8 -*- # vispy: gallery 2000 """N-dimensional scatter plot with GPU-based projections. The projection axes evolve smoothly over time, following a path on the Lie group SO(n). """ from vispy import gloo from vispy import app from vispy.color import ColorArray from vispy.io import load_iris import numpy as np from scipy.linalg import logm # Load the Iris dataset and normalize. iris = load_iris() position = iris['data'].astype(np.float32) n, ndim = position.shape position -= position.mean() position /= np.abs(position).max() v_position = position * .75 v_color = ColorArray(['orange', 'magenta', 'darkblue']) v_color = v_color.rgb[iris['group'], :].astype(np.float32) v_color *= np.random.uniform(.5, 1.5, (n, 3)) v_color = np.clip(v_color, 0, 1) v_size = np.random.uniform(2, 12, (n, 1)).astype(np.float32) VERT_SHADER = """ #version 120 attribute vec4 a_position;
>>> op = OrthogonalPath(mat1, mat2) >>> mat = op(t) """ def __init__(self, mat, origin=None): if origin is None: origin = np.eye(len(mat)) self.a, self.b = np.matrix(origin), np.matrix(mat) self._logainvb = logm(self.a.I * self.b) def __call__(self, t): return np.real(self.a * expm(t * self._logainvb)) # Load the Iris dataset and normalize. iris = load_iris() position = iris['data'].astype(np.float32) n, ndim = position.shape position -= position.mean() position /= np.abs(position).max() v_position = position*.75 v_color = ColorArray(['orange', 'magenta', 'darkblue']) v_color = v_color.rgb[iris['group'], :].astype(np.float32) v_color *= np.random.uniform(.5, 1.5, (n, 3)) v_color = np.clip(v_color, 0, 1) v_size = np.random.uniform(2, 12, (n, 1)).astype(np.float32) VERT_SHADER = """ #version 120 attribute vec4 a_position;