|
|
|
"""
|
|
|
|
(c) 2018 - 2021, Vanderbilt University Medical Center
|
|
|
|
Steve L. Nyemba, steve.l.nyemba@vumc.org
|
|
|
|
|
|
|
|
This file is designed to handle preconditions for a generative adversarial network:
|
|
|
|
- The file will read/get data from a source specified by transport (or data-frame)
|
|
|
|
- The class will convert the data to a binary vector
|
|
|
|
- The class will also help rebuild the data from a binary matrix.
|
|
|
|
Usage :
|
|
|
|
|
|
|
|
"""
|
|
|
|
import transport
|
|
|
|
import json
|
|
|
|
import pandas as pd
|
|
|
|
import numpy as np
|
|
|
|
def __init__(self,**_args):
|
|
|
|
This function will initialize the class on the basis of a data-store and optionally pre-defined columns to be used to be synthesized
|
|
|
|
:param store data-store configuration
|
|
|
|
:param columns list of columns to be
|
|
|
|
"""
|
|
|
|
|
|
|
|
if 'columns' not in _args :
|
|
|
|
self._initcols(data=self.df)
|
|
|
|
else:
|
|
|
|
self._initcols(data=self.df,columns=_args['columns'])
|
|
|
|
|
|
|
|
pass
|
|
|
|
# MIN_SPACE_SIZE = 2
|
|
|
|
# if not _column :
|
|
|
|
# _matrix = matrix[:,_beg:_end] #-- The understanding is that _end is not included
|
|
|
|
# else:
|
|
|
|
# _matrix = matrix
|
|
|
|
_matrix = matrix[:,_beg:_end]
|
|
|
|
#
|
|
|
|
# vectorize the matrix to replace the bits by their actual values (accounting for the data-types)
|
|
|
|
# @TODO: Find ways to do this on a GPU (for big data) or across threads
|
|
|
|
#
|
|
|
|
row_count = _matrix.shape[0]
|
|
|
|
# r[key] = [columns[np.where(row == 1) [0][0] ] for row in _matrix[:,_beg:_end]]
|
|
|
|
|
|
|
|
r[key] = [columns[np.where(row==1)[0][0]] if np.where(row==1)[0].size > 0 else '' for row in _matrix]
|
|
|
|
|
|
|
|
# x = _matrix.apply(lambda row: _values[row.values == 1 ].tolist()[0] if row.values.sum() > 0 else None, axis=1).tolist()
|