コード例 #1
0
def exercise_random():
    from scitbx.random import variate, uniform_distribution

    g = random_matrices = variate(
        sparse.matrix_distribution(5,
                                   3,
                                   density=0.4,
                                   elements=uniform_distribution(min=-1,
                                                                 max=0.5)))
    for a in itertools.islice(g, 10):
        assert a.n_rows == 5 and a.n_cols == 3
        assert approx_equal(a.non_zeroes, a.n_rows * a.n_cols * 0.4, eps=1)
        for j in range(a.n_cols):
            for i, x in a.col(j):
                assert -1 <= x < 0.5, (i, j, x)

    g = random_vectors = variate(
        sparse.vector_distribution(6,
                                   density=0.3,
                                   elements=uniform_distribution(min=-2,
                                                                 max=2)))
    for v in itertools.islice(g, 10):
        assert v.size == 6
        assert approx_equal(v.non_zeroes, v.size * 0.3, eps=1)
        for i, x in v:
            assert -2 <= x < 2, (i, j, x)
コード例 #2
0
def exercise_matrix_x_vector():
  from scitbx.random import variate, uniform_distribution
  for m,n in [(5,5), (3,5), (5,3)]:
    random_vectors = variate(
      sparse.vector_distribution(
        n, density=0.4,
        elements=uniform_distribution(min=-2, max=2)))
    random_matrices = variate(
      sparse.matrix_distribution(
        m, n, density=0.3,
        elements=uniform_distribution(min=-2, max=2)))
    for n_test in xrange(50):
      a = random_matrices.next()
      x = random_vectors.next()
      y = a*x
      aa = a.as_dense_matrix()
      xx = x.as_dense_vector()
      yy1 = y.as_dense_vector()
      yy2 = aa.matrix_multiply(xx)
      assert approx_equal(yy1,yy2)

  for m,n in [(5,5), (3,5), (5,3)]:
    random_matrices = variate(
      sparse.matrix_distribution(
        m, n, density=0.4,
        elements=uniform_distribution(min=-2, max=2)))
    for n_test in xrange(50):
      a = random_matrices.next()
      x = flex.random_double(n)
      y = a*x
      aa = a.as_dense_matrix()
      yy = aa.matrix_multiply(x)
      assert approx_equal(y, yy)
コード例 #3
0
 def linear_combination_trial_vectors():
   u = sparse.vector(8, {1: 1.1, 3: 1.3})
   v = sparse.vector(8, {0: 2.0, 2: 2.2, 3: 2.3, 4: 2.4})
   w = list(-2*u.as_dense_vector() + 3*v.as_dense_vector())
   yield u, v, w
   random_vectors = scitbx.random.variate(
     sparse.vector_distribution(
       8, density=0.4,
       elements=scitbx.random.uniform_distribution(min=-2, max=2)))
   u = random_vectors.next()
   v = random_vectors.next()
   w = list(-2*u.as_dense_vector() + 3*v.as_dense_vector())
   yield u, v, w
コード例 #4
0
ファイル: tst_sparse.py プロジェクト: cctbx/cctbx-playground
def exercise_random():
  from scitbx.random import variate, uniform_distribution

  g = random_matrices = variate(
      sparse.matrix_distribution(
        5, 3, density=0.4,
        elements=uniform_distribution(min=-1, max=0.5)))
  for a in itertools.islice(g, 10):
    assert a.n_rows== 5 and a.n_cols == 3
    assert approx_equal(a.non_zeroes, a.n_rows*a.n_cols*0.4, eps=1)
    for j in xrange(a.n_cols):
      for i,x in a.col(j):
        assert -1 <= x < 0.5, (i,j, x)

  g = random_vectors = variate(
      sparse.vector_distribution(
        6, density=0.3,
        elements=uniform_distribution(min=-2, max=2)))
  for v in itertools.islice(g, 10):
    assert v.size == 6
    assert approx_equal(v.non_zeroes, v.size*0.3, eps=1)
    for i,x in v:
      assert -2 <= x < 2, (i,j, x)