コード例 #1
0
ファイル: relation.py プロジェクト: ericmjonas/netmotifs
    def delete_group(self, type_name, group_id):
        #
        self.type_groups[type_name].remove(group_id)

        grp_list = [self.type_groups[n] for n, s in self.relation_def]

        del_ss = set(self.suffstats.keys()) - set(util.cart_prod(grp_list))

        # delete those ss
        for d in del_ss:
            del self.suffstats[d]
            del self.component_dp_count[d]
コード例 #2
0
ファイル: relation.py プロジェクト: ericmjonas/netmotifs
    def __init__(self, domain_def, data, modeltype=None):

        assert len(domain_def) > 1

        self.relation_def = domain_def

        self.data = data.flatten()

        self.model = modeltype

        self.axes = [dom_name for dom_name, size in self.relation_def]
        self.domains = {}
        for domain_name, domain_size in domain_def:
            self.domains[domain_name] = domain_size

        self.domain_to_axispos = {}
        for d in self.domains:
            self.domain_to_axispos[d] = tuple([
                i for n, i in zip(self.axes, range(len(self.axes))) if n == d
            ])

        self.components = {}
        self.components_dp_count = {}

        self.group_id = 0

        self.domain_entity_assignment = {}
        self.domain_groups = {}
        for d in self.domains:
            self.domain_entity_assignment[d] = np.ones(
                self.domains[d], dtype=np.int32) * NOT_ASSIGNED
            self.domain_groups[d] = set()
        # initial setup
        self.datapoint_groups = np.ones((len(self.data), len(self.axes)),
                                        dtype=np.int32)
        self.datapoint_groups[:] = NOT_ASSIGNED
        self.datapoint_entity_index = np.zeros(
            (len(self.data), len(self.axes)), dtype=np.int32)

        self.entity_to_dp = {
            domain_name: {i: set()
                          for i in range(N)}
            for domain_name, N in self.domains.iteritems()
        }
        # create rediciulous look-up table
        pos = 0
        for dp_coord in util.cart_prod(
            [range(s) for n, s in self.relation_def]):
            for ax_pos, ax_name in zip(range(len(self.axes)), self.axes):
                entity_id = dp_coord[ax_pos]
                self.entity_to_dp[ax_name][entity_id].add(pos)
            self.datapoint_entity_index[pos] = dp_coord
            pos += 1
コード例 #3
0
ファイル: relation.py プロジェクト: ericmjonas/netmotifs
    def delete_group(self, type_name, group_id):
        #
        self.type_groups[type_name].remove(group_id)
        
        grp_list = [self.type_groups[n] for n, s in self.relation_def]

        del_ss = set(self.suffstats.keys()) - set(util.cart_prod(grp_list))

        # delete those ss
        for d in del_ss:
            del self.suffstats[d]
            del self.component_dp_count[d]
コード例 #4
0
ファイル: relation.py プロジェクト: ericmjonas/netmotifs
    def __init__(self, domain_def, data, modeltype = None):

        assert len(domain_def) > 1
        
        self.relation_def = domain_def
        
        self.data = data.flatten()

        self.model = modeltype

        self.axes = [dom_name for dom_name, size in self.relation_def]
        self.domains = {}
        for domain_name, domain_size in domain_def:
            self.domains[domain_name] = domain_size

        self.domain_to_axispos = {}
        for d in self.domains:
            self.domain_to_axispos[d] = tuple([i for n,i in zip(self.axes, range(len(self.axes))) if n == d])

        self.components = {}
        self.components_dp_count = {}

        self.group_id = 0

        self.domain_entity_assignment = {}
        self.domain_groups = {}
        for d in self.domains:
            self.domain_entity_assignment[d] = np.ones(self.domains[d], dtype=np.int32)*NOT_ASSIGNED
            self.domain_groups[d] = set()
        # initial setup 
        self.datapoint_groups = np.ones((len(self.data), 
                                         len(self.axes)), dtype=np.int32)
        self.datapoint_groups[:] = NOT_ASSIGNED
        self.datapoint_entity_index = np.zeros((len(self.data), 
                                         len(self.axes)), dtype=np.int32)

        self.entity_to_dp = {domain_name: {i : set() for i in range(N)} for domain_name, N in self.domains.iteritems()}
        # create rediciulous look-up table
        pos = 0
        for dp_coord in util.cart_prod([range(s) for n, s in self.relation_def]):
            for ax_pos, ax_name in zip(range(len(self.axes)), self.axes):
                entity_id = dp_coord[ax_pos]
                self.entity_to_dp[ax_name][entity_id].add(pos)
            self.datapoint_entity_index[pos] = dp_coord
            pos += 1
コード例 #5
0
ファイル: relation.py プロジェクト: ericmjonas/netmotifs
    def create_group(self, type_name, rng):
        """
        Return a group id, an opaque group handle
        """
        # create the group
        grp_id = self.group_pos[type_name]
        self.group_pos[type_name] += 1
        self.type_groups[type_name].add(grp_id)

        # what are the new groups to create?
        grp_list = [self.type_groups[n] for n, s in self.relation_def]

        # create the suffstat blocks along every other axis
        new_ss = set(util.cart_prod(grp_list)) - set(self.suffstats.keys())
        # create all of them
        for k in new_ss:
            self.suffstats[k] = self.model.create_ss(self.hps)
            self.component_dp_count[k] = 0
        return grp_id
コード例 #6
0
ファイル: relation.py プロジェクト: ericmjonas/netmotifs
    def create_group(self, type_name, rng):
        """
        Return a group id, an opaque group handle
        """
        # create the group
        grp_id = self.group_pos[type_name]
        self.group_pos[type_name] += 1
        self.type_groups[type_name].add(grp_id)

        # what are the new groups to create? 
        grp_list = [self.type_groups[n] for n, s in self.relation_def]

        # create the suffstat blocks along every other axis
        new_ss = set(util.cart_prod(grp_list)) - set(self.suffstats.keys()) 
        # create all of them
        for k in new_ss:
            self.suffstats[k] = self.model.create_ss(self.hps)
            self.component_dp_count[k] = 0
        return grp_id
コード例 #7
0
ファイル: model.py プロジェクト: ericmjonas/netmotifs
def get_components_in_relation(domains_as_axes, relation):
    """
    Return the components for a given relation indexed by
    the axes tuples of the outer (python) domains

    domains_as_axes: [(domain_obj, relpos)] 
    
    """

    possible_group_axes = [d[0].get_groups() for d in domains_as_axes]
    domain_coords = util.cart_prod(possible_group_axes)

    comp_vals = {}

    for ci, coord in enumerate(domain_coords):
        rel_coords = []
        for di, (dobj, relpos) in enumerate(domains_as_axes):
            r_gid = dobj.get_relation_groupid(relpos, coord[di])
            rel_coords.append(r_gid)
        c = relation.get_component(tuple(rel_coords))
        comp_vals[coord] = c
    return comp_vals
コード例 #8
0
ファイル: model.py プロジェクト: ericmjonas/netmotifs
def get_components_in_relation(domains_as_axes, relation):
    """
    Return the components for a given relation indexed by
    the axes tuples of the outer (python) domains

    domains_as_axes: [(domain_obj, relpos)] 
    
    """
    
    possible_group_axes = [d[0].get_groups() for d in domains_as_axes]
    domain_coords = util.cart_prod(possible_group_axes)

    comp_vals = {}

    for ci, coord in enumerate(domain_coords):
        rel_coords = []
        for di, (dobj, relpos) in enumerate(domains_as_axes):
            r_gid = dobj.get_relation_groupid(relpos, coord[di])
            rel_coords.append(r_gid)
        c = relation.get_component(tuple(rel_coords))
        comp_vals[coord] = c
    return comp_vals