Last active
July 23, 2017 15:12
-
-
Save krishnachaitanya7/a2014215d905830782488d9d6aa3c56d to your computer and use it in GitHub Desktop.
This is a utility to generate all decision types from all.txt, 0 for animal, 1 for human, 2 for clutter. By this an overview can be achieved on which type of algorithm can perform better
This file contains hidden or 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
''' | |
This is a utility to generate all decision types from all.txt, 0 for animal, 1 for human, 2 for clutter. By this an overview can be achieved on which type of algorithm can perform better | |
''' | |
import xlwt | |
from itertools import groupby | |
def print_required_info(tuplearray1, final_indice1): | |
global row_number | |
global sheet | |
ones_power = 0 | |
zeros_power = 0 | |
total_ones = 0 | |
total_zeros =0 | |
for every_element_tupplearray in tuplearray1: | |
if every_element_tupplearray[0] == 0: | |
if zeros_power < every_element_tupplearray[1]: | |
zeros_power = every_element_tupplearray[1] | |
total_zeros += every_element_tupplearray[1] | |
if every_element_tupplearray[0] == 1: | |
if ones_power < every_element_tupplearray[1]: | |
ones_power = every_element_tupplearray[1] | |
total_ones += every_element_tupplearray[1] | |
print 'highest ones',ones_power,' highest zeros',zeros_power,' tuple is',tuplearray1,' Line is',lines_in_alltxt[final_indice1],' total ones',total_ones,' total zeros',total_zeros | |
if total_ones > total_zeros: | |
majordecision = "Human" | |
if total_ones < total_zeros: | |
majordecision = "Animal" | |
if total_zeros == total_ones: | |
majordecision = "Ambiguous" | |
if tuplearray1[0][0] == 0: | |
first_decision = "Animal" | |
if tuplearray1[0][0] == 1: | |
first_decision = "Human" | |
sheet.write(row_number,0,first_decision) | |
sheet.write(row_number,1,majordecision) | |
sheet.write(row_number,2,ones_power) | |
sheet.write(row_number,3,zeros_power) | |
sheet.write(row_number,4,lines_in_alltxt[final_indice1]) | |
row_number += 1 | |
def find_index_of_decision(tuplearray): | |
global final_indice | |
if tuplearray[0][0] != 2: | |
print_required_info(tuplearray, final_indice) | |
for every_consecutive_decisions in tuplearray: | |
final_indice = final_indice + every_consecutive_decisions[1] | |
# print tuplearray, 'present indice is ', final_indice | |
def consecutive_human_animal_lists(grouped_list_of_all_decision): | |
between_twos_list = list() | |
twos_list = list() | |
for index1, every_grouped_list_of_all_decision in enumerate(grouped_list_of_all_decision): | |
if every_grouped_list_of_all_decision[0] != 2: | |
between_twos_list.append(every_grouped_list_of_all_decision) | |
grouped_list_of_all_decision = grouped_list_of_all_decision[1:] | |
else: | |
twos_list.append(every_grouped_list_of_all_decision) | |
grouped_list_of_all_decision = grouped_list_of_all_decision[1:] | |
break | |
try: | |
find_index_of_decision(between_twos_list) | |
except: | |
pass | |
try: | |
find_index_of_decision(twos_list) | |
except: | |
pass | |
if len(grouped_list_of_all_decision) != 0: | |
consecutive_human_animal_lists(grouped_list_of_all_decision) | |
else: | |
print 'All done' | |
filename = 'all.txt' | |
f = open(filename, 'r') | |
lines_in_alltxt = f.readlines() | |
list_of_all_decisions = list() | |
previous_element = int() | |
final_indice = 0 | |
for each_line in lines_in_alltxt: | |
try: | |
list_of_all_decisions.append(int(each_line[-3:-2])) | |
except: | |
final_indice += 1 | |
pass | |
grouped_list_of_all_decisions = [(k, sum(1 for i in g)) for k, g in groupby(list_of_all_decisions)] | |
# print grouped_list_of_all_decisions | |
between_twos_list = list() | |
workbook = xlwt.Workbook() | |
sheet = workbook.add_sheet("Misclassification decisions", cell_overwrite_ok=True) | |
sheet.write(0, 0, 'First Decision') | |
sheet.write(0, 1, 'Majority Decision') | |
sheet.write(0, 2, 'Highest no of ones consecutively') | |
sheet.write(0, 3, 'highest no of zeros consecutively') | |
sheet.write(0, 4, 'Line') | |
row_number = 1 | |
consecutive_human_animal_lists(grouped_list_of_all_decisions) | |
# for every_between_two_list in between_twos_list: | |
# if len(every_between_two_list) > 2: | |
# print every_between_two_list | |
# consecutive_human_animal_lists([(2,60)]) | |
workbook.save("test_stats.xls") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment