예제 #1
0
def plot_false_and_true_positives(positive_file_name, false_file_name):
	positive_data = ft.get_data_from_file(positive_file_name)
	false_data = ft.get_data_from_file(false_file_name)

	positive_x, positive_y = get_list_of_data_as_x_and_y(positive_data)
	false_x, false_y = get_list_of_data_as_x_and_y(false_data)

	plt.plot(positive_x, positive_y, "b-", false_x, false_y, "ro")
	plt.show()
예제 #2
0
def plot_time_series_file(file_name, title = "", ylabel = "", xlabel = ""):
	data = ft.get_data_from_file(file_name)
	transposed_data = map(list, zip(*data))
	set_font_of_plot()
	plt.ylabel(ylabel)
	plt.xlabel(xlabel)
	plt.title(title)
	plt.plot(transposed_data)
	plt.show()
예제 #3
0
def plot_error_if_greater_than_zero(file_name):

	def is_greater_than_zero(list_of_values):
		return [1 if int(val) > 0 else 0 for val in list_of_values]

	data = ft.get_data_from_file(file_name)
	y, _ = get_list_of_data_as_x_and_y(data)

	warmup_time = 1500
	x = range(warmup_time, len(y) + warmup_time)
	y = is_greater_than_zero(y)

	show_scatter_plot_of_data(x, y, "Anomalies vs no anomalies", "Time", "Is rare event?")
예제 #4
0
def plot_scatter_plot_of_errors(file_name):
	"""
	this function is for plotting the errors detected vs errors inserted.
	Usually file name is final.csv
	"""
	data = ft.get_data_from_file(file_name)

	x, y = get_list_of_data_as_x_and_y(data)

	plt.ylabel("number of detected errors")
	plt.xlabel("number of induced errors")
	plt.title("Correlation among induced errors and detected errors")
	plt.scatter(x, y, marker=",")
	plt.show()
예제 #5
0
def show_rare_event_menu(lattice_of_sensors, random_generator, min_hearable_volume = 0.1,
	error_threshold = 0.02, loudness = 0.3, max_dist = 1):
	"This functions shows a rare event menu. file name usually: rare_song_normalized.csv"
	print "You are adding a rare event!!"
	file_name = prompt_for_input("Enter rare song file name:")
	rare_event_song = ft.get_data_from_file(file_name)

	should_use_default_parameters = True if prompt_for_input("Do you want to use default parameters? yes/no:") == "yes" else False

	if not should_use_default_parameters:
		error_threshold = float(prompt_for_input("Enter error threshold:"))
		loudness = float(prompt_for_input("Enter loudness:"))
		min_hearable_volume = float(prompt_for_input("Enter min_hearable_volume:"))
		max_dist = int(prompt_for_input("Enter max distance:"))

	add_rare_event(lattice_of_sensors, rare_event_song[0], random_generator, max_dist, 
		loudness, min_hearable_volume)
예제 #6
0
def plot_number_of_sensors_that_deviate_and_is_rare_event(file_name):
	"""
	Plots the number of sensors that deviate and are rare event from the file.
	usually the file name is number_of_sensors_that_deviate_and_is_rare_event.csv.
	"""
	def add_wiggle(ys, amount):
		return [y + random.random() * amount for y in ys]

	def count_quadrants(x, y, x_threshold, y_threshold):
		true_positives = false_positives = true_negatives = false_negatives = 0
		for x, y in zip(x, y):
			if x < x_threshold and y < y_threshold:
				true_negatives += 1
			elif x < x_threshold and y > y_threshold:
				false_negatives += 1
			elif x > x_threshold and y < y_threshold:
				false_positives += 1
			else:
				true_positives += 1

		print "True negatives:", true_negatives
		print "True positives:", true_positives
		print "False negatives:", false_negatives
		print "False positives:", false_positives

	def change_from_boolean_string_to_integer(list_of_boolean_string_values):
		"Returns a list containing 1 for True and 0 for False"
		return [1 if val == 'True' else 0 for val in list_of_boolean_string_values]

	warmup_time = 1500
	data = ft.get_data_from_file(file_name)
	data = data[warmup_time:]
	x , y = get_list_of_data_as_x_and_y(data)
	x = [int(i) for i in x]
	y = change_from_boolean_string_to_integer(y)

	count_quadrants(x, y, 0.5, 0.5)
	
	y = add_wiggle(y, 0.1)


	plt.axhline(0.5, xmin = 0, xmax =100, color="r")
	plt.axvline(0.5, ymin = 0, ymax =1, color="r")

	show_scatter_plot_of_data(x, y, "Anomalies vs no anomalies", "Number of deviating sensors", "Is rare event?")
예제 #7
0
def plot_file_in_columns(file_name):
	data = ft.get_data_from_file(file_name)
	plt.plot(data)
	plt.show()
예제 #8
0
def get_list_of_time_series():
	name_of_file_of_time_series = prompt_for_input("Enter name of file of time series:")
	return ft.get_data_from_file(name_of_file_of_time_series)