Exemplo n.º 1
0
def c_class_neighbors(SIDE_N, class_connectivity, 
                      JITTER = 0.0, default_param=0.01, obsmodel=None):

    """
    for each of c classes, we create a grid of SIDE_N x SIDE_N
    and then use the class_connectivity dictionary to set up 
    threshold connectivity

    class_connectivity = {(c1, c2) : (threshold, param), 
                          }
    PROX: proximitiy of neighbors
    
    Planar

    returns nodes, connectivity -- note that connectivity is really observations

    """ 
    
    CLASS_N = np.max(np.array([class_connectivity.keys()]).flatten()) + 1

    nodes = create_nodes_grid(SIDE_N, CLASS_N, JITTER)

    def node_pred(c1, pos1, c2, pos2):

        for (c1_t, c2_t), (thold, params) in class_connectivity.iteritems():
            if (c1 == c1_t) and (c2 == c2_t):
                d = dist(pos1, pos2)
                if d < thold:
                    return params
            
        return default_param 

    observations = synth.connect(nodes, node_pred, obsmodel)

    return nodes, observations
Exemplo n.º 2
0
def c_mixed_dist_block(SIDE_N, class_connectivity, 
                       JITTER = 0.0, rand_conn_prob = 0.01, 
                       obsmodel = None):

    """
    Mixed membership 

    class_connectivity = {(c1, c2) : ('p', prob), 
                          (c2, c3) : ('d', dist, prob)
                          }

    """ 
    
    CLASS_N = np.max(np.array([class_connectivity.keys()]).flatten()) + 1

    nodes = create_nodes_grid(SIDE_N, CLASS_N, JITTER)

    def node_pred(c1, pos1, c2, pos2):

        for (c1_t, c2_t), v in class_connectivity.iteritems():
            if (c1 == c1_t) and (c2 == c2_t):
                if v[0] == 'p' :
                    return v[1]
                else :
                    thold = v[1]
                    prob = v[2]
                    d = dist(pos1, pos2)
                    if d < thold:
                        return prob
            
        return rand_conn_prob

    connectivity = synth.connect(nodes, node_pred, obsmodel)

    return nodes, connectivity
Exemplo n.º 3
0
def c_bump_dist_block(SIDE_N, class_connectivity, 
                      JITTER = 0.0, rand_conn_prob = 0.01, 
                      p_min = 0.01, obsmodel=None):

    """
    Mixed membership 

    class_connectivity = {(c1, c2) : (dist, prob, width), 
                          }

    """ 
    
    CLASS_N = np.max(np.array([class_connectivity.keys()]).flatten()) + 1

    nodes = create_nodes_grid(SIDE_N, CLASS_N, JITTER)

    def node_pred(c1, pos1, c2, pos2):

        for (c1_t, c2_t), v in class_connectivity.iteritems():
            if (c1 == c1_t) and (c2 == c2_t):
                mu = v[0]
                prob = v[1]
                width = v[2] 


                d = dist(pos1, pos2)

                return util.norm_dist_bump(d, mu, width, prob, p_min)             
        return rand_conn_prob

    connectivity = synth.connect(nodes, node_pred, obsmodel)

    return nodes, connectivity