Created
April 28, 2017 16:35
-
-
Save aniquetahir/77a56697eaa203819f23200a4665691f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/anaconda/bin/python | |
import sys | |
def GetIntersection(source_data, check_data): | |
num_intersection = 0 | |
for row in check_data: | |
if row in source_data: | |
num_intersection+=1 | |
return num_intersection | |
def PrintJaccard(source_filename, check_filename): | |
source_data = [] | |
check_data = [] | |
num_lines_source = 0 | |
num_lines_check = 0 | |
num_lines_intersection = 0 | |
union = 0 | |
source_file = open(source_filename, 'r') | |
check_file = open(check_filename, 'r') | |
for source_line in source_file: | |
source_line_elements = source_line.split(',') | |
if len(source_line_elements)>2: | |
num_lines_source += 1 | |
source_data.append([float(source_line_elements[0]), #lat | |
float(source_line_elements[1]), #lng | |
float(source_line_elements[2])])#timestep | |
for check_line in check_file: | |
try: | |
check_line_elements = check_line.split(',') | |
if len(check_line_elements)>2: | |
num_lines_check += 1 | |
check_data.append([float(check_line_elements[0]), #lat | |
float(check_line_elements[1]), #lng | |
float(check_line_elements[2])])#timestep | |
except: | |
continue | |
check_file.close() | |
source_file.close() | |
num_lines_intersection = GetIntersection(source_data, check_data) | |
union = num_lines_source+num_lines_check-num_lines_intersection | |
jaccard = float(num_lines_intersection)/union | |
print "%f"%jaccard | |
if __name__ == "__main__": | |
arguments = sys.argv | |
source_filename = arguments[1] | |
check_filename = arguments[2] | |
PrintJaccard(source_filename,check_filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment