示例#1
0
    def test_randomize_extra_entries_bm(self, its=50):
        for it in range(its):
            size = random.choice([0, 1, randint(0, 10), randint(0, 100)])
            mat_bm = gen_BandMat_simple(size)

            mat_full = mat_bm.full()
            th.randomize_extra_entries_bm(mat_bm)
            th.assert_allequal(mat_bm.full(), mat_full)
示例#2
0
def gen_symmetric_BandMat(size, depth=None, transposed=None):
    if depth is None:
        depth = random.choice([0, 1, randint(0, 10)])
    if transposed is None:
        transposed = rand_bool()
    a_bm = gen_BandMat(size, l=depth, u=depth, transposed=transposed)
    b_bm = a_bm + a_bm.T
    randomize_extra_entries_bm(b_bm)
    return b_bm
示例#3
0
def gen_symmetric_BandMat(size, depth=None, transposed=None):
    if depth is None:
        depth = random.choice([0, 1, randint(0, 10)])
    if transposed is None:
        transposed = rand_bool()
    a_bm = gen_BandMat(size, l=depth, u=depth, transposed=transposed)
    b_bm = a_bm + a_bm.T
    randomize_extra_entries_bm(b_bm)
    return b_bm
示例#4
0
def gen_pos_def_BandMat(size, depth=None, contrib_rank=2, transposed=None):
    """Generates a random positive definite BandMat."""
    assert contrib_rank >= 0
    if depth is None:
        depth = random.choice([0, 1, randint(0, 10)])
    if transposed is None:
        transposed = rand_bool()
    mat_bm = bm.zeros(depth, depth, size)
    for _ in range(contrib_rank):
        diff = randint(0, depth + 1)
        chol_bm = gen_BandMat(size, l=depth - diff, u=diff)
        bm.dot_mm_plus_equals(chol_bm, chol_bm.T, mat_bm)
    if transposed:
        mat_bm = mat_bm.T
    randomize_extra_entries_bm(mat_bm)
    return mat_bm
示例#5
0
def gen_pos_def_BandMat(size, depth=None, contrib_rank=2, transposed=None):
    """Generates a random positive definite BandMat."""
    assert contrib_rank >= 0
    if depth is None:
        depth = random.choice([0, 1, randint(0, 10)])
    if transposed is None:
        transposed = rand_bool()
    mat_bm = bm.zeros(depth, depth, size)
    for _ in range(contrib_rank):
        diff = randint(0, depth + 1)
        chol_bm = gen_BandMat(size, l=depth - diff, u=diff)
        bm.dot_mm_plus_equals(chol_bm, chol_bm.T, mat_bm)
    if transposed:
        mat_bm = mat_bm.T
    randomize_extra_entries_bm(mat_bm)
    return mat_bm
示例#6
0
def gen_chol_factor_BandMat(size, depth=None, contrib_rank=2, transposed=None):
    """Generates a random Cholesky factor BandMat.

    This works by generating a random positive definite matrix and then
    computing its Cholesky factor, since using a random matrix as a Cholesky
    factor seems to often lead to ill-conditioned matrices.
    """
    if transposed is None:
        transposed = rand_bool()
    mat_bm = gen_pos_def_BandMat(size, depth=depth, contrib_rank=contrib_rank)
    chol_bm = bla.cholesky(mat_bm, lower=rand_bool())
    if transposed:
        chol_bm = chol_bm.T
    assert chol_bm.l == 0 or chol_bm.u == 0
    assert chol_bm.l + chol_bm.u == mat_bm.l
    randomize_extra_entries_bm(chol_bm)
    return chol_bm
示例#7
0
def gen_chol_factor_BandMat(size, depth=None, contrib_rank=2, transposed=None):
    """Generates a random Cholesky factor BandMat.

    This works by generating a random positive definite matrix and then
    computing its Cholesky factor, since using a random matrix as a Cholesky
    factor seems to often lead to ill-conditioned matrices.
    """
    if transposed is None:
        transposed = rand_bool()
    mat_bm = gen_pos_def_BandMat(size, depth=depth, contrib_rank=contrib_rank)
    chol_bm = bla.cholesky(mat_bm, lower=rand_bool())
    if transposed:
        chol_bm = chol_bm.T
    assert chol_bm.l == 0 or chol_bm.u == 0
    assert chol_bm.l + chol_bm.u == mat_bm.l
    randomize_extra_entries_bm(chol_bm)
    return chol_bm