def _make(self, fig): sh = DATA.getFigure(fig) for i in range(4): peice = sh[i] self.shape.append([peice[0], peice[1]]) self.position.append([peice[0] + 1, peice[1] + 1]) self.color = DATA.getColor(fig)
def paintEvent(self, e): qp = QPainter() qp.begin(self) qp.setPen(QColor(200, 100, 100)) for i in range(200): x = i % 10 y = (i - x) // 10 if self.board[i] != 0: tpl = DATA.getColor(self.board[i]) qp.setBrush(QColor(tpl[0], tpl[1], tpl[2])) qp.drawRect(x * self.cube, y * self.cube, self.cube, self.cube) qp.setBrush( QColor(self.figure.color[0], self.figure.color[1], self.figure.color[2])) for i in range(4): qp.drawRect(self.figure.position[i][0] * self.cube, self.figure.position[i][1] * self.cube, self.cube, self.cube) qp.drawLine(self.width() - 1, 0, self.width() - 1, self.height()) qp.drawLine(0, self.height() - 1, self.width(), self.height() - 1) qp.end()
import matplotlib.pyplot as plt import numpy as np from Data import DATA from Sketching_methods import gaussian_projection from Sketching_methods import hadamard_projection # Parameters c = np.linspace(0.1, 1, 20) rep = 50 track_msd = np.zeros((20, 2)) track_flight = np.zeros((20, 2)) # MSD n = 2000 np.random.seed(13) data = DATA(type='MSD', n=n, p=90) i = 0 for xi in c: print(i) r = int(n * xi) for k in range(rep): track_msd[i, 0] = track_msd[i, 0] + gaussian_projection(data, r)[2] track_msd[i, 1] = track_msd[i, 1] + hadamard_projection(data, r)[2] i = i + 1 track_msd = track_msd / rep # nycflight np.random.seed(130) data = DATA(type='nycflight', n=2000, p=21) i = 0 for xi in c:
gamma = p / n np.random.seed(130) X = np.random.randn(n, p) beta = np.random.rand(p, 1) rep = 50 c = np.linspace(0.1, 1, 20) track = np.empty((20, 4)) # uniform sampling i = 0 for xi in c: print(i) r = int(n * xi) vpro = np.empty((rep, 4)) for k in range(rep): data = DATA(type='Gaussian', n=n, p=p, X=X, beta=beta) vpro[k, :] = uniform_sampling(data, r) track[i, :] = np.mean(vpro, axis=0) i = i + 1 # Figure 7 d = np.linspace(0.15, 1, 500) plt.figure(0, figsize=(10, 8)) p11 = plt.subplot(221) p11.cla() p11.scatter(c[1:], track[1:, 0], label='Simulation') p11.plot(d, (1-gamma)/(d-gamma), label=r'Theory: $\frac{n-p}{r-p}$') p11.grid(linestyle='dotted') p11.set_ylabel('VE', fontsize=13) p11.legend()
def dropFigure(self): color = DATA.getColors().index(self.figure.color) for i in range(4): coord = self.figure.position[i][0] + self.figure.position[i][1] * 10 self.board[coord] = color