forked from atulsinha007/Domain-adaptation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataset2_dataf.py
118 lines (99 loc) · 3.52 KB
/
dataset2_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
import os
import pandas as pd
import random
import numpy as np
import pickle
rng = random
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()