def make_cascades_summary(self, cascade_networks, logweight=True):
     new_nodes = {}
     new_links = {}
     self.cascades_network = Network()
     for cascade in cascade_networks:
         for node_id in cascade.network.nodes_ids:
             if new_nodes.get(node_id) is None:
                 new_nodes[node_id] = 0
             new_nodes[node_id] += 1
         for from_id, to_id in cascade.network.links.keys():
             if new_links.get((from_id, to_id)) is None:
                 new_links[(from_id, to_id)] = 0
             new_links[(from_id, to_id)] += 1
     self.cascades_network.nodes_attributes.append({'id': 'w', 'title': 'LogWeight', 'type': 'float'})
     for node_id, quantity in new_nodes.items():
         self.cascades_network.add_node(node_id)
         if logweight:
             w = math.log(quantity) + 1
         else:
             w = quantity
         self.cascades_network.add_meta_for_node(node_id, {'w': w})
     for link, quantity in new_links.items():
         if logweight:
             w = math.log(quantity) + 1
         else:
             w = quantity
         self.cascades_network.add_link(link[0], link[1], mutual=False, weighted=True, weight=w)
def make_test_network_star():
    ntw = Network(optimisation=NetworkOptimisation.id_only)
    for i in range(31):
        ntw.add_node(i + 1)
    for i in range(30):
        ntw.add_link(1, i + 2)
    return ntw
def make_test_network_chain(n=31):
    ntw = Network(optimisation=NetworkOptimisation.id_only)
    for i in range(n):
        ntw.add_node(i + 1)
    for i in range(n - 1):
        ntw.add_link(i + 1, i + 2)
    return ntw
Example #4
0
 def __init__(self, net=Network(), name='', base_dir=''):
     super().__init__(net, name, base_dir)
     self.post_meta = {}
     self.posters = {}
     self.hiddens = set()
     self.likers = set()
     self.timestamp = datetime.datetime.now()
def make_test_network_traingle():
    ntw = Network(optimisation=NetworkOptimisation.id_only)
    for i in range(3):
        ntw.add_node(i + 1)
    ntw.add_link(1, 2)
    ntw.add_link(1, 3)
    ntw.add_link(2, 3)
    return ntw
def make_test_network_connected():
    ntw = Network(optimisation=NetworkOptimisation.id_only)
    for i in range(31):
        ntw.add_node(i + 1)
    for i in range(30):
        for j in range(i + 1, 31):
            ntw.add_link(i + 1, j + 1)
    return ntw
Example #7
0
 def __init__(self,
              net=Network(optimisation=NetworkOptimisation.id_only),
              name='',
              base_dir=''):
     super().__init__(net, name, base_dir)
     self.nodes_meta = {}
     self.crawled_nodes = set()
     self.counters_meta = {}
 def make_underlying_summary(self, underlyings):
     if len(underlyings) == 1:
         self.underlying = underlyings[0].network
     else:
         self.underlying = Network(optimisation=NetworkOptimisation.id_only)
         for underlying in underlyings:
             for node_id, neighbors in underlying.network.nodes.items():
                 self.underlying.add_node(node_id)
                 self.underlying.nodes[node_id].update(neighbors)
def make_test_network():
    ntw = Network(optimisation=NetworkOptimisation.id_only)
    for i in range(31):
        ntw.add_node(i + 1)
    ntw.add_link(1, 2)
    ntw.add_link(1, 3)
    ntw.add_link(2, 3)
    ntw.add_link(3, 4)
    ntw.add_link(4, 5)
    ntw.add_link(4, 6)
    ntw.add_link(5, 6)
    ntw.add_link(4, 7)
    ntw.add_link(7, 8)
    ntw.add_link(7, 9)
    ntw.add_link(7, 10)
    ntw.add_link(8, 10)
    ntw.add_link(9, 10)
    ntw.add_link(9, 11)
    ntw.add_link(11, 12)
    ntw.add_link(11, 13)
    ntw.add_link(12, 13)
    ntw.add_link(13, 14)
    ntw.add_link(8, 15)
    ntw.add_link(3, 16)
    ntw.add_link(16, 17)
    ntw.add_link(17, 18)
    ntw.add_link(18, 19)
    ntw.add_link(19, 20)
    ntw.add_link(15, 20)
    ntw.add_link(1, 21)
    ntw.add_link(1, 22)
    ntw.add_link(1, 23)
    ntw.add_link(1, 24)
    ntw.add_link(1, 25)
    ntw.add_link(1, 26)
    ntw.add_link(2, 21)
    ntw.add_link(2, 22)
    ntw.add_link(2, 23)
    ntw.add_link(2, 24)
    ntw.add_link(2, 25)
    ntw.add_link(2, 26)
    ntw.add_link(3, 21)
    ntw.add_link(3, 22)
    ntw.add_link(3, 23)
    ntw.add_link(3, 24)
    ntw.add_link(3, 25)
    ntw.add_link(3, 26)
    return ntw
Example #10
0
 def __init__(self, net=Network(), name='', base_dir=''):
     self.network = net
     self.name = name
     self.base_dir = base_dir
     self.source = NetworkSource.vkontakte
     self.crawl_plan = []
 def __init__(self):
     self.cascades_network = Network()
     self.underlying = Network()
     pass
Example #12
0
 def remake_network(self,
                    possible_links: dict,
                    uselikes=True,
                    usehiddens=True,
                    dynamic=True,
                    logdyn=False,
                    start_from_zero=False):
     # print('This method updates network from post_meta, hiddens, likers etc.')
     self.network = Network()
     if dynamic:
         self.network.nodes_attributes.append({
             'id': 'start',
             'title': 'start',
             'type': 'float'
         })
         self.network.nodes_attributes.append({
             'id': 'n',
             'title': 'Underlying_degree',
             'type': 'integer'
         })
         self.network.nodes_attributes.append({
             'id': 'g',
             'title': 'Is_group',
             'type': 'boolean'
         })
         self.network.links_attributes.append({
             'id': 'start',
             'title': 'start',
             'type': 'float'
         })
         self.network.links_attributes.append({
             'id': 'delay',
             'title': 'delay',
             'type': 'float'
         })
     if usehiddens:
         for node_id in self.hiddens:
             self.network.add_node(node_id)
     if uselikes:
         for node_id in self.likers:
             self.network.add_node(node_id)
     nodes = self.posters.keys()
     min_date = float("inf")
     if start_from_zero:
         for node_id in nodes:
             date = self.posters[node_id]['date']
             if date < min_date:
                 min_date = date
     for node_id in nodes:
         self.network.add_node(node_id)
         if node_id > 0:
             self.network.add_meta_for_node(node_id, {'g': "False"})
         else:
             self.network.add_meta_for_node(node_id, {'g': "True"})
         date = self.posters[node_id]['date']
         neighs_set = possible_links.get(node_id)
         if neighs_set:
             self.network.add_meta_for_node(node_id, {'n': len(neighs_set)})
         else:
             self.network.add_meta_for_node(node_id, {'n': 0})
         if start_from_zero:
             date -= min_date
         if dynamic:
             if logdyn:
                 self.network.add_meta_for_node(
                     node_id, {'start': math.log(date + 1)})
             else:
                 self.network.add_meta_for_node(node_id, {'start': date})
         for node2_id in nodes:
             if node2_id != node_id:
                 date2 = self.posters[node2_id]['date']
                 if start_from_zero:
                     date2 -= min_date
                 if date < date2:
                     if neighs_set and node2_id in neighs_set:
                         self.network.add_link(node_id,
                                               node2_id,
                                               mutual=False)
                         self.network.add_meta_for_link(
                             node_id, node2_id, {'delay': date2 - date})
                         if dynamic:
                             if logdyn:
                                 self.network.add_meta_for_link(
                                     node_id, node2_id,
                                     {'start': math.log(date2 + 1)})
                             else:
                                 self.network.add_meta_for_link(
                                     node_id, node2_id, {'start': date2})