Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add original to generic data converter #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/data/data_converter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from data import data_utilities
import numpy as np

def map_original_to_generic_name(file_path, out_path = '../data/generic_data.txt', lookup_out_path = '../data/lookup_data.txt'):
ALL_FEATURE_FILE_PATH = file_path

all_unique_features = data_utilities.get_features(data_utilities.read_file(ALL_FEATURE_FILE_PATH))

generic_data_names = []
for i in range(len(all_unique_features)):
generic_data_names.append('P' + "{:04d}".format(i))

data_utilities.write_file([generic_data_names], out_path)
data_utilities.write_file([all_unique_features], lookup_out_path)

def convert_sequence(data_seq, save_path='../data/generic_data.txt', look_up_save_path = '../data/lookup_data.txt'):
generic_data = data_utilities.read_file(save_path)[0]
lookup = data_utilities.read_file(look_up_save_path)[0]

all_converted_seq = []
for i in range(len(data_seq)):
each_converted_seq = []
for j in data_seq[i]:
index = np.where(lookup == j)[0][0]
each_converted_seq.append(generic_data[index])

all_converted_seq.append(np.array(each_converted_seq))

return all_converted_seq




11 changes: 9 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import artificial_set_data_generator as dg
from features import feature
from data import data_utilities
from data import data_utilities, data_converter
from imbalance import size
import numpy as np

Expand All @@ -16,12 +16,19 @@
DIMENSION = 200
DISTANCE_THRESHOLD = 0.85
SIZE_OF_SET = (4,20)
ALL_FEATURE_FILE_PATH = '../data/50000.txt'
ALL_FEATURE_FILE_PATH = '../data/50000_range.txt'
GT_REPRESENTATIVE_FILE_PATH = '../data/1000N_6K_gt_representative.txt'
CONVERT_TO_GENERIC_NAME = True

if CONVERT_TO_GENERIC_NAME:
data_converter.map_original_to_generic_name(ALL_FEATURE_FILE_PATH)

# Read ground truth representative
if GT_REPRESENTATIVE_FILE_PATH != '':
gt_representative = data_utilities.read_file(GT_REPRESENTATIVE_FILE_PATH)

if CONVERT_TO_GENERIC_NAME:
gt_representative = data_converter.convert_sequence(gt_representative, '../data/generic_data.txt', '../data/lookup_data.txt')
else:
gt_representative = []

Expand Down