Skip to content

Commit

Permalink
Merge 2158b75 into d8b175d
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronmartino committed Mar 8, 2019
2 parents d8b175d + 2158b75 commit a93a068
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ __pycache__/
*.py[cod]
*$py.class
*.pyc
*.DS_Store
.DS_Store
*/*.DS_Store

# C extensions
*.so
Expand All @@ -26,6 +29,7 @@ wheels/
*.egg
MANIFEST
*.DS_Store
.DS_Store

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down
12 changes: 9 additions & 3 deletions gemelli/tensor_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def fit_transform(self,table,mapping,IDcol,timecol,
self.min_sample_count = min_sample_count
self.min_feature_count = min_feature_count
self._fit()
return self.T, (self.tensor_columns, self.tensor_index, elf.tensor_time), self.mapping_time
return self.T, (self.tensor_columns, self.tensor_index, self.tensor_time), self.mapping_time

def _fit(self):
"""
Expand Down Expand Up @@ -94,7 +94,7 @@ def _fit(self):
' consider increasing the feature'
' read count cutoff')
# if passed zero check
self.tensor = T
self.T = T
self.mapping_time = mapping_time
self.tensor_columns = table_tmp.columns
self.tensor_index = table_tmp.index
Expand Down Expand Up @@ -136,7 +136,7 @@ def reshape_tensor(table,mapping,timecol,IDcol):

def tensor_rclr(T):
"""
Tensor wrapped for deicode rclr transform
Tensor wrapped for rclr transform
"""

if len(T.shape) != 3:
Expand All @@ -157,8 +157,14 @@ def tensor_rclr(T):
# flatten, transform, and reshape
T_rclr = np.concatenate([T[i,:,:].T
for i in range(T.shape[0])],axis=0)
# add one to zero index (could be any) for fully missing
T_rclr[T_rclr.sum(axis=1)==0,0]+=1
T_rclr[0,T_rclr.sum(axis=0)==0]+=1
# transform flat
T_rclr = rclr().fit_transform(T_rclr)
# re-build tensor
T_rclr = np.dstack([T_rclr[(i-1)*T.shape[-1]:(i)*T.shape[-1]]
for i in range(1,T.shape[0]+1)])
# fill nan with zero
T_rclr[np.isnan(T_rclr)] = 0
return T_rclr

0 comments on commit a93a068

Please sign in to comment.