forked from atulsinha007/Domain-adaptation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataset3_dataf.py
137 lines (117 loc) · 4.24 KB
/
dataset3_dataf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import os
import pandas as pd
import random
import numpy as np
import pickle
rng = random
# to convert .xlsx to feature array for source
'''source_data = pd.read_excel("./dataset_1/source_features.xlsx", header=None)
source_feat_mat = source_data.as_matrix()
assert( source_feat_mat.shape[0] == 200 )
#to read the labels for source
file_ob = open( "./dataset_1/source_output.csv", "rb")
lis = file_ob.readlines()
lis = lis[1:]
assert( len(lis) == 200)
source_label_lis = [item.rstrip().lower().decode("utf-8") for item in lis]
ann = len(lis)
file_ob.close()
#converting label in string to that to corresponding number
sorted_lis = list(set( source_label_lis ))
sorted_lis.sort()
dic = { sorted_lis[i]:i for i in range(len(sorted_lis)) }
print(dic)
source_label_lis_num = [ dic[item] for item in source_label_lis ]'''
pstri = './'
path = 'pickle_jar/'
assert (os.path.isfile(os.path.join(pstri + path, 'src_data.pickle')))
fs = open(pstri + "pickle_jar/src_data.pickle", "rb")
source_feat_mat, source_label_lis_num_arr = pickle.load(fs)
fs.close()
dum_arr = source_label_lis_num_arr.reshape((source_label_lis_num_arr.shape[0], 1))
clumped_arr = np.concatenate((source_feat_mat, dum_arr), axis=1)
numlis = np.arange(clumped_arr.shape[0])
ann = source_feat_mat.shape[0]
print(clumped_arr[:3])
rng.shuffle(numlis)
clumped_arr = clumped_arr[numlis]
clumped_source = clumped_arr[:]
assert (os.path.isfile(os.path.join(pstri + path, 'tar_data.pickle')))
fs = open(pstri + "pickle_jar/tar_data.pickle", "rb")
target_feat_mat, target_label_lis_num_arr = pickle.load(fs)
bann = target_feat_mat.shape[0]
fs.close()
dum_arr = target_label_lis_num_arr.reshape((target_label_lis_num_arr.shape[0], 1))
clumped_arr = np.concatenate((target_feat_mat, dum_arr), axis=1)
# print(dic)
numlis = np.arange(clumped_arr.shape[0])
rng.shuffle(numlis)
clumped_arr = clumped_arr[numlis]
# clumped_arr = clumped_arr[ numlis ]
clumped_target = clumped_arr[:]
# rng.shuffle(pimadata)
def give_source_data():
'''
returns two tuples each tuple has one array as feature set and other as column arrray of numerical labels
this one is for source
'''
aann = ann
# print(aann)
rest_setx = clumped_source[:aann, :-1] # tuple of two shared variable of array
rest_sety = clumped_source[:aann, -1:]
test_setx = clumped_source[aann:, :-1]
test_sety = clumped_source[aann:, -1:]
'''assert( rest_setx.shape == (150,128))
#print(rest_sety.shape)
assert( rest_sety.shape == (150,1))
assert( test_setx.shape == (50,640))
assert( test_sety.shape == (50,1))'''
return ((rest_setx, rest_sety), (test_setx, test_sety))
def give_target_data():
bbann = (bann * 3) // 4
rest_setx = clumped_target[:bbann, :-1]
rest_sety = clumped_target[:bbann, -1:]
test_setx = clumped_target[bbann:, :-1]
test_sety = clumped_target[bbann:, -1:]
# print(test_setx.shape)
# print(test_sety.shape)
'''assert( rest_setx.shape == (37,640))
assert( rest_sety.shape == (37,1))
assert( test_setx.shape == (13,640))
assert( test_sety.shape == (13,1))'''
return ((rest_setx, rest_sety), (test_setx, test_sety))
def give_source_data_just_src():
'''
returns two tuples each tuple has one array as feature set and other as column arrray of numerical labels
this one is for source
'''
aann = ann * 3 // 4
# print(aann)
rest_setx = clumped_source[:aann, :-1] # tuple of two shared variable of array
rest_sety = clumped_source[:aann, -1:]
test_setx = clumped_source[aann:, :-1]
test_sety = clumped_source[aann:, -1:]
'''assert( rest_setx.shape == (150,128))
#print(rest_sety.shape)
assert( rest_sety.shape == (150,1))
assert( test_setx.shape == (50,640))
assert( test_sety.shape == (50,1))'''
return ((rest_setx, rest_sety), (test_setx, test_sety))
def give_target_data_just_src_just_tar():
bbann = 0
rest_setx = clumped_target[:bbann, :-1]
rest_sety = clumped_target[:bbann, -1:]
test_setx = clumped_target[bbann:, :-1]
test_sety = clumped_target[bbann:, -1:]
# print(test_setx.shape)
# print(test_sety.shape)
'''assert( rest_setx.shape == (37,640))
assert( rest_sety.shape == (37,1))
assert( test_setx.shape == (13,640))
assert( test_sety.shape == (13,1))'''
return ((rest_setx, rest_sety), (test_setx, test_sety))
def main():
print(give_source_data()[0][0][:10])
print(give_target_data()[1][0][:10])
if __name__ == "__main__":
main()