Beispiel #1
0
    def testTotalTrianglesWeight(self):

        g = Graph()

        g.add_edge(1, 2)
        g.add_edge(2, 3)
        g.add_edge(3, 1)

        g.add_edge(5, 6)
        g.add_edge(6, 7)
        g.add_edge(7, 5)

        g.create_index_triangles()
        g.index_parameter_from_parameter('triangles', 'unseen_triangles')

        self.assertEqual(g.total_triangles_weight(1), 2)
        self.assertEqual(g.total_triangles_weight(2), 0)
        self.assertEqual(g.total_unseen_triangles(), 2)

        g.update_edge_weight(1, 2, 2)

        self.assertEqual(g.total_triangles_weight(1), 1)
        self.assertEqual(g.total_triangles_weight(2), 0)

        g.update_edge_weight(2, 3, 2)
        g.update_edge_weight(3, 1, 2)

        self.assertEqual(g.total_triangles_weight(1), 1)
        self.assertEqual(g.total_triangles_weight(2), 1)
Beispiel #2
0
    def setUp(self):
        self.digraph = BigDiGraph()
        self.digraph.debug = False
        self.digraph.input_debug_links = 1
        self.digraph.output_debug_nodes = 1
        self.digraph.load_edgelist(StringIO(example_txt), num=False)

        self.graph = Graph()
Beispiel #3
0
 def setUp(self):
     self.graph = Graph()
     self.graph.debug = False
     self.graph.input_debug_links = 50000
     self.graph.max_links_input = 25000
     self.graph.output_debug_nodes = 10000
     use_big_alphabet = False
     self.graph.load_compressed_graph(cloudlight.tests.data_enc1,
                                      use_big_alphabet)
Beispiel #4
0
    def setUp(self):
        self.graph = Graph()
        self.graph.debug = False
        self.graph.input_debug_links = 500000
        self.graph.output_debug_nodes = 10000
        use_big_alphabet = False
        self.graph.load_compressed_graph(cloudlight.tests.data_enc1,
                                         use_big_alphabet)

        random.seed(666)
        self.nodes = self.graph.random_nodes(10000)
Beispiel #5
0
    def testGraphHistogram(self):
        self.graph = Graph()
        self.graph.debug = False
        self.graph.input_debug_links = 200000
        self.graph.output_debug_nodes = 10000
        self.graph.load_edgelist(StringIO(example_txt2))

        degrees = list(self.graph.degrees())
        p = Plot()
        p.clear()
        p.hist(degrees, 15, True, True, False)
Beispiel #6
0
    def visitTwitterNode(self, node, *args):

        print 'Visitando nodo twitter: id = %s, user = %s' % (node.num_id,
                                                              node.screen_name)

        tw_local_graph = Graph()

        friends = self.twitter_browser.friends(node)
        for f in friends:
            tw_local_graph.add_edge(node, f)

        return tw_local_graph
Beispiel #7
0
    def setUp(self):
        self.graph = Graph()
        self.graph.debug = False
        self.graph.max_links_input = 50000
        self.graph.input_debug_links = 1000  #200000
        self.graph.output_debug_nodes = 10000
        use_big_alphabet = False
        self.graph.load_compressed_graph(cloudlight.tests.data_enc1,
                                         use_big_alphabet,
                                         has_num=True)

        self.graph.create_indices()
Beispiel #8
0
    def setUp(self):
        g = Graph()
        n1 = Node()
        n2 = Node()
        n3 = Node()
        n4 = Node()
        g.add_edge(n1, n2)
        g.add_edge(n2, n3)
        g.add_edge(n3, n1)
        g.add_edge(n3, n4)

        self.g = g
Beispiel #9
0
    def testPlotSave(self):
        self.graph = Graph()
        self.graph.debug = False
        self.graph.input_debug_links = 200000
        self.graph.output_debug_nodes = 10000
        self.graph.load_edgelist(StringIO(example_txt))

        clusts = list(self.graph.eccentricities())
        clusts
        p = Plot()
        p.clear()
        p.hist(clusts, 3, True, True, True)
        p.save('testPlotSave.png')
Beispiel #10
0
    def visitFacebookNode(self, node, *args):

        print 'Visitando nodo facebook: id = %s, name = %s' % (node.id,
                                                               node.name)

        fb_local_graph = Graph()

        friends = self.facebook_browser.friends(node)
        for f in friends:
            print node, f
            fb_local_graph.add_edge(node, f)

        return fb_local_graph
Beispiel #11
0
    def __init__(self, graph, lookahead, debug=False):
        '''
        graph:     graph where the attack is made.
        lookahead: visibility of the nodes in the graph.
        '''
        self.debug = debug
        self.graph = graph
        self.lookahead = lookahead + 1

        if self.debug:
            print 'INFO: Initializing LinkPrivacyModel...'

        self.rogues = set([])  # remember extra rogues nodes added
        self.false_links_graph = Graph()  # remember false links added
        self.visible_graph = Graph()  # infiltrated subgraph
        self.unseen_graph = copy.deepcopy(graph)  # uninfiltrated subgraph

        self.rogue_effort = 0  # cost in new nodes created
        self.bribe_effort = 0  # cost in existing nodes bribed
        self.false_link_effort = 0  # cost in new links created

        self.cache_korolova_coverage = set([])
        self.cached_sorted_degrees_dec = None
Beispiel #12
0
    def testVisitFriends(self):

        g = Graph()
        g.add_node(self.node)

        friends = self.node.friends()
        self.assertEqual(
            set(map(str, friends)),
            set([
                '3108351', '26601797', '18149408', '19253848', '36544954',
                '75970385', '18114931', '55463984', '19732920', '42917391',
                '25566068', '25925954', '44674512', '19305701', '45712556'
            ]))

        self.g = g
Beispiel #13
0
    def testComplexTwitterBot(self):

        mynodemap = {
            str(TwitterNode('AAA').__class__): TwitterNode.visit_friends
        }

        bot = Transform(mynodemap, None, Constructor())

        graph = Graph()
        graph.add_node(TwitterNode('therm000'))

        list(bot.visit(graph))

        self.assertTrue(
            'therm000' in map(str, bot.decoratedBot.new_graph.nodes()))
        self.assertTrue(
            '89945612' in map(str, bot.decoratedBot.new_graph.nodes()))
Beispiel #14
0
    def setUp(self):
        self.graph = Graph()
        self.graph.debug = False
        self.graph.max_links_input = 100000
        self.graph.input_debug_links = 200000
        self.graph.output_debug_nodes = 10000
        use_big_alphabet = False
        self.graph.load_compressed_graph(cloudlight.tests.data_enc1, use_big_alphabet)
        self.graph.create_index_degree()
        self.graph.create_index_unseen_degree()

        lookahead = 0
        coverage = 'link'

        self.strategies = PrivacyAttackStrategies(self.graph, lookahead, coverage, False)
        
        random.seed(666)

        self.coverages = [0.1] # [ float(f)/100 for f in range(2, 104, 2) ]
Beispiel #15
0
    def testComplexFacebookBot(self):

        FacebookNode.initialize({}, '*****@*****.**',
                                'asdfasdf0', False)
        #FacebookNode.initialize({}, '*****@*****.**', 'asdfasdf0', False)

        mynodemap = {
            str(FacebookNode(1151613578).__class__): FacebookNode.visit_friends
        }

        bot = Transform(mynodemap, None, Constructor())

        graph = Graph()
        graph.add_node(FacebookNode(1151613578))

        list(bot.visit(graph))

        self.assertTrue(
            '1151613578' in map(str, bot.decoratedBot.new_graph.nodes()))
        self.assertTrue(
            '507271730' in map(str, bot.decoratedBot.new_graph.nodes()))
Beispiel #16
0
    def testTotalTriangles(self):

        self.graph = Graph()

        self.graph.add_edge(1234000, 1234001)
        self.graph.add_edge(1234001, 1234002)
        self.graph.add_edge(1234002, 1234000)

        self.graph.add_edge(1234000, 1234001)
        self.graph.add_edge(1234001, 1234003)
        self.graph.add_edge(1234003, 1234000)

        self.graph.create_index_triangles()

        self.assertEqual(self.graph.get_parameter_cache('triangles', 1234000),
                         2)
        self.assertEqual(self.graph.get_parameter_cache('triangles', 1234001),
                         2)
        self.assertEqual(self.graph.get_parameter_cache('triangles', 1234002),
                         1)
        self.assertEqual(self.graph.get_parameter_cache('triangles', 1234003),
                         1)

        print
        for node, value in self.graph.get_parameter_cache_iter('triangles'):
            print node, value

        self.assertEqual(self.graph.total_triangles(), 2)

        self.assertEqual(self.graph.total_triangles_weight(1), 2)
        self.assertEqual(self.graph.total_triangles_weight(2), 0)

        self.assertEqual(self.graph.triangles_weight(1234000, 1), 2)
        self.assertEqual(self.graph.triangles_weight(1234000, 2), 0)
        self.assertEqual(self.graph.triangles_weight(6756443, 1), 0)
        self.assertEqual(self.graph.triangles_weight(6756443, 2), 0)
Beispiel #17
0
 def setUp(self):
     self.graph = Graph()
     self.graph.debug = False
     self.graph.input_debug_links = 200000
     self.graph.output_debug_nodes = 10000
     self.graph.load_edgelist(StringIO(example_txt2))
Beispiel #18
0
 def __init__(self):
     super(GraphBuilder, self).__init__()
     self.initial = Graph()
Beispiel #19
0
#!/usr/bin/python


import sys

from cloudlight.classes.graph import Graph
from cloudlight.algorithms.plot import Plot
import cloudlight.tests.data_enc1

graph = Graph()

graph.debug = True
graph.input_debug_links = 200000
graph.output_debug_nodes = 100

graph.max_links_input = 5*10**7
graph.max_nodes_analysis = 10000

filename =  len(sys.argv) > 1 and sys.argv[1] or None 

filename = '/media/truecrypt1/temp/livejournal-links.txt-symmetric.snowball.10k'

if not filename:
    print 'Error: first argument missing, input filename with space separated graph!'
    exit(-1)

folder =  len(sys.argv) > 2 and sys.argv[2] or None 

folder = '/media/truecrypt1/temp/lj/'

if not folder:
Beispiel #20
0
 def setUp(self):
     self.graph = Graph()
     self.graph.debug = False
     self.graph.max_links_input = 100000
     self.graph.input_debug_links = 200000
     self.graph.output_debug_nodes = 10000
Beispiel #21
0
'''
Created on Apr 8, 2010

@author: jose
'''

from cloudlight.classes.graph import Graph
from cloudlight.algorithms.plot import Plot

g = Graph()

g.max_links_input = 50000

g.load_edgelist(open('orkut-links-fst.txt.toundirected.3mill'), num=True)

g.save_compressed_graph('./cloudlight/tests/data_enc1.py', False)
g.save_compressed_graph('./cloudlight/tests/data_enc2.py', True)