예제 #1
0
파일: mutrics.py 프로젝트: iitis/mutrics
def bks(limit, fmt, cstats, stats, train, test, profile):
	src = ArffReader.ArffReader(sys.stdin)
	dst = sys.stdout
	cs = BKS(profile)
	st = Stats()

	# setup proto filter
	if hasattr(P, "skip"):
		check = lambda gt: gt not in P.skip
	elif hasattr(P, "select"):
		check = lambda gt: gt in P.select
	else:
		check = lambda: True

	# arff header?
	if fmt == "arff":
		src.printh(nodata=True, dst=dst)
		dst.write("%% Multilevel Traffic Classifier: BKS approach\n")
		dst.write("% bks_proto: the identified protocol\n")
		dst.write("@attribute bks_proto string\n\n")
		dst.write("@data\n")

	# load a model?
	if test:
		cs.train_load(test)

	# go!
	for d in src:
		# check if gt is enabled
		gt = d[P.gtcol]
		if not check(gt): continue

		# parse and pass to classifiers
		f = Flow(src, d, gt)
		s = cs.ask(f)

		if train:
			cs.train(s, f.gt)
		elif test:
			cs.classify(f, s)

			# print it to the user?
			if limit:
				if f.isunk():
					if "unk" not in limit: continue
				elif "ans" not in limit:
					if f.isok()  and "ok"  not in limit: continue
					if f.iserr() and "err" not in limit: continue

			# print and count
			f.write(fmt, dst)
			st.count(f)

	# finish training
	if train:
		cs.train_finish()
		cs.train_store(train)

	# finish profiling
	if profile:
		cs.profile_store(profile)

	# algo stats?
	if cstats:
		print("BKS statistics")
		print("==============")
		print(cs.get_stats())

	# stats?
	if stats:
		if train:
			cs.train_show()
		else:
			print("Performance statistics")
			print("======================")
			print(st.get_cm())
예제 #2
0
파일: mutrics.py 프로젝트: iitis/mutrics
def waterfall(dump, dumpl, limit, fmt, cstats, stats):
	# init modules
	src = ArffReader.ArffReader(sys.stdin)
	dst = sys.stdout
	cs = Cascade()
	st = Stats()

	# setup proto filter
	if hasattr(P, "skip"):
		check = lambda gt: gt not in P.skip
	elif hasattr(P, "select"):
		check = lambda gt: gt in P.select
	else:
		check = lambda: True

	# arff header?
	if fmt == "arff":
		src.printh(nodata=True, dst=dst)
		dst.write("%% Multilevel Traffic Classifier: Waterfall approach\n")
		dst.write("% waterfall_module: classifier that contributed the answer\n")
		dst.write("% waterfall_proto: the identified protocol\n")
		dst.write("@attribute waterfall_module string\n")
		dst.write("@attribute waterfall_proto string\n\n")
		dst.write("@data\n")

	# go!
	for d in src:
		# check if gt is enabled
		gt = d[P.gtcol]
		if not check(gt): continue

		# parse and classify
		f = Flow(src, d, gt)
		show = cs.classify(f, dump, dumpl)

		# print it to the user?
		if not show:
			continue
		if limit:
			if f.isunk():
				if "unk" not in limit: continue
			elif "ans" not in limit:
				if f.isok()  and "ok"  not in limit: continue
				if f.iserr() and "err" not in limit: continue

		# print and count
		f.write(fmt, dst)
		st.count(f)

	# cascade stats?
	if cstats:
		if fmt != "none": print("")
		print("Cascade statistics")
		print("==================")
		print(cs.get_stats())

	# perf stats?
	if stats:
		if cstats: print("")
		print("Performance statistics")
		print("======================")
		print(st.get_cm())