def ho_svd(self): X = square_tensor_gen(self.n, self.rank, dim=self.dim, typ=self.gen_typ, noise_level=self.noise_level) start_time = time.time() core, tucker_factors = tucker( X, ranks=[self.rank for _ in range(self.dim)], init='random') X_hat = tl.tucker_to_tensor(core, tucker_factors) running_time = time.time() - start_time rerr = eval_mse(X, X_hat) return (-1, running_time), rerr
def two_pass(self): X = square_tensor_gen(self.n, self.rank, dim=self.dim, typ=self.gen_typ, noise_level=self.noise_level) start_time = time.time() sketch = Sketch(X, self.k, random_seed=None) sketchs, _, = sketch.get_sketchs() sketch_time = time.time() - start_time start_time = time.time() sketch_two_pass = SketchTwoPassRecover(X, sketchs, self.rank) X_hat, _, _ = sketch_two_pass.recover() recover_time = time.time() - start_time rerr = eval_mse(X, X_hat) return (sketch_time, recover_time), rerr
def one_pass(self): X = square_tensor_gen(self.n, self.rank, dim=self.dim, typ=self.gen_typ, noise_level=self.noise_level) start_time = time.time() sketch = Sketch(X, self.k, s=self.s, random_seed=self.random_seed) sketchs, core_sketch, = sketch.get_sketchs() sketch_time = time.time() - start_time start_time = time.time() sketch_one_pass = SketchOnePassRecover(sketchs, core_sketch, self.Tinfo_bucket, self.Rinfo_bucket) X_hat, _, _ = sketch_one_pass.recover() recover_time = time.time() - start_time rerr = eval_mse(X, X_hat) return (sketch_time, recover_time), rerr
reduxs2 = [redux1, redux6, redux7] sims_colspace4 = Simulations(X, reduxs2) sims_colspace4_result = sims_colspace4.run_colspace_varyk(ks) pickle.dump(sims_colspace4_result, open("data/col_dim"+str(dim)+"_krao_m"+str(m)+".pickle", "wb" )) # sims_colspace4_result = pickle.load( open("data/col_dim"+str(dim)+"_krao_m"+str(m)+".pickle", "rb" ) ) # sims_colspace4.plot_colspace_varyk(sims_colspace4_result, ks, ["Gaussian","Gaussian Khatri-Rao", "Gaussian Khatri-Rao Variance Reduced"], str(dim)+"-D "+dim_str(n,dim)+" Tensor Sketching: m = "+str(m),"col_dim"+ str(dim)+"_krao_m"+str(m)) ''' # In[ ]: k = 30 n = 100 dim = 4 X0 = square_tensor_gen(n, r = 5, dim = dim, typ = 'lk', noise_level=0.1)[0] X = tl.unfold(X0,mode = 0).T m = X.shape[0] krao_ms = np.repeat(int(np.sqrt(n)),2*(dim - 1)) ks = np.arange(5,30,5) redux1 = DimRedux('g',k, m) redux2 = DimRedux('u',k, m) redux3 = DimRedux('sgn',k, m) redux4 = DimRedux('sp0',k, m) redux5 = DimRedux('sp1',k, m) redux6 = DimRedux('g',k, m, krao = True, krao_ms = krao_ms) redux7 = DimRedux('g',k, m, krao = True, krao_ms = krao_ms, vr = True, vr_typ = 'geom_median_l2') reduxs1 = [redux1, redux2, redux3, redux4, redux5] reduxs2 = [redux1, redux6, redux7]
self.core_tensor, np.linalg.pinv(np.dot(phis[mode_n], Qs[mode_n])), mode=mode_n) core_tensor, factors = tucker(self.core_tensor, ranks=[self.rank for _ in range(dim)]) self.core_tensor = core_tensor for n in range(dim): self.arms.append(np.dot(Qs[n], factors[n])) X_hat = tl.tucker_to_tensor(self.core_tensor, self.arms) return X_hat, self.arms, self.core_tensor from util import square_tensor_gen from sketch import * if __name__ == "__main__": tl.set_backend('numpy') X = square_tensor_gen(10, 3, dim=3, typ='spd', noise_level=0.1) print(tl.unfold(X, mode=1).shape) tensor_sketch = Sketch(X, 5, random_seed=1, s=-1, typ='g', sparse_factor=0.1) sketchs, core_sketch = tensor_sketch.get_sketchs() SketchTwoPassRecover(tensor_sketch, np.repeat(3, 3)) # SketchOnePassRecover(tensor_sketch)