コード例 #1
0
ファイル: test_ssvd.py プロジェクト: muddimedia/spartan-1
def benchmark_ssvd(ctx, timer):
  expr.set_random_seed()
  DIM = (1280, 1280)
  #A = expr.randn(*DIM, dtype=np.float64)
  A = np.random.randn(*DIM)
  A = expr.from_numpy(A)
  t1 = datetime.now()
  U,S,VT = svd(A)
  t2 = datetime.now()
  cost_time = millis(t1, t2)

  print "total cost time:%s ms" % (cost_time)
コード例 #2
0
def benchmark_pca(ctx, timer):
  expr.set_random_seed()
  DIM = (1280, 512)
  data = np.random.randn(*DIM)
  A = expr.from_numpy(data)
  #A = expr.randn(*DIM, dtype=np.float64)
  t1 = datetime.now()
  m = PCA(N_COMPONENTS)
  m.fit(A)
  t2 = datetime.now()
  cost_time = millis(t1, t2)

  print "total cost time:%s ms" % (cost_time)
コード例 #3
0
  def test_pca(self):
    expr.set_random_seed()
    FLAGS.opt_parakeet_gen = 0
    data = np.random.randn(*DIM)
    A = expr.from_numpy(data, tile_hint=util.calc_tile_hint(DIM, axis=0))

    m = PCA(N_COMPONENTS)
    m2 = SK_PCA(N_COMPONENTS)

    m.fit(A)
    m2.fit(data)
    print m2.components_ - m.components_
    assert np.allclose(absolute(m.components_), absolute(m2.components_))
コード例 #4
0
ファイル: test_ssvd.py プロジェクト: muddimedia/spartan-1
  def test_ssvd(self):
    expr.set_random_seed()
    ctx = blob_ctx.get()
    # Create a sparse matrix.
    A = expr.randn(*DIM, tile_hint = (int(DIM[0]/ctx.num_workers), DIM[1]),
                   dtype=np.float64)

    U,S,VT = svd(A)
    U2,S2,VT2 = linalg.svd(A.glom(), full_matrices=0)

    assert np.allclose(absolute(U.glom()), absolute(U2))
    assert np.allclose(absolute(S), absolute(S2))
    assert np.allclose(absolute(VT), absolute(VT2))