Esempio n. 1
0
	def tmetric_run(self, idxn, seeds, caps, tmetric_type):
		"""
		 * tmetric_run: Run trust metric.
		 * @idxn: the name of the trust metric
		 * @seeds: An array of usernames for the seed.
		 * @caps: Capacity array.
		 * @tmetric_type: the type of the trust metric
		 *
		 * Return value: NodeInfo array.
		"""
		in_type = tmetric_type in ["in", "for", "of"]

		self.flows = []
		for i in range(self.max_levels):
			flow = NetFlow()
			self.flows.append(flow)
			# flow.set_debuglevel(1)

		self.result = {}

		dn_seed = self.tmetric_find_node(idxn, self.result, SUPERSINK)

		for seed_name in seeds:

			self.tmetric_find_node(idxn, self.result, seed_name)

			for i in range(self.min_level, self.max_levels):
				self.flows[i].netflow_add_edge(SUPERSINK, seed_name)

		self.tmetric_loop(in_type, idxn)

		# calculate maximum flow
		for i in range(self.min_level, self.max_levels):
			flow = self.flows[i].netflow_max_flow_extract(dn_seed, caps)
			# print "flow", flow
			for idx in self.result.keys():
				# print "idx", idx
				if flow.has_key(idx) and flow[idx] > 0:
					self.result[idx] = i

		del self.flows
Esempio n. 2
0
from TensorflowToolbox.utility import read_proto as rp
from TensorflowToolbox.utility import file_io
from net_flow import NetFlow
import sys
import yaml
import json

if __name__ == "__main__":
    if len(sys.argv) == 2:
        model_proto_file = sys.argv[1]
    else:
        model_proto_file = "model_proto.yaml"

    with open(model_proto_file, 'r') as f:
        model_params = yaml.load(f)

    print(json.dumps(model_params, indent=4))

    file_io.check_exist(model_params["train_file_name"])
    file_io.check_exist(model_params["test_file_name"])

    net = NetFlow(model_params, True, True)
    net.mainloop()
Esempio n. 3
0
def net_flow_run():
  log.logger.info("net_flow thread start...")
  net = NetFlow(_u_id)
  while True:
    net.on_timer()
    time.sleep(0.01)
Esempio n. 4
0
def orig_test():
	from pprint import pprint

	# large test of max flow.
	#
	# notes.
	#
	# this test is to double-check that if you have a large
	# group of nodes that are interlinked to each other, and
	# another group that is interlinked to itself and the first
	# group, that none of the second group gets any flow.
	# 
	# it's also quite a good test of the amount of
	# time / memory this takes up (about 1k per node).
	# try 100,000: it's fun!

	from random import randint

	f = NetFlow()
	f.netflow_add_edge("-", 0)
	len = 10000
	for i in range(len):
		f.netflow_add_edge(randint(0, len/4), randint(0, len/4))
		f.netflow_add_edge(randint(len/4+1, len/2), randint(0, len/2))

	e = f.netflow_max_flow_extract("-", [800, 200, 50, 12, 4, 2, 1])

	for x in e.keys():
		if type(x) == type(0) and x > (len/4) and e[x] != 0:
			raise ("untrusted group (%d->%d) linked to trusted (0->%d)\n" % \
					(len/4+1, len/2, len/4))
	
	print "random test passed ok"
	print 

	# pretty test of max flow.
	#
	# notes.
	#
	# mary and bob like each other, but the seeds aren't
	# interested in mary and bob, so they don't show up
	# in the max flow diagram.
	#
	# fleas ad infinitum is so far down from the seeds that
	# despite being linked, no flow reaches it: the
	# available capacity, which is limited in this test to
	# 7 degrees away from the supersink ("-") _anyway_,
	# is all used up.
	#
	# 1: -, 2: seed, 3: heather, 4: rob,
	# 5: fleas, 6: lit-f, 7: less-f - whoops! 8: fad.
	# yeah, that's right.  the capacity chain is only 7-long
	# so anything beyond 7 degrees from the supersink isn't
	# included.  cool.
	
	# the second test is what heather likes, and heather's likes'
	# likes, and heather's likes' likes' likes... etc., up to
	# 7 degrees.  which is why fleas ad infinitum _is_ shown
	# in the flow, this time.  cool.

	f = NetFlow()
	f.set_debuglevel(1)
	f.netflow_add_edge("-", "seed")
	f.netflow_add_edge("-", "seed2")
	f.netflow_add_edge("seed", "heather")
	f.netflow_add_edge("seed2", "heather")
	f.netflow_add_edge("seed", 55)
	f.netflow_add_edge("seed", u"luke")
	f.netflow_add_edge(55, 10)
	f.netflow_add_edge(10, u"luke")
	f.netflow_add_edge(u"luke", "heather")
	f.netflow_add_edge("heather", u"luke")
	f.netflow_add_edge("heather", "flat-faced cat")
	f.netflow_add_edge("flat-faced cat", "heather")
	f.netflow_add_edge("luke", "flat-faced cat")
	f.netflow_add_edge("heather", "mo the mad orange pony")
	f.netflow_add_edge("heather", "robbie the old crock pony")
	f.netflow_add_edge("robbie the old crock pony", "fleas")
	f.netflow_add_edge("fleas", "little fleas")
	f.netflow_add_edge("little fleas", "lesser fleas")
	f.netflow_add_edge("lesser fleas", "fleas ad infinitum")

	f.netflow_add_edge("bob", "heather")
	f.netflow_add_edge("bob", "mary")
	f.netflow_add_edge("mary", "bob")

	print "pretty node graph (yes, the numbers 55 and 10 are nodes):"
	pprint(f.succs)
	print 

	e = f.netflow_max_flow_extract("-", [800, 200, 50, 12, 4, 2, 1])
	print "supersink as seed - avg_capacity:", f.get_avg_capacity()
	pprint(e)
	print 

	e = f.netflow_max_flow_extract("heather", [800, 200, 50, 12, 4, 2, 1])
	print "heather as seed - avg_capacity:", f.get_avg_capacity()
	pprint(e)
	print 
Esempio n. 5
0
	print "heather as seed - avg_capacity:", f.get_avg_capacity()
	pprint(e)
	print 


if __name__ == '__main__':
    if True:
        orig_test()
    else:
        a = Advogato()
        print "Loading Advogato dataset"

	G = networkx.read_dot(a.numbersfilepath)

	# use G.edges(node)
        f = NetFlow(G)
        print "netflow"
	# f.netflow_add_edge("-", "raph")

	# FIX: multiple edges from source
	# f.netflow_add_edge("-", "miguel")
	f.netflow_add_edge("-", "alan")
	f.netflow_add_edge("-", "federico")

	# Do this 3 times
        e = f.netflow_max_flow_extract("-")
	# masters = ..
	# journeyors =
	# apprentices =
	
Esempio n. 6
0
from TensorflowToolbox.utility import read_proto as rp
from TensorflowToolbox.utility import file_io
from net_flow import NetFlow
import sys

if __name__ == "__main__":
    if len(sys.argv) == 2:
        model_proto_file = sys.argv[1]
    else:
        model_proto_file = "model.tfproto"

    model_params = rp.load_proto(model_proto_file)
    model_params['restore_model'] = True

    file_io.check_exist(model_params["test_file_name"])

    net = NetFlow(model_params, False, False)
    net.mainloop()