text stringlengths 1 93.6k |
|---|
X_int_t = [0]*group_size
|
y = [0]*group_size
|
start = [0]*group_size
|
end = [0]*group_size
|
for ig in range(group_size):
|
i = file_group[ii] + ig
|
filename_i = d_path + npzfile + "_{0}_processed.npz".format(i)
|
# setup start and end ranges
|
start[ig] = offset_per_file[i]
|
end[ig] = offset_per_file[i + 1]
|
# print(filename_i)
|
# load a group of files
|
with np.load(filename_i) as data:
|
X_cat_t[ig] = np.transpose(data["X_cat"])
|
X_int_t[ig] = np.transpose(data["X_int"])
|
y[ig] = data["y"]
|
# sanity check
|
if total_per_file[i] != len(y[ig]):
|
sys.exit("ERROR: sanity check on number of samples failed")
|
# print("start=" + str(start) + " end=" + str(end)
|
# + " diff=" + str(end[ig]-start[ig]) + "=" + str(total_per_file[i]))
|
for j in range(tot_fea):
|
filename_j = trafile + "_{0}_reordered.npy".format(j)
|
fj = np.load(filename_j, mmap_mode='r+')
|
for ig in range(group_size):
|
if j < tar_fea:
|
fj[indices[start[ig]:end[ig]]] = y[ig]
|
elif tar_fea <= j and j < tad_fea:
|
fj[indices[start[ig]:end[ig]]] = X_int_t[ig][j - tar_fea, :]
|
else:
|
fj[indices[start[ig]:end[ig]]] = X_cat_t[ig][j - tad_fea, :]
|
del fj
|
else:
|
print("Reordered fea files already exist, skipping ...")
|
# check if data already exists
|
recreate_flag = False
|
for i in range(days):
|
filename_i = d_path + npzfile + "_{0}_reordered.npz".format(i)
|
if path.exists(filename_i):
|
print("Using existing " + filename_i)
|
else:
|
recreate_flag = True
|
# split reordered data by files (memmap all reordered files per feature)
|
# on the day boundary del the file object and memmap again
|
if recreate_flag:
|
for ii in range(group_num):
|
# for last may be group_size != group_num, therefore reset it below
|
group_size = file_group[ii + 1] - file_group[ii]
|
X_cat_t= []; X_int_t = []
|
for ig in range(group_size):
|
i = file_group[ii] + ig
|
X_int_t.append(np.zeros((den_fea, total_per_file[i])))
|
X_cat_t.append(np.zeros((spa_fea, total_per_file[i])))
|
y = [0]*group_size
|
start = [0]*group_size
|
end = [0]*group_size
|
for j in range(tot_fea):
|
filename_j = trafile + "_{0}_reordered.npy".format(j)
|
fj = np.load(filename_j, mmap_mode='r')
|
# load a group of files
|
for ig in range(group_size):
|
i = file_group[ii] + ig
|
# setup start and end ranges
|
start[ig] = offset_per_file[i]
|
end[ig] = offset_per_file[i + 1]
|
# load data for the group of files
|
if j < tar_fea:
|
y[ig] = fj[start[ig]:end[ig]]
|
elif tar_fea <= j and j < tad_fea:
|
X_int_t[ig][j - tar_fea, :] = fj[start[ig]:end[ig]]
|
else:
|
X_cat_t[ig][j - tad_fea, :] = fj[start[ig]:end[ig]]
|
del fj
|
for ig in range(group_size):
|
i = file_group[ii] + ig
|
filename_i = d_path + npzfile + "_{0}_reordered.npz".format(i)
|
print("Creating " + filename_i)
|
np.savez_compressed(
|
filename_i,
|
X_cat=np.transpose(X_cat_t[ig]), # transpose of the data
|
X_int=np.transpose(X_int_t[ig]), # transpose of the data
|
y=y[ig],
|
)
|
else:
|
print("Reordered day files already exist, skipping ...")
|
'''
|
'''
|
# Approach 3: group features
|
# check if data already exists
|
group_fea = 5 # e.g. 8, 5 or 4
|
group_num = tot_fea // group_fea
|
if tot_fea % group_fea != 0: # sanity check
|
sys.exit("ERROR: the group_fea must divided tot_fea evenly.")
|
recreate_flag = False
|
for jn in range(group_num):
|
filename_j = trafile + "_{0}_reordered{1}.npy".format(
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.