Ejemplo n.º 1
0
def dirichlet(name, arity, pdomain):
    """
    Generate a CPD where each value is the cumulative distribution of 
    the categorical random variable given the parents configuration as the key.

    In this case, we will use a random distribution for each state of the 
    parents variables.
    """
    params = {}
    for key in fast_space_iterator(pdomain):
        params[key] = np.random.dirichlet([1.] * (arity))[:-1]
    return CPD(name, arity, params, pdomain)
Ejemplo n.º 2
0
def dirichlet(name, arity, pdomain):
    """
    Generate a CPD where each value is the cumulative distribution of 
    the categorical random variable given the parents configuration as the key.

    In this case, we will use a random distribution for each state of the 
    parents variables.
    """
    params = {}
    for key in fast_space_iterator(pdomain):
        params[key] = np.random.dirichlet([1.]*(arity))[:-1]
    return CPD(name, arity, params, pdomain)
Ejemplo n.º 3
0
def noisylogic(name, arity, pdomain):
    """
    Generate a CPD where each value is the cumulative distribution of 
    the categorical random variable given the parents configuration as the key.

    In this case, we want to pick a random logic function, and then return that.

    Assuming binary valued nodes for now.
    """
    eps = 0.1
    if pdomain == {}:
        if np.random.rand() < 0.5:
            params = {(): np.array([ra.choice([0 + eps, 1 - eps])])}
        else:
            params = {(): np.array([0.5])}
    else:
        params = {}
        for key in fast_space_iterator(pdomain):
            params[key] = np.array([ra.choice([0 + eps, 1 - eps])])
    return CPD(name, arity, params, pdomain)
Ejemplo n.º 4
0
def noisylogic(name, arity, pdomain):
    """
    Generate a CPD where each value is the cumulative distribution of 
    the categorical random variable given the parents configuration as the key.

    In this case, we want to pick a random logic function, and then return that.

    Assuming binary valued nodes for now.
    """
    eps = 0.1
    if pdomain == {}:
        if np.random.rand() < 0.5:
            params = {(): np.array([ra.choice([0+eps, 1-eps])])}
        else:
            params = {(): np.array([0.5])}
    else:
        params = {}
        for key in fast_space_iterator(pdomain):
            params[key] = np.array([ra.choice([0+eps, 1-eps])])
    return CPD(name, arity, params, pdomain)