Esempio n. 1
0
def test_cart_prod():
    x = irm.cart_prod([5, 8, 12])
    set_x = set(tuple(a) for a in x)
    assert_equal(len(x), 5*8*12)
    assert_equal(len(x), len(set_x))
    assert_equal(set_x, set(util.cart_prod([range(5), range(8), range(12)])))

    # test with singletons
    x = irm.cart_prod([5, 1, 1])
    set_x = set(tuple(a) for a in x)
    assert_equal(len(x), 5*1*1)
    assert_equal(len(x), len(set_x))
    assert_equal(set_x, set(util.cart_prod([range(5), range(1), range(1)])))
Esempio n. 2
0
def test_cart_prod():
    x = irm.cart_prod([5, 8, 12])
    set_x = set(tuple(a) for a in x)
    assert_equal(len(x), 5 * 8 * 12)
    assert_equal(len(x), len(set_x))
    assert_equal(set_x, set(util.cart_prod([range(5), range(8), range(12)])))

    # test with singletons
    x = irm.cart_prod([5, 1, 1])
    set_x = set(tuple(a) for a in x)
    assert_equal(len(x), 5 * 1 * 1)
    assert_equal(len(x), len(set_x))
    assert_equal(set_x, set(util.cart_prod([range(5), range(1), range(1)])))
Esempio n. 3
0
import numpy as np
from irm import util

def grid_gibbs(set_func, get_score, vals_list):
    scores = []
    for v in vals_list:
        set_func(v)
        scores.append(get_score())
    i = util.sample_from_scores(scores)
    set_func(vals_list[i])


    
DEFAULT_RELATION_GRIDS = {}
DEFAULT_RELATION_GRIDS['BetaBernoulli'] =  [{'alpha' : a, 'beta' : b} for a, b in util.cart_prod([[0.1, 0.5, 1.0, 2.0, 5.0], [0.1, 0.5, 1.0, 2.0, 5.0]])]
DEFAULT_RELATION_GRIDS['BetaBernoulliNonConj'] =  [{'alpha' : a, 'beta' : b} for a, b in util.cart_prod([[0.1, 0.5, 1.0, 2.0, 5.0], [0.1, 0.5, 1.0, 2.0, 5.0]])]

DEFAULT_RELATION_GRIDS['GammaPoisson'] =  [{'alpha' : a, 'beta' : b} for a, b in util.cart_prod([[0.1, 0.5, 1.0, 2.0, 5.0, 10.0], [0.1, 0.5, 1.0, 2.0, 5.0, 10.0]])]

def default_grid_logistic_distance(scale=1.0):
    space_vals =  np.logspace(-1.5, 1.8, 10)*scale
    p_mins = np.array([0.001, 0.01, 0.02])
    p_maxs = np.array([0.90, 0.80, 0.50, 0.20])
    res = []
    for s in space_vals:
        for p_min in p_mins:
            for p_max in p_maxs:
                res.append({'lambda_hp' : s, 'mu_hp' : s, 
                           'p_min' : p_min, 'p_max' : p_max})
    return res
Esempio n. 4
0

def grid_gibbs(set_func, get_score, vals_list):
    scores = []
    for v in vals_list:
        set_func(v)
        scores.append(get_score())
    i = util.sample_from_scores(scores)
    set_func(vals_list[i])


DEFAULT_RELATION_GRIDS = {}
DEFAULT_RELATION_GRIDS['BetaBernoulli'] = [{
    'alpha': a,
    'beta': b
} for a, b in util.cart_prod([[0.1, 0.5, 1.0, 2.0, 5.0],
                              [0.1, 0.5, 1.0, 2.0, 5.0]])]
DEFAULT_RELATION_GRIDS['BetaBernoulliNonConj'] = [{
    'alpha': a,
    'beta': b
} for a, b in util.cart_prod([[0.1, 0.5, 1.0, 2.0, 5.0],
                              [0.1, 0.5, 1.0, 2.0, 5.0]])]

DEFAULT_RELATION_GRIDS['GammaPoisson'] = [{
    'alpha': a,
    'beta': b
} for a, b in util.cart_prod([[0.1, 0.5, 1.0, 2.0, 5.0, 10.0],
                              [0.1, 0.5, 1.0, 2.0, 5.0, 10.0]])]


def default_grid_logistic_distance(scale=1.0):
    space_vals = np.logspace(-1.5, 1.8, 10) * scale